Commit 2bff23cb authored by Robert Bradshaw's avatar Robert Bradshaw

avoid argument parsing (via meth_o, meth_noargs) for non-python-object...

avoid argument parsing (via meth_o, meth_noargs) for non-python-object arguments, upgrade version number to 0.9.6.4

compiles and runs SAGE fine
parent 4eba71dc
...@@ -6,7 +6,7 @@ import Naming ...@@ -6,7 +6,7 @@ import Naming
import Options import Options
from Cython.Utils import open_new_file from Cython.Utils import open_new_file
from PyrexTypes import py_object_type, typecast from PyrexTypes import py_object_type, typecast
from TypeSlots import get_special_method_signature, method_coexist from TypeSlots import method_coexist
class CCodeWriter: class CCodeWriter:
# f file output file # f file output file
...@@ -291,7 +291,7 @@ class CCodeWriter: ...@@ -291,7 +291,7 @@ class CCodeWriter:
doc_code = 0 doc_code = 0
method_flags = entry.signature.method_flags() method_flags = entry.signature.method_flags()
if method_flags: if method_flags:
if get_special_method_signature(entry.name): if entry.is_special:
method_flags += [method_coexist] method_flags += [method_coexist]
self.putln( self.putln(
'{"%s", (PyCFunction)%s, %s, %s}%s' % ( '{"%s", (PyCFunction)%s, %s, %s}%s' % (
......
...@@ -821,16 +821,17 @@ class DefNode(FuncDefNode): ...@@ -821,16 +821,17 @@ class DefNode(FuncDefNode):
def analyse_signature(self, env): def analyse_signature(self, env):
any_type_tests_needed = 0 any_type_tests_needed = 0
# Use the simpler calling signature for zero- and one-argument functions. # Use the simpler calling signature for zero- and one-argument functions.
if self.entry.signature is TypeSlots.pyfunction_signature: if not self.entry.is_special and not self.star_arg and not self.starstar_arg:
if len(self.args) == 0: if self.entry.signature is TypeSlots.pyfunction_signature:
self.entry.signature = TypeSlots.pyfunction_noargs if len(self.args) == 0:
elif len(self.args) == 1 and self.args[0].type.is_pyobject and self.args[0].default is None: self.entry.signature = TypeSlots.pyfunction_noargs
self.entry.signature = TypeSlots.pyfunction_onearg elif len(self.args) == 1 and self.args[0].default is None:
elif self.entry.signature is TypeSlots.pymethod_signature: self.entry.signature = TypeSlots.pyfunction_onearg
if len(self.args) == 1: elif self.entry.signature is TypeSlots.pymethod_signature:
self.entry.signature = TypeSlots.unaryfunc if len(self.args) == 1:
elif len(self.args) == 2 and self.args[1].type.is_pyobject and self.args[1].default is None: self.entry.signature = TypeSlots.unaryfunc
self.entry.signature = TypeSlots.ibinaryfunc elif len(self.args) == 2 and self.args[1].default is None:
self.entry.signature = TypeSlots.ibinaryfunc
sig = self.entry.signature sig = self.entry.signature
nfixed = sig.num_fixed_args() nfixed = sig.num_fixed_args()
for i in range(nfixed): for i in range(nfixed):
...@@ -975,7 +976,7 @@ class DefNode(FuncDefNode): ...@@ -975,7 +976,7 @@ class DefNode(FuncDefNode):
else: else:
arg_code_list.append( arg_code_list.append(
arg.hdr_type.declaration_code(arg.hdr_cname)) 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") arg_code_list.append("PyObject *unused")
if sig.has_generic_args: if sig.has_generic_args:
arg_code_list.append( arg_code_list.append(
...@@ -1004,7 +1005,6 @@ class DefNode(FuncDefNode): ...@@ -1004,7 +1005,6 @@ class DefNode(FuncDefNode):
code.putln("PyObject *%s = 0;" % arg.hdr_cname) code.putln("PyObject *%s = 0;" % arg.hdr_cname)
else: else:
code.put_var_declaration(arg.entry) code.put_var_declaration(arg.entry)
def generate_keyword_list(self, code): def generate_keyword_list(self, code):
if self.entry.signature.has_generic_args: if self.entry.signature.has_generic_args:
...@@ -1116,7 +1116,7 @@ class DefNode(FuncDefNode): ...@@ -1116,7 +1116,7 @@ class DefNode(FuncDefNode):
old_type = arg.hdr_type old_type = arg.hdr_type
new_type = arg.type new_type = arg.type
if old_type.is_pyobject: 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) self.generate_arg_conversion_from_pyobject(arg, code)
code.putln("}") code.putln("}")
elif new_type.is_pyobject: elif new_type.is_pyobject:
......
...@@ -29,6 +29,7 @@ class Entry: ...@@ -29,6 +29,7 @@ class Entry:
# is_pyglobal boolean Is a Python module-level variable # is_pyglobal boolean Is a Python module-level variable
# or class attribute during # or class attribute during
# class construction # class construction
# is_special boolean Is a special class method
# is_variable boolean Is a variable # is_variable boolean Is a variable
# is_cfunction boolean Is a C function # is_cfunction boolean Is a C function
# is_cmethod boolean Is a C method of an extension type # is_cmethod boolean Is a C method of an extension type
...@@ -69,6 +70,7 @@ class Entry: ...@@ -69,6 +70,7 @@ class Entry:
is_builtin = 0 is_builtin = 0
is_cglobal = 0 is_cglobal = 0
is_pyglobal = 0 is_pyglobal = 0
is_special = 0
is_variable = 0 is_variable = 0
is_cfunction = 0 is_cfunction = 0
is_cmethod = 0 is_cmethod = 0
...@@ -199,9 +201,9 @@ class Scope: ...@@ -199,9 +201,9 @@ class Scope:
# Create new entry, and add to dictionary if # Create new entry, and add to dictionary if
# name is not None. Reports a warning if already # name is not None. Reports a warning if already
# declared. # 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 # 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 dict = self.entries
if name and dict.has_key(name): if name and dict.has_key(name):
warning(pos, "'%s' redeclared " % name, 0) warning(pos, "'%s' redeclared " % name, 0)
...@@ -1089,8 +1091,10 @@ class CClassScope(ClassScope): ...@@ -1089,8 +1091,10 @@ class CClassScope(ClassScope):
# Special methods get put in the method table with a particular # Special methods get put in the method table with a particular
# signature declared in advance. # signature declared in advance.
entry.signature = special_sig entry.signature = special_sig
entry.is_special = 1
else: else:
entry.signature = pymethod_signature entry.signature = pymethod_signature
entry.is_special = 0
self.pyfunc_entries.append(entry) self.pyfunc_entries.append(entry)
return entry return entry
......
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