[Bf-blender-cvs] [6347b0b0aa4] datablock_idprops: Some cleanup regarding STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES.
Bastien Montagne
noreply at git.blender.org
Tue Apr 4 16:23:32 CEST 2017
Commit: 6347b0b0aa43a42f8927fe688799ecc30fb5538f
Author: Bastien Montagne
Date: Tue Apr 4 10:29:14 2017 +0200
Branches: datablock_idprops
https://developer.blender.org/rB6347b0b0aa43a42f8927fe688799ecc30fb5538f
Some cleanup regarding STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES.
This whole system (how to prevent IDP_ID-forbidden structs to get
assigned IDP_ID-allowed IDProps) still seems somewhat brittle to me,
took me some time to wrap my head around it, but... could not find
any better way to do that so far.
===================================================================
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_access.c
M source/blender/python/intern/bpy_props.c
M source/blender/python/intern/bpy_rna.c
===================================================================
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index bf0498f60d1..a1af3f98274 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -768,7 +768,7 @@ struct IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create);
bool RNA_struct_idprops_check(StructRNA *srna);
bool RNA_struct_idprops_register_check(const StructRNA *type);
bool RNA_struct_idprops_datablock_allowed(const StructRNA *type);
-bool RNA_struct_contains_id(const StructRNA *type);
+bool RNA_struct_idprops_contains_datablock(const StructRNA *type);
bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier);
PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index d1113448a2f..6a6ec9d1b14 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -592,10 +592,15 @@ bool RNA_struct_idprops_register_check(const StructRNA *type)
bool RNA_struct_idprops_datablock_allowed(const StructRNA *type)
{
- return (type->flag & STRUCT_NO_DATABLOCK_IDPROPERTIES) == 0;
+ return (type->flag & (STRUCT_NO_DATABLOCK_IDPROPERTIES | STRUCT_NO_IDPROPERTIES)) == 0;
}
-bool RNA_struct_contains_id(const StructRNA *type)
+/**
+ * Whether given type implies datablock usage by IDProperties.
+ * This is used to prevent classes allowed to have IDProperties, but not datablock ones, to indirectly use some
+ * (e.g. by assigning an IDP_GROUP containing some IDP_ID pointers...).
+ */
+bool RNA_struct_idprops_contains_datablock(const StructRNA *type)
{
return (type->flag & (STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES | STRUCT_ID)) != 0;
}
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index adf423fb256..e01078b287f 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -2922,9 +2922,10 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
bpy_prop_assign_flag(prop, opts);
}
- if (RNA_struct_contains_id(ptype)) {
- if (RNA_struct_is_a(srna, &RNA_PropertyGroup))
+ if (RNA_struct_idprops_contains_datablock(ptype)) {
+ if (RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
RNA_def_struct_flag(srna, STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES);
+ }
}
bpy_prop_callback_assign_update(prop, update_cb);
bpy_prop_callback_assign_pointer(prop, poll_cb);
@@ -2989,9 +2990,10 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
bpy_prop_assign_flag(prop, opts);
}
- if (RNA_struct_contains_id(ptype)) {
- if (RNA_struct_is_a(srna, &RNA_PropertyGroup))
+ if (RNA_struct_idprops_contains_datablock(ptype)) {
+ if (RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
RNA_def_struct_flag(srna, STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES);
+ }
}
RNA_def_property_duplicate_pointers(srna, prop);
}
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 2cdac5c5321..5e336b7dc16 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -3273,7 +3273,9 @@ static int pyrna_struct_ass_subscript(BPy_StructRNA *self, PyObject *key, PyObje
BPy_StructRNA* val = (BPy_StructRNA*)value;
if (val && self->ptr.type && val->ptr.type) {
- if (!RNA_struct_idprops_datablock_allowed(self->ptr.type) && RNA_struct_contains_id(val->ptr.type)) {
+ if (!RNA_struct_idprops_datablock_allowed(self->ptr.type) &&
+ RNA_struct_idprops_contains_datablock(val->ptr.type))
+ {
PyErr_SetString(PyExc_TypeError, "bpy_struct[key] = val: datablock id properties not supported for this type");
return -1;
}
@@ -7098,12 +7100,12 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
PyObject *type = PyDict_GetItemString(py_kw, "type");
StructRNA *type_srna = srna_from_self(type, "");
- if (type_srna)
- {
+ if (type_srna) {
if (!RNA_struct_idprops_datablock_allowed(srna) &&
- (*(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_PointerProperty ||
- *(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_CollectionProperty) &&
- RNA_struct_contains_id(type_srna)) {
+ (*(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_PointerProperty ||
+ *(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_CollectionProperty) &&
+ RNA_struct_idprops_contains_datablock(type_srna))
+ {
PyErr_Format(PyExc_ValueError,
"bpy_struct \"%.200s\" doesn't support datablock properties \n",
RNA_struct_identifier(srna));
More information about the Bf-blender-cvs
mailing list