[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54865] trunk/blender/source/blender/ python/intern/bpy_rna.c: fix [#34423] Foreach_get crash for any non existant attribute
Campbell Barton
ideasman42 at gmail.com
Tue Feb 26 01:31:38 CET 2013
Revision: 54865
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54865
Author: campbellbarton
Date: 2013-02-26 00:31:36 +0000 (Tue, 26 Feb 2013)
Log Message:
-----------
fix [#34423] Foreach_get crash for any non existant attribute
also improve exception messages.
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 2013-02-26 00:09:26 UTC (rev 54864)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2013-02-26 00:31:36 UTC (rev 54865)
@@ -4257,7 +4257,7 @@
return PyLong_FromLong(index);
}
-static void foreach_attr_type(BPy_PropertyRNA *self, const char *attr,
+static bool foreach_attr_type(BPy_PropertyRNA *self, const char *attr,
/* values to assign */
RawPropertyType *raw_type, int *attr_tot, bool *attr_signed)
{
@@ -4265,17 +4265,26 @@
*raw_type = PROP_RAW_UNSET;
*attr_tot = 0;
*attr_signed = false;
+ bool attr_found;
/* note: this is fail with zero length lists, so don't let this get caled in that case */
RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop)
{
prop = RNA_struct_find_property(&itemptr, attr);
- *raw_type = RNA_property_raw_type(prop);
- *attr_tot = RNA_property_array_length(&itemptr, prop);
- *attr_signed = (RNA_property_subtype(prop) == PROP_UNSIGNED) ? false : true;
+ if (prop) {
+ *raw_type = RNA_property_raw_type(prop);
+ *attr_tot = RNA_property_array_length(&itemptr, prop);
+ *attr_signed = (RNA_property_subtype(prop) != PROP_UNSIGNED);
+ attr_found = true;
+ }
+ else {
+ attr_found = false;
+ }
break;
}
RNA_PROP_END;
+
+ return attr_found;
}
/* pyrna_prop_collection_foreach_get/set both use this */
@@ -4295,15 +4304,26 @@
*attr_signed = false;
*raw_type = PROP_RAW_UNSET;
- if (!PyArg_ParseTuple(args, "sO", attr, seq) || (!PySequence_Check(*seq) && PyObject_CheckBuffer(*seq))) {
- PyErr_SetString(PyExc_TypeError, "foreach_get(attr, sequence) expects a string and a sequence");
+ if (!PyArg_ParseTuple(args, "sO:foreach_get/set", attr, seq)) {
return -1;
}
+ if (!PySequence_Check(*seq) && PyObject_CheckBuffer(*seq)) {
+ PyErr_Format(PyExc_TypeError,
+ "foreach_get/set expected second argument to be a sequence or buffer, not a %.200s",
+ Py_TYPE(seq)->tp_name);
+ return -1;
+ }
+
*tot = PySequence_Size(*seq); /* TODO - buffer may not be a sequence! array.array() is tho. */
if (*tot > 0) {
- foreach_attr_type(self, *attr, raw_type, attr_tot, attr_signed);
+ if (!foreach_attr_type(self, *attr, raw_type, attr_tot, attr_signed)) {
+ PyErr_Format(PyExc_AttributeError,
+ "foreach_get/set '%.200s.%200s[...]' elements have no attribute '%.200s'",
+ RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), *attr);
+ return -1;
+ }
*size = RNA_raw_type_sizeof(*raw_type);
#if 0 /* works fine but not strictly needed, we could allow RNA_property_collection_raw_* to do the checks */
More information about the Bf-blender-cvs
mailing list