Embedding Python - Freeing Python Objects Not Using Py_DECREF

Discussion in 'Python' started by yuri.feldman@gmail.com, Jan 17, 2008.

  1. Guest

    Hello,

    I'm embedding Python interpreter in a Win32 console application. I use
    C++.

    I would like to use the WinAPI LoadLibrary function to load the python
    dll at runtime (followed by GetProcAddress calls), so that I have to
    make no assumptions about the location of the dll.

    However I can't use the macro Py_DECREF if I load the dll this way.

    Is there a way to properly free python objects (specifically -
    dictionaries created by PyDict_New() and the object returned by
    PyRun_String()) not using Py_DECREF?

    Alternatively, is there a way to include the python header - to make
    the macro Py_DECREF available, but to be able to locate the python dll
    whenever python is installed?

    (The problem is that python may be installed anywhere, and the python
    dll does not always appear in system folders - sometimes it is in the
    python installation directory, thus it is unclear which targets to
    specify to the linker to search for the dll).

    I'd appreciate any help.
    Thanks in advance,
     
    , Jan 17, 2008
    #1
    1. Advertising

  2. schrieb:
    > Hello,
    >
    > I'm embedding Python interpreter in a Win32 console application. I use
    > C++.
    >
    > I would like to use the WinAPI LoadLibrary function to load the python
    > dll at runtime (followed by GetProcAddress calls), so that I have to
    > make no assumptions about the location of the dll.
    >
    > However I can't use the macro Py_DECREF if I load the dll this way.
    >
    > Is there a way to properly free python objects (specifically -
    > dictionaries created by PyDict_New() and the object returned by
    > PyRun_String()) not using Py_DECREF?
    >
    > Alternatively, is there a way to include the python header - to make
    > the macro Py_DECREF available, but to be able to locate the python dll
    > whenever python is installed?
    >
    > (The problem is that python may be installed anywhere, and the python
    > dll does not always appear in system folders - sometimes it is in the
    > python installation directory, thus it is unclear which targets to
    > specify to the linker to search for the dll).


    Use the Py_DecRef function, which was added for exactly this purpose.

    Thomas
     
    Thomas Heller, Jan 17, 2008
    #2
    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. Jeremy Moles

    Py_DECREF Question:

    Jeremy Moles, Aug 15, 2005, in forum: Python
    Replies:
    2
    Views:
    424
    Raymond Hettinger
    Aug 15, 2005
  2. Hrvoje =?UTF-8?Q?Nik=C5=A1i=C4=87?=

    Py_DECREF after an exception

    Hrvoje =?UTF-8?Q?Nik=C5=A1i=C4=87?=, Jan 23, 2007, in forum: Python
    Replies:
    0
    Views:
    319
    Hrvoje =?UTF-8?Q?Nik=C5=A1i=C4=87?=
    Jan 23, 2007
  3. Kevin D. Smith

    Py_DECREF/Py_INCREF as Functions?

    Kevin D. Smith, Mar 31, 2007, in forum: Python
    Replies:
    1
    Views:
    339
    Gabriel Genellina
    Mar 31, 2007
  4. Ecir Hana
    Replies:
    2
    Views:
    591
    Ecir Hana
    Dec 27, 2009
  5. Chris Angelico
    Replies:
    0
    Views:
    318
    Chris Angelico
    May 6, 2011
Loading...

Share This Page