malloc'ed PyTypeObject

Discussion in 'Python' started by Gabriel de Dietrich, Apr 6, 2006.

  1. 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
    Gabriel de Dietrich, Apr 6, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    13
    Views:
    699
  2. ravi
    Replies:
    0
    Views:
    450
  3. Peter
    Replies:
    34
    Views:
    1,937
    Richard Tobin
    Oct 22, 2004
  4. chris
    Replies:
    1
    Views:
    654
    Hrvoje Niksic
    Aug 25, 2008
  5. Aaron Brady

    PyTypeObject subclass

    Aaron Brady, Feb 18, 2009, in forum: Python
    Replies:
    0
    Views:
    266
    Aaron Brady
    Feb 18, 2009
Loading...

Share This Page