[PyKDE] SIP generated code SEGV
Bjorn Pettersen
BPettersen at narex.com
Fri Aug 2 22:58:01 BST 2002
I've got the following simple app, embedding Python. NDate is a trivial
class holding three values -- it does have a __repr__ method defined,
but I don't think that is relevant(?):
#include <Python.h>
#include <sip.h>
extern "C" SIP_IMPORT void initlibnrxc();
extern "C" SIP_IMPORT void initlibsip();
void main() {
Py_Initialize();
initlibsip();
initlibnrxc();
PyObject* mainmod = PyImport_AddModule("__main__");
Py_INCREF(mainmod);
PyObject* ns = PyModule_GetDict(mainmod);
Py_INCREF(ns);
PyRun_String("import nrx\n", Py_file_input, ns, ns);
PyRun_String("x = nrx.NDate(1970,5,2)\n", Py_file_input, ns,
ns);
/**/ PyRun_String("x = nrx.NDate(1970,5,2)\n", Py_file_input, ns,
ns);
Py_DECREF(ns);
Py_DECREF(mainmod);
Py_Finalize();
}
In debug builds, it's failing (asserts) on the line marked /**/. From
the stacktrace (see below), it looks like it's failing in _Py_Dealloc as
part of decrementing the reference count of x and disposing of the
object. It works without problems in release builds (checked by
inspecting 'x'). The assertion it is failing is (from MS's dbgheap.c):
/*
* If this ASSERT fails, a bad pointer has been passed in. It
may be
* totally bogus, or it may have been allocated from another
heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
It almost seems like the sip NDate class was allocated on the .dll's
heap and then deallocated on the main program's heap, but this doesn't
make sense since all access to the class is through python22_d.dll (and
deleting the wrapped NDate object proceeds without any
warning/assertion).
I'm using sip 3.2.3 which has been modified to put "try {} catch (...)
{}" around most method calls and set a Python exception and return NULL
if it enters the catch block. No catch blocks are invoked in this
example...
Any insight would be greatly apppreciated.
-- bjorn
Bjorn Pettersen
NAREX Inc.
303.526.4000 ext. 312
303.526.5130 fax
www.narex.com
NTDLL! 77f7f570()
NTDLL! 77f67dc6()
KERNEL32! 77e6c936()
_CrtIsValidHeapPointer(const void * 0x02cd1f78) line 1697
_free_dbg_lk(void * 0x02cd1f78, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x02cd1f78, int 1) line 1001 + 13 bytes
free(void * 0x02cd1f78) line 956 + 11 bytes
_PyObject_Del(_object * 0x02cd1f78) line 143 + 10 bytes
sipDeleteThis(_sipThisType * 0x02cd1f78) line 2277 + 12 bytes
sipDealloc_NDate(_sipThisType * 0x02cd1f78) line 459 + 12 bytes
_Py_Dealloc(_object * 0x02cd1f78) line 1826 + 7 bytes
sipDtor(_object * 0x00000000, _object * 0x02ecf700) line 1243 + 65 bytes
PyCFunction_Call(_object * 0x02f32b58, _object * 0x02ecf700, _object *
0x00000000) line 80 + 11 bytes
PyObject_Call(_object * 0x02f32b58, _object * 0x02ecf700, _object *
0x00000000) line 1684 + 15 bytes
instancemethod_call(_object * 0x02f32b58, _object * 0x02ecf700, _object
* 0x00000000) line 2276 + 17 bytes
PyObject_Call(_object * 0x02f00348, _object * 0x02cbb9e0, _object *
0x00000000) line 1684 + 15 bytes
PyEval_CallObjectWithKeywords(_object * 0x02f00348, _object *
0x02cbb9e0, _object * 0x00000000) line 3049 + 17 bytes
instance_dealloc(PyInstanceObject * 0x02f40988) line 616 + 13 bytes
_Py_Dealloc(_object * 0x02f40988) line 1826 + 7 bytes
insertdict(_dictobject * 0x02ee2410, _object * 0x02fdd610, long
-1819822983, _object * 0x02efe460) line 373 + 59 bytes
PyDict_SetItem(_object * 0x02ee2410, _object * 0x02fdd610, _object *
0x02efe460) line 541 + 21 bytes
eval_frame(_frame * 0x02eeb388) line 1538 + 17 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x02f71f18, _object * 0x02ee2410,
_object * 0x02ee2410, _object * * 0x00000000, int 0, _object * *
0x00000000, int 0, _object * * 0x00000000, int 0, _object * 0x00000000)
line 2585 + 9 bytes
PyEval_EvalCode(PyCodeObject * 0x02f71f18, _object * 0x02ee2410, _object
* 0x02ee2410) line 488 + 31 bytes
run_node(_node * 0x02efe450, char * 0x1e17c2b4, _object * 0x02ee2410,
_object * 0x02ee2410, PyCompilerFlags * 0x00000000) line 1079 + 17 bytes
run_err_node(_node * 0x02efe450, char * 0x1e17c2b4, _object *
0x02ee2410, _object * 0x02ee2410, PyCompilerFlags * 0x00000000) line
1066 + 25 bytes
PyRun_String(char * 0x00422074 `string', int 257, _object * 0x02ee2410,
_object * 0x02ee2410) line 1009 + 37 bytes
main() line 20 + 26 bytes
mainCRTStartup() line 206 + 25 bytes
KERNEL32! 77e7eb69()
More information about the PyQt
mailing list