471,119 Members | 1,262 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

malloc'ed PyTypeObject


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

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
0 1153

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Woodster | last post: by
reply views Thread by Simon Nickerson | last post: by
14 posts views Thread by dam_fool_2003 | last post: by
11 posts views Thread by Sushil | last post: by
33 posts views Thread by apropo | last post: by
5 posts views Thread by Bidule | last post: by
2 posts views Thread by Khookie | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.