[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43502] trunk/blender/source/blender/ python/intern/bpy_rna.c: fix [#27589] Random crash with python UI

Campbell Barton ideasman42 at gmail.com
Wed Jan 18 20:50:45 CET 2012


Revision: 43502
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43502
Author:   campbellbarton
Date:     2012-01-18 19:50:44 +0000 (Wed, 18 Jan 2012)
Log Message:
-----------
fix [#27589] Random crash with python UI

This script was defining an operator within the panels draw function, while its possible to support this its really asking for trouble.

the fix is to raise an error when this happens.

also fix crash passing non classes to register_class/unregister_class

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	2012-01-18 17:25:05 UTC (rev 43501)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2012-01-18 19:50:44 UTC (rev 43502)
@@ -7158,11 +7158,28 @@
 	const char *identifier;
 	PyObject *py_cls_meth;
 
+	if (!PyType_Check(py_class)) {
+		PyErr_Format(PyExc_ValueError,
+		             "register_class(...): "
+		             "expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
+		return NULL;
+	}
+
 	if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
-		PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
+		PyErr_SetString(PyExc_ValueError,
+		                "register_class(...): "
+		                "already registered as a subclass");
 		return NULL;
 	}
 
+	if (!pyrna_write_check()) {
+		PyErr_Format(PyExc_RuntimeError,
+		             "register_class(...): "
+		             "can't run in readonly state '%.200s'",
+		             ((PyTypeObject *)py_class)->tp_name);
+		return NULL;
+	}
+
 	/* warning: gets parent classes srna, only for the register function */
 	srna = pyrna_struct_as_srna(py_class, 1, "register_class(...):");
 	if (srna == NULL)
@@ -7284,12 +7301,27 @@
 	StructRNA *srna;
 	PyObject *py_cls_meth;
 
+	if (!PyType_Check(py_class)) {
+		PyErr_Format(PyExc_ValueError,
+		             "register_class(...): "
+		             "expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
+		return NULL;
+	}
+
 	/*if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna) == NULL) {
 		PWM_cursor_wait(0);
 		PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
 		return NULL;
 	}*/
 
+	if (!pyrna_write_check()) {
+		PyErr_Format(PyExc_RuntimeError,
+		             "unregister_class(...): "
+		             "can't run in readonly state '%.200s'",
+		             ((PyTypeObject *)py_class)->tp_name);
+		return NULL;
+	}
+
 	srna = pyrna_struct_as_srna(py_class, 0, "unregister_class(...):");
 	if (srna == NULL)
 		return NULL;



More information about the Bf-blender-cvs mailing list