List Info

Thread: Problems with an instance of a Python class




Problems with an instance of a Python class
country flaguser name
Finland
2007-03-20 06:59:03
I am having troubles using an instance of a Python
class. The offending code is below. I can create
the instance and call its method without problems, but
when the scope ends, I get a segmentation fault with
the stack trace

#0 PyErr_Fetch
#1 PyInstance_NewRaw
#2 ~object_base
#3 ~object

If I comment out the instance creation and calling
the method of the instance, there are no problems, so
it seems that the problem is in instance's destructor.

I'm assuming it is something simple that I am overlooking,
which causes reference counting to go haywire.

Any ideas?

	Pertti

-------------------------------------------
{
     Py_Initialize();

     // Run Python file defining PythonSchedulerClass
     FILE *fp = fopen(pythonFile_.c_str(), "r");
     PyRun_SimpleFileEx(fp, pythonFile_.c_str(), 1);

     // Retrieve the main module
     object main_module((
        handle<>(boost::python::borrowed(
                   
PyImport_AddModule("__main__")))));

     // Get the class
     object
passClass(main_module.attr("PythonSchedulerPass"))
;

     // Create an instance
     object instance(passClass());

     // Call a method of the obejct
     needsTarget_ = call_method<bool>(instance.ptr(),
"needsTarget");

     Py_Finalize();

     // Crash here in ~object()
}
--------------------------------------------
_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )