[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36509] trunk/blender/source/blender/ python/intern/bpy_rna.c: py/rna debugging option (defaults to off), which quickly exposes errors with RNA functions holding string pointers by making a temp copy of the string and freeing after the function is called .

Campbell Barton ideasman42 at gmail.com
Fri May 6 05:29:56 CEST 2011


Revision: 36509
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36509
Author:   campbellbarton
Date:     2011-05-06 03:29:55 +0000 (Fri, 06 May 2011)
Log Message:
-----------
py/rna debugging option (defaults to off), which quickly exposes errors with RNA functions holding string pointers by making a temp copy of the string and freeing after the function is called.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2011-05-06 02:55:09 UTC (rev 36508)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2011-05-06 03:29:55 UTC (rev 36509)
@@ -4243,6 +4243,14 @@
 	PropertyRNA *pret_single= NULL;
 	void *retdata_single= NULL;
 
+	/* enable this so all strings are copied and freed after calling.
+	 * this exposes bugs where the pointer to the string is held and re-used */
+// #define DEBUG_STRING_FREE
+
+#ifdef DEBUG_STRING_FREE
+	PyObject *string_free_ls= PyList_New(0);
+#endif
+
 	/* Should never happen but it does in rare cases */
 	BLI_assert(self_ptr != NULL);
 
@@ -4331,10 +4339,20 @@
 				err= -1;
 				break;
 			}
-			else /* PyDict_GetItemString wont raise an error */
+			else { /* PyDict_GetItemString wont raise an error */
 				continue;
+			}
 		}
 
+#ifdef DEBUG_STRING_FREE
+		if(item) {
+			if(PyUnicode_Check(item)) {
+				item= PyUnicode_FromString(_PyUnicode_AsString(item));
+				PyList_Append(string_free_ls, item);
+				Py_DECREF(item);
+			}
+		}
+#endif
 		err= pyrna_py_to_prop(&funcptr, parm, iter.data, item, "");
 
 		if(err!=0) {
@@ -4470,6 +4488,13 @@
 		}
 	}
 
+
+#ifdef DEBUG_STRING_FREE
+	// if(PyList_Size(string_free_ls)) printf("%.200s.%.200s():  has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_Size(string_free_ls));
+	Py_DECREF(string_free_ls);
+#undef DEBUG_STRING_FREE
+#endif
+
 	/* cleanup */
 	RNA_parameter_list_end(&iter);
 	RNA_parameter_list_free(&parms);




More information about the Bf-blender-cvs mailing list