Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ck_create does not call pre-constructor #350

Open
nshaheed opened this issue Aug 20, 2023 · 0 comments
Open

ck_create does not call pre-constructor #350

nshaheed opened this issue Aug 20, 2023 · 0 comments
Labels

Comments

@nshaheed
Copy link
Contributor

When calling API->object_create() in a chugin, it instantiates the object, but does not call the pre-constructor. This means that chugin_ctor is not called when objects are created this way.

An example:

  Chuck_DL_Api::Object obj = API->object->create(API, SHRED, API->object->get_type(API, SHRED, "Hydra"));
  // Need to be cast from Object to Chuck_Object in a separate line for some reason...
  Chuck_Object * object = (Chuck_Object *) obj;
  Hydra * obj_class = (Hydra *) OBJ_MEMBER_INT(object, hydra_data_offset);

  // because hydra_ctor was never called, this Hydra object was never initializes, this segfaults.
  obj_class->init(config_path, config_name);

If you +d on declaring an object inside chuck itself you get this vm code:

[hydra_test.ck]: Hydra h;
[hydra_test.ck]: [0] Chuck_Instr_Instantiate_Object( Hydra )
[hydra_test.ck]: [1] Chuck_Instr_Pre_Constructor(  )
[hydra_test.ck]: [2] Chuck_Instr_Pre_Constructor(  )
[hydra_test.ck]: [3] Chuck_Instr_Alloc_Word( 0 )
[hydra_test.ck]: [4] Chuck_Instr_Assign_Object(  )
[hydra_test.ck]: [5] Chuck_Instr_Reg_Pop_Word4( 2 )

Since the code emitter doesn't come into play inside chugin code, these steps need to be done inside ck_create.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant