We don't bite newbies here... much | |
PerlMonks |
perl embedded in C++: how to undefine perl objects that are blessed references to C++ objects when the C++ object destructsby kingkongrevenge (Scribe) |
on Sep 19, 2009 at 15:20 UTC ( [id://796297]=perlquestion: print w/replies, xml ) | Need Help?? |
kingkongrevenge has asked for the wisdom of the Perl Monks concerning the following question:
I have perl embedded in a C++ program. Various C++ objects are wrapped up with XS interfaces. The objects live on the C++ side of things; the perl scripting bits just need to talk to the C++ objects for small time slices. Perl functions get called with the relevant objects as arguments. This all works fine.
My problem is how to invalidate (set to undef) all scalar references to a C++ object when the object is destroyed on the C++ side. $some_cpp_obj->do_it; will crash with memory access violations if the relevant object has been destroyed. I want the C++ destructor to reach into the perl interpreter and set $some_cpp_obj to undef. Any copies of $some_cpp_obj also need to be undefined. I guess conceptually I want something like *sv = PL_sv_undef, so all SvRefs to that piece of memory now point to undef. Except I think that would crash the application. My best guess is I actually need to scan the whole interpreter for SvRefs for the now invalid pointer.
I guess another way to represent the problem in pure perl is thusly.
Back to
Seekers of Perl Wisdom
|
|