|
11 | 11 |
|
12 | 12 | ignored_arg_types = ["RNG*"]
|
13 | 13 |
|
14 |
| -gen_template_check_self = Template(""" if(!PyObject_TypeCheck(self, &pyopencv_${name}_Type)) |
| 14 | +gen_template_check_self = Template(""" $cname* _self_ = NULL; |
| 15 | + if(PyObject_TypeCheck(self, &pyopencv_${name}_Type)) |
| 16 | + _self_ = ${amp}((pyopencv_${name}_t*)self)->v${get}; |
| 17 | + if (_self_ == NULL) |
15 | 18 | return failmsgp("Incorrect type of self (must be '${name}' or its derivative)");
|
16 |
| - $cname* _self_ = ${amp}((pyopencv_${name}_t*)self)->v${get}; |
17 | 19 | """)
|
18 | 20 |
|
19 |
| -gen_template_check_self_algo = Template(""" if(!PyObject_TypeCheck(self, &pyopencv_${name}_Type)) |
| 21 | +gen_template_check_self_algo = Template(""" $cname* _self_ = NULL; |
| 22 | + if(PyObject_TypeCheck(self, &pyopencv_${name}_Type)) |
| 23 | + _self_ = dynamic_cast<$cname*>(${amp}((pyopencv_${name}_t*)self)->v.get()); |
| 24 | + if (_self_ == NULL) |
20 | 25 | return failmsgp("Incorrect type of self (must be '${name}' or its derivative)");
|
21 |
| - $cname* _self_ = dynamic_cast<$cname*>(${amp}((pyopencv_${name}_t*)self)->v.get()); |
22 | 26 | """)
|
23 | 27 |
|
24 | 28 | gen_template_call_constructor_prelude = Template("""self = PyObject_NEW(pyopencv_${name}_t, &pyopencv_${name}_Type);
|
|
200 | 204 | gen_template_get_prop_algo = Template("""
|
201 | 205 | static PyObject* pyopencv_${name}_get_${member}(pyopencv_${name}_t* p, void *closure)
|
202 | 206 | {
|
203 |
| - return pyopencv_from(dynamic_cast<$cname*>(p->v.get())${access}${member}); |
| 207 | + $cname* _self_ = dynamic_cast<$cname*>(p->v.get()); |
| 208 | + if (_self_ == NULL) |
| 209 | + return failmsgp("Incorrect type of object (must be '${name}' or its derivative)"); |
| 210 | + return pyopencv_from(_self_${access}${member}); |
204 | 211 | }
|
205 | 212 | """)
|
206 | 213 |
|
|
224 | 231 | PyErr_SetString(PyExc_TypeError, "Cannot delete the ${member} attribute");
|
225 | 232 | return -1;
|
226 | 233 | }
|
227 |
| - return pyopencv_to(value, dynamic_cast<$cname*>(p->v.get())${access}${member}) ? 0 : -1; |
| 234 | + $cname* _self_ = dynamic_cast<$cname*>(p->v.get()); |
| 235 | + if (_self_ == NULL) |
| 236 | + { |
| 237 | + failmsgp("Incorrect type of object (must be '${name}' or its derivative)"); |
| 238 | + return -1; |
| 239 | + } |
| 240 | + return pyopencv_to(value, _self_${access}${member}) ? 0 : -1; |
228 | 241 | }
|
229 | 242 | """)
|
230 | 243 |
|
|
0 commit comments