I do have C++ object typemapped into perl class. Then I have two functions which creates and destroys that object

create_object ($obj);
destroy_object ($obj);

first function is easy, I create the object like:
c_obj *x=new c_obj;
sv_setref_pv( ST(0)), CLASS, (void*)x );
SvSETMAGIC(ST(0));

but the destroy_function has to call delete on the object (sometime, in another thread, I can't stop that), but I don't know how to de-mortalize' variable, in order to stop perl to call destructor on it again. One solution is to create copy of the object and free that copy, but I would like to do it without copying.

If anyone cares, I found different, imho better and easier solution.
Just whenever new object is created, I store to map it's pointer. When object is destroyed, I delete his pointer from the map. Then I overloaded the DESTROY method, so that it first check if the pointer is in the map, and call actual delete(obj) only if it is found.


Why simple solution is found as the last one usually ? :)

Reply via email to