[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16356] trunk/blender/source: fix for 2 python refcounting errors

Campbell Barton ideasman42 at gmail.com
Thu Sep 4 01:51:55 CEST 2008


Revision: 16356
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16356
Author:   campbellbarton
Date:     2008-09-04 01:51:55 +0200 (Thu, 04 Sep 2008)

Log Message:
-----------
fix for 2 python refcounting errors

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2008-09-03 20:25:47 UTC (rev 16355)
+++ trunk/blender/source/blender/python/BPY_interface.c	2008-09-03 23:51:55 UTC (rev 16356)
@@ -292,7 +292,7 @@
 	short ok=1;
 	PyErr_Clear(  );
 
-	dir = Py_BuildValue( "s", dirname );
+	dir = PyString_FromString( dirname );
 
 	mod_sys = PyImport_ImportModule( "sys" );	/* new ref */
 	
@@ -308,32 +308,29 @@
 	}
 	
 	if (PySequence_Contains(path, dir)==0) { /* Only add if we need to */
-		if (ok && PyList_Append( path, dir ) != 0)
+		if (ok && PyList_Append( path, dir ) != 0) /* decref below */
 			ok = 0; /* append failed */
 	
 		if( (ok==0) || PyErr_Occurred(  ) )
 			Py_FatalError( "could import or build sys.path, can't continue" );
 	}
+	Py_DECREF( dir );
 	Py_XDECREF( mod_sys );
 }
 
 void init_syspath( int first_time )
 {
-	PyObject *path;
 	PyObject *mod, *d;
 	char *progname;
 	char execdir[FILE_MAXDIR];	/*defines from DNA_space_types.h */
 
 	int n;
-	
-	
-	path = Py_BuildValue( "s", bprogname );
 
 	mod = PyImport_ImportModule( "Blender.sys" );
 
 	if( mod ) {
 		d = PyModule_GetDict( mod );
-		EXPP_dict_set_item_str( d, "progname", path );
+		EXPP_dict_set_item_str( d, "progname", PyString_FromString( bprogname ) );
 		Py_DECREF( mod );
 	} else
 		printf( "Warning: could not set Blender.sys.progname\n" );

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2008-09-03 20:25:47 UTC (rev 16355)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2008-09-03 23:51:55 UTC (rev 16356)
@@ -274,7 +274,7 @@
 {
 	char cpath[sizeof(G.sce)];
 	char *searchpath = NULL;
-	PyObject* list;
+	PyObject* list, *value;
 	
     DIR *dp;
     struct dirent *dirp;
@@ -300,7 +300,9 @@
 	
     while ((dirp = readdir(dp)) != NULL) {
 		if (BLI_testextensie(dirp->d_name, ".blend")) {
-			PyList_Append(list, PyString_FromString(dirp->d_name));
+			value = PyString_FromString(dirp->d_name);
+			PyList_Append(list, value);
+			Py_DECREF(value);
 		}
     }
 	





More information about the Bf-blender-cvs mailing list