Embedding Python - Freeing Python Objects Not Using Py_DECREF

Y

yuri.feldman

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,
 
T

Thomas Heller

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top