Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2010-03-16 20:20:15 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2010-03-16 20:20:15 +0300
commit9a986d194c85187fcbcbe84d2355763012661992 (patch)
treee22426f974a700f05a1e5145bbcde9d4e7da142d /source/blender/python
parent46ed51ce26ee78e82b8dfbc12040edbdbd39c6ad (diff)
fix for nasty bug where registering properties would register them in the parent classes SRNA, made for confusing rigify args turning up in add sequencer adding collection.
(commit 27433 by Campbell from render25 branch)
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c2
-rw-r--r--source/blender/python/intern/bpy_props.c36
-rw-r--r--source/blender/python/intern/bpy_rna.c53
-rw-r--r--source/blender/python/intern/bpy_rna.h4
4 files changed, 42 insertions, 53 deletions
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 56d49fcc889..0c1eafb4948 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -111,7 +111,7 @@ PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
}
/* identifiers */
- srna= srna_from_self(macro);
+ srna= srna_from_self(macro, "Macro Define:");
macroname = RNA_struct_identifier(srna);
ot = WM_operatortype_exists(macroname);
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index 5bddd52dadf..c23ff2f2951 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -115,7 +115,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "BoolProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -181,7 +181,7 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "BoolVectorProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -258,7 +258,7 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "IntProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -325,7 +325,7 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "IntVectorProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -406,7 +406,7 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "FloatProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -481,7 +481,7 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "FloatVectorProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -559,7 +559,7 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "StringProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -671,7 +671,7 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "EnumProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -716,18 +716,22 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
}
}
-static StructRNA *pointer_type_from_py(PyObject *value)
+static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
{
StructRNA *srna;
- srna= srna_from_self(value);
+ srna= srna_from_self(value, "BoolProperty(...):");
if(!srna) {
- PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup");
+
+ PyObject *msg= BPY_exception_buffer();
+ char *msg_char= _PyUnicode_AsString(msg);
+ PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with: %s", error_prefix, msg_char);
+ Py_DECREF(msg);
return NULL;
}
if(!RNA_struct_is_a(srna, &RNA_IDPropertyGroup)) {
- PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup");
+ PyErr_Format(PyExc_SystemError, "%.200s expected an RNA type derived from IDPropertyGroup", error_prefix);
return NULL;
}
@@ -752,7 +756,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "PointerProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -777,7 +781,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "PointerProperty(options={...}):"))
return NULL;
- ptype= pointer_type_from_py(type);
+ ptype= pointer_type_from_py(type, "PointerProperty(...):");
if(!ptype)
return NULL;
@@ -813,7 +817,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- srna= srna_from_self(self);
+ srna= srna_from_self(self, "CollectionProperty(...):");
if(srna==NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
@@ -838,7 +842,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "CollectionProperty(options={...}):"))
return NULL;
- ptype= pointer_type_from_py(type);
+ ptype= pointer_type_from_py(type, "CollectionProperty(...):");
if(!ptype)
return NULL;
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index b995fbb8800..c9906bb1599 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -3537,26 +3537,6 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
}
}
-/*
-static StructRNA *srna_from_self(PyObject *self);
-PyObject *BPy_GetStructRNA(PyObject *self)
-{
- StructRNA *srna= pyrna_struct_as_srna(self);
- PointerRNA ptr;
- PyObject *ret;
-
- RNA_pointer_create(NULL, &RNA_Struct, srna, &ptr);
- ret= pyrna_struct_CreatePyObject(&ptr);
-
- if(ret) {
- return ret;
- }
- else {
- Py_RETURN_NONE;
- }
-}
-*/
-
static PyObject* pyrna_srna_Subtype(StructRNA *srna);
/* return a borrowed reference */
@@ -3897,7 +3877,7 @@ PyObject *BPY_rna_types(void)
return (PyObject *)self;
}
-StructRNA *pyrna_struct_as_srna(PyObject *self)
+StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix)
{
BPy_StructRNA *py_srna = NULL;
StructRNA *srna;
@@ -3907,23 +3887,27 @@ StructRNA *pyrna_struct_as_srna(PyObject *self)
py_srna = (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
Py_XINCREF(py_srna);
}
-
- if(py_srna==NULL)
- py_srna = (BPy_StructRNA*)PyObject_GetAttrString(self, "bl_rna");
+
+ if(parent) {
+ /* be very careful with this since it will return a parent classes srna.
+ * modifying this will do confusing stuff! */
+ if(py_srna==NULL)
+ py_srna = (BPy_StructRNA*)PyObject_GetAttrString(self, "bl_rna");
+ }
if(py_srna==NULL) {
- PyErr_SetString(PyExc_SystemError, "internal error, self had no bl_rna attribute, should never happen.");
+ PyErr_Format(PyExc_SystemError, "%.200s internal error, self of type '%.200s' had no bl_rna attribute, should never happen", error_prefix, Py_TYPE(self)->tp_name);
return NULL;
}
if(!BPy_StructRNA_Check(py_srna)) {
- PyErr_Format(PyExc_SystemError, "internal error, bl_rna was of type %.200s, instead of %.200s instance.", Py_TYPE(py_srna)->tp_name, pyrna_struct_Type.tp_name);
+ PyErr_Format(PyExc_SystemError, "%.200s internal error, bl_rna was of type '%.200s', instead of %.200s instance", error_prefix, Py_TYPE(py_srna)->tp_name, pyrna_struct_Type.tp_name);
Py_DECREF(py_srna);
return NULL;
}
if(py_srna->ptr.type != &RNA_Struct) {
- PyErr_SetString(PyExc_SystemError, "internal error, bl_rna was not a RNA_Struct type of rna struct.");
+ PyErr_Format(PyExc_SystemError, "%.200s internal error, bl_rna was not a RNA_Struct type of rna struct", error_prefix);
Py_DECREF(py_srna);
return NULL;
}
@@ -3937,7 +3921,7 @@ StructRNA *pyrna_struct_as_srna(PyObject *self)
/* Orphan functions, not sure where they should go */
/* get the srna for methods attached to types */
/* */
-StructRNA *srna_from_self(PyObject *self)
+StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
{
/* a bit sloppy but would cause a very confusing bug if
* an error happened to be set here */
@@ -3955,7 +3939,7 @@ StructRNA *srna_from_self(PyObject *self)
/* These cases above not errors, they just mean the type was not compatible
* After this any errors will be raised in the script */
- return pyrna_struct_as_srna(self);
+ return pyrna_struct_as_srna(self, 0, error_prefix);
}
static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key, PyObject *dummy_args)
@@ -4451,11 +4435,12 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
const char *identifier= "";
if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) {
- PyErr_SetString(PyExc_AttributeError, "bpy.types.register(): already registered as a subclass.");
+ PyErr_SetString(PyExc_AttributeError, "bpy.types.register(...): already registered as a subclass.");
return NULL;
}
- srna= pyrna_struct_as_srna(py_class);
+ /* warning: gets parent classes srna, only for the register function */
+ srna= pyrna_struct_as_srna(py_class, 1, "bpy.types.register(...):");
if(srna==NULL)
return NULL;
@@ -4463,7 +4448,7 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
reg= RNA_struct_register(srna);
if(!reg) {
- PyErr_SetString(PyExc_ValueError, "bpy.types.register(): expected a Type subclassed from a registerable rna type (no register supported).");
+ PyErr_SetString(PyExc_ValueError, "bpy.types.register(...): expected a Type subclassed from a registerable rna type (no register supported).");
return NULL;
}
@@ -4526,7 +4511,7 @@ PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class)
return NULL;
}*/
- srna= pyrna_struct_as_srna(py_class);
+ srna= pyrna_struct_as_srna(py_class, 0, "bpy.types.unregister(...):");
if(srna==NULL)
return NULL;
@@ -4534,7 +4519,7 @@ PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class)
unreg= RNA_struct_unregister(srna);
if(!unreg) {
- PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(): expected a Type subclassed from a registerable rna type (no unregister supported).");
+ PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(...): expected a Type subclassed from a registerable rna type (no unregister supported).");
return NULL;
}
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 770e88e1a1d..9892ed6989b 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -64,8 +64,8 @@ typedef struct {
/* cheap trick */
#define BPy_BaseTypeRNA BPy_PropertyRNA
-StructRNA *srna_from_self(PyObject *self);
-StructRNA *pyrna_struct_as_srna(PyObject *self);
+StructRNA *srna_from_self(PyObject *self, const char *error_prefix);
+StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix);
void BPY_rna_init( void );
PyObject *BPY_rna_module( void );