Creating C++ objects from PyRoot/GaudiPython vs. from C++

From: Brett Viren <bv_at_bnl.gov>
Date: Fri, 25 Feb 2011 10:13:02 -0800


I'm trying to understand a problem with creating C++ objects from Python vs. creating them from C++ and accessing them from Python.

I'm using objects with Reflex dictionaries (defined with GaudiObjDesc). On the C++ side, they are stored in a Gaudi event store as well as other locations. They are long-lived and are memory managed via reference counting.

In Python I can access these objects created by C++ with no problem.

What I now try to do is create them from the Python side. I can do this via something like:

    from GaudiPython import gbl
    ud = gbl.DayaBay.UserDataHeader()

Here DayaBay is a namespace and UserDataHeader is the class (subclass of GaudiKernel's DataObject). I get a valid object and can add it to our event store.

The problem is that soon after the Python variable ("ud" in this example) goes out of scope the job dies with a SegV.

What I suspect is that when I create a C++ object from Python, Python marks it as owned-by-Python and takes over explicit memory management which defeats the reference-counting that is supposed to be done on the C++ side.

If this is the case, is there some way to tell Python not to memory manage the underlying object (or better, to participate in the C++-side reference counting)?

Thanks for any ideas,
-Brett.

Received on Fri Feb 25 2011 - 19:13:10 CET

This archive was generated by hypermail 2.2.0 : Fri Feb 25 2011 - 23:50:01 CET