in reply to Re^3: perl embedded in C++: how to undefine perl objects that are blessed references to C++ objects when the C++ object destructs
in thread perl embedded in C++: how to undefine perl objects that are blessed references to C++ objects when the C++ object destructs
ThePerlClass=(BlessedSvRef) -> UnblessedSvRef -> theCppObjPointer
I only had to add the extra layer of indirection in the typemap and everything continued to work.
When the C++ destructor for the relevant object is called, it sets the one and only copy of UnblessedSvRef to null. Any copies of the perl object floating around now just point to undef, which fails with a fathomable explanation (and a catchable exception) rather than catastrophically. When the last BlessedSvRef goes out of scope the ref count of UnblessedSvRef goes to zero and it's destroyed.
I overloaded the bool operator to test for undef in UnblessedSvRef.
I also overloaded the dereference operator so it's impossible for the user to get to the underlying UnblessedSvRef and store a pointer that can end up invalid.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: perl embedded in C++: how to undefine perl objects that are blessed references to C++ objects when the C++ object destructs
by BrowserUk (Patriarch) on Sep 21, 2009 at 22:39 UTC | |
by kingkongrevenge (Scribe) on Sep 21, 2009 at 23:58 UTC |