[Bf-committers] Python crash plus suggested patch

Jonathan Thambidurai bf-committers@blender.org
Sun, 22 Jun 2003 23:36:59 -0400


--Boundary_(ID_Y7RH4VDHv0/OC+3WT/SDLg)
Content-type: text/plain
Content-transfer-encoding: 7BIT

	The python code at the end of this message, after several subsequent,
consecutive runs (or even on the first run sometimes), results in a
segfault.  As you can see, the problem lies with Object.getParent().  If
you look at this function (in the C code), you will see that it relies
on the "non-nullness" of the self->parent pointer; this pointer, however
is not initialized to zero in the M_Object_Get() C function, resulting
in the random failure of getParent() of objects that are not created by
M_Object_New().  The first attached patch (fix.patch) fixes this.  Allow
me also suggest that we do return Py_None in object.getParent() if an
object has no parent.  The second attached patch (enhance.patch) does
this and also fixes the NULL pointer problem.

--Jonathan Thambidurai

--------------------------------------------------------------------

from Blender import *

objectname_list = Object.get()

#file = sys.stdout
file = open( "/home/jonathan/tmp/testjglblend", "w" );

for object_name in objectname_list:
    object = Object.get( object_name )

    if object.getType() == "Mesh":
          parent = object.getParent()


--Boundary_(ID_Y7RH4VDHv0/OC+3WT/SDLg)
Content-type: text/x-patch; charset=ANSI_X3.4-1968; NAME=fix.patch
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=fix.patch
Content-description:

Index: Object.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.16
diff -u -r1.16 Object.c
--- Object.c	12 Jun 2003 04:51:49 -0000	1.16
+++ Object.c	21 Jun 2003 21:19:22 -0000
@@ -400,6 +400,7 @@
         }
         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);

--Boundary_(ID_Y7RH4VDHv0/OC+3WT/SDLg)
Content-type: text/x-patch; charset=ANSI_X3.4-1968; NAME=enhance.patch
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=enhance.patch
Content-description:

Index: Object.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.16
diff -u -r1.16 Object.c
--- Object.c	12 Jun 2003 04:51:49 -0000	1.16
+++ Object.c	21 Jun 2003 21:27:21 -0000
@@ -400,6 +400,7 @@
         }
         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);
@@ -709,6 +710,11 @@
     }
 
     /* 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)

--Boundary_(ID_Y7RH4VDHv0/OC+3WT/SDLg)--