forked from bartvdbraak/blender
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.
This commit is contained in:
parent
22c22d4961
commit
ba5d18b41f
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user