Commit 3d5ac9f9 authored by Jeroen Demeyer's avatar Jeroen Demeyer Committed by Stefan Behnel

Minor cleanup in handling METH_xxx flags (#3004)

parent d48b30fd
...@@ -2202,9 +2202,7 @@ class CCodeWriter(object): ...@@ -2202,9 +2202,7 @@ class CCodeWriter(object):
method_flags += [TypeSlots.method_coexist] method_flags += [TypeSlots.method_coexist]
func_ptr = wrapper_code_writer.put_pymethoddef_wrapper(entry) if wrapper_code_writer else entry.func_cname func_ptr = wrapper_code_writer.put_pymethoddef_wrapper(entry) if wrapper_code_writer else entry.func_cname
# Add required casts, but try not to shadow real warnings. # Add required casts, but try not to shadow real warnings.
cast = '__Pyx_PyCFunctionFast' if 'METH_FASTCALL' in method_flags else 'PyCFunction' cast = entry.signature.method_function_type()
if 'METH_KEYWORDS' in method_flags:
cast += 'WithKeywords'
if cast != 'PyCFunction': if cast != 'PyCFunction':
func_ptr = '(void*)(%s)%s' % (cast, func_ptr) func_ptr = '(void*)(%s)%s' % (cast, func_ptr)
self.putln( self.putln(
...@@ -2218,8 +2216,9 @@ class CCodeWriter(object): ...@@ -2218,8 +2216,9 @@ class CCodeWriter(object):
def put_pymethoddef_wrapper(self, entry): def put_pymethoddef_wrapper(self, entry):
func_cname = entry.func_cname func_cname = entry.func_cname
if entry.is_special: if entry.is_special:
method_flags = entry.signature.method_flags() method_flags = entry.signature.method_flags() or []
if method_flags and 'METH_NOARGS' in method_flags: from .TypeSlots import method_noargs
if method_noargs in method_flags:
# Special NOARGS methods really take no arguments besides 'self', but PyCFunction expects one. # Special NOARGS methods really take no arguments besides 'self', but PyCFunction expects one.
func_cname = Naming.method_wrapper_prefix + func_cname func_cname = Naming.method_wrapper_prefix + func_cname
self.putln("static PyObject *%s(PyObject *self, CYTHON_UNUSED PyObject *arg) {return %s(self);}" % ( self.putln("static PyObject *%s(PyObject *self, CYTHON_UNUSED PyObject *arg) {return %s(self);}" % (
......
...@@ -170,6 +170,17 @@ class Signature(object): ...@@ -170,6 +170,17 @@ class Signature(object):
return [method_varargs, method_keywords] return [method_varargs, method_keywords]
return None return None
def method_function_type(self):
# Return the C function type
mflags = self.method_flags()
kw = "WithKeywords" if (method_keywords in mflags) else ""
for m in mflags:
if m == method_noargs or m == method_onearg:
return "PyCFunction"
if m == method_varargs:
return "PyCFunction" + kw
return None
class SlotDescriptor(object): class SlotDescriptor(object):
# Abstract base class for type slot descriptors. # Abstract base class for type slot descriptors.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment