avoid argument parsing (via meth_o, meth_noargs) for non-python-object arguments...
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 19 Aug 2007 11:14:41 +0000 (04:14 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 19 Aug 2007 11:14:41 +0000 (04:14 -0700)
compiles and runs SAGE fine

Cython/Compiler/Code.py
Cython/Compiler/Nodes.py
Cython/Compiler/Symtab.py

index c24541ecd6863326d78b3de4005a320e7949cb08..f52f6962775e87fbe2e7905f5a07400020c38873 100644 (file)
@@ -6,7 +6,7 @@ import Naming
 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
@@ -291,7 +291,7 @@ class CCodeWriter:
             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' % (
index 498c9aa99b38f89e449cbbaaedeeef46fb220ecb..86ec00d8e102a7d2c2beda9ae3c67c553436c362 100644 (file)
@@ -821,16 +821,17 @@ class DefNode(FuncDefNode):
     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):
@@ -975,7 +976,7 @@ class DefNode(FuncDefNode):
                 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(
@@ -1004,7 +1005,6 @@ class DefNode(FuncDefNode):
                     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:
@@ -1116,7 +1116,7 @@ class DefNode(FuncDefNode):
         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:
index 0cdd70d5ea7fe25c112856d044386da69e621a03..592b56982c6b82d589046210f6457cfdb01e8d33 100644 (file)
@@ -29,6 +29,7 @@ class Entry:
     # 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
@@ -69,6 +70,7 @@ class Entry:
     is_builtin = 0
     is_cglobal = 0
     is_pyglobal = 0
+    is_special = 0
     is_variable = 0
     is_cfunction = 0
     is_cmethod = 0
@@ -199,9 +201,9 @@ class Scope:
         # 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)
@@ -1089,8 +1091,10 @@ class CClassScope(ClassScope):
             # 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