Skip to content

Commit

Permalink
fix unused arguments warning for tp_new() functions without base type
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Apr 18, 2012
1 parent 668a2d8 commit 0663454
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Cython/Compiler/ModuleNode.py
Expand Up @@ -991,11 +991,18 @@ def generate_new_function(self, scope, code, cclass_entry):
have_entries, (py_attrs, py_buffers, memoryview_slices) = \ have_entries, (py_attrs, py_buffers, memoryview_slices) = \
scope.get_refcounted_entries(include_weakref=True) scope.get_refcounted_entries(include_weakref=True)


new_func_entry = scope.lookup_here("__new__")
if base_type or (new_func_entry and new_func_entry.is_special
and not new_func_entry.trivial_signature):
unused_marker = ''
else:
unused_marker = 'CYTHON_UNUSED '

need_self_cast = type.vtabslot_cname or have_entries need_self_cast = type.vtabslot_cname or have_entries
code.putln("") code.putln("")
code.putln( code.putln(
"static PyObject *%s(PyTypeObject *t, PyObject *a, PyObject *k) {" "static PyObject *%s(PyTypeObject *t, %sPyObject *a, %sPyObject *k) {"
% scope.mangle_internal("tp_new")) % (scope.mangle_internal("tp_new"), unused_marker, unused_marker))
if need_self_cast: if need_self_cast:
code.putln( code.putln(
"%s;" "%s;"
Expand Down Expand Up @@ -1046,15 +1053,14 @@ def generate_new_function(self, scope, code, cclass_entry):
if cclass_entry.cname == '__pyx_memoryviewslice': if cclass_entry.cname == '__pyx_memoryviewslice':
code.putln("p->from_slice.memview = NULL;") code.putln("p->from_slice.memview = NULL;")


entry = scope.lookup_here("__new__") if new_func_entry and new_func_entry.is_special:
if entry and entry.is_special: if new_func_entry.trivial_signature:
if entry.trivial_signature:
cinit_args = "o, %s, NULL" % Naming.empty_tuple cinit_args = "o, %s, NULL" % Naming.empty_tuple
else: else:
cinit_args = "o, a, k" cinit_args = "o, a, k"
code.putln( code.putln(
"if (%s(%s) < 0) {" % "if (%s(%s) < 0) {" %
(entry.func_cname, cinit_args)) (new_func_entry.func_cname, cinit_args))
code.put_decref_clear("o", py_object_type, nanny=False); code.put_decref_clear("o", py_object_type, nanny=False);
code.putln( code.putln(
"}") "}")
Expand Down

0 comments on commit 0663454

Please sign in to comment.