Commit 9bb67b49 authored by Stefan Behnel's avatar Stefan Behnel

more builtin method cleanups

parent 96925842
...@@ -108,7 +108,8 @@ builtin_types_table = [ ...@@ -108,7 +108,8 @@ builtin_types_table = [
("bytes", "PyBytes_Type", []), ("bytes", "PyBytes_Type", []),
("str", "PyString_Type", []), ("str", "PyString_Type", []),
("unicode", "PyUnicode_Type", []), ("unicode", "PyUnicode_Type", [("join", "TO", "T", "PyUnicode_Join"),
]),
("tuple", "PyTuple_Type", []), ("tuple", "PyTuple_Type", []),
...@@ -120,7 +121,7 @@ builtin_types_table = [ ...@@ -120,7 +121,7 @@ builtin_types_table = [
("dict", "PyDict_Type", [("items", "T", "O", "PyDict_Items"), ("dict", "PyDict_Type", [("items", "T", "O", "PyDict_Items"),
("keys", "T", "O", "PyDict_Keys"), ("keys", "T", "O", "PyDict_Keys"),
("values","T", "O", "PyDict_Values"), ("values","T", "O", "PyDict_Values"),
("copy", "T", "O", "PyDict_Copy")]), ("copy", "T", "T", "PyDict_Copy")]),
("slice", "PySlice_Type", []), ("slice", "PySlice_Type", []),
# ("file", "PyFile_Type", []), # not in Py3 # ("file", "PyFile_Type", []), # not in Py3
......
...@@ -2187,24 +2187,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): ...@@ -2187,24 +2187,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
node, "PyUnicode_Splitlines", self.PyUnicode_Splitlines_func_type, node, "PyUnicode_Splitlines", self.PyUnicode_Splitlines_func_type,
'splitlines', is_unbound_method, args) '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( PyUnicode_Split_func_type = PyrexTypes.CFuncType(
Builtin.list_type, [ Builtin.list_type, [
PyrexTypes.CFuncTypeArg("str", Builtin.unicode_type, None), PyrexTypes.CFuncTypeArg("str", Builtin.unicode_type, None),
......
...@@ -64,6 +64,7 @@ class Signature(object): ...@@ -64,6 +64,7 @@ class Signature(object):
error_value_map = { error_value_map = {
'O': "NULL", 'O': "NULL",
'T': "NULL",
'i': "-1", 'i': "-1",
'b': "-1", 'b': "-1",
'l': "-1", 'l': "-1",
...@@ -91,6 +92,10 @@ class Signature(object): ...@@ -91,6 +92,10 @@ class Signature(object):
# argument is 'self' for methods or 'class' for classmethods # argument is 'self' for methods or 'class' for classmethods
return self.fixed_arg_format[i] == 'T' 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): def fixed_arg_type(self, i):
return self.format_map[self.fixed_arg_format[i]] return self.format_map[self.fixed_arg_format[i]]
...@@ -110,7 +115,10 @@ class Signature(object): ...@@ -110,7 +115,10 @@ class Signature(object):
else: else:
arg_type = self.fixed_arg_type(i) arg_type = self.fixed_arg_type(i)
args.append(PyrexTypes.CFuncTypeArg("", arg_type, None)) 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() exc_value = self.exception_value()
return PyrexTypes.CFuncType(ret_type, args, exception_value = exc_value) return PyrexTypes.CFuncType(ret_type, args, exception_value = exc_value)
......
...@@ -180,9 +180,12 @@ pipe_sep = u'|' ...@@ -180,9 +180,12 @@ pipe_sep = u'|'
@cython.test_fail_if_path_exists( @cython.test_fail_if_path_exists(
"//CoerceToPyTypeNode", "//CoerceFromPyTypeNode", "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
"//CastNode", "//TypecastNode") "//CastNode", "//TypecastNode",
"//SimpleCallNode//AttributeNode[@is_py_attr = true]")
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//PythonCapiCallNode") "//SimpleCallNode",
"//SimpleCallNode//NoneCheckNode",
"//SimpleCallNode//AttributeNode[@is_py_attr = false]")
def join(unicode sep, l): def join(unicode sep, l):
""" """
>>> l = text.split() >>> l = text.split()
...@@ -197,9 +200,11 @@ def join(unicode sep, l): ...@@ -197,9 +200,11 @@ def join(unicode sep, l):
@cython.test_fail_if_path_exists( @cython.test_fail_if_path_exists(
"//CoerceToPyTypeNode", "//CoerceFromPyTypeNode", "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
"//CastNode", "//TypecastNode", "//NoneCheckNode") "//CastNode", "//TypecastNode", "//NoneCheckNode",
"//SimpleCallNode//AttributeNode[@is_py_attr = true]")
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//PythonCapiCallNode") "//SimpleCallNode",
"//SimpleCallNode//AttributeNode[@is_py_attr = false]")
def join_sep(l): def join_sep(l):
""" """
>>> l = text.split() >>> l = text.split()
......
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