diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index 2dd2db3..86122b9 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -2284,7 +2284,7 @@ typedef struct { construct_name = self.get_construct_name() copy_wrapper_name = '_wrap_%s__copy__' % self.pystruct code_sink.writeln(''' -static PyObject*\n%s(%s *self) +static PyObject*\n%s(%s *self, PyObject *PYBINDGEN_UNUSED(_args)) { ''' % (copy_wrapper_name, self.pystruct)) code_sink.indent() diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index 9d29e2f..6f25dff 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -84,7 +84,7 @@ class CppMethod(ForwardWrapperBase): # bug 399870 if is_virtual is None: is_virtual = is_pure_virtual - + if return_value is None: return_value = ReturnValue.new('void') @@ -291,7 +291,7 @@ class CppMethod(ForwardWrapperBase): self.method_name, template_params, ", ".join(self.call_params), - + class_.full_name, self.method_name, template_params, ", ".join(self.call_params) ))) @@ -354,14 +354,23 @@ class CppMethod(ForwardWrapperBase): "extra_wrapper_params can only be used with"\ " full varargs/kwargs wrappers" self.wrapper_args = ["%s *%s" % (self._get_pystruct(), _self_name), - "PyObject *args"] + "PyObject *args", + "PyObject *PYBINDGEN_UNUSED(_kwargs)"] else: assert not extra_wrapper_params, \ "extra_wrapper_params can only be used with full varargs/kwargs wrappers" if 'METH_STATIC' in flags: - self.wrapper_args = ['void'] + self.wrapper_args = [ + 'PyObject *PYBINDGEN_UNUSED(_self)', + "PyObject *PYBINDGEN_UNUSED(_args)", + "PyObject *PYBINDGEN_UNUSED(_kwargs)", + ] else: - self.wrapper_args = ["%s *%s" % (self._get_pystruct(), _self_name)] + self.wrapper_args = [ + "%s *%s" % (self._get_pystruct(), _self_name), + "PyObject *PYBINDGEN_UNUSED(_args)", + "PyObject *PYBINDGEN_UNUSED(_kwargs)", + ] self.wrapper_args.extend(extra_wrapper_params) return self.wrapper_return, "%s(%s)" % (self.wrapper_actual_name, ', '.join(self.wrapper_args)) @@ -439,7 +448,7 @@ class CppMethod(ForwardWrapperBase): pure_virtual = " = 0" else: pure_virtual = '' - + if self.return_value is None: retval = "retval?" else: @@ -631,7 +640,7 @@ class CppConstructor(ForwardWrapperBase): "Get the class wrapper object (CppClass)" return self._class class_ = property(get_class, set_class) - + def generate_call(self, class_=None): "virtual method implementation; do not call" if class_ is None: @@ -758,7 +767,7 @@ class CppConstructor(ForwardWrapperBase): cls_name = "???" else: cls_name = self._class.full_name - + if self.return_value is None: retval = "retval?" else: @@ -839,7 +848,7 @@ class CppNoConstructor(ForwardWrapperBase): def generate_call(self): "dummy method, not really called" pass - + def generate(self, code_sink, class_): """ Generates the wrapper code @@ -922,7 +931,7 @@ class CppVirtualMethodParentCaller(CppMethod): ', '.join([param.name for param in self.parameters]))) else: code_sink.writeln('{ return %s::%s(%s); }' % (self.method.class_.full_name, self.method_name, - ', '.join([param.name for param in self.parameters]))) + ', '.join([param.name for param in self.parameters]))) def generate_call(self, class_=None): @@ -937,7 +946,7 @@ class CppVirtualMethodParentCaller(CppMethod): "%s == NULL" % helper, 'PyErr_SetString(PyExc_TypeError, "Method %s of class %s is protected and can only be called by a subclass");' % (self.method_name, self.class_.name)) - + if self.return_value.ctype == 'void': self.before_call.write_code( '%s(%s);' % @@ -1066,7 +1075,7 @@ class CppVirtualMethodProxy(ReverseWrapperBase): self.before_call.write_code('%s = PyObject_GetAttrString(m_pyself, (char *) "%s"); PyErr_Clear();' % (py_method, self.method_name)) self.before_call.add_cleanup_code('Py_XDECREF(%s);' % py_method) - + self.before_call.write_code( r'if (%s == NULL || Py_TYPE(%s) == &PyCFunction_Type) {' % (py_method, py_method)) if self.return_value.ctype == 'void': @@ -1111,7 +1120,7 @@ Py_FatalError("Error detected, but parent virtual is pure virtual or private vir (self.class_.pystruct, this_expression)) self.before_call.add_cleanup_code("reinterpret_cast< %s* >(m_pyself)->obj = %s;" % (self.class_.pystruct, self_obj_before)) - + super(CppVirtualMethodProxy, self).generate( code_sink, '::'.join((self._helper_class.name, self.method_name)), decl_modifiers=[], diff --git a/pybindgen/function.py b/pybindgen/function.py index 19b0883..f3f2f18 100644 --- a/pybindgen/function.py +++ b/pybindgen/function.py @@ -60,13 +60,13 @@ class Function(ForwardWrapperBase): if unblock_threads is None: unblock_threads = settings.unblock_threads - + ## backward compatibility check if isinstance(return_value, string_types) and isinstance(function_name, ReturnValue): warnings.warn("Function has changed API; see the API documentation (but trying to correct...)", DeprecationWarning, stacklevel=2) function_name, return_value = return_value, function_name - + if return_value is None: return_value = ReturnValue.new('void') @@ -175,7 +175,7 @@ class Function(ForwardWrapperBase): self.wrapper_base_name = "_wrap_%s_%s" % ( module.prefix, self.mangled_name) module = property(get_module, set_module) - + def generate_call(self): "virtual method implementation; do not call" if self.foreign_cpp_namespace: @@ -189,7 +189,7 @@ class Function(ForwardWrapperBase): template_params = '< %s >' % ', '.join(self.template_parameters) else: template_params = '' - + if self.throw: self.before_call.write_code('try\n{') self.before_call.indent() @@ -260,12 +260,17 @@ class Function(ForwardWrapperBase): self.wrapper_args.append("PyObject *args") if 'METH_KEYWORDS' in flags: self.wrapper_args.append("PyObject *kwargs") + else: + self.wrapper_args.append("PyObject *PYBINDGEN_UNUSED(_kwargs)") + else: + self.wrapper_args.append("PyObject *PYBINDGEN_UNUSED(_args)") + self.wrapper_args.append("PyObject *PYBINDGEN_UNUSED(_kwargs)") self.wrapper_args.extend(extra_wrapper_params) self.wrapper_return = "PyObject *" self.write_open_wrapper(code_sink) tmp_sink.flush_to(code_sink) self.write_close_wrapper(code_sink) - + def generate_declaration(self, code_sink, extra_wrapper_parameters=()): ## We need to fake generate the code (and throw away the diff --git a/pybindgen/pytypeobject.py b/pybindgen/pytypeobject.py index 7dc6d51..e045cd2 100644 --- a/pybindgen/pytypeobject.py +++ b/pybindgen/pytypeobject.py @@ -291,7 +291,7 @@ static Py_ssize_t PyObject *py_result; Py_ssize_t result; - py_result = %(method_name)s(py_self); + py_result = %(method_name)s(py_self, NULL, NULL); if (py_result == NULL) { PyErr_SetString(PyExc_RuntimeError, "Unknown error in attempting to determine __len__."); Py_XDECREF(py_result);