Author: Taavi Burns <[email protected]>
Branch: numpy-ufuncs2
Changeset: r53511:f0195130288b
Date: 2012-03-13 15:50 -0700
http://bitbucket.org/pypy/pypy/changeset/f0195130288b/
Log: merge with default
diff --git a/lib-python/2.7/SimpleXMLRPCServer.py
b/lib-python/2.7/SimpleXMLRPCServer.py
--- a/lib-python/2.7/SimpleXMLRPCServer.py
+++ b/lib-python/2.7/SimpleXMLRPCServer.py
@@ -486,7 +486,10 @@
L = []
while size_remaining:
chunk_size = min(size_remaining, max_chunk_size)
- L.append(self.rfile.read(chunk_size))
+ chunk = self.rfile.read(chunk_size)
+ if not chunk:
+ break
+ L.append(chunk)
size_remaining -= len(L[-1])
data = ''.join(L)
diff --git a/lib-python/2.7/test/test_xmlrpc.py
b/lib-python/2.7/test/test_xmlrpc.py
--- a/lib-python/2.7/test/test_xmlrpc.py
+++ b/lib-python/2.7/test/test_xmlrpc.py
@@ -308,7 +308,7 @@
global ADDR, PORT, URL
ADDR, PORT = serv.socket.getsockname()
#connect to IP address directly. This avoids
socket.create_connection()
- #trying to connect to to "localhost" using all address families, which
+ #trying to connect to "localhost" using all address families, which
#causes slowdown e.g. on vista which supports AF_INET6. The server
listens
#on AF_INET only.
URL = "http://%s:%d"%(ADDR, PORT)
@@ -367,7 +367,7 @@
global ADDR, PORT, URL
ADDR, PORT = serv.socket.getsockname()
#connect to IP address directly. This avoids
socket.create_connection()
- #trying to connect to to "localhost" using all address families, which
+ #trying to connect to "localhost" using all address families, which
#causes slowdown e.g. on vista which supports AF_INET6. The server
listens
#on AF_INET only.
URL = "http://%s:%d"%(ADDR, PORT)
@@ -472,6 +472,9 @@
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
+ def test_unicode_host(self):
+ server = xmlrpclib.ServerProxy(u"http://%s:%d/RPC2"%(ADDR, PORT))
+ self.assertEqual(server.add("a", u"\xe9"), u"a\xe9")
# [ch] The test 404 is causing lots of false alarms.
def XXXtest_404(self):
@@ -586,6 +589,12 @@
# This avoids waiting for the socket timeout.
self.test_simple1()
+ def test_partial_post(self):
+ # Check that a partial POST doesn't make the server loop: issue #14001.
+ conn = httplib.HTTPConnection(ADDR, PORT)
+ conn.request('POST', '/RPC2 HTTP/1.0\r\nContent-Length:
100\r\n\r\nbye')
+ conn.close()
+
class MultiPathServerTestCase(BaseServerTestCase):
threadFunc = staticmethod(http_multi_server)
request_count = 2
diff --git a/lib-python/modified-2.7/distutils/sysconfig_pypy.py
b/lib-python/modified-2.7/distutils/sysconfig_pypy.py
--- a/lib-python/modified-2.7/distutils/sysconfig_pypy.py
+++ b/lib-python/modified-2.7/distutils/sysconfig_pypy.py
@@ -60,6 +60,7 @@
g['EXE'] = ""
g['SO'] = _get_so_extension() or ".so"
g['SOABI'] = g['SO'].rsplit('.')[0]
+ g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
global _config_vars
_config_vars = g
@@ -71,6 +72,7 @@
g['EXE'] = ".exe"
g['SO'] = _get_so_extension() or ".pyd"
g['SOABI'] = g['SO'].rsplit('.')[0]
+ g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
global _config_vars
_config_vars = g
diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -599,7 +599,7 @@
# if convenient for the backend, we compute the info about
# the flag as (byte-offset, single-byte-flag).
import struct
- value = struct.pack("l", flag_word)
+ value = struct.pack(lltype.SignedFmt, flag_word)
assert value.count('\x00') == len(value) - 1 # only one byte is != 0
i = 0
while value[i] == '\x00': i += 1
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -4,7 +4,7 @@
from pypy.rpython.ootypesystem import ootype
from pypy.rlib.objectmodel import we_are_translated, Symbolic
from pypy.rlib.objectmodel import compute_unique_id
-from pypy.rlib.rarithmetic import r_int64
+from pypy.rlib.rarithmetic import r_int64, is_valid_int
from pypy.conftest import option
from pypy.jit.metainterp.resoperation import ResOperation, rop
@@ -213,7 +213,7 @@
def __init__(self, value):
if not we_are_translated():
- if isinstance(value, int):
+ if is_valid_int(value):
value = int(value) # bool -> int
else:
assert isinstance(value, Symbolic)
diff --git a/pypy/module/marshal/interp_marshal.py
b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -327,8 +327,10 @@
# %r not supported in rpython
#u.raise_exc('invalid typecode in unmarshal: %r' % tc)
c = ord(tc)
- if c < 32 or c > 126:
- s = '\\x' + hex(c)
+ if c < 16:
+ s = '\\x0%x' % c
+ elif c < 32 or c > 126:
+ s = '\\x%x' % c
elif tc == '\\':
s = r'\\'
else:
diff --git a/pypy/module/marshal/test/test_marshal.py
b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -174,6 +174,11 @@
pass
raises(ValueError, marshal.dumps, subtype)
+ def test_bad_typecode(self):
+ import marshal
+ exc = raises(ValueError, marshal.loads, chr(1))
+ assert r"'\x01'" in exc.value.message
+
class AppTestRope(AppTestMarshal):
def setup_class(cls):
diff --git a/pypy/module/mmap/__init__.py b/pypy/module/mmap/__init__.py
--- a/pypy/module/mmap/__init__.py
+++ b/pypy/module/mmap/__init__.py
@@ -18,7 +18,7 @@
def buildloaders(cls):
from pypy.module.mmap import interp_mmap
for constant, value in rmmap.constants.iteritems():
- if isinstance(value, int):
+ if isinstance(value, (int, long)):
Module.interpleveldefs[constant] = "space.wrap(%r)" % value
super(Module, cls).buildloaders()
diff --git a/pypy/module/signal/interp_signal.py
b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -11,11 +11,11 @@
import sys
from pypy.tool import autopath
from pypy.rlib import jit, rposix
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, is_valid_int
def setup():
for key, value in cpy_signal.__dict__.items():
- if key.startswith('SIG') and isinstance(value, int):
+ if key.startswith('SIG') and is_valid_int(value):
globals()[key] = value
yield key
diff --git a/pypy/objspace/flow/model.py b/pypy/objspace/flow/model.py
--- a/pypy/objspace/flow/model.py
+++ b/pypy/objspace/flow/model.py
@@ -8,6 +8,8 @@
from pypy.tool.descriptor import roproperty
from pypy.tool.sourcetools import PY_IDENTIFIER, nice_repr_for_func
from pypy.tool.identity_dict import identity_dict
+from pypy.rlib.rarithmetic import is_valid_int
+
"""
memory size before and after introduction of __slots__
@@ -542,7 +544,7 @@
cases = [link.exitcase for link in block.exits]
has_default = cases[-1] == 'default'
for n in cases[:len(cases)-has_default]:
- if isinstance(n, (int, long)):
+ if is_valid_int(n):
continue
if isinstance(n, (str, unicode)) and len(n) == 1:
continue
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -14,6 +14,7 @@
from pypy.objspace.flow import flowcontext, operation, specialcase
from pypy.rlib.unroll import unrolling_iterable, _unroller
from pypy.rlib import rstackovf, rarithmetic
+from pypy.rlib.rarithmetic import is_valid_int
# method-wrappers have not enough introspection in CPython
@@ -141,7 +142,7 @@
def int_w(self, w_obj):
if isinstance(w_obj, Constant):
val = w_obj.value
- if type(val) not in (int,long):
+ if not is_valid_int(val):
raise TypeError("expected integer: " + repr(w_obj))
return val
return self.unwrap(w_obj)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -9,7 +9,7 @@
from pypy.objspace.descroperation import DescrOperation, raiseattrerror
from pypy.rlib.objectmodel import instantiate, r_dict, specialize,
is_annotation_constant
from pypy.rlib.debug import make_sure_not_resized
-from pypy.rlib.rarithmetic import base_int, widen
+from pypy.rlib.rarithmetic import base_int, widen, maxint
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib import jit
@@ -165,6 +165,10 @@
return self.newbool(x)
else:
return self.newint(x)
+ # this is an inlined 'is_valid_int' which cannot be used
+ # due to the special annotation nature of 'wrap'.
+ if isinstance(x, long) and (-maxint - 1 <= x <= maxint):
+ return self.newint(x)
if isinstance(x, str):
return wrapstr(self, x)
if isinstance(x, unicode):
diff --git a/pypy/rlib/_rffi_stacklet.py b/pypy/rlib/_rffi_stacklet.py
--- a/pypy/rlib/_rffi_stacklet.py
+++ b/pypy/rlib/_rffi_stacklet.py
@@ -3,6 +3,7 @@
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rpython.tool import rffi_platform
+from pypy.rlib.rarithmetic import is_emulated_long
import sys
@@ -14,7 +15,11 @@
separate_module_sources = ['#include "src/stacklet/stacklet.c"\n'],
)
if sys.platform == 'win32':
- eci.separate_module_files += (cdir / "src/stacklet/switch_x86_msvc.asm", )
+ if is_emulated_long:
+ asmsrc = 'switch_x64_msvc.asm'
+ else:
+ asmsrc = 'switch_x86_msvc.asm'
+ eci.separate_module_files += (cdir / 'src' / 'stacklet' / asmsrc, )
eci.export_symbols += (
'stacklet_newthread',
'stacklet_deletethread',
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -5,7 +5,7 @@
from pypy.rpython.tool import rffi_platform
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.rarithmetic import intmask, r_uint
+from pypy.rlib.rarithmetic import intmask, r_uint, is_emulated_long
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.rmmap import alloc
from pypy.rlib.rdynload import dlopen, dlclose, dlsym, dlsym_byordinal
@@ -27,6 +27,7 @@
_MSVC = platform.name == "msvc"
_MINGW = platform.name == "mingw32"
_WIN32 = _MSVC or _MINGW
+_WIN64 = _WIN32 and is_emulated_long
_MAC_OS = platform.name == "darwin"
_FREEBSD_7 = platform.name == "freebsd7"
@@ -119,6 +120,10 @@
])
else:
libffidir = py.path.local(pypydir).join('translator', 'c', 'src',
'libffi_msvc')
+ if not _WIN64:
+ asm_ifc = 'win32.c'
+ else:
+ asm_ifc = 'win64.asm'
eci = ExternalCompilationInfo(
includes = ['ffi.h', 'windows.h'],
libraries = ['kernel32'],
@@ -126,7 +131,7 @@
separate_module_sources = separate_module_sources,
separate_module_files = [libffidir.join('ffi.c'),
libffidir.join('prep_cif.c'),
- libffidir.join('win32.c'),
+ libffidir.join(asm_ifc),
libffidir.join('pypy_ffi.c'),
],
export_symbols = ['ffi_call', 'ffi_prep_cif', 'ffi_prep_closure',
@@ -142,7 +147,7 @@
FFI_OK = rffi_platform.ConstantInteger('FFI_OK')
FFI_BAD_TYPEDEF = rffi_platform.ConstantInteger('FFI_BAD_TYPEDEF')
FFI_DEFAULT_ABI = rffi_platform.ConstantInteger('FFI_DEFAULT_ABI')
- if _WIN32:
+ if _WIN32 and not _WIN64:
FFI_STDCALL = rffi_platform.ConstantInteger('FFI_STDCALL')
FFI_TYPE_STRUCT = rffi_platform.ConstantInteger('FFI_TYPE_STRUCT')
@@ -312,7 +317,7 @@
FFI_OK = cConfig.FFI_OK
FFI_BAD_TYPEDEF = cConfig.FFI_BAD_TYPEDEF
FFI_DEFAULT_ABI = cConfig.FFI_DEFAULT_ABI
-if _WIN32:
+if _WIN32 and not _WIN64:
FFI_STDCALL = cConfig.FFI_STDCALL
FFI_TYPE_STRUCT = cConfig.FFI_TYPE_STRUCT
FFI_CIFP = rffi.COpaquePtr('ffi_cif', compilation_info=eci)
@@ -458,7 +463,7 @@
FUNCFLAG_USE_LASTERROR = 16
def get_call_conv(flags, from_jit):
- if _WIN32 and (flags & FUNCFLAG_CDECL == 0):
+ if _WIN32 and not _WIN64 and (flags & FUNCFLAG_CDECL == 0):
return FFI_STDCALL
else:
return FFI_DEFAULT_ABI
diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py
--- a/pypy/rlib/debug.py
+++ b/pypy/rlib/debug.py
@@ -1,5 +1,7 @@
import sys, time
from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rlib.rarithmetic import is_valid_int
+
def ll_assert(x, msg):
"""After translation to C, this becomes an RPyAssert."""
@@ -335,7 +337,7 @@
"""Give a translation-time error if 'x' is not a plain int
(e.g. if it's a r_longlong or an r_uint).
"""
- assert type(x) is int
+ assert is_valid_int(x)
return x
class Entry(ExtRegistryEntry):
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -103,7 +103,7 @@
n &= LONG_MASK
if n >= LONG_TEST:
n -= 2*LONG_TEST
- return n
+ return int(n)
def longlongmask(n):
assert isinstance(n, (int, long))
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -1,5 +1,5 @@
from pypy.rlib.rarithmetic import LONG_BIT, intmask, r_uint, r_ulonglong
-from pypy.rlib.rarithmetic import ovfcheck, r_longlong, widen
+from pypy.rlib.rarithmetic import ovfcheck, r_longlong, widen, is_valid_int
from pypy.rlib.rarithmetic import most_neg_value_of_same_type
from pypy.rlib.rfloat import isfinite
from pypy.rlib.debug import make_sure_not_resized, check_regular_int
@@ -44,21 +44,19 @@
def _mask_digit(x):
- if not we_are_translated():
- assert type(x) is not long, "overflow occurred!"
return intmask(x & MASK)
_mask_digit._annspecialcase_ = 'specialize:argtype(0)'
def _widen_digit(x):
if not we_are_translated():
- assert type(x) is int, "widen_digit() takes an int, got a %r" % type(x)
+ assert is_valid_int(x), "widen_digit() takes an int, got a %r" %
type(x)
if SHIFT <= 15:
return int(x)
return r_longlong(x)
def _store_digit(x):
if not we_are_translated():
- assert type(x) is int, "store_digit() takes an int, got a %r" % type(x)
+ assert is_valid_int(x), "store_digit() takes an int, got a %r" %
type(x)
if SHIFT <= 15:
return rffi.cast(rffi.SHORT, x)
elif SHIFT <= 31:
diff --git a/pypy/rlib/rdtoa.py b/pypy/rlib/rdtoa.py
--- a/pypy/rlib/rdtoa.py
+++ b/pypy/rlib/rdtoa.py
@@ -58,8 +58,8 @@
try:
result = dg_strtod(ll_input, end_ptr)
- endpos = (rffi.cast(rffi.LONG, end_ptr[0]) -
- rffi.cast(rffi.LONG, ll_input))
+ endpos = (rffi.cast(lltype.Signed, end_ptr[0]) -
+ rffi.cast(lltype.Signed, ll_input))
if endpos == 0 or endpos < len(input):
raise ValueError("invalid input at position %d" % (endpos,))
@@ -244,8 +244,8 @@
# The only failure mode is no memory
raise MemoryError
try:
- buflen = (rffi.cast(rffi.LONG, end_ptr[0]) -
- rffi.cast(rffi.LONG, digits))
+ buflen = (rffi.cast(lltype.Signed, end_ptr[0]) -
+ rffi.cast(lltype.Signed, digits))
sign = rffi.cast(lltype.Signed, sign_ptr[0])
# Handle nan and inf
diff --git a/pypy/rlib/rerased.py b/pypy/rlib/rerased.py
--- a/pypy/rlib/rerased.py
+++ b/pypy/rlib/rerased.py
@@ -24,11 +24,11 @@
from pypy.rpython.lltypesystem.rclass import OBJECTPTR
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.error import TyperError
-
+from pypy.rlib.rarithmetic import is_valid_int
def erase_int(x):
- assert isinstance(x, int)
+ assert is_valid_int(x)
res = 2 * x + 1
if res > sys.maxint or res < -sys.maxint - 1:
raise OverflowError
@@ -36,7 +36,7 @@
def unerase_int(y):
assert y._identity is _identity_for_ints
- assert isinstance(y._x, int)
+ assert is_valid_int(y._x)
return y._x
diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py
--- a/pypy/rlib/rwin32.py
+++ b/pypy/rlib/rwin32.py
@@ -133,8 +133,8 @@
# Prior to Visual Studio 8, the MSVCRT dll doesn't export the
# _dosmaperr() function, which is available only when compiled
# against the static CRT library.
- from pypy.translator.platform import platform, Windows
- static_platform = Windows()
+ from pypy.translator.platform import host_factory
+ static_platform = host_factory()
if static_platform.name == 'msvc':
static_platform.cflags = ['/MT'] # static CRT
static_platform.version = 0 # no manifest
diff --git a/pypy/rpython/lltypesystem/llarena.py
b/pypy/rpython/lltypesystem/llarena.py
--- a/pypy/rpython/lltypesystem/llarena.py
+++ b/pypy/rpython/lltypesystem/llarena.py
@@ -1,5 +1,7 @@
import array, weakref
from pypy.rpython.lltypesystem import llmemory
+from pypy.rlib.rarithmetic import is_valid_int
+
# An "arena" is a large area of memory which can hold a number of
# objects, not necessarily all of the same type or size. It's used by
@@ -164,7 +166,7 @@
return '<arenaaddr %s + %d>' % (self.arena, self.offset)
def __add__(self, other):
- if isinstance(other, (int, long)):
+ if is_valid_int(other):
position = self.offset + other
elif isinstance(other, llmemory.AddressOffset):
# this is really some Do What I Mean logic. There are two
@@ -184,7 +186,7 @@
def __sub__(self, other):
if isinstance(other, llmemory.AddressOffset):
other = llmemory.raw_malloc_usage(other)
- if isinstance(other, (int, long)):
+ if is_valid_int(other):
return self.arena.getaddr(self.offset - other)
if isinstance(other, fakearenaaddress):
if self.arena is not other.arena:
diff --git a/pypy/rpython/lltypesystem/opimpl.py
b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -4,6 +4,8 @@
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.lltypesystem.lloperation import opimpls
from pypy.rlib import debug
+from pypy.rlib.rarithmetic import is_valid_int
+
# ____________________________________________________________
# Implementation of the 'canfold' operations
@@ -22,14 +24,14 @@
from pypy.rpython.lltypesystem.llmemory import AddressAsInt
if r_longlong is r_int:
- r_longlong_arg = (r_longlong, int)
- r_longlong_result = int
+ r_longlong_arg = (r_longlong, int, long)
+ r_longlong_result = long # XXX was int
else:
r_longlong_arg = r_longlong
r_longlong_result = r_longlong
argtype_by_name = {
- 'int': int,
+ 'int': (int, long),
'float': float,
'uint': r_uint,
'llong': r_longlong_arg,
@@ -173,7 +175,7 @@
def op_direct_ptradd(obj, index):
checkptr(obj)
- assert isinstance(index, int)
+ assert is_valid_int(index)
return lltype.direct_ptradd(obj, index)
@@ -182,29 +184,30 @@
return not b
def op_int_add(x, y):
- if not isinstance(x, (int, llmemory.AddressOffset)):
+ if not isinstance(x, (int, long, llmemory.AddressOffset)):
from pypy.rpython.lltypesystem import llgroup
assert isinstance(x, llgroup.CombinedSymbolic)
- assert isinstance(y, (int, llmemory.AddressOffset))
+ assert isinstance(y, (int, long, llmemory.AddressOffset))
return intmask(x + y)
def op_int_sub(x, y):
- if not isinstance(x, int):
+ if not is_valid_int(x):
from pypy.rpython.lltypesystem import llgroup
assert isinstance(x, llgroup.CombinedSymbolic)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return intmask(x - y)
def op_int_ge(x, y):
# special case for 'AddressOffset >= 0'
- assert isinstance(x, (int, llmemory.AddressOffset))
- assert isinstance(y, int)
+ assert isinstance(x, (int, long, llmemory.AddressOffset))
+ assert is_valid_int(y)
return x >= y
def op_int_lt(x, y):
# special case for 'AddressOffset < 0'
- assert isinstance(x, (int, llmemory.AddressOffset))
- assert isinstance(y, int)
+ # hack for win64
+ assert isinstance(x, (int, long, llmemory.AddressOffset))
+ assert is_valid_int(y)
return x < y
def op_int_between(a, b, c):
@@ -214,50 +217,51 @@
return a <= b < c
def op_int_and(x, y):
- if not isinstance(x, int):
+ if not is_valid_int(x):
from pypy.rpython.lltypesystem import llgroup
assert isinstance(x, llgroup.CombinedSymbolic)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return x & y
def op_int_or(x, y):
- if not isinstance(x, int):
+ if not is_valid_int(x):
from pypy.rpython.lltypesystem import llgroup
assert isinstance(x, llgroup.CombinedSymbolic)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return x | y
def op_int_xor(x, y):
# used in computing hashes
if isinstance(x, AddressAsInt): x = llmemory.cast_adr_to_int(x.adr)
if isinstance(y, AddressAsInt): y = llmemory.cast_adr_to_int(y.adr)
- assert isinstance(x, int)
- assert isinstance(y, int)
+ assert is_valid_int(x)
+ assert is_valid_int(y)
return x ^ y
def op_int_mul(x, y):
- assert isinstance(x, (int, llmemory.AddressOffset))
- assert isinstance(y, (int, llmemory.AddressOffset))
+ assert isinstance(x, (int, long, llmemory.AddressOffset))
+ assert isinstance(y, (int, long, llmemory.AddressOffset))
return intmask(x * y)
def op_int_rshift(x, y):
- if not isinstance(x, int):
+ if not is_valid_int(x):
from pypy.rpython.lltypesystem import llgroup
assert isinstance(x, llgroup.CombinedSymbolic)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return x >> y
def op_int_floordiv(x, y):
- assert isinstance(x, (int, llmemory.AddressOffset))
- assert isinstance(y, (int, llmemory.AddressOffset))
+ # hack for win64
+ assert isinstance(x, (int, long, llmemory.AddressOffset))
+ assert isinstance(y, (int, long, llmemory.AddressOffset))
r = x//y
if x^y < 0 and x%y != 0:
r += 1
return r
def op_int_mod(x, y):
- assert isinstance(x, (int, llmemory.AddressOffset))
- assert isinstance(y, (int, llmemory.AddressOffset))
+ assert isinstance(x, (int, long, llmemory.AddressOffset))
+ assert isinstance(y, (int, long, llmemory.AddressOffset))
r = x%y
if x^y < 0 and x%y != 0:
r -= y
@@ -281,22 +285,22 @@
def op_uint_lshift(x, y):
assert isinstance(x, r_uint)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return r_uint(x << y)
def op_uint_rshift(x, y):
assert isinstance(x, r_uint)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return r_uint(x >> y)
def op_llong_lshift(x, y):
assert isinstance(x, r_longlong_arg)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return r_longlong_result(x << y)
def op_llong_rshift(x, y):
assert isinstance(x, r_longlong_arg)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return r_longlong_result(x >> y)
def op_ullong_lshift(x, y):
@@ -306,7 +310,7 @@
def op_ullong_rshift(x, y):
assert isinstance(x, r_ulonglong)
- assert isinstance(y, int)
+ assert is_valid_int(y)
return r_ulonglong(x >> y)
def op_same_as(x):
@@ -318,7 +322,8 @@
op_cast_primitive.need_result_type = True
def op_cast_int_to_float(i):
- assert type(i) is int
+ # assert type(i) is int
+ assert is_valid_int(i)
return float(i)
def op_cast_uint_to_float(u):
@@ -340,7 +345,8 @@
return ui + li
def op_cast_int_to_char(b):
- assert type(b) is int
+ #assert type(b) is int
+ assert is_valid_int(b)
return chr(b)
def op_cast_bool_to_int(b):
@@ -384,11 +390,12 @@
return ord(b)
def op_cast_int_to_unichar(b):
- assert type(b) is int
+ assert is_valid_int(b)
return unichr(b)
def op_cast_int_to_uint(b):
- assert type(b) is int
+ # assert type(b) is int
+ assert is_valid_int(b)
return r_uint(b)
def op_cast_uint_to_int(b):
@@ -396,7 +403,7 @@
return intmask(b)
def op_cast_int_to_longlong(b):
- assert type(b) is int
+ assert is_valid_int(b)
return r_longlong_result(b)
def op_truncate_longlong_to_int(b):
@@ -570,7 +577,7 @@
if isinstance(memberoffset, llgroup.GroupMemberOffset):
return memberoffset.index != 0
else:
- assert isinstance(memberoffset, int)
+ assert is_valid_int(memberoffset)
return memberoffset != 0
def op_extract_ushort(combinedoffset):
diff --git a/pypy/rpython/lltypesystem/test/test_llmemory.py
b/pypy/rpython/lltypesystem/test/test_llmemory.py
--- a/pypy/rpython/lltypesystem/test/test_llmemory.py
+++ b/pypy/rpython/lltypesystem/test/test_llmemory.py
@@ -1,6 +1,7 @@
from pypy.rpython.lltypesystem.llmemory import *
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.test.test_llinterp import interpret
+from pypy.rlib.rarithmetic import is_valid_int
import py
def test_simple():
@@ -639,12 +640,12 @@
assert cast_int_to_adr(0) == NULL
#
i = cast_adr_to_int(adr, mode="emulated")
- assert type(i) is int
+ assert is_valid_int(i)
i = cast_adr_to_int(NULL, mode="emulated")
- assert type(i) is int and i == 0
+ assert is_valid_int(i) and i == 0
#
i = cast_adr_to_int(adr, mode="forced")
- assert type(i) is int
+ assert is_valid_int(i)
#assert cast_int_to_adr(i) == adr -- depends on ll2ctypes details
i = cast_adr_to_int(NULL, mode="forced")
- assert type(i) is int and i == 0
+ assert is_valid_int(i) and i == 0
diff --git a/pypy/rpython/memory/gc/inspector.py
b/pypy/rpython/memory/gc/inspector.py
--- a/pypy/rpython/memory/gc/inspector.py
+++ b/pypy/rpython/memory/gc/inspector.py
@@ -109,7 +109,7 @@
self.gc = gc
self.gcflag = gc.gcflag_extra
self.fd = rffi.cast(rffi.INT, fd)
- self.writebuffer = lltype.malloc(rffi.LONGP.TO, self.BUFSIZE,
+ self.writebuffer = lltype.malloc(rffi.SIGNEDP.TO, self.BUFSIZE,
flavor='raw')
self.buf_count = 0
if self.gcflag == 0:
diff --git a/pypy/rpython/memory/gc/markcompact.py
b/pypy/rpython/memory/gc/markcompact.py
--- a/pypy/rpython/memory/gc/markcompact.py
+++ b/pypy/rpython/memory/gc/markcompact.py
@@ -11,6 +11,8 @@
from pypy.rlib.objectmodel import we_are_translated, running_on_llinterp
from pypy.rpython.lltypesystem import rffi
from pypy.rpython.memory.gcheader import GCHeaderBuilder
+from pypy.rlib.rarithmetic import is_valid_int
+
# Mark'n'compact garbage collector
#
@@ -353,7 +355,7 @@
# like header(), but asserts that we have a forwarding header
hdr = MovingGCBase.header(self, addr)
if not we_are_translated():
- assert isinstance(hdr.tid, int)
+ assert is_valid_int(hdr.tid)
return hdr
def combine(self, typeid16, flags):
diff --git a/pypy/rpython/memory/lltypelayout.py
b/pypy/rpython/memory/lltypelayout.py
--- a/pypy/rpython/memory/lltypelayout.py
+++ b/pypy/rpython/memory/lltypelayout.py
@@ -1,4 +1,5 @@
from pypy.rpython.lltypesystem import lltype, llmemory, llarena
+from pypy.rlib.rarithmetic import is_emulated_long
import struct
@@ -12,7 +13,11 @@
lltype.Float: "d",
llmemory.Address: "P",
}
-
+if is_emulated_long:
+ primitive_to_fmt.update( {
+ lltype.Signed: "q",
+ lltype.Unsigned: "Q",
+ } )
#___________________________________________________________________________
# Utility functions that know about the memory layout of the lltypes
diff --git a/pypy/rpython/memory/test/test_transformed_gc.py
b/pypy/rpython/memory/test/test_transformed_gc.py
--- a/pypy/rpython/memory/test/test_transformed_gc.py
+++ b/pypy/rpython/memory/test/test_transformed_gc.py
@@ -737,7 +737,7 @@
def f():
from pypy.rpython.lltypesystem import rffi
alist = [A() for i in range(50)]
- idarray = lltype.malloc(rffi.LONGP.TO, len(alist), flavor='raw')
+ idarray = lltype.malloc(rffi.SIGNEDP.TO, len(alist), flavor='raw')
# Compute the id of all the elements of the list. The goal is
# to not allocate memory, so that if the GC needs memory to
# remember the ids, it will trigger some collections itself
diff --git a/pypy/rpython/module/ll_os_stat.py
b/pypy/rpython/module/ll_os_stat.py
--- a/pypy/rpython/module/ll_os_stat.py
+++ b/pypy/rpython/module/ll_os_stat.py
@@ -319,6 +319,7 @@
def attributes_to_mode(attributes):
m = 0
+ attributes = intmask(attributes)
if attributes & win32traits.FILE_ATTRIBUTE_DIRECTORY:
m |= win32traits._S_IFDIR | 0111 # IFEXEC for user,group,other
else:
diff --git a/pypy/rpython/module/test/test_ll_os.py
b/pypy/rpython/module/test/test_ll_os.py
--- a/pypy/rpython/module/test/test_ll_os.py
+++ b/pypy/rpython/module/test/test_ll_os.py
@@ -80,8 +80,12 @@
pwd = os.getcwd()
import ctypes
buf = ctypes.create_string_buffer(1000)
- ctypes.windll.kernel32.GetEnvironmentVariableA('=%c:' % pwd[0], buf,
1000)
- assert str(buf.value) == pwd
+ len = ctypes.windll.kernel32.GetEnvironmentVariableA('=%c:' % pwd[0],
buf, 1000)
+ if (len == 0) and "WINGDB_PYTHON" in os.environ:
+ # the ctypes call seems not to work in the Wing debugger
+ return
+ assert str(buf.value).lower() == pwd
+ # ctypes returns the drive letter in uppercase, os.getcwd does not
pwd = os.getcwd()
try:
diff --git a/pypy/rpython/module/test/test_ll_os_stat.py
b/pypy/rpython/module/test/test_ll_os_stat.py
--- a/pypy/rpython/module/test/test_ll_os_stat.py
+++ b/pypy/rpython/module/test/test_ll_os_stat.py
@@ -26,7 +26,7 @@
assert wstat(unicode(f)).st_mtime == expected
check('c:/')
- check('c:/temp')
+ check(os.environ['TEMP'])
check('c:/pagefile.sys')
def test_fstat(self):
diff --git a/pypy/rpython/module/test/test_posix.py
b/pypy/rpython/module/test/test_posix.py
--- a/pypy/rpython/module/test/test_posix.py
+++ b/pypy/rpython/module/test/test_posix.py
@@ -1,6 +1,8 @@
import py
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.tool.udir import udir
+from pypy.rlib.rarithmetic import is_valid_int
+
import os
exec 'import %s as posix' % os.name
@@ -18,10 +20,10 @@
def test_open(self):
def f():
- ff = posix.open(path,posix.O_RDONLY,0777)
+ ff = posix.open(path, posix.O_RDONLY, 0777)
return ff
- func = self.interpret(f,[])
- assert type(func) == int
+ func = self.interpret(f, [])
+ assert is_valid_int(func)
def test_fstat(self):
def fo(fi):
@@ -61,25 +63,25 @@
assert isinstance(times, tuple)
assert len(times) == 5
for value in times:
- assert isinstance(value, int)
+ assert is_valid_int(value)
def test_lseek(self):
- def f(fi,pos):
- posix.lseek(fi,pos,0)
- fi = os.open(path,os.O_RDONLY,0777)
- func = self.interpret(f,[fi,5])
- res = os.read(fi,2)
+ def f(fi, pos):
+ posix.lseek(fi, pos, 0)
+ fi = os.open(path, os.O_RDONLY, 0777)
+ func = self.interpret(f, [fi, 5])
+ res = os.read(fi, 2)
assert res =='is'
def test_isatty(self):
def f(fi):
posix.isatty(fi)
- fi = os.open(path,os.O_RDONLY,0777)
- func = self.interpret(f,[fi])
+ fi = os.open(path, os.O_RDONLY, 0777)
+ func = self.interpret(f, [fi])
assert not func
os.close(fi)
- func = self.interpret(f,[fi])
+ func = self.interpret(f, [fi])
assert not func
def test_getcwd(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit