more builtin method cleanups
authorStefan Behnel <scoder@users.berlios.de>
Sun, 7 Nov 2010 13:11:48 +0000 (14:11 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 7 Nov 2010 13:11:48 +0000 (14:11 +0100)
Cython/Compiler/Builtin.py
Cython/Compiler/Optimize.py
Cython/Compiler/TypeSlots.py
tests/run/unicodemethods.pyx

index 7b20b756904854824fe28275117527e9fd2b0b5b..830b3f6f8099a0e20df794c26d7f1b06e8f462bf 100644 (file)
@@ -108,7 +108,8 @@ builtin_types_table = [
 
     ("bytes",   "PyBytes_Type",    []),
     ("str",     "PyString_Type",   []),
-    ("unicode", "PyUnicode_Type",  []),
+    ("unicode", "PyUnicode_Type",  [("join",  "TO",   "T", "PyUnicode_Join"),
+                                    ]),
 
     ("tuple",   "PyTuple_Type",    []),
 
@@ -120,7 +121,7 @@ builtin_types_table = [
     ("dict",    "PyDict_Type",     [("items", "T",   "O", "PyDict_Items"),
                                     ("keys",  "T",   "O", "PyDict_Keys"),
                                     ("values","T",   "O", "PyDict_Values"),
-                                    ("copy",  "T",   "O", "PyDict_Copy")]),
+                                    ("copy",  "T",   "T", "PyDict_Copy")]),
 
     ("slice",   "PySlice_Type",    []),
 #    ("file",    "PyFile_Type",     []),  # not in Py3
index a54c916ed986d3ca721f5346b86cc3af9e36d804..ba96caf345d0dc8f2a29685e35dc5dc3ba6adcfd 100644 (file)
@@ -2187,24 +2187,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
             node, "PyUnicode_Splitlines", self.PyUnicode_Splitlines_func_type,
             'splitlines', is_unbound_method, args)
 
-    PyUnicode_Join_func_type = PyrexTypes.CFuncType(
-        Builtin.unicode_type, [
-            PyrexTypes.CFuncTypeArg("sep", Builtin.unicode_type, None),
-            PyrexTypes.CFuncTypeArg("iterable", PyrexTypes.py_object_type, None),
-            ])
-
-    def _handle_simple_method_unicode_join(self, node, args, is_unbound_method):
-        """Replace unicode.join(...) by a direct call to the
-        corresponding C-API function.
-        """
-        if len(args) != 2:
-            self._error_wrong_arg_count('unicode.join', node, args, 2)
-            return node
-
-        return self._substitute_method_call(
-            node, "PyUnicode_Join", self.PyUnicode_Join_func_type,
-            'join', is_unbound_method, args)
-
     PyUnicode_Split_func_type = PyrexTypes.CFuncType(
         Builtin.list_type, [
             PyrexTypes.CFuncTypeArg("str", Builtin.unicode_type, None),
index 9f44eb4462b3216f4d4b9fbefa5b92922fd67f63..955f66f65d79b55485ded5f9af3dde6990d75895 100644 (file)
@@ -64,6 +64,7 @@ class Signature(object):
     
     error_value_map = {
         'O': "NULL",
+        'T': "NULL",
         'i': "-1",
         'b': "-1",
         'l': "-1",
@@ -91,6 +92,10 @@ class Signature(object):
         # argument is 'self' for methods or 'class' for classmethods
         return self.fixed_arg_format[i] == 'T'
     
+    def returns_self_type(self):
+        # return type is same as 'self' argument type
+        return self.ret_format == 'T'
+    
     def fixed_arg_type(self, i):
         return self.format_map[self.fixed_arg_format[i]]
     
@@ -110,7 +115,10 @@ class Signature(object):
             else:
                 arg_type = self.fixed_arg_type(i)
                 args.append(PyrexTypes.CFuncTypeArg("", arg_type, None))
-        ret_type = self.return_type()
+        if self_arg_override is not None and self.returns_self_type():
+            ret_type = self_arg_override.type
+        else:
+            ret_type = self.return_type()
         exc_value = self.exception_value()
         return PyrexTypes.CFuncType(ret_type, args, exception_value = exc_value)
 
index 743366595fdb7dd7742630177349adabeb501c07..3c0cf6ae5815faa66a0a1449f7286c3fe237b15d 100644 (file)
@@ -180,9 +180,12 @@ pipe_sep = u'|'
 
 @cython.test_fail_if_path_exists(
     "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
-    "//CastNode", "//TypecastNode")
+    "//CastNode", "//TypecastNode",
+    "//SimpleCallNode//AttributeNode[@is_py_attr = true]")
 @cython.test_assert_path_exists(
-    "//PythonCapiCallNode")
+    "//SimpleCallNode",
+    "//SimpleCallNode//NoneCheckNode",
+    "//SimpleCallNode//AttributeNode[@is_py_attr = false]")
 def join(unicode sep, l):
     """
     >>> l = text.split()
@@ -197,9 +200,11 @@ def join(unicode sep, l):
 
 @cython.test_fail_if_path_exists(
     "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
-    "//CastNode", "//TypecastNode", "//NoneCheckNode")
+    "//CastNode", "//TypecastNode", "//NoneCheckNode",
+    "//SimpleCallNode//AttributeNode[@is_py_attr = true]")
 @cython.test_assert_path_exists(
-    "//PythonCapiCallNode")
+    "//SimpleCallNode",
+    "//SimpleCallNode//AttributeNode[@is_py_attr = false]")
 def join_sep(l):
     """
     >>> l = text.split()