py/rna debugging option (defaults to off), which quickly exposes errors with RNA...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 6 May 2011 03:29:55 +0000 (03:29 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 6 May 2011 03:29:55 +0000 (03:29 +0000)
source/blender/python/intern/bpy_rna.c

index 74af9761b98f1e1ec15b6eb1c392c1ff7df85d34..8af0db6ee13b8ea77b50f00a05a753758b4103ae 100644 (file)
@@ -4243,6 +4243,14 @@ static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
        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 @@ static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
                                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 @@ static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
                }
        }
 
+
+#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);