wrapit icon indicating copy to clipboard operation
wrapit copied to clipboard

Need to wrap object destructors

Open peremato opened this issue 1 year ago • 1 comments

In same C++ libraries the API may return a pointer to an object for which the user has the responsibility to delete it. This is not possible with the generated wrapper since the destructor is not wrapped. This can be easily done by adding a method delete for each wrapped class.

 mod.method("delete", [] (MyClass* ptr) { delete ptr; } );

peremato avatar May 23 '24 14:05 peremato

Meanwhile I have added by hand the destructors I needed. But it would be nice if this could be added in subsequent releases.

peremato avatar May 29 '24 07:05 peremato

@grasph Any progress on this one?

peremato avatar Oct 31 '24 12:10 peremato

CxxWrap already exports as CxxWrap.CxxWrapCore.__delete() a finalize() c++ method that calls delete().

It defines the method CxxWrap.CxxWrapCore.delete(), that will also set the pointer of the Julia object to zero.

I expect the CxxWrap.CxxWrapCore.delete(), method should be used and there is no need to generate a new one. You may want to wrap it in your module, to list delete under the methods of the module for classes which are expected to be explicitly destructed.

grasph avatar Oct 31 '24 15:10 grasph

Yes you are right. I can use CxxWrap.CxxWrapCore.__delete(), not CxxWrap.CxxWrapCore.delete() since my object is already a C++ pointer. Closing the issue.

peremato avatar Oct 31 '24 15:10 peremato

Not needed

peremato avatar Oct 31 '24 15:10 peremato

Not needed

peremato avatar Oct 31 '24 15:10 peremato