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