[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37692] trunk/blender/source/blender/ python/intern/bpy_rna.c: py api: make all classes __init__ functions in a readonly state, except for operators.
Campbell Barton
ideasman42 at gmail.com
Tue Jun 21 10:09:43 CEST 2011
Revision: 37692
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37692
Author: campbellbarton
Date: 2011-06-21 08:09:42 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
py api: make all classes __init__ functions in a readonly state, except for operators.
In bug [#27701], the panels __init__ function (which runs on every draw), was adding new rna properties.
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-06-21 07:41:49 UTC (rev 37691)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2011-06-21 08:09:42 UTC (rev 37692)
@@ -6041,9 +6041,10 @@
PyGILState_STATE gilstate;
#ifdef USE_PEDANTIC_WRITE
+ const int is_operator= RNA_struct_is_a(ptr->type, &RNA_Operator);
const char *func_id= RNA_function_identifier(func);
/* testing, for correctness, not operator and not draw function */
- const short is_readonly= strstr("draw", func_id) || /*strstr("render", func_id) ||*/ !RNA_struct_is_a(ptr->type, &RNA_Operator);
+ const short is_readonly= strstr("draw", func_id) || /*strstr("render", func_id) ||*/ !is_operator;
#endif
py_class= RNA_struct_py_type_get(ptr->type);
@@ -6099,6 +6100,11 @@
* Although this is annoying to have to impliment a part of pythons typeobject.c:type_call().
*/
if(py_class->tp_init) {
+#ifdef USE_PEDANTIC_WRITE
+ const int prev_write= rna_disallow_writes;
+ rna_disallow_writes= is_operator ? FALSE : TRUE; /* only operators can write on __init__ */
+#endif
+
/* true in most cases even when the class its self doesn't define an __init__ function. */
args= PyTuple_New(0);
if (py_class->tp_init(py_srna, args, NULL) < 0) {
@@ -6107,11 +6113,16 @@
/* err set below */
}
Py_DECREF(args);
+#ifdef USE_PEDANTIC_WRITE
+ rna_disallow_writes= prev_write;
+#endif
}
-
py_class_instance= py_srna;
#else
+ const int prev_write= rna_disallow_writes;
+ rna_disallow_writes= TRUE;
+
/* 'almost' all the time calling the class isn't needed.
* We could just do...
py_class_instance= py_srna;
@@ -6125,7 +6136,10 @@
py_class_instance= PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
+ rna_disallow_writes= prev_write;
+
#endif
+
if(py_class_instance == NULL) {
err= -1; /* so the error is not overridden below */
}
More information about the Bf-blender-cvs
mailing list