fix ticket #589: bound methods of optimised builtin types
authorStefan Behnel <scoder@users.berlios.de>
Mon, 8 Nov 2010 07:46:41 +0000 (08:46 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 8 Nov 2010 07:46:41 +0000 (08:46 +0100)
Cython/Compiler/Builtin.py
Cython/Compiler/Symtab.py
tests/bugs.txt
tests/run/bound_builtin_methods_T589.pyx

index c67175bdc82307ab32b1e82f54de8c630cdaaa28..0662ef0b3d0b18bf6f590f43cc549660a18b9a12 100644 (file)
@@ -320,8 +320,8 @@ class BuiltinMethod(_BuiltinOverride):
             self_arg = PyrexTypes.CFuncTypeArg("", self_type, None)
             self_arg.not_none = True
             method_type = sig.function_type(self_arg)
-        self_type.scope.declare_cfunction(self.py_name, method_type, None, self.cname,
-                                          utility_code = self.utility_code)
+        self_type.scope.declare_builtin_cfunction(
+            self.py_name, method_type, self.cname, utility_code = self.utility_code)
 
 
 builtin_function_table = [
index 021435a5419cecd7c9199c866f31e54b7ca41c34..c6062ec15b7cc841cf250d94ef8d4b6069b71b98 100644 (file)
@@ -1586,7 +1586,20 @@ class CClassScope(ClassScope):
         entry.is_cmethod = 1
         entry.prev_entry = prev_entry
         return entry
-    
+
+    def declare_builtin_cfunction(self, name, type, cname, utility_code = None):
+        # overridden methods of builtin types still have their Python
+        # equivalent that must be accessible to support bound methods
+        name = EncodedString(name)
+        entry = self.declare_cfunction(name, type, None, cname, visibility='extern',
+                                       utility_code = utility_code)
+        var_entry = Entry(name, name, py_object_type)
+        var_entry.is_variable = 1
+        var_entry.is_builtin = 1
+        var_entry.utility_code = utility_code
+        entry.as_variable = var_entry
+        return entry
+
     def declare_property(self, name, doc, pos):
         entry = self.lookup_here(name)
         if entry is None:
index 7ed33400d149fddf7156fca4ca31869e3e7e7861..d172b4c68354d741e6862df0de969853c8c81068 100644 (file)
@@ -16,7 +16,6 @@ with_statement_module_level_T536
 function_as_method_T494
 closure_inside_cdef_T554
 ipow_crash_T562
-bound_builtin_methods_T589
 
 
 # CPython regression tests that don't current work:
index 0439489280abefa23f6108e63fc4c9700b022598..4e9cff0b8c7f8e25371d89bbcfc16d561cfee2dc 100644 (file)
@@ -1,6 +1,8 @@
 
 cimport cython
 
+_set = set # CPython may not define it (in Py2.3), but Cython does :)
+
 def test_set_clear_bound():
     """
     >>> type(test_set_clear_bound()) is _set