[Bf-python] BPY_interface.c patch

Stephen Swaney sswaney at swbell.net
Tue Sep 30 00:44:04 CEST 2003


fix for unchecked pointer reference in init_syspath
which may be the cause of the crash mentioned in 
this thread:

http://www.blender.org/modules.php?op=modload&name=phpBB2&file=viewtopic&t=2204

Apparently, not all python site modules have a 
sitedirs member. Hmmmm...

-- 
Stephen Swaney			
sswaney at swbell.net
-------------- next part --------------
Index: BPY_interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/BPY_interface.c,v
retrieving revision 1.23
diff -u -r1.23 BPY_interface.c
--- BPY_interface.c	18 Sep 2003 00:54:41 -0000	1.23
+++ BPY_interface.c	29 Sep 2003 22:23:40 -0000
@@ -205,20 +205,25 @@
 
   if (mod) {
     PyObject* item;
-    int size, index;
+    int size = 0;
+    int index;
 
     /* get the value of 'sitedirs' from the module */
+
+    /* the ref man says GetDict() never fails!!! */
     d = PyModule_GetDict (mod); /* borrowed ref */
     p = PyDict_GetItemString (d, "sitedirs");  /* borrowed ref */
 
-    /* append each item in sitedirs list to path */
-    size = PyList_Size (p);
+    if( p ) {  /* we got our string */
+      /* append each item in sitedirs list to path */
+      size = PyList_Size (p);
 
-    for (index = 0; index < size; index++) {
-      item  = PySequence_GetItem (p, index);  /* new ref */
-      syspath_append (item);
+      for (index = 0; index < size; index++) {
+	item  = PySequence_GetItem (p, index);  /* new ref */
+	if( item )
+	  syspath_append (item);
+      }
     }
-
     Py_DECREF(mod);
   }
   else PyErr_Clear();


More information about the Bf-python mailing list