Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r66690:fc28fe5c3deb
Date: 2013-08-29 12:48 -0700
http://bitbucket.org/pypy/pypy/changeset/fc28fe5c3deb/
Log: recursive remove of C++ object from python (CINT-only)
diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx
b/pypy/module/cppyy/src/cintcwrapper.cxx
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ b/pypy/module/cppyy/src/cintcwrapper.cxx
@@ -57,6 +57,16 @@
TList* fAllPubMethod; //all public methods (including from
base classes)
};
+// memory regulation (cppyy_recursive_remove is generated a la cpyext capi
calls)
+extern "C" void cppyy_recursive_remove(void*);
+
+class Cppyy_MemoryRegulator : public TObject {
+public:
+ virtual void RecursiveRemove(TObject* object) {
+ cppyy_recursive_remove((void*)object);
+ }
+};
+
} // unnamed namespace
@@ -82,6 +92,8 @@
/* initialization of the ROOT system (debatable ... ) --------------------- */
namespace {
+static Cppyy_MemoryRegulator s_memreg;
+
class TCppyyApplication : public TApplication {
public:
TCppyyApplication(const char* acn, Int_t* argc, char** argv, Bool_t
do_load = kTRUE)
@@ -114,6 +126,9 @@
// enable auto-loader
gInterpreter->EnableAutoLoading();
+
+ // enable memory regulation
+ gROOT->GetListOfCleanups()->Add(&s_memreg);
}
};
diff --git a/pypy/module/cppyy/test/test_cint.py
b/pypy/module/cppyy/test/test_cint.py
--- a/pypy/module/cppyy/test/test_cint.py
+++ b/pypy/module/cppyy/test/test_cint.py
@@ -576,3 +576,17 @@
assert None != l3 # id.
assert l3 != l5
assert l5 != l3
+
+ def test10_recursive_remove(self):
+ """Verify that objects are recursively removed when destroyed"""
+
+ import cppyy
+
+ c = cppyy.gbl.TClass.GetClass("TObject")
+
+ o = cppyy.gbl.TObject()
+ assert o
+
+ o.SetBit(cppyy.gbl.TObject.kMustCleanup)
+ c.Destructor(o)
+ assert not o
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit