|
From: David B. <dav...@us...> - 2005-01-21 07:23:17
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv581 Modified Files: Tag: sidewinder-branch langpython.c Log Message: fixed serious bug in handling InternalValue and ExternalValue objects. The problem was this -- I was not using copyvaluerecord, I was just assigning from one value record to another. Frontier was reclaiming them and using them for other values without me knowing, and I was causing random parts of the Frontier database to be modified. After restoring my root file, I was able to locate and fix this particularly scary bug. Index: langpython.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langpython.c,v retrieving revision 1.2.4.37 retrieving revision 1.2.4.38 diff -C2 -d -r1.2.4.37 -r1.2.4.38 *** langpython.c 19 Jan 2005 07:59:46 -0000 1.2.4.37 --- langpython.c 21 Jan 2005 07:23:07 -0000 1.2.4.38 *************** *** 208,211 **** --- 208,212 ---- PyObject * (*ptr_PyErr_Occurred) (void); void (*ptr_PyErr_Print) (void); + void (*ptr_PyErr_Fetch) (PyObject **, PyObject **, PyObject **); void (*ptr_PyErr_SetString) (PyObject *, const char *); void (*ptr_PyErr_SetInterrupt) (void); *************** *** 324,327 **** --- 325,329 ---- #define PyErr_Occurred (*py.ptr_PyErr_Occurred) #define PyErr_Print (*py.ptr_PyErr_Print) + #define PyErr_Fetch (*py.ptr_PyErr_Fetch) #define PyErr_SetString (*py.ptr_PyErr_SetString) #define PyErr_SetInterrupt (*py.ptr_PyErr_SetInterrupt) *************** *** 477,480 **** --- 479,483 ---- fl = fl && IMPORTSYMBOL (hm, PyErr_Occurred); fl = fl && IMPORTSYMBOL (hm, PyErr_Print); + fl = fl && IMPORTSYMBOL (hm, PyErr_Fetch); fl = fl && IMPORTSYMBOL (hm, PyErr_SetString); fl = fl && IMPORTSYMBOL (hm, PyErr_SetInterrupt); *************** *** 1968,1972 **** class = PyObject_GetAttrString(frontierModule, "Script"); obj = PyObject_New(frontier_ScriptObject, (PyTypeObject *)class); ! obj->value = *tvr; obj->parent = parent; copystring(loc, obj->name); --- 1971,1978 ---- class = PyObject_GetAttrString(frontierModule, "Script"); obj = PyObject_New(frontier_ScriptObject, (PyTypeObject *)class); ! ! copyvaluerecord(*tvr, &(obj->value)); ! exemptfromtmpstack(&(obj->value)); ! obj->parent = parent; copystring(loc, obj->name); *************** *** 1982,1987 **** class = PyObject_GetAttrString(frontierModule, "InternalValue"); obj = PyObject_New(frontier_InternalValue, (PyTypeObject *)class); obj->vartype = vt; - obj->value = *tvr; return (PyObject *)obj; --- 1988,1996 ---- class = PyObject_GetAttrString(frontierModule, "InternalValue"); obj = PyObject_New(frontier_InternalValue, (PyTypeObject *)class); + + copyvaluerecord(*tvr, &(obj->value)); + exemptfromtmpstack(&(obj->value)); + obj->vartype = vt; return (PyObject *)obj; *************** *** 1995,2000 **** class = PyObject_GetAttrString(frontierModule, "ExternalValue"); obj = PyObject_New(frontier_ExternalValue, (PyTypeObject *)class); obj->extvartype = ei; - obj->value = *tvr; return (PyObject *)obj; --- 2004,2012 ---- class = PyObject_GetAttrString(frontierModule, "ExternalValue"); obj = PyObject_New(frontier_ExternalValue, (PyTypeObject *)class); + + copyvaluerecord(*tvr, &(obj->value)); + exemptfromtmpstack(&(obj->value)); + obj->extvartype = ei; return (PyObject *)obj; *************** *** 2211,2214 **** --- 2223,2252 ---- char *defArgv[] = {""}; + static void handlePythonError() { + bigstring errtyp; + bigstring errtxt; + bigstring errmsg; + PyObject *ptype; + PyObject *pvalue; + PyObject *ptraceback; + + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + + copyctopstring("", errmsg); + copyctopstring(PyString_AsString(PyObject_Str(ptype)), errtyp); + copyctopstring(PyString_AsString(PyObject_Str(pvalue)), errtxt); + pushstring(errtyp, errmsg); + pushstring("\p: ", errmsg); + pushstring(errtxt, errmsg); + + Py_DECREF(ptype); + Py_DECREF(pvalue); + Py_DECREF(ptraceback); + + langerrormessage(errmsg); + + PyErr_Clear(); + } + boolean callpythonscript(tyvaluerecord code, hdltreenode hparam1, bigstring bsname, tyvaluerecord *vreturned, boolean runbutton) { PyObject *globals; *************** *** 2255,2260 **** // handle errors if (PyErr_Occurred()) { ! PyErr_Print(); ! PyErr_Clear(); releasepythonlock(); return false; --- 2293,2297 ---- // handle errors if (PyErr_Occurred()) { ! handlePythonError(); releasepythonlock(); return false; *************** *** 2288,2293 **** // handle errors if (PyErr_Occurred()) { ! PyErr_Print(); ! PyErr_Clear(); releasepythonlock(); return false; --- 2325,2329 ---- // handle errors if (PyErr_Occurred()) { ! handlePythonError(); releasepythonlock(); return false; |