problems extending & embedding python

Srivatsan Raghavan vraghavan at cnmnetwork.com
Wed Aug 14 03:44:46 CEST 2002


Hi all , 

i'm having problems extending and embedding python
i wrote an extension module to expose a logging system (written in
C++)
to python  (using boost::python v1) 
and i then wrote a dll for the logging system to dynamically embed a
call to
the python interpeter to have it execute a python file .. 

i would have like to pass a copy of an object (from the dll)  to
python , however
that isn't possible, so i tried to use the hack described on this
page: http://www.boost.org/libs/python/doc/pointers.html (under <b>If
you can't (afford to) copy the referent, or the pointer is
non-const</b> )

but when that python script trys to call back into the dll i get an
access violation, after debugging & analyzing the call stack 
it appears that the python dll has a function pointer that points to
the
middle of nowhere.. 

i'm not sure what's causing this , since if i call the function from
IDLE
i get a return of None (which is what i should get since the
GetCurrentLogEvent returns a pointer to a global object, and since
i've not set that object (from a different dll) the pointer is NULL)

basically it works something like this

i have a test app that sends of an event (links to a dll called
EPBase.dll)
EPBase.dll has a registered list of modules, in this case PythonEP.dll
(and at this point Py_Initialize() is called by DllMain() ) , which
it then calls passing a loads & passes a copy of the Event (by
instantiating a new object of type PythonEndpoint and tell calls that
object's OutputEvent() module)
then the PythonEP module sets the Current LogEvent , then calls
PyRun_SimpleFile(fp , "script.py")

then in script.py , it calls import the Logging module (by loading
Logging_d.dll (the name of the extension module(in debug mode))) and
then calls Logging.GetCurrentLogEvent() , and which point i get an
access violation
here is the msvc call stack (if that helps anyone)  : 

a16400d8()
PyObject_Call(_object * 0x00c8755c, _object * 0x00c87370, _object *
0x00000000) line 1684 + 15 bytes
do_call(_object * 0x00c8755c, _object * * * 0x00a4f9ec, int 0, int 0)
line 3262 + 17 bytes
eval_frame(_frame * 0x00cb2340) line 2028 + 30 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x00c61410, _object * 0x00c8d9b8,
_object * 0x00000000, _object * * 0x00c96778, int 0, _object * *
0x00c96778, int 0, _object * * 0x00000000, int 0, _object *
0x00000000) line 2585 + 9 bytes
fast_function(_object * 0x00cf6038, _object * * * 0x00a4fc18, int 0,
int 0, int 0) line 3164 + 65 bytes
eval_frame(_frame * 0x00c96620) line 2025 + 37 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x00cf6ac0, _object * 0x00c8d9b8,
_object * 0x00c8d9b8, _object * * 0x00000000, int 0, _object * *
0x00000000, int 0, _object * * 0x00000000, int 0, _object *
0x00000000) line 2585 + 9 bytes
PyEval_EvalCode(PyCodeObject * 0x00cf6ac0, _object * 0x00c8d9b8,
_object * 0x00c8d9b8) line 488 + 31 bytes
run_node(_node * 0x00ccddd0, char * 0x00c87909, _object * 0x00c8d9b8,
_object * 0x00c8d9b8, PyCompilerFlags * 0x00000000) line 1079 + 17
bytes
run_err_node(_node * 0x00ccddd0, char * 0x00c87909, _object *
0x00c8d9b8, _object * 0x00c8d9b8, PyCompilerFlags * 0x00000000) line
1066 + 25 bytes
PyRun_FileExFlags(_iobuf * 0x102618a8, char * 0x00c87909, int 257,
_object * 0x00c8d9b8, _object * 0x00c8d9b8, int 0, PyCompilerFlags *
0x00000000) line 1057 + 25 bytes
PyRun_SimpleFileExFlags(_iobuf * 0x102618a8, char * 0x00c87909, int 0,
PyCompilerFlags * 0x00000000) line 686 + 34 bytes
PyRun_SimpleFileEx(_iobuf * 0x102618a8, char * 0x00c87909, int 0) line
657 + 19 bytes
PyRun_SimpleFile(_iobuf * 0x102618a8, char * 0x00c87909) line 604 + 15
bytes
Logging::PythonLogEndpoint::OutputEvent(Logging::LogEvent & {...})
line 117 + 34 bytes
Logging::DistributeLogEvent(const Logging::LogEvent & {...}) line 183
+ 17 bytes
Logging::LogQueue::ExtractionThread(void * 0x00000000) line 156 + 17
bytes
KERNEL32! 77e96523()

--vat
vraghavan at cnmnetwork.com



More information about the Python-list mailing list