[opencv] 31/251: static analyze: python dynamic_cast checks
Nobuhiro Iwamatsu
iwamatsu at moszumanska.debian.org
Sun Aug 27 23:27:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
iwamatsu pushed a commit to annotated tag 3.3.0
in repository opencv.
commit b32d914aab8c095f07f3685fdbb9f7d92bbe2add
Author: Alexander Alekhin <alexander.alekhin at intel.com>
Date: Thu Jul 6 15:57:12 2017 +0300
static analyze: python dynamic_cast checks
---
modules/python/src2/gen2.py | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py
index 04c455c..da7a923 100755
--- a/modules/python/src2/gen2.py
+++ b/modules/python/src2/gen2.py
@@ -11,14 +11,18 @@ else:
ignored_arg_types = ["RNG*"]
-gen_template_check_self = Template(""" if(!PyObject_TypeCheck(self, &pyopencv_${name}_Type))
+gen_template_check_self = Template(""" $cname* _self_ = NULL;
+ if(PyObject_TypeCheck(self, &pyopencv_${name}_Type))
+ _self_ = ${amp}((pyopencv_${name}_t*)self)->v${get};
+ if (_self_ == NULL)
return failmsgp("Incorrect type of self (must be '${name}' or its derivative)");
- $cname* _self_ = ${amp}((pyopencv_${name}_t*)self)->v${get};
""")
-gen_template_check_self_algo = Template(""" if(!PyObject_TypeCheck(self, &pyopencv_${name}_Type))
+gen_template_check_self_algo = Template(""" $cname* _self_ = NULL;
+ if(PyObject_TypeCheck(self, &pyopencv_${name}_Type))
+ _self_ = dynamic_cast<$cname*>(${amp}((pyopencv_${name}_t*)self)->v.get());
+ if (_self_ == NULL)
return failmsgp("Incorrect type of self (must be '${name}' or its derivative)");
- $cname* _self_ = dynamic_cast<$cname*>(${amp}((pyopencv_${name}_t*)self)->v.get());
""")
gen_template_call_constructor_prelude = Template("""self = PyObject_NEW(pyopencv_${name}_t, &pyopencv_${name}_Type);
@@ -200,7 +204,10 @@ static PyObject* pyopencv_${name}_get_${member}(pyopencv_${name}_t* p, void *clo
gen_template_get_prop_algo = Template("""
static PyObject* pyopencv_${name}_get_${member}(pyopencv_${name}_t* p, void *closure)
{
- return pyopencv_from(dynamic_cast<$cname*>(p->v.get())${access}${member});
+ $cname* _self_ = dynamic_cast<$cname*>(p->v.get());
+ if (_self_ == NULL)
+ return failmsgp("Incorrect type of object (must be '${name}' or its derivative)");
+ return pyopencv_from(_self_${access}${member});
}
""")
@@ -224,7 +231,13 @@ static int pyopencv_${name}_set_${member}(pyopencv_${name}_t* p, PyObject *value
PyErr_SetString(PyExc_TypeError, "Cannot delete the ${member} attribute");
return -1;
}
- return pyopencv_to(value, dynamic_cast<$cname*>(p->v.get())${access}${member}) ? 0 : -1;
+ $cname* _self_ = dynamic_cast<$cname*>(p->v.get());
+ if (_self_ == NULL)
+ {
+ failmsgp("Incorrect type of object (must be '${name}' or its derivative)");
+ return -1;
+ }
+ return pyopencv_to(value, _self_${access}${member}) ? 0 : -1;
}
""")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git
More information about the debian-science-commits
mailing list