Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Embedding Python - Freeing Python Objects Not Using Py_DECREF

Reply
Thread Tools

Embedding Python - Freeing Python Objects Not Using Py_DECREF

 
 
yuri.feldman@gmail.com
Guest
Posts: n/a
 
      01-17-2008
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,
 
Reply With Quote
 
 
 
 
Thomas Heller
Guest
Posts: n/a
 
      01-17-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Py_XDECREF/Py_DECREF evaluating its argument more than once Chris Angelico Python 0 05-06-2011 12:51 AM
PyCFunction_New(): to Py_DECREF() or not to Py_DECREF() Ecir Hana Python 2 12-27-2009 03:41 AM
Py_DECREF/Py_INCREF as Functions? Kevin D. Smith Python 1 03-31-2007 05:16 AM
Py_DECREF after an exception Hrvoje =?UTF-8?Q?Nik=C5=A1i=C4=87?= Python 0 01-23-2007 03:36 PM
Py_DECREF Question: Jeremy Moles Python 2 08-15-2005 09:08 PM



Advertisments