Advertisement

Python embedding

Started by February 01, 2005 01:40 PM
-1 comments, last by pnroach 19 years, 7 months ago
I am trying to embed Python into my C++ app. For some reason it behaves very odd. I did get expected results by putting the code altogether Py_Initialize(); ... pModule = PyImport_Import(pName); ... Py_DECREF(pModule); Py_Finalize(); But when i tried to put the PyImport_Import thingy into a class method the whole thing gets messed up. i made sure that the scope consideration for object is met so i am pretty sure that pModule class member doesn't get deleted before decreasing its reference counter. void some_obj::Init() { pModule = PyImport_Import(pName); } ... void some_obj::Clear() { Py_DECREF(pModule); // also tried Py_XDECREF } ... some_obj obj; ... Py_Initialize(); obj.Init(); obj.Clear(); Py_Finalize(); //here the access violation occurs And the funniest thing is that when i run the built exe file no violation occurs and the program exits normally. any ideas?

This topic is closed to new replies.

Advertisement