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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-12-20 07:08:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-12-20 07:08:27 +0400
commit3c9f50204961b7fa8f6de259fa36deb24696a918 (patch)
tree50ca581a1ec01e56fee18ea37b4ae13eaba44e9f /source
parent3bc3e178b368d70856b951dc48049a1a35039f31 (diff)
py api: be more strict with boolean assignment, only accept 0 or 1, True/False. Would allow any nonzero value.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/intern/bpy_rna.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 55983c73895..b70e855d332 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1510,12 +1510,18 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
/* prefer not to have an exception here
* however so many poll functions return None or a valid Object.
* its a hassle to convert these into a bool before returning, */
- if (RNA_property_flag(prop) & PROP_OUTPUT)
+ if (RNA_property_flag(prop) & PROP_OUTPUT) {
param = PyObject_IsTrue(value);
- else
+ }
+ else {
param = PyLong_AsLong(value);
- if (param < 0) {
+ if (UNLIKELY(param & ~1)) { /* only accept 0/1 */
+ param = -1; /* error out below */
+ }
+ }
+
+ if (param == -1) {
PyErr_Format(PyExc_TypeError,
"%.200s %.200s.%.200s expected True/False or 0/1, not %.200s",
error_prefix, RNA_struct_identifier(ptr->type),