364,111 Members | 2059 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

malloc'ed PyTypeObject

Gabriel de Dietrich
P: n/a
Gabriel de Dietrich
Hi,

I'm doing my first project on embedding and then extending Python in
an application. The idea is to import a set of C++ plug-ins into Python
and then be able to run a script that uses these plug-ins. Please note
that what I'm importing into Python are the plug-in classes in order to
be able to instanciate as many objects as needed.

As usual, all the plug-ins derive from a base class. But two
important things differ for each plug-in, its name and a set of
parameters.

For instance, the C++ class

class SNRFilter : public BaseFilter
{
...
};

can be instanciated in a Python script as

snr = SNRFilter()

(This is a quite simplified example as there is also a quite trivial
SNRFilterClass class deriving fron BaseFilterClass. But those are
implementation details).

So, everything works OK, but there will probably be a memory issue.
Each time I add a plug-in class into Python, I malloc a PyTypeObject
and copy its contents from a template static PyTypeObject. Then I
malloc and assign its tp_name and its tp_getset (array of PyGetSetDef).

Now the question is, how can I be sure that all this memory will be
properly free'd after calling Py_Finalize()? Is it enough to add
Py_TPFLAGS_HEAPTYPE? Can I safely free tp_getset after calling
PyType_Ready()? What will the weather be for the next week-end?

Thank you for reading.

--
Gabriel de Dietrich

Apr 6 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Help answer this question



Didn't find the answer to your Python question?

You can also browse similar questions: Python