From 40368aa390a268c64ac40b4912b80c925cc27b20 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 16 Jul 2009 18:27:51 +0100 Subject: [PATCH] Fix bug 400338: PyObject_HasAttrString check in virtual method wrappers does not work. --- pybindgen/cppmethod.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index 98e1071..c11459c 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -809,8 +809,13 @@ class CppVirtualMethodProxy(ReverseWrapperBase): ## if the python subclass doesn't define a virtual method, ## just chain to parent class and don't do anything else call_params = ', '.join([param.name for param in self.parameters]) + py_method = self.declarations.declare_variable('PyObject*', 'py_method') + self.before_call.write_code('%s = PyObject_GetAttrString(m_pyself, (char *) "_%s");' + % (py_method, self.method_name)) + self.before_call.add_cleanup_code('Py_XDECREF(%s);' % py_method) + self.before_call.write_code( - r'if (!PyObject_HasAttrString(m_pyself, (char *) "_%s")) {' % self.method_name) + r'if (%s == NULL || %s->ob_type == &PyCFunction_Type) {' % (py_method, py_method)) if self.return_value.ctype == 'void': if not (self.method.is_pure_virtual or self.method.visibility == 'private'): self.before_call.write_code(r' %s::%s(%s);'