Commit 46bbbaba authored by Vitja Makarov's avatar Vitja Makarov

Merge remote branch 'upstream/master'

parents 3c2d9b37 e3c9a786
...@@ -2612,6 +2612,7 @@ class SliceIndexNode(ExprNode): ...@@ -2612,6 +2612,7 @@ class SliceIndexNode(ExprNode):
self.start_code(), self.start_code(),
self.stop_code())) self.stop_code()))
self.generate_subexpr_disposal_code(code) self.generate_subexpr_disposal_code(code)
self.free_subexpr_temps(code)
def generate_slice_guard_code(self, code, target_size): def generate_slice_guard_code(self, code, target_size):
if not self.base.type.is_array: if not self.base.type.is_array:
......
...@@ -579,6 +579,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -579,6 +579,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#endif #endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject #define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type #define PyInt_Type PyLong_Type
......
...@@ -2081,7 +2081,7 @@ class DefNode(FuncDefNode): ...@@ -2081,7 +2081,7 @@ class DefNode(FuncDefNode):
# staticmethod() was overridden - not much we can do here ... # staticmethod() was overridden - not much we can do here ...
self.is_staticmethod = False self.is_staticmethod = False
if self.name == '__new__': if self.name == '__new__' and env.is_py_class_scope:
self.is_staticmethod = 1 self.is_staticmethod = 1
self.analyse_argument_types(env) self.analyse_argument_types(env)
......
...@@ -1986,20 +1986,26 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): ...@@ -1986,20 +1986,26 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
test_nodes = [] test_nodes = []
env = self.current_env() env = self.current_env()
for test_type_node in types: for test_type_node in types:
if not test_type_node.entry: builtin_type = None
return node if isinstance(test_type_node, ExprNodes.NameNode):
if test_type_node.entry:
entry = env.lookup(test_type_node.entry.name) entry = env.lookup(test_type_node.entry.name)
if not entry or not entry.type or not entry.type.is_builtin_type: if entry and entry.type and entry.type.is_builtin_type:
return node builtin_type = entry.type
if builtin_type and builtin_type is not Builtin.type_type:
type_check_function = entry.type.type_check_function(exact=False) type_check_function = entry.type.type_check_function(exact=False)
if not type_check_function: type_check_args = [arg]
elif test_type_node.type is Builtin.type_type:
type_check_function = '__Pyx_TypeCheck'
type_check_args = [arg, test_type_node]
else:
return node return node
if type_check_function not in tests: if type_check_function not in tests:
tests.append(type_check_function) tests.append(type_check_function)
test_nodes.append( test_nodes.append(
ExprNodes.PythonCapiCallNode( ExprNodes.PythonCapiCallNode(
test_type_node.pos, type_check_function, self.Py_type_check_func_type, test_type_node.pos, type_check_function, self.Py_type_check_func_type,
args = [arg], args = type_check_args,
is_temp = True, is_temp = True,
)) ))
......
...@@ -1583,9 +1583,8 @@ class CClassScope(ClassScope): ...@@ -1583,9 +1583,8 @@ class CClassScope(ClassScope):
if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'): if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'):
error(pos, "Special method %s must be implemented via __richcmp__" % name) error(pos, "Special method %s must be implemented via __richcmp__" % name)
if name == "__new__": if name == "__new__":
warning(pos, "__new__ method of extension type will change semantics " error(pos, "__new__ method of extension type will change semantics "
"in a future version of Pyrex and Cython. Use __cinit__ instead.") "in a future version of Pyrex and Cython. Use __cinit__ instead.")
name = EncodedString("__cinit__")
entry = self.declare_var(name, py_object_type, pos, visibility='extern') entry = self.declare_var(name, py_object_type, pos, visibility='extern')
special_sig = get_special_method_signature(name) special_sig = get_special_method_signature(name)
if special_sig: if special_sig:
......
...@@ -49,9 +49,9 @@ cdef extern from "Python.h": ...@@ -49,9 +49,9 @@ cdef extern from "Python.h":
# 0 is returned on success and -1 on error. # 0 is returned on success and -1 on error.
void PyBuffer_Release(object obj, object view) void PyBuffer_Release(Py_buffer *view)
# Release the buffer view over obj. This should be called when the # Release the buffer view. This should be called when the buffer
# buffer is no longer being used as it may free memory from it. # is no longer being used as it may free memory from it.
void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices) void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
# ?? # ??
......
"""
>>> a = A() class A(object):
>>> a.f() """
[2, 1] >>> a = A()
>>> a.g() >>> a.f()
(False, True) [2, 1]
>>> del_item({1: 'a', 2: 'b'}, 1) >>> a.g()
{2: 'b'} (False, True)
>>> del_item(list(range(10)), 2) """
[0, 1, 3, 4, 5, 6, 7, 8, 9]
>>> del_dict({1: 'a', 2: 'b'}, 1)
{2: 'b'}
>>> del_list(list(range(5)), 3)
[0, 1, 2, 4]
>>> del_int(list(range(5)), 3)
[0, 1, 2, 4]
>>> del_list_int(list(range(5)), 3)
[0, 1, 2, 4]
>>> del_int({-1: 'neg', 1: 'pos'}, -1)
{1: 'pos'}
"""
class A:
def f(self): def f(self):
self.refs = [3,2,1] self.refs = [3,2,1]
del self.refs[0] del self.refs[0]
...@@ -33,21 +18,65 @@ class A: ...@@ -33,21 +18,65 @@ class A:
return (hasattr(self, u"a"), hasattr(self, u"g")) return (hasattr(self, u"a"), hasattr(self, u"g"))
def del_item(L, o): def del_item(L, o):
"""
>>> del_item({1: 'a', 2: 'b'}, 1)
{2: 'b'}
>>> del_item(list(range(10)), 2)
[0, 1, 3, 4, 5, 6, 7, 8, 9]
"""
del L[o] del L[o]
return L return L
def del_dict(dict D, o): def del_dict(dict D, o):
"""
>>> del_dict({1: 'a', 2: 'b'}, 1)
{2: 'b'}
"""
del D[o] del D[o]
return D return D
def del_list(list L, o): def del_list(list L, o):
"""
>>> del_list(list(range(5)), 3)
[0, 1, 2, 4]
"""
del L[o] del L[o]
return L return L
def del_int(L, int i): def del_int(L, int i):
"""
>>> del_int(list(range(5)), 3)
[0, 1, 2, 4]
>>> del_int({-1: 'neg', 1: 'pos'}, -1)
{1: 'pos'}
"""
del L[i] del L[i]
return L return L
def del_list_int(L, int i): def del_list_int(L, int i):
"""
>>> del_list_int(list(range(5)), 3)
[0, 1, 2, 4]
"""
del L[i] del L[i]
return L return L
def del_temp_slice(a):
"""
>>> class A(object):
... attr = [1,2,3]
>>> a = A()
>>> a.attr
[1, 2, 3]
>>> del_temp_slice(a)
[]
>>> a.attr
[]
>>> del_temp_slice(a)
[]
>>> a.attr
[]
"""
while a.attr:
del a.attr[:]
return a.attr
...@@ -48,6 +48,11 @@ def test_optimised(): ...@@ -48,6 +48,11 @@ def test_optimised():
assert isinstance(complex(), complex) assert isinstance(complex(), complex)
assert not isinstance(u"foo", int) assert not isinstance(u"foo", int)
assert isinstance(A, type) assert isinstance(A, type)
assert isinstance(A(), A)
cdef type typed_type = A
assert isinstance(A(), typed_type)
cdef object untyped_type = A
assert isinstance(A(), <type>untyped_type)
return True return True
@cython.test_assert_path_exists('//PythonCapiCallNode') @cython.test_assert_path_exists('//PythonCapiCallNode')
...@@ -59,13 +64,11 @@ def test_optimised_tuple(): ...@@ -59,13 +64,11 @@ def test_optimised_tuple():
>>> test_optimised_tuple() >>> test_optimised_tuple()
True True
""" """
assert isinstance(int(), (int, long, float, bytes, str, unicode, tuple, list, dict, set, slice)) assert isinstance(int(), (int, long, float, bytes, str, unicode, tuple, list, dict, set, slice, A))
assert isinstance(list(), (int, long, float, bytes, str, unicode, tuple, list, dict, set, slice)) assert isinstance(list(), (int, long, float, bytes, str, unicode, tuple, list, dict, set, slice, A))
assert isinstance(A(), (int, long, float, bytes, str, unicode, tuple, list, dict, set, slice, A))
return True return True
@cython.test_assert_path_exists('//SimpleCallNode//SimpleCallNode')
@cython.test_fail_if_path_exists('//SimpleCallNode//PythonCapiCallNode',
'//PythonCapiCallNode//SimpleCallNode')
def test_custom(): def test_custom():
""" """
>>> test_custom() >>> test_custom()
......
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