From: Stefan Behnel Date: Sun, 7 Nov 2010 13:11:48 +0000 (+0100) Subject: more builtin method cleanups X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9bb67b4937f6cf0af1da69120936e08c1e54e300;p=cython.git more builtin method cleanups --- diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index 7b20b756..830b3f6f 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -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 diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index a54c916e..ba96caf3 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -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), diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index 9f44eb44..955f66f6 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -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) diff --git a/tests/run/unicodemethods.pyx b/tests/run/unicodemethods.pyx index 74336659..3c0cf6ae 100644 --- a/tests/run/unicodemethods.pyx +++ b/tests/run/unicodemethods.pyx @@ -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()