[C++-sig] Embedding Python - data exchange && no Boost

Thomas Hrabe thrabe at burnham.org
Thu May 8 01:22:45 CEST 2008


Meanwhile, I have made up another possible approach to my problem.
Is there a attribute in the PyObject structure storing the name of the PyObject in the interpreter.

If we have a variable in the Python Interpreter for instance:

a = 1

is there a name attribute in the PyObject representation stating 

(object.name == "a") == true    ?

Could it possible to set such a name of a custom object and load it into the highest level of the python namespace?

C example code:

PyObject a = PyObj_FromLong(1);
a.name = "a";
PyObj_LoadToIntepreter(a);

So that a is available in the embedded python terminal afterwards?

Best,
Thomas
  

-----Original Message-----
From: c++-sig-bounces at python.org on behalf of Thomas Hrabe
Sent: Wed 5/7/2008 1:48 PM
To: c++-sig at python.org
Subject: [C++-sig] Embedding Python - data exchange && no Boost
 
Hi all,

I am writing an embedded python application in C/C++ with the following features:

1. The user is able to execute python commands (works fine with PyRun_SimpleString)
2. I want the user to be able to load C objects from C into the current python interpreter, so that the user is able to manipulate the python copies with python tools -> no go.

I first wrote a function within a module which is loaded after Py_Initialize(), returning an PyObject.
I thought it might be possible to share a static variable between the module and the C application, where the module function could access the static variable, convert it to a PyObject and provide it to the interpreter.

Think of this procedure in terms of python calls:

import PA; //imports the module in the embedded interpreter
a = PA.set() ; //access the static object, create a PyObject, return it as a

The later python calls should be able to manipulate a and then return it back to C by setting the static object again like
PA.get(a) ; //or similar

However, it turned out that the static object in the interpreter differs from the one in the C program -> other adresses in memory, so that I can not share the memory space.
Does anybody know of a solution for such a problem? Any tips?

I do not use Boost because the program is supposed to process numpy's nd-arrays and, furthermore, must remain independent of additional libraries such as Boost. I'd use it otherwise...

Thank you in advance for your help,
Thomas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080507/eb6fbe06/attachment.htm>


More information about the Cplusplus-sig mailing list