Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r68424:64115be033cf
Date: 2013-12-13 12:57 -0800
http://bitbucket.org/pypy/pypy/changeset/64115be033cf/
Log: merged upstream
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -328,21 +328,23 @@
raise ValueError(
"native COM method call without 'this' parameter"
)
- thisarg = cast(args[0], POINTER(POINTER(c_void_p)))
- keepalives, newargs, argtypes, outargs =
self._convert_args(argtypes,
-
args[1:], kwargs)
- newargs.insert(0, args[0].value)
+ thisvalue = args.pop(0)
+ thisarg = cast(thisvalue, POINTER(POINTER(c_void_p)))
+ keepalives, newargs, argtypes, outargs, errcheckargs = (
+ self._convert_args(argtypes, args, kwargs))
+ args.insert(0, thisvalue)
+ newargs.insert(0, thisvalue.value)
argtypes.insert(0, c_void_p)
else:
thisarg = None
- keepalives, newargs, argtypes, outargs =
self._convert_args(argtypes,
- args,
kwargs)
+ keepalives, newargs, argtypes, outargs, errcheckargs = (
+ self._convert_args(argtypes, args, kwargs))
funcptr = self._getfuncptr(argtypes, self._restype_, thisarg)
result = self._call_funcptr(funcptr, *newargs)
- result = self._do_errcheck(result, args)
+ result, forced = self._do_errcheck(result, errcheckargs)
- if not outargs:
+ if not outargs or forced:
return result
from ctypes import c_void_p
@@ -377,22 +379,22 @@
set_last_error(tmp)
#
try:
- return self._build_result(self._restype_, result, newargs)
+ return self._build_result(self._restype_, result)
finally:
funcptr.free_temp_buffers()
def _do_errcheck(self, result, args):
# The 'errcheck' protocol
if self._errcheck_:
- v = self._errcheck_(result, self, args)
+ v = self._errcheck_(result, self, tuple(args))
# If the errcheck funtion failed, let it throw
# If the errcheck function returned newargs unchanged,
# continue normal processing.
# If the errcheck function returned something else,
# use that as result.
if v is not args:
- return v
- return result
+ return v, True
+ return result, False
def _getfuncptr_fromaddress(self, argtypes, restype):
address = self._get_address()
@@ -495,16 +497,16 @@
newargtypes = []
total = len(args)
paramflags = self._paramflags
- inargs_idx = 0
if not paramflags and total < len(argtypes):
raise TypeError("not enough arguments")
- for i, argtype in enumerate(argtypes):
- flag = 0
- name = None
- defval = marker
- if paramflags:
+ if paramflags:
+ errcheckargs = []
+ inargs_idx = 0
+ for i, argtype in enumerate(argtypes):
+ flag = 0
+ defval = marker
paramflag = paramflags[i]
paramlen = len(paramflag)
name = None
@@ -519,6 +521,7 @@
val = defval
if val is marker:
val = 0
+ errcheckargs.append(val)
keepalive, newarg, newargtype = self._conv_param(argtype,
val)
keepalives.append(keepalive)
newargs.append(newarg)
@@ -536,27 +539,31 @@
raise TypeError("required argument '%s' missing" %
name)
else:
raise TypeError("not enough arguments")
+ errcheckargs.append(val)
keepalive, newarg, newargtype = self._conv_param(argtype,
val)
keepalives.append(keepalive)
newargs.append(newarg)
newargtypes.append(newargtype)
elif flag == PARAMFLAG_FOUT:
if defval is not marker:
- outargs.append(defval)
+ val = defval
keepalive, newarg, newargtype =
self._conv_param(argtype, defval)
else:
import ctypes
val = argtype._type_()
- outargs.append(val)
keepalive = None
newarg = ctypes.byref(val)
newargtype = type(newarg)
+ errcheckargs.append(val)
+ outargs.append(val)
keepalives.append(keepalive)
newargs.append(newarg)
newargtypes.append(newargtype)
else:
raise ValueError("paramflag %d not yet implemented" % flag)
- else:
+ else:
+ errcheckargs = args
+ for i, argtype in enumerate(argtypes):
try:
keepalive, newarg, newargtype = self._conv_param(argtype,
args[i])
except (UnicodeError, TypeError, ValueError), e:
@@ -564,7 +571,6 @@
keepalives.append(keepalive)
newargs.append(newarg)
newargtypes.append(newargtype)
- inargs_idx += 1
if len(newargs) < len(args):
extra = args[len(newargs):]
@@ -576,7 +582,7 @@
keepalives.append(keepalive)
newargs.append(newarg)
newargtypes.append(newargtype)
- return keepalives, newargs, newargtypes, outargs
+ return keepalives, newargs, newargtypes, outargs, errcheckargs
@staticmethod
def _is_primitive(argtype):
@@ -601,7 +607,7 @@
retval = restype._CData_retval(buf)
return retval
- def _build_result(self, restype, result, argsandobjs):
+ def _build_result(self, restype, result):
"""Build the function result:
If there is no OUT parameter, return the actual function result
If there is one OUT parameter, return it
@@ -611,11 +617,6 @@
# i.e. an array of ints. Now it takes a result, which is already a
# python object. All places that do "resbuffer[0]" should check that
# result is actually an int and just use it.
- #
- # Also, argsandobjs used to be "args" in __call__, now it's "newargs"
- # (i.e., the already unwrapped objects). It's used only when we have a
- # PARAMFLAG_FOUT and it's probably wrong, I'll fix it when I find a
- # failing test
retval = None
@@ -704,7 +705,7 @@
funcptr = self._getfuncptr(argtypes, restype, thisarg)
try:
result = self._call_funcptr(funcptr, *args)
- result = self._do_errcheck(result, args)
+ result, _ = self._do_errcheck(result, args)
except (TypeError, ArgumentError, UnicodeDecodeError):
assert self._slowpath_allowed
return CFuncPtr.__call__(self, *args)
diff --git a/pypy/module/math/app_math.py b/pypy/module/math/app_math.py
--- a/pypy/module/math/app_math.py
+++ b/pypy/module/math/app_math.py
@@ -1,5 +1,7 @@
def factorial(x):
- """Find x!."""
+ """factorial(x) -> Integral
+
+ "Find x!. Raise a ValueError if x is negative or non-integral."""
if isinstance(x, float):
fl = int(x)
if fl != x:
@@ -14,15 +16,15 @@
res *= i
return res
- #Experimentally this gap seems good
- gap = max(100, x>>7)
+ # Experimentally this gap seems good
+ gap = max(100, x >> 7)
def _fac_odd(low, high):
- if low+gap >= high:
+ if low + gap >= high:
t = 1
for i in range(low, high, 2):
t *= i
return t
-
+
mid = ((low + high) >> 1) | 1
return _fac_odd(low, mid) * _fac_odd(mid, high)
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -502,3 +502,6 @@
def getlength(self):
return self.impl.size
+
+ def get_raw_address(self):
+ return self.impl.storage
diff --git a/pypy/module/micronumpy/interp_boxes.py
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -163,6 +163,12 @@
assert isinstance(box, W_Float64Box)
return space.wrap(box.value)
+ def descr_oct(self, space):
+ return space.oct(self.descr_int(space))
+
+ def descr_hex(self, space):
+ return space.hex(self.descr_int(space))
+
def descr_nonzero(self, space):
dtype = self.get_dtype(space)
return space.wrap(dtype.itemtype.bool(self))
@@ -320,8 +326,7 @@
pass
class W_IntegerBox(W_NumberBox):
- def int_w(self, space):
- return space.int_w(self.descr_int(space))
+ pass
class W_SignedIntegerBox(W_IntegerBox):
pass
@@ -511,6 +516,8 @@
__long__ = interp2app(W_GenericBox.descr_long),
__float__ = interp2app(W_GenericBox.descr_float),
__nonzero__ = interp2app(W_GenericBox.descr_nonzero),
+ __oct__ = interp2app(W_GenericBox.descr_oct),
+ __hex__ = interp2app(W_GenericBox.descr_hex),
__add__ = interp2app(W_GenericBox.descr_add),
__sub__ = interp2app(W_GenericBox.descr_sub),
diff --git a/pypy/module/micronumpy/interp_flagsobj.py
b/pypy/module/micronumpy/interp_flagsobj.py
--- a/pypy/module/micronumpy/interp_flagsobj.py
+++ b/pypy/module/micronumpy/interp_flagsobj.py
@@ -18,6 +18,16 @@
def descr_get_writeable(self, space):
return space.w_True
+ def descr_get_fnc(self, space):
+ return space.wrap(
+ space.is_true(self.descr_get_fortran(space)) and not
+ space.is_true(self.descr_get_contiguous(space)))
+
+ def descr_get_forc(self, space):
+ return space.wrap(
+ space.is_true(self.descr_get_fortran(space)) or
+ space.is_true(self.descr_get_contiguous(space)))
+
def descr_getitem(self, space, w_item):
key = space.str_w(w_item)
if key == "C" or key == "CONTIGUOUS" or key == "C_CONTIGUOUS":
@@ -26,6 +36,10 @@
return self.descr_get_fortran(space)
if key == "W" or key == "WRITEABLE":
return self.descr_get_writeable(space)
+ if key == "FNC":
+ return self.descr_get_fnc(space)
+ if key == "FORC":
+ return self.descr_get_forc(space)
raise OperationError(space.w_KeyError, space.wrap(
"Unknown flag"))
@@ -56,4 +70,6 @@
f_contiguous = GetSetProperty(W_FlagsObject.descr_get_fortran),
fortran = GetSetProperty(W_FlagsObject.descr_get_fortran),
writeable = GetSetProperty(W_FlagsObject.descr_get_writeable),
+ fnc = GetSetProperty(W_FlagsObject.descr_get_fnc),
+ forc = GetSetProperty(W_FlagsObject.descr_get_forc),
)
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -493,8 +493,11 @@
if not space.is_none(w_dtype):
raise OperationError(space.w_NotImplementedError, space.wrap(
"__array__(dtype) not implemented"))
- # stub implementation of __array__()
- return self
+ if type(self) is W_NDimArray:
+ return self
+ return W_NDimArray.from_shape_and_storage(
+ space, self.get_shape(), self.implementation.storage,
+ self.get_dtype(), w_base=self)
def descr_array_iface(self, space):
addr = self.implementation.get_storage_as_int(space)
@@ -1065,9 +1068,9 @@
return w_obj
pass
-@unwrap_spec(offset=int, order=str)
+@unwrap_spec(offset=int)
def descr_new_array(space, w_subtype, w_shape, w_dtype=None, w_buffer=None,
- offset=0, w_strides=None, order='C'):
+ offset=0, w_strides=None, w_order=None):
from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArray
from pypy.module.micronumpy.support import calc_strides
dtype = space.interp_w(interp_dtype.W_Dtype,
@@ -1101,6 +1104,11 @@
if not shape:
return W_NDimArray.new_scalar(space, dtype)
+ order = order_converter(space, w_order, NPY_CORDER)
+ if order == NPY_CORDER:
+ order = 'C'
+ else:
+ order = 'F'
if space.is_w(w_subtype, space.gettypefor(W_NDimArray)):
return W_NDimArray.from_shape(space, shape, dtype, order)
strides, backstrides = calc_strides(shape, dtype.base, order)
@@ -1172,6 +1180,7 @@
__int__ = interp2app(W_NDimArray.descr_int),
__long__ = interp2app(W_NDimArray.descr_long),
__float__ = interp2app(W_NDimArray.descr_float),
+ __buffer__ = interp2app(W_NDimArray.descr_get_data),
__pos__ = interp2app(W_NDimArray.descr_pos),
__neg__ = interp2app(W_NDimArray.descr_neg),
diff --git a/pypy/module/micronumpy/test/test_flagsobj.py
b/pypy/module/micronumpy/test/test_flagsobj.py
--- a/pypy/module/micronumpy/test/test_flagsobj.py
+++ b/pypy/module/micronumpy/test/test_flagsobj.py
@@ -12,6 +12,10 @@
a = np.array([1,2,3])
assert a.flags.c_contiguous == True
assert a.flags['W'] == True
+ assert a.flags.fnc == False
+ assert a.flags.forc == True
+ assert a.flags['FNC'] == False
+ assert a.flags['FORC'] == True
raises(KeyError, "a.flags['blah']")
raises(KeyError, "a.flags['C_CONTIGUOUS'] = False")
raises((TypeError, AttributeError), "a.flags.c_contiguous = False")
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -271,6 +271,17 @@
# test uninitialized value crash?
assert len(str(a)) > 0
+ import sys
+ for order in [False, True, 'C', 'F']:
+ a = ndarray.__new__(ndarray, (2, 3), float, order=order)
+ assert a.shape == (2, 3)
+ if order in [True, 'F'] and '__pypy__' not in
sys.builtin_module_names:
+ assert a.flags['F']
+ assert not a.flags['C']
+ else:
+ assert a.flags['C']
+ assert not a.flags['F']
+
def test_ndmin(self):
from numpypy import array
@@ -309,6 +320,12 @@
e = d.repeat(3, 0)
assert e.shape == (9, 4, 0)
+ def test_buffer(self):
+ import numpy as np
+ a = np.array([1,2,3])
+ b = buffer(a)
+ assert type(b) is buffer
+
def test_type(self):
from numpypy import array
ar = array(range(5))
@@ -1941,11 +1958,13 @@
assert a.itemsize == 3
a = array(3.1415).astype('S3').dtype
assert a.itemsize == 3
- try:
+
+ import sys
+ if '__pypy__' not in sys.builtin_module_names:
a = array(['1', '2','3']).astype(float)
assert a[2] == 3.0
- except NotImplementedError:
- skip('astype("float") not implemented for str arrays')
+ else:
+ raises(NotImplementedError, array(['1', '2', '3']).astype, float)
def test_base(self):
from numpypy import array
diff --git a/pypy/module/micronumpy/test/test_scalar.py
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -18,6 +18,15 @@
#raises(TypeError, np.complex_, '1+2j')
assert math.isnan(np.complex_(None))
+ def test_builtin(self):
+ import numpy as np
+ assert oct(np.int32(11)) == '013'
+ assert oct(np.float32(11.6)) == '013'
+ assert oct(np.complex64(11-12j)) == '013'
+ assert hex(np.int32(11)) == '0xb'
+ assert hex(np.float32(11.6)) == '0xb'
+ assert hex(np.complex64(11-12j)) == '0xb'
+
def test_pickle(self):
from numpypy import dtype, zeros
try:
diff --git a/pypy/module/micronumpy/test/test_subtype.py
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -50,6 +50,14 @@
b[0]=100
assert a[0,0] == 100
+ assert type(a) is not ndarray
+ assert a[0,0] == 100
+ assert a.base is not None
+ b = a.__array__()
+ assert type(b) is ndarray
+ assert b[0,0] == 100
+ assert b.base is a
+
def test_subtype_view(self):
from numpypy import ndarray, array
class matrix(ndarray):
@@ -62,6 +70,11 @@
assert isinstance(b, matrix)
assert (b == a).all()
+ def test_subtype_like_matrix(self):
+ import numpy as np
+ arr = np.array([1,2,3])
+ ret = np.ndarray.__new__(np.ndarray, arr.shape, arr.dtype, buffer=arr)
+ assert (arr == ret).all()
def test_finalize(self):
#taken from
http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#simple-example-adding-an-extra-attribute-to-ndarray
@@ -245,4 +258,3 @@
assert isinstance(b, D)
c = array(a, float)
assert c.dtype is dtype(float)
-
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
--- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
@@ -567,3 +567,13 @@
errno = result + 1;
return result;
}
+
+EXPORT(int *) test_issue1655(char const *tag, int *len)
+{
+ static int data[] = { -1, -2, -3, -4 };
+ *len = -42;
+ if (strcmp(tag, "testing!") != 0)
+ return NULL;
+ *len = sizeof(data) / sizeof(data[0]);
+ return data;
+}
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -559,3 +559,25 @@
assert (res, n) == (42, 43)
set_errno(0)
assert get_errno() == 0
+
+ def test_issue1655(self):
+ def ret_list_p(icount):
+ def sz_array_p(obj, func, args):
+ assert ('.LP_c_int object' in repr(obj) or
+ '.LP_c_long object' in repr(obj))
+ assert repr(args) in ("('testing!', c_int(4))",
+ "('testing!', c_long(4))")
+ assert args[icount].value == 4
+ return [ obj[i] for i in range(args[icount].value) ]
+ return sz_array_p
+
+ get_data_prototype = CFUNCTYPE(POINTER(c_int),
+ c_char_p, POINTER(c_int))
+ get_data_paramflag = ((1,), (2,))
+ get_data_signature = ('test_issue1655', dll)
+
+ get_data = get_data_prototype( get_data_signature, get_data_paramflag )
+ assert get_data('testing!') == 4
+
+ get_data.errcheck = ret_list_p(1)
+ assert get_data('testing!') == [-1, -2, -3, -4]
diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py
--- a/pypy/objspace/std/floattype.py
+++ b/pypy/objspace/std/floattype.py
@@ -27,12 +27,8 @@
def descr__new__(space, w_floattype, w_x):
from pypy.objspace.std.floatobject import W_FloatObject
w_value = w_x # 'x' is the keyword argument name in CPython
- w_special = space.lookup(w_value, "__float__")
- if w_special is not None:
- w_obj = space.get_and_call_function(w_special, w_value)
- if not space.isinstance_w(w_obj, space.w_float):
- raise OperationError(space.w_TypeError,
- space.wrap("__float__ returned non-float"))
+ if space.lookup(w_value, "__float__") is not None:
+ w_obj = space.float(w_value)
if space.is_w(w_floattype, space.w_float):
return w_obj
value = space.float_w(w_obj)
diff --git a/pypy/objspace/std/inttype.py b/pypy/objspace/std/inttype.py
--- a/pypy/objspace/std/inttype.py
+++ b/pypy/objspace/std/inttype.py
@@ -91,41 +91,15 @@
w_value = w_x # 'x' is the keyword argument name in CPython
value = 0
if w_base is None:
- ok = False
# check for easy cases
if type(w_value) is W_IntObject:
value = w_value.intval
- ok = True
- elif space.isinstance_w(w_value, space.w_str):
- value, w_longval = string_to_int_or_long(space,
space.str_w(w_value))
- ok = True
- elif space.isinstance_w(w_value, space.w_unicode):
- from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
- string = unicode_to_decimal_w(space, w_value)
- value, w_longval = string_to_int_or_long(space, string)
- ok = True
- else:
- # If object supports the buffer interface
- try:
- w_buffer = space.buffer(w_value)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- else:
- buf = space.interp_w(Buffer, w_buffer)
- value, w_longval = string_to_int_or_long(space, buf.as_str())
- ok = True
-
- if not ok:
+ elif space.lookup(w_value, '__int__') is not None or \
+ space.lookup(w_value, '__trunc__') is not None:
# otherwise, use the __int__() or the __trunc__() methods
w_obj = w_value
if space.lookup(w_obj, '__int__') is None:
- if space.lookup(w_obj, '__trunc__') is not None:
- w_obj = space.trunc(w_obj)
- else:
- raise operationerrfmt(space.w_TypeError,
- "int() argument must be a string or a number, not
'%T'",
- w_obj)
+ w_obj = space.trunc(w_obj)
w_obj = space.int(w_obj)
# 'int(x)' should return what x.__int__() returned, which should
# be an int or long or a subclass thereof.
@@ -134,13 +108,26 @@
# int_w is effectively what we want in this case,
# we cannot construct a subclass of int instance with an
# an overflowing long
+ value = space.int_w(w_obj)
+ elif space.isinstance_w(w_value, space.w_str):
+ value, w_longval = string_to_int_or_long(space,
space.str_w(w_value))
+ elif space.isinstance_w(w_value, space.w_unicode):
+ from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
+ string = unicode_to_decimal_w(space, w_value)
+ value, w_longval = string_to_int_or_long(space, string)
+ else:
+ # If object supports the buffer interface
try:
- value = space.int_w(w_obj)
+ w_buffer = space.buffer(w_value)
except OperationError, e:
- if e.match(space, space.w_TypeError):
- raise OperationError(space.w_ValueError,
- space.wrap("value can't be converted to int"))
- raise e
+ if not e.match(space, space.w_TypeError):
+ raise
+ raise operationerrfmt(space.w_TypeError,
+ "int() argument must be a string or a number, not '%T'",
+ w_value)
+ else:
+ buf = space.interp_w(Buffer, w_buffer)
+ value, w_longval = string_to_int_or_long(space, buf.as_str())
else:
base = space.int_w(w_base)
diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -27,6 +27,18 @@
return w_value
elif type(w_value) is W_LongObject:
return newbigint(space, w_longtype, w_value.num)
+ elif (space.lookup(w_value, '__long__') is not None or
+ space.lookup(w_value, '__int__') is not None):
+ w_obj = space.long(w_value)
+ return newbigint(space, w_longtype, space.bigint_w(w_obj))
+ elif space.lookup(w_value, '__trunc__') is not None:
+ w_obj = space.trunc(w_value)
+ # :-( blame CPython 2.7
+ if space.lookup(w_obj, '__long__') is not None:
+ w_obj = space.long(w_obj)
+ else:
+ w_obj = space.int(w_obj)
+ return newbigint(space, w_longtype, space.bigint_w(w_obj))
elif space.isinstance_w(w_value, space.w_str):
return string_to_w_long(space, w_longtype, space.str_w(w_value))
elif space.isinstance_w(w_value, space.w_unicode):
@@ -34,24 +46,9 @@
return string_to_w_long(space, w_longtype,
unicode_to_decimal_w(space, w_value))
else:
- # otherwise, use the __long__() or the __trunc__ methods
- w_obj = w_value
- if (space.lookup(w_obj, '__long__') is not None or
- space.lookup(w_obj, '__int__') is not None):
- w_obj = space.long(w_obj)
- elif space.lookup(w_obj, '__trunc__') is not None:
- w_obj = space.trunc(w_obj)
- # :-( blame CPython 2.7
- if space.lookup(w_obj, '__long__') is not None:
- w_obj = space.long(w_obj)
- else:
- w_obj = space.int(w_obj)
- else:
- raise operationerrfmt(space.w_TypeError,
- "long() argument must be a string or a number, not '%T'",
- w_obj)
- bigint = space.bigint_w(w_obj)
- return newbigint(space, w_longtype, bigint)
+ raise operationerrfmt(space.w_TypeError,
+ "long() argument must be a string or a number, not '%T'",
+ w_value)
else:
base = space.int_w(w_base)
diff --git a/pypy/objspace/std/test/test_intobject.py
b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -478,6 +478,12 @@
return Integral()
assert int(TruncReturnsNonInt()) == 42
+ def test_int_before_string(self):
+ class Integral(str):
+ def __int__(self):
+ return 42
+ assert int(Integral('abc')) == 42
+
def test_getnewargs(self):
assert 0 .__getnewargs__() == (0,)
@@ -488,7 +494,7 @@
# __eq__ & the others.
assert 1 .__cmp__
assert int .__cmp__
-
+
def test_bit_length(self):
for val, bits in [
(0, 0),
diff --git a/pypy/objspace/std/test/test_longobject.py
b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -291,6 +291,12 @@
return Integral()
assert long(TruncReturnsNonLong()) == 42
+ def test_long_before_string(self):
+ class A(str):
+ def __long__(self):
+ return 42
+ assert long(A('abc')) == 42
+
def test_conjugate(self):
assert (7L).conjugate() == 7L
assert (-7L).conjugate() == -7L
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -54,6 +54,12 @@
from rpython.rlib.rfile import create_temp_rfile
return space.appcall(create_temp_rfile)
+@register_flow_sc(os.remove)
+def sc_os_remove(space, *args_w):
+ # on top of PyPy only: 'os.remove != os.unlink'
+ # (on CPython they are '==', but not identical either)
+ return space.appcall(os.unlink, *args_w)
+
# _________________________________________________________________________
# a simplified version of the basic printing routines, for RPython programs
class StdOutBuffer:
diff --git a/rpython/flowspace/test/test_objspace.py
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -1244,6 +1244,20 @@
graph = self.codetest(g)
assert "Undefined closure variable 'b'" in str(excinfo.value)
+ def call_os_remove(msg):
+ os.remove(msg)
+ os.unlink(msg)
+
+ def test_call_os_remove(self):
+ x = self.codetest(self.call_os_remove)
+ simplify_graph(x)
+ self.show(x)
+ ops = x.startblock.operations
+ assert ops[0].opname == 'simple_call'
+ assert ops[0].args[0].value is os.unlink
+ assert ops[1].opname == 'simple_call'
+ assert ops[1].args[0].value is os.unlink
+
DATA = {'x': 5,
'y': 6}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit