diff options
author | Michel Selten <michel@mselten.demon.nl> | 2003-06-22 22:34:36 +0400 |
---|---|---|
committer | Michel Selten <michel@mselten.demon.nl> | 2003-06-22 22:34:36 +0400 |
commit | d253eb4b757ac5f01c01201815cb3db0c7308d33 (patch) | |
tree | 95ff32031d2134ad2260737663e02cc047d9f447 | |
parent | 85f580433327c6be84e2fcc57a555ae251fb9b8a (diff) |
* Fixes segfault caused in the Object.getParent function.
Found by Jonathan Thambidurai
* Fixes a scriptlink problem when a script is run using ALT-p.
Found by Yann Vernier (LoneTech)
* Prints unhandled exceptions. Should fix some memory leaks too.
Fixed by Yann Verniet (LoneTech)
-rw-r--r-- | source/blender/python/BPY_interface.c | 16 | ||||
-rw-r--r-- | source/blender/python/api2_2x/EXPP_interface.c | 11 | ||||
-rw-r--r-- | source/blender/python/api2_2x/EXPP_interface.h | 1 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 6 |
4 files changed, 32 insertions, 2 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 2dff0d1b0e1..bf58a417c63 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -240,6 +240,8 @@ struct _object *BPY_txt_do_python(struct SpaceText* st) else dict = PyModule_GetDict(PyImport_AddModule("__main__")); + clearScriptLinks (); + ret = RunPython (st->text, dict); /* Run the script */ if (!ret) { /* Failed execution of the script */ @@ -353,6 +355,7 @@ void BPY_do_pyscript(struct ID *id, short event) ScriptLink * scriptlink; int index; PyObject * dict; + PyObject * ret; printf ("In BPY_do_pyscript(id=%s, event=%d)\n",id->name, event); @@ -368,8 +371,19 @@ void BPY_do_pyscript(struct ID *id, short event) (scriptlink->scripts[index] != NULL)) { dict = CreateGlobalDictionary(); - RunPython ((Text*) scriptlink->scripts[index], dict); + ret = RunPython ((Text*) scriptlink->scripts[index], dict); ReleaseGlobalDictionary (dict); + if (!ret) + { + /* Failed execution of the script */ + BPY_Err_Handle ((Text*) scriptlink->scripts[index]); + BPY_end_python (); + BPY_start_python (); + } + else + { + Py_DECREF (ret); + } } } diff --git a/source/blender/python/api2_2x/EXPP_interface.c b/source/blender/python/api2_2x/EXPP_interface.c index 77267db1a32..d987af6c004 100644 --- a/source/blender/python/api2_2x/EXPP_interface.c +++ b/source/blender/python/api2_2x/EXPP_interface.c @@ -54,6 +54,17 @@ void initBlenderApi2_2x (void) M_Blender_Init (); } +void clearScriptLinks (void) +{ + Py_INCREF (Py_False); + PyDict_SetItemString (g_blenderdict, "bylink", Py_False); + /* Old API meant link could be unset. Or even valid when bylink is false. + * This way, you can import it and check its value afterwards, ignoring + * bylink. */ + Py_INCREF (Py_None); + PyDict_SetItemString (g_blenderdict, "link", Py_None); +} + ScriptLink * setScriptLinks(ID *id, short event) { ScriptLink * scriptlink; diff --git a/source/blender/python/api2_2x/EXPP_interface.h b/source/blender/python/api2_2x/EXPP_interface.h index e61e6c2d2dc..6e4ef1f2687 100644 --- a/source/blender/python/api2_2x/EXPP_interface.h +++ b/source/blender/python/api2_2x/EXPP_interface.h @@ -32,4 +32,5 @@ #include <DNA_ID.h> void initBlenderApi2_2x (void); +void clearScriptLinks (void); ScriptLink * setScriptLinks(ID *id, short event); diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index ed5d536a1df..708a89fbb17 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -400,6 +400,7 @@ PyObject *M_Object_Get(PyObject *self, PyObject *args) } blen_object = (C_Object*)PyObject_NEW (C_Object, &Object_Type); blen_object->object = object; + blen_object->parent = NULL; blen_object->data = NULL; return ((PyObject*)blen_object); @@ -708,7 +709,10 @@ static PyObject *Object_getParent (C_Object *self) return ((PyObject*)self->parent); } - /* TODO: what if self->object->parent==NULL? Should we return Py_None? */ + if (self->object->parent == NULL) + { + return (EXPP_incr_ret (Py_None)); + } attr = M_ObjectCreatePyObject (self->object->parent); if (attr) |