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

CPointer instances created via a native function call that takes a callback argument and has its result assigned to a scalar variable don't have DESTROY called #4452

Open
p6rt opened this issue Aug 2, 2015 · 2 comments

Comments

@p6rt
Copy link

p6rt commented Aug 2, 2015

Migrated from rt.perl.org#125738 (status was 'new')

Searchable as RT125738$

@p6rt
Copy link
Author

p6rt commented Aug 2, 2015

From @hoelzro

See the attached file.

Let's say I have a native function that returns a pointer to a type and takes a callback​:

  my_struct *create_my_struct(size_t size, void (*error_callback)(error_t *error));

...and I call that function via NativeCall, and assign the result to a scalar variable​:

  class MyStruct is repr('CPointer') {
  my sub create_my_struct(int $size, &error-callback (Error)) returns MyStruct is native('mystructlib') { * }

  method new() {
  my $err;
  my $result = create_my_struct(8, -> Error $e { $err = $e.copy });
  $err.throw if $err;
  $result
  }
  }

In that case, the DESTROY finalizer on that pointer is never called. If I assign to a backslash variable​:

  my \result = create_my_struct(8, > Error $e { $err = $e.copy });

...DESTROY *is* called.

@p6rt
Copy link
Author

p6rt commented Aug 2, 2015

@p6rt p6rt added the NativeCall label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant