import Options
from Cython.Utils import open_new_file
from PyrexTypes import py_object_type, typecast
-from TypeSlots import get_special_method_signature, method_coexist
+from TypeSlots import method_coexist
class CCodeWriter:
# f file output file
doc_code = 0
method_flags = entry.signature.method_flags()
if method_flags:
- if get_special_method_signature(entry.name):
+ if entry.is_special:
method_flags += [method_coexist]
self.putln(
'{"%s", (PyCFunction)%s, %s, %s}%s' % (
def analyse_signature(self, env):
any_type_tests_needed = 0
# Use the simpler calling signature for zero- and one-argument functions.
- if self.entry.signature is TypeSlots.pyfunction_signature:
- if len(self.args) == 0:
- self.entry.signature = TypeSlots.pyfunction_noargs
- elif len(self.args) == 1 and self.args[0].type.is_pyobject and self.args[0].default is None:
- self.entry.signature = TypeSlots.pyfunction_onearg
- elif self.entry.signature is TypeSlots.pymethod_signature:
- if len(self.args) == 1:
- self.entry.signature = TypeSlots.unaryfunc
- elif len(self.args) == 2 and self.args[1].type.is_pyobject and self.args[1].default is None:
- self.entry.signature = TypeSlots.ibinaryfunc
+ if not self.entry.is_special and not self.star_arg and not self.starstar_arg:
+ if self.entry.signature is TypeSlots.pyfunction_signature:
+ if len(self.args) == 0:
+ self.entry.signature = TypeSlots.pyfunction_noargs
+ elif len(self.args) == 1 and self.args[0].default is None:
+ self.entry.signature = TypeSlots.pyfunction_onearg
+ elif self.entry.signature is TypeSlots.pymethod_signature:
+ if len(self.args) == 1:
+ self.entry.signature = TypeSlots.unaryfunc
+ elif len(self.args) == 2 and self.args[1].default is None:
+ self.entry.signature = TypeSlots.ibinaryfunc
sig = self.entry.signature
nfixed = sig.num_fixed_args()
for i in range(nfixed):
else:
arg_code_list.append(
arg.hdr_type.declaration_code(arg.hdr_cname))
- if self.entry.meth_flags == [TypeSlots.method_noargs]:
+ if not self.entry.is_special and sig.method_flags() == [TypeSlots.method_noargs]:
arg_code_list.append("PyObject *unused")
if sig.has_generic_args:
arg_code_list.append(
code.putln("PyObject *%s = 0;" % arg.hdr_cname)
else:
code.put_var_declaration(arg.entry)
-
def generate_keyword_list(self, code):
if self.entry.signature.has_generic_args:
old_type = arg.hdr_type
new_type = arg.type
if old_type.is_pyobject:
- code.putln("if (%s) {" % arg.hdr_cname)
+ code.putln("if (likely(%s)) {" % arg.hdr_cname)
self.generate_arg_conversion_from_pyobject(arg, code)
code.putln("}")
elif new_type.is_pyobject:
# is_pyglobal boolean Is a Python module-level variable
# or class attribute during
# class construction
+ # is_special boolean Is a special class method
# is_variable boolean Is a variable
# is_cfunction boolean Is a C function
# is_cmethod boolean Is a C method of an extension type
is_builtin = 0
is_cglobal = 0
is_pyglobal = 0
+ is_special = 0
is_variable = 0
is_cfunction = 0
is_cmethod = 0
# Create new entry, and add to dictionary if
# name is not None. Reports a warning if already
# declared.
- if not self.in_cinclude and re.match("^_[_A-Z]+$", cname):
+ if not self.in_cinclude and cname and re.match("^_[_A-Z]+$", cname):
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
- error(pos, "'%s' is a reserved name in C." % cname)
+ warning(pos, "'%s' is a reserved name in C." % cname, -1)
dict = self.entries
if name and dict.has_key(name):
warning(pos, "'%s' redeclared " % name, 0)
# Special methods get put in the method table with a particular
# signature declared in advance.
entry.signature = special_sig
+ entry.is_special = 1
else:
entry.signature = pymethod_signature
+ entry.is_special = 0
self.pyfunc_entries.append(entry)
return entry