[pypy-svn] r72721 - in pypy/trunk/pypy: interpreter interpreter/test jit/backend/llsupport jit/backend/x86/test module/_socket module/_socket/test module/posix module/posix/test objspace/std objspace/std/test rlib rlib/test rpython/lltypesystem rpython/lltypesystem/test rpython/memory/gc rpython/memory/gc/test rpython/memory/test translator/c translator/c/gcc/test translator/c/src translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Wed Mar 24 16:01:03 CET 2010
Author: arigo
Date: Wed Mar 24 16:01:00 2010
New Revision: 72721
Modified:
pypy/trunk/pypy/interpreter/baseobjspace.py
pypy/trunk/pypy/interpreter/gateway.py
pypy/trunk/pypy/interpreter/test/test_gateway.py
pypy/trunk/pypy/jit/backend/llsupport/gc.py
pypy/trunk/pypy/jit/backend/x86/test/conftest.py
pypy/trunk/pypy/module/_socket/interp_func.py
pypy/trunk/pypy/module/_socket/test/test_sock_app.py
pypy/trunk/pypy/module/posix/interp_posix.py
pypy/trunk/pypy/module/posix/test/test_posix2.py
pypy/trunk/pypy/objspace/std/floatobject.py
pypy/trunk/pypy/objspace/std/longobject.py
pypy/trunk/pypy/objspace/std/test/test_floatobject.py
pypy/trunk/pypy/objspace/std/test/test_longobject.py
pypy/trunk/pypy/rlib/rarithmetic.py
pypy/trunk/pypy/rlib/rbigint.py
pypy/trunk/pypy/rlib/rmarshal.py
pypy/trunk/pypy/rlib/rstack.py
pypy/trunk/pypy/rlib/test/test_rarithmetic.py
pypy/trunk/pypy/rlib/test/test_rbigint.py
pypy/trunk/pypy/rlib/test/test_rmarshal.py
pypy/trunk/pypy/rlib/test/test_rstruct.py
pypy/trunk/pypy/rpython/lltypesystem/llgroup.py
pypy/trunk/pypy/rpython/lltypesystem/test/test_llgroup.py
pypy/trunk/pypy/rpython/memory/gc/generation.py
pypy/trunk/pypy/rpython/memory/gc/hybrid.py
pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py
pypy/trunk/pypy/rpython/memory/test/test_gc.py
pypy/trunk/pypy/rpython/memory/test/test_transformed_gc.py
pypy/trunk/pypy/translator/c/gcc/test/conftest.py
pypy/trunk/pypy/translator/c/node.py
pypy/trunk/pypy/translator/c/primitive.py
pypy/trunk/pypy/translator/c/src/llgroup.h
pypy/trunk/pypy/translator/c/test/test_lltyped.py
Log:
Merge the branch/fix-64 into trunk: first round of fixing
test failures that show on a 64-bit machine.
Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py (original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py Wed Mar 24 16:01:00 2010
@@ -9,11 +9,14 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.debug import make_sure_not_resized
from pypy.rlib.timer import DummyTimer, Timer
+from pypy.rlib.rarithmetic import r_uint
from pypy.rlib import jit
import os, sys
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
+UINT_MAX_32_BITS = r_uint(4294967295)
+
class W_Root(object):
"""This is the abstract root class of all wrapped objects that live
@@ -1095,6 +1098,24 @@
self.wrap("expected a non-negative integer"))
return value
+ def c_int_w(self, w_obj):
+ # Like space.int_w(), but raises an app-level OverflowError if
+ # the integer does not fit in 32 bits. Mostly here for gateway.py.
+ value = self.int_w(w_obj)
+ if value < -2147483647-1 or value > 2147483647:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected a 32-bit integer"))
+ return value
+
+ def c_uint_w(self, w_obj):
+ # Like space.uint_w(), but raises an app-level OverflowError if
+ # the integer does not fit in 32 bits. Mostly here for gateway.py.
+ value = self.uint_w(w_obj)
+ if value > UINT_MAX_32_BITS:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected an unsigned 32-bit integer"))
+ return value
+
def warn(self, msg, w_warningcls):
self.appexec([self.wrap(msg), w_warningcls], """(msg, warningcls):
import warnings
Modified: pypy/trunk/pypy/interpreter/gateway.py
==============================================================================
--- pypy/trunk/pypy/interpreter/gateway.py (original)
+++ pypy/trunk/pypy/interpreter/gateway.py Wed Mar 24 16:01:00 2010
@@ -126,6 +126,12 @@
def visit_nonnegint(self, el, app_sig):
self.checked_space_method(el, app_sig)
+ def visit_c_int(self, el, app_sig):
+ self.checked_space_method(el, app_sig)
+
+ def visit_c_uint(self, el, app_sig):
+ self.checked_space_method(el, app_sig)
+
def visit__Wrappable(self, el, app_sig):
name = el.__name__
argname = self.orig_arg()
@@ -230,6 +236,12 @@
def visit_nonnegint(self, typ):
self.run_args.append("space.nonnegint_w(%s)" % (self.scopenext(),))
+ def visit_c_int(self, typ):
+ self.run_args.append("space.c_int_w(%s)" % (self.scopenext(),))
+
+ def visit_c_uint(self, typ):
+ self.run_args.append("space.c_uint_w(%s)" % (self.scopenext(),))
+
def _make_unwrap_activation_class(self, unwrap_spec, cache={}):
try:
key = tuple(unwrap_spec)
@@ -348,6 +360,12 @@
def visit_nonnegint(self, typ):
self.unwrap.append("space.nonnegint_w(%s)" % (self.nextarg(),))
+ def visit_c_int(self, typ):
+ self.unwrap.append("space.c_int_w(%s)" % (self.nextarg(),))
+
+ def visit_c_uint(self, typ):
+ self.unwrap.append("space.c_uint_w(%s)" % (self.nextarg(),))
+
def make_fastfunc(unwrap_spec, func):
unwrap_info = UnwrapSpec_FastFunc_Unwrap()
unwrap_info.apply_over(unwrap_spec)
Modified: pypy/trunk/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_gateway.py (original)
+++ pypy/trunk/pypy/interpreter/test/test_gateway.py Wed Mar 24 16:01:00 2010
@@ -197,6 +197,40 @@
space.raises_w(space.w_ValueError,
space.call_function, w_app_g, space.wrap(-1))
+ def test_interp2app_unwrap_spec_c_int(self):
+ from pypy.rlib.rarithmetic import r_longlong
+ space = self.space
+ w = space.wrap
+ def g(space, x):
+ return space.wrap(x + 6)
+ app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_int'])
+ app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_uint'])
+ assert app_ug is not app_g
+ w_app_g = space.wrap(app_g)
+ w_app_ug = space.wrap(app_ug)
+ #
+ assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)),
+ space.wrap(13))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_g,
+ space.wrap(r_longlong(0x80000000)))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_g,
+ space.wrap(r_longlong(-0x80000001)))
+ #
+ assert self.space.eq_w(space.call_function(w_app_ug, space.wrap(7)),
+ space.wrap(13))
+ assert self.space.eq_w(space.call_function(w_app_ug,
+ space.wrap(0x7FFFFFFF)),
+ space.wrap(r_longlong(0x7FFFFFFF+6)))
+ space.raises_w(space.w_ValueError,
+ space.call_function, w_app_ug, space.wrap(-1))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_ug,
+ space.wrap(r_longlong(0x100000000)))
+
def test_interp2app_unwrap_spec_args_w(self):
space = self.space
w = space.wrap
Modified: pypy/trunk/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llsupport/gc.py (original)
+++ pypy/trunk/pypy/jit/backend/llsupport/gc.py Wed Mar 24 16:01:00 2010
@@ -2,6 +2,7 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.debug import fatalerror
from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass, rstr
+from pypy.rpython.lltypesystem import llgroup
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.annlowlevel import llhelper
from pypy.translator.tool.cbuild import ExternalCompilationInfo
@@ -309,7 +310,7 @@
# if convenient for the backend, we also compute the info about
# the flag as (byte-offset, single-byte-flag).
import struct
- value = struct.pack("i", self.jit_wb_if_flag)
+ value = struct.pack("l", self.jit_wb_if_flag)
assert value.count('\x00') == len(value) - 1 # only one byte is != 0
i = 0
while value[i] == '\x00': i += 1
@@ -372,8 +373,8 @@
# make a malloc function, with three arguments
def malloc_basic(size, tid):
- type_id = llop.extract_ushort(rffi.USHORT, tid)
- has_finalizer = bool(tid & (1<<16))
+ type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
+ has_finalizer = bool(tid & (1<<llgroup.HALFSHIFT))
_check_typeid(type_id)
try:
res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
@@ -393,7 +394,7 @@
self.write_barrier_descr = WriteBarrierDescr(self)
#
def malloc_array(itemsize, tid, num_elem):
- type_id = llop.extract_ushort(rffi.USHORT, tid)
+ type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
_check_typeid(type_id)
try:
return llop1.do_malloc_varsize_clear(
@@ -483,7 +484,7 @@
type_id = self.layoutbuilder.get_type_id(S)
assert not self.layoutbuilder.is_weakref(type_id)
has_finalizer = bool(self.layoutbuilder.has_finalizer(S))
- flags = int(has_finalizer) << 16
+ flags = int(has_finalizer) << llgroup.HALFSHIFT
descr.tid = llop.combine_ushort(lltype.Signed, type_id, flags)
def init_array_descr(self, A, descr):
@@ -599,7 +600,7 @@
def can_inline_malloc(self, descr):
assert isinstance(descr, BaseSizeDescr)
if descr.size < self.max_size_of_young_obj:
- has_finalizer = bool(descr.tid & (1<<16))
+ has_finalizer = bool(descr.tid & (1<<llgroup.HALFSHIFT))
if has_finalizer:
return False
return True
Modified: pypy/trunk/pypy/jit/backend/x86/test/conftest.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/test/conftest.py (original)
+++ pypy/trunk/pypy/jit/backend/x86/test/conftest.py Wed Mar 24 16:01:00 2010
@@ -1,9 +1,9 @@
import py
from pypy.jit.backend import detect_cpu
-class Directory(py.test.collect.Directory):
+class Module(py.test.collect.Module):
def collect(self):
cpu = detect_cpu.autodetect()
if cpu != 'x86':
py.test.skip("x86 directory skipped: cpu is %r" % (cpu,))
- return super(Directory, self).collect()
+ return super(Module, self).collect()
Modified: pypy/trunk/pypy/module/_socket/interp_func.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/interp_func.py (original)
+++ pypy/trunk/pypy/module/_socket/interp_func.py Wed Mar 24 16:01:00 2010
@@ -2,6 +2,7 @@
from pypy.module._socket.interp_socket import converted_error, W_RSocket
from pypy.rlib import rsocket
from pypy.rlib.rsocket import SocketError
+from pypy.rlib.rarithmetic import r_uint
from pypy.interpreter.error import OperationError, operationerrfmt
def gethostname(space):
@@ -152,30 +153,24 @@
return space.newtuple([space.wrap(sock1), space.wrap(sock2)])
socketpair.unwrap_spec = [ObjSpace, int, int, int]
+# The following 4 functions refuse all negative numbers, like CPython 2.6.
+# They could also check that the argument is not too large, but CPython 2.6
+# is not doing that consistently.
def ntohs(space, x):
"""ntohs(integer) -> integer
Convert a 16-bit integer from network to host byte order.
"""
return space.wrap(rsocket.ntohs(x))
-ntohs.unwrap_spec = [ObjSpace, int]
+ntohs.unwrap_spec = [ObjSpace, r_uint]
-def ntohl(space, w_x):
+def ntohl(space, x):
"""ntohl(integer) -> integer
Convert a 32-bit integer from network to host byte order.
"""
- if space.is_true(space.isinstance(w_x, space.w_int)):
- x = space.int_w(w_x)
- elif space.is_true(space.isinstance(w_x, space.w_long)):
- x = space.uint_w(w_x)
- else:
- raise operationerrfmt(space.w_TypeError,
- "expected int/long, %s found",
- space.type(w_x).getname(space, "?"))
-
return space.wrap(rsocket.ntohl(x))
-ntohl.unwrap_spec = [ObjSpace, W_Root]
+ntohl.unwrap_spec = [ObjSpace, r_uint]
def htons(space, x):
"""htons(integer) -> integer
@@ -183,24 +178,15 @@
Convert a 16-bit integer from host to network byte order.
"""
return space.wrap(rsocket.htons(x))
-htons.unwrap_spec = [ObjSpace, int]
+htons.unwrap_spec = [ObjSpace, r_uint]
-def htonl(space, w_x):
+def htonl(space, x):
"""htonl(integer) -> integer
Convert a 32-bit integer from host to network byte order.
"""
- if space.is_true(space.isinstance(w_x, space.w_int)):
- x = space.int_w(w_x)
- elif space.is_true(space.isinstance(w_x, space.w_long)):
- x = space.uint_w(w_x)
- else:
- raise operationerrfmt(space.w_TypeError,
- "expected int/long, %s found",
- space.type(w_x).getname(space, "?"))
-
return space.wrap(rsocket.htonl(x))
-htonl.unwrap_spec = [ObjSpace, W_Root]
+htonl.unwrap_spec = [ObjSpace, r_uint]
def inet_aton(space, ip):
"""inet_aton(string) -> packed 32-bit IP representation
Modified: pypy/trunk/pypy/module/_socket/test/test_sock_app.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/test/test_sock_app.py (original)
+++ pypy/trunk/pypy/module/_socket/test/test_sock_app.py Wed Mar 24 16:01:00 2010
@@ -338,6 +338,7 @@
s.close()
def test_NtoH(self):
+ import sys
import _socket as socket
# This just checks that htons etc. are their own inverse,
# when looking at the lower 16 or 32 bits.
@@ -351,7 +352,28 @@
swapped = func(mask)
assert swapped & mask == mask
try:
- func(1L<<34)
+ func(-1)
+ except (OverflowError, ValueError):
+ pass
+ else:
+ assert False
+ try:
+ func(sys.maxint*2+2)
+ except OverflowError:
+ pass
+ else:
+ assert False
+
+ def test_NtoH_overflow(self):
+ skip("we are not checking for overflowing values yet")
+ import _socket as socket
+ # Checks that we cannot give too large values to htons etc.
+ # Skipped for now; CPython 2.6 is also not consistent.
+ sizes = {socket.htonl: 32, socket.ntohl: 32,
+ socket.htons: 16, socket.ntohs: 16}
+ for func, size in sizes.items():
+ try:
+ func(1L << size)
except OverflowError:
pass
else:
Modified: pypy/trunk/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/trunk/pypy/module/posix/interp_posix.py (original)
+++ pypy/trunk/pypy/module/posix/interp_posix.py Wed Mar 24 16:01:00 2010
@@ -20,7 +20,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(fd)
-open.unwrap_spec = [ObjSpace, str, int, int]
+open.unwrap_spec = [ObjSpace, str, "c_int", "c_int"]
def lseek(space, fd, pos, how):
"""Set the current position of a file descriptor. Return the new position.
@@ -32,7 +32,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(pos)
-lseek.unwrap_spec = [ObjSpace, int, r_longlong, int]
+lseek.unwrap_spec = [ObjSpace, "c_int", r_longlong, "c_int"]
def isatty(space, fd):
"""Return True if 'fd' is an open file descriptor connected to the
@@ -43,7 +43,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(res)
-isatty.unwrap_spec = [ObjSpace, int]
+isatty.unwrap_spec = [ObjSpace, "c_int"]
def read(space, fd, buffersize):
"""Read data from a file descriptor."""
@@ -53,7 +53,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(s)
-read.unwrap_spec = [ObjSpace, int, int]
+read.unwrap_spec = [ObjSpace, "c_int", int]
def write(space, fd, data):
"""Write a string to a file descriptor. Return the number of bytes
@@ -64,7 +64,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(res)
-write.unwrap_spec = [ObjSpace, int, 'bufferstr']
+write.unwrap_spec = [ObjSpace, "c_int", 'bufferstr']
def close(space, fd):
"""Close a file descriptor (for low level IO)."""
@@ -72,12 +72,12 @@
os.close(fd)
except OSError, e:
raise wrap_oserror(space, e)
-close.unwrap_spec = [ObjSpace, int]
+close.unwrap_spec = [ObjSpace, "c_int"]
def closerange(fd_low, fd_high):
"""Closes all file descriptors in [fd_low, fd_high), ignoring errors."""
rposix.closerange(fd_low, fd_high)
-closerange.unwrap_spec = [int, int]
+closerange.unwrap_spec = ["c_int", "c_int"]
def ftruncate(space, fd, length):
"""Truncate a file to a specified length."""
@@ -85,21 +85,21 @@
os.ftruncate(fd, length)
except OSError, e:
raise wrap_oserror(space, e)
-ftruncate.unwrap_spec = [ObjSpace, int, r_longlong]
+ftruncate.unwrap_spec = [ObjSpace, "c_int", r_longlong]
def fsync(space, fd):
try:
os.fsync(fd)
except OSError, e:
raise wrap_oserror(space, e)
-fsync.unwrap_spec = [ObjSpace, int]
+fsync.unwrap_spec = [ObjSpace, "c_int"]
def fdatasync(space, fd):
try:
os.fdatasync(fd)
except OSError, e:
raise wrap_oserror(space, e)
-fdatasync.unwrap_spec = [ObjSpace, int]
+fdatasync.unwrap_spec = [ObjSpace, "c_int"]
# ____________________________________________________________
@@ -157,7 +157,7 @@
raise wrap_oserror(space, e)
else:
return build_stat_result(space, st)
-fstat.unwrap_spec = [ObjSpace, int]
+fstat.unwrap_spec = [ObjSpace, "c_int"]
def stat(space, path):
"""Perform a stat system call on the given path. Return an object
@@ -221,7 +221,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(newfd)
-dup.unwrap_spec = [ObjSpace, int]
+dup.unwrap_spec = [ObjSpace, "c_int"]
def dup2(space, old_fd, new_fd):
"""Duplicate a file descriptor."""
@@ -229,7 +229,7 @@
os.dup2(old_fd, new_fd)
except OSError, e:
raise wrap_oserror(space, e)
-dup2.unwrap_spec = [ObjSpace, int, int]
+dup2.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def access(space, path, mode):
"""
@@ -247,7 +247,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(ok)
-access.unwrap_spec = [ObjSpace, str, int]
+access.unwrap_spec = [ObjSpace, str, "c_int"]
def times(space):
@@ -335,7 +335,7 @@
os.mkdir(path, mode)
except OSError, e:
raise wrap_oserror(space, e)
-mkdir.unwrap_spec = [ObjSpace, str, int]
+mkdir.unwrap_spec = [ObjSpace, str, "c_int"]
def rmdir(space, path):
"""Remove a directory."""
@@ -353,7 +353,7 @@
raise OperationError(space.w_ValueError,
space.wrap("strerror() argument out of range"))
return space.wrap(text)
-strerror.unwrap_spec = [ObjSpace, int]
+strerror.unwrap_spec = [ObjSpace, "c_int"]
# ____________________________________________________________
@@ -440,7 +440,7 @@
os.chmod(path, mode)
except OSError, e:
raise wrap_oserror(space, e)
-chmod.unwrap_spec = [ObjSpace, str, int]
+chmod.unwrap_spec = [ObjSpace, str, "c_int"]
def rename(space, old, new):
"Rename a file or directory."
@@ -454,7 +454,7 @@
"Set the current numeric umask and return the previous umask."
prevmask = os.umask(mask)
return space.wrap(prevmask)
-umask.unwrap_spec = [ObjSpace, int]
+umask.unwrap_spec = [ObjSpace, "c_int"]
def getpid(space):
"Return the current process id."
@@ -471,7 +471,7 @@
os.kill(pid, sig)
except OSError, e:
raise wrap_oserror(space, e)
-kill.unwrap_spec = [ObjSpace, int, int]
+kill.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def abort(space):
"""Abort the interpreter immediately. This 'dumps core' or otherwise fails
@@ -531,11 +531,11 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.newtuple([space.wrap(pid), space.wrap(status)])
-waitpid.unwrap_spec = [ObjSpace, int, int]
+waitpid.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def _exit(space, status):
os._exit(status)
-_exit.unwrap_spec = [ObjSpace, int]
+_exit.unwrap_spec = [ObjSpace, "c_int"]
def execv(space, command, w_args):
""" execv(path, args)
@@ -649,7 +649,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setuid.unwrap_spec = [ObjSpace, int]
+setuid.unwrap_spec = [ObjSpace, "c_uint"]
def seteuid(space, arg):
""" seteuid(uid)
@@ -661,7 +661,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-seteuid.unwrap_spec = [ObjSpace, int]
+seteuid.unwrap_spec = [ObjSpace, "c_uint"]
def setgid(space, arg):
""" setgid(gid)
@@ -673,7 +673,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setgid.unwrap_spec = [ObjSpace, int]
+setgid.unwrap_spec = [ObjSpace, "c_uint"]
def setegid(space, arg):
""" setegid(gid)
@@ -685,7 +685,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setegid.unwrap_spec = [ObjSpace, int]
+setegid.unwrap_spec = [ObjSpace, "c_uint"]
def chroot(space, path):
""" chroot(path)
@@ -761,7 +761,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(pgid)
-getpgid.unwrap_spec = [ObjSpace, int]
+getpgid.unwrap_spec = [ObjSpace, "c_int"]
def setpgid(space, pid, pgrp):
""" setpgid(pid, pgrp)
@@ -773,7 +773,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setpgid.unwrap_spec = [ObjSpace, int, int]
+setpgid.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def setreuid(space, ruid, euid):
""" setreuid(ruid, euid)
@@ -785,7 +785,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setreuid.unwrap_spec = [ObjSpace, int, int]
+setreuid.unwrap_spec = [ObjSpace, "c_uint", "c_uint"]
def setregid(space, rgid, egid):
""" setregid(rgid, egid)
@@ -797,7 +797,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setregid.unwrap_spec = [ObjSpace, int, int]
+setregid.unwrap_spec = [ObjSpace, "c_uint", "c_uint"]
def getsid(space, pid):
""" getsid(pid) -> sid
@@ -809,7 +809,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(sid)
-getsid.unwrap_spec = [ObjSpace, int]
+getsid.unwrap_spec = [ObjSpace, "c_int"]
def setsid(space):
""" setsid()
@@ -831,7 +831,7 @@
def WSTAR(space, status):
return space.newbool(getattr(os, name)(status))
WSTAR.__doc__ = getattr(os, name).__doc__
- WSTAR.unwrap_spec = [ObjSpace, int]
+ WSTAR.unwrap_spec = [ObjSpace, "c_int"]
WSTAR.func_name = name
return WSTAR
@@ -845,7 +845,7 @@
return space.wrap(os.ttyname(fd))
except OSError, e:
raise wrap_oserror(space, e)
-ttyname.unwrap_spec = [ObjSpace, int]
+ttyname.unwrap_spec = [ObjSpace, "c_int"]
def sysconf(space, w_num_or_name):
# XXX slightly non-nice, reuses the sysconf of the underlying os module
@@ -866,7 +866,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-chown.unwrap_spec = [ObjSpace, str, int, int]
+chown.unwrap_spec = [ObjSpace, str, "c_uint", "c_uint"]
if _WIN:
from pypy.rlib import rwin32
Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/trunk/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/trunk/pypy/module/posix/test/test_posix2.py Wed Mar 24 16:01:00 2010
@@ -380,7 +380,7 @@
if hasattr(os, 'setuid'):
def test_os_setuid_error(self):
os = self.posix
- raises(OSError, os.setuid, -100000)
+ raises((OSError, ValueError, OverflowError), os.setuid, -100000)
if hasattr(os, 'getgid'):
def test_os_getgid(self):
@@ -396,13 +396,13 @@
if hasattr(os, 'setgid'):
def test_os_setgid_error(self):
os = self.posix
- raises(OSError, os.setgid, -100000)
+ raises((OSError, ValueError, OverflowError), os.setgid, -100000)
if hasattr(os, 'getsid'):
def test_os_getsid(self):
os = self.posix
assert os.getsid(0) == self.getsid0
- raises(OSError, os.getsid, -100000)
+ raises((OSError, ValueError, OverflowError), os.getsid, -100000)
if hasattr(os, 'sysconf'):
def test_os_sysconf(self):
Modified: pypy/trunk/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/floatobject.py (original)
+++ pypy/trunk/pypy/objspace/std/floatobject.py Wed Mar 24 16:01:00 2010
@@ -1,9 +1,11 @@
+import operator, new
from pypy.objspace.std.objspace import *
from pypy.interpreter import gateway
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.longobject import W_LongObject
from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf, isnan
-from pypy.rlib.rarithmetic import formatd
+from pypy.rlib.rarithmetic import formatd, LONG_BIT
+from pypy.rlib.rbigint import rbigint
import math
from pypy.objspace.std.intobject import W_IntObject
@@ -88,82 +90,115 @@
s = formatd("%.12g", x)
return space.wrap(should_not_look_like_an_int(s))
+# ____________________________________________________________
+# A mess to handle all cases of float comparison without relying
+# on delegation, which can unfortunately loose precision when
+# casting an int or a long to a float.
+
+def list_compare_funcs(declarator):
+ for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
+ func, name = declarator(op)
+ globals()[name] = func_with_new_name(func, name)
+
+def _reverse(opname):
+ if opname[0] == 'l': return 'g' + opname[1:]
+ elif opname[0] == 'g': return 'l' + opname[1:]
+ else: return opname
-def declare_new_float_comparison(opname):
- import operator
- from pypy.tool.sourcetools import func_with_new_name
- op = getattr(operator, opname)
- def f(space, w_int1, w_int2):
- i = w_int1.floatval
- j = w_int2.floatval
- return space.newbool(op(i, j))
- name = opname + "__Float_Float"
- return func_with_new_name(f, name), name
-
-for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
- func, name = declare_new_float_comparison(op)
- globals()[name] = func
-
-# for overflowing comparisons between longs and floats
-# XXX we might have to worry (later) about eq__Float_Int, for the case
-# where int->float conversion may lose precision :-(
-def eq__Float_Long(space, w_float1, w_long2):
- # XXX naive implementation
- x = w_float1.floatval
- if isinf(x) or math.floor(x) != x:
- return space.w_False
- try:
- w_long1 = W_LongObject.fromfloat(x)
- except OverflowError:
- return space.w_False
- return space.eq(w_long1, w_long2)
-
-def eq__Long_Float(space, w_long1, w_float2):
- return eq__Float_Long(space, w_float2, w_long1)
-
-def ne__Float_Long(space, w_float1, w_long2):
- return space.not_(eq__Float_Long(space, w_float1, w_long2))
-
-def ne__Long_Float(space, w_long1, w_float2):
- return space.not_(eq__Float_Long(space, w_float2, w_long1))
-
-def lt__Float_Long(space, w_float1, w_long2):
- # XXX naive implementation
- x = w_float1.floatval
- if isinf(x):
- return space.newbool(x < 0.0)
- x_floor = math.floor(x)
- try:
- w_long1 = W_LongObject.fromfloat(x_floor)
- except OverflowError:
- return space.newbool(x < 0.0)
- return space.lt(w_long1, w_long2)
-
-def lt__Long_Float(space, w_long1, w_float2):
- return space.not_(le__Float_Long(space, w_float2, w_long1))
-def le__Float_Long(space, w_float1, w_long2):
- # XXX it's naive anyway
- if space.is_true(space.lt(w_float1, w_long2)):
- return space.w_True
+def declare_compare_bigint(opname):
+ """Return a helper function that implements a float-bigint comparison."""
+ op = getattr(operator, opname)
+ #
+ if opname == 'eq' or opname == 'ne':
+ def do_compare_bigint(f1, b2):
+ """f1 is a float. b2 is a bigint."""
+ if isinf(f1) or isnan(f1) or math.floor(f1) != f1:
+ return opname == 'ne'
+ b1 = rbigint.fromfloat(f1)
+ res = b1.eq(b2)
+ if opname == 'ne':
+ res = not res
+ return res
else:
- return space.eq(w_float1, w_long2)
+ def do_compare_bigint(f1, b2):
+ """f1 is a float. b2 is a bigint."""
+ if isinf(f1) or isnan(f1):
+ return op(f1, 0.0)
+ if opname == 'gt' or opname == 'le':
+ # 'float > long' <==> 'ceil(float) > long'
+ # 'float <= long' <==> 'ceil(float) <= long'
+ f1 = math.ceil(f1)
+ else:
+ # 'float < long' <==> 'floor(float) < long'
+ # 'float >= long' <==> 'floor(float) >= long'
+ f1 = math.floor(f1)
+ b1 = rbigint.fromfloat(f1)
+ return getattr(b1, opname)(b2)
+ #
+ return do_compare_bigint, 'compare_bigint_' + opname
+list_compare_funcs(declare_compare_bigint)
-def le__Long_Float(space, w_long1, w_float2):
- return space.not_(lt__Float_Long(space, w_float2, w_long1))
-def gt__Float_Long(space, w_float1, w_long2):
- return space.not_(le__Float_Long(space, w_float1, w_long2))
+def declare_cmp_float_float(opname):
+ op = getattr(operator, opname)
+ def f(space, w_float1, w_float2):
+ f1 = w_float1.floatval
+ f2 = w_float2.floatval
+ return space.newbool(op(f1, f2))
+ return f, opname + "__Float_Float"
+list_compare_funcs(declare_cmp_float_float)
-def gt__Long_Float(space, w_long1, w_float2):
- return lt__Float_Long(space, w_float2, w_long1)
+def declare_cmp_float_int(opname):
+ op = getattr(operator, opname)
+ compare = globals()['compare_bigint_' + opname]
+ def f(space, w_float1, w_int2):
+ f1 = w_float1.floatval
+ i2 = w_int2.intval
+ f2 = float(i2)
+ if LONG_BIT > 32 and int(f2) != i2:
+ res = compare(f1, rbigint.fromint(i2))
+ else:
+ res = op(f1, f2)
+ return space.newbool(res)
+ return f, opname + "__Float_Int"
+list_compare_funcs(declare_cmp_float_int)
+
+def declare_cmp_float_long(opname):
+ compare = globals()['compare_bigint_' + opname]
+ def f(space, w_float1, w_long2):
+ f1 = w_float1.floatval
+ b2 = w_long2.num
+ return space.newbool(compare(f1, b2))
+ return f, opname + "__Float_Long"
+list_compare_funcs(declare_cmp_float_long)
-def ge__Float_Long(space, w_float1, w_long2):
- return space.not_(lt__Float_Long(space, w_float1, w_long2))
+def declare_cmp_int_float(opname):
+ op = getattr(operator, opname)
+ revcompare = globals()['compare_bigint_' + _reverse(opname)]
+ def f(space, w_int1, w_float2):
+ f2 = w_float2.floatval
+ i1 = w_int1.intval
+ f1 = float(i1)
+ if LONG_BIT > 32 and int(f1) != i1:
+ res = revcompare(f2, rbigint.fromint(i1))
+ else:
+ res = op(f1, f2)
+ return space.newbool(res)
+ return f, opname + "__Int_Float"
+list_compare_funcs(declare_cmp_int_float)
+
+def declare_cmp_long_float(opname):
+ revcompare = globals()['compare_bigint_' + _reverse(opname)]
+ def f(space, w_long1, w_float2):
+ f2 = w_float2.floatval
+ b1 = w_long1.num
+ return space.newbool(revcompare(f2, b1))
+ return f, opname + "__Long_Float"
+list_compare_funcs(declare_cmp_long_float)
-def ge__Long_Float(space, w_long1, w_float2):
- return le__Float_Long(space, w_float2, w_long1)
+# ____________________________________________________________
def hash__Float(space, w_value):
return space.wrap(_hash_float(space, w_value.floatval))
Modified: pypy/trunk/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/longobject.py (original)
+++ pypy/trunk/pypy/objspace/std/longobject.py Wed Mar 24 16:01:00 2010
@@ -120,11 +120,46 @@
def str__Long(space, w_long):
return space.wrap(w_long.num.str())
-def eq__Long_Long(space, w_long1, w_long2):
- return space.newbool(w_long1.num.eq(w_long2.num))
def lt__Long_Long(space, w_long1, w_long2):
return space.newbool(w_long1.num.lt(w_long2.num))
+def le__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.le(w_long2.num))
+def eq__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.eq(w_long2.num))
+def ne__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.ne(w_long2.num))
+def gt__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.gt(w_long2.num))
+def ge__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.ge(w_long2.num))
+
+def lt__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.lt(rbigint.fromint(w_int2.intval)))
+def le__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.le(rbigint.fromint(w_int2.intval)))
+def eq__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.eq(rbigint.fromint(w_int2.intval)))
+def ne__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.ne(rbigint.fromint(w_int2.intval)))
+def gt__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.gt(rbigint.fromint(w_int2.intval)))
+def ge__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.ge(rbigint.fromint(w_int2.intval)))
+
+def lt__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).lt(w_long2.num))
+def le__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).le(w_long2.num))
+def eq__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).eq(w_long2.num))
+def ne__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).ne(w_long2.num))
+def gt__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).gt(w_long2.num))
+def ge__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).ge(w_long2.num))
+
def hash__Long(space, w_value):
return space.wrap(w_value.num.hash())
Modified: pypy/trunk/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_floatobject.py Wed Mar 24 16:01:00 2010
@@ -212,6 +212,8 @@
assert 13 <= 13.01
def test_comparison_more(self):
+ import sys
+ is_pypy = '__pypy__' in sys.builtin_module_names
infinity = 1e200*1e200
nan = infinity/infinity
for x in (123, 1 << 30,
@@ -239,12 +241,27 @@
assert ((x + 1) > float(x))
assert not ((x + 1) < float(x))
#
- #assert not (x == nan)
- #assert not (x >= nan)
- #assert not (x <= nan)
- #assert (x != nan)
- #assert not (x > nan)
- #assert not (x < nan)
+ assert not (x == infinity)
+ assert not (x >= infinity)
+ assert (x <= infinity)
+ assert (x != infinity)
+ assert not (x > infinity)
+ assert (x < infinity)
+ #
+ assert not (x == -infinity)
+ assert (x >= -infinity)
+ assert not (x <= -infinity)
+ assert (x != -infinity)
+ assert (x > -infinity)
+ assert not (x < -infinity)
+ #
+ if is_pypy:
+ assert not (x == nan)
+ assert not (x >= nan)
+ assert not (x <= nan)
+ assert (x != nan)
+ assert not (x > nan)
+ assert not (x < nan)
#
assert (float(x) == x)
assert (float(x) <= x)
@@ -267,19 +284,35 @@
assert (float(x) < (x + 1))
assert not (float(x) > (x + 1))
#
- #assert not (nan == x)
- #assert not (nan <= x)
- #assert not (nan >= x)
- #assert (nan != x)
- #assert not (nan < x)
- #assert not (nan > x)
+ assert not (infinity == x)
+ assert (infinity >= x)
+ assert not (infinity <= x)
+ assert (infinity != x)
+ assert (infinity > x)
+ assert not (infinity < x)
+ #
+ assert not (-infinity == x)
+ assert not (-infinity >= x)
+ assert (-infinity <= x)
+ assert (-infinity != x)
+ assert not (-infinity > x)
+ assert (-infinity < x)
+ #
+ if is_pypy:
+ assert not (nan == x)
+ assert not (nan <= x)
+ assert not (nan >= x)
+ assert (nan != x)
+ assert not (nan < x)
+ assert not (nan > x)
def test_multimethod_slice(self):
assert 5 .__add__(3.14) is NotImplemented
assert 3.25 .__add__(5) == 8.25
- if hasattr(int, '__eq__'): # for py.test -A: CPython is inconsistent
- assert 5 .__eq__(3.14) is NotImplemented
- assert 3.14 .__eq__(5) is False
+ # xxx we are also a bit inconsistent about the following
+ #if hasattr(int, '__eq__'): # for py.test -A: CPython is inconsistent
+ # assert 5 .__eq__(3.14) is NotImplemented
+ # assert 3.14 .__eq__(5) is False
#if hasattr(long, '__eq__'): # for py.test -A: CPython is inconsistent
# assert 5L .__eq__(3.14) is NotImplemented
# assert 3.14 .__eq__(5L) is False
Modified: pypy/trunk/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_longobject.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_longobject.py Wed Mar 24 16:01:00 2010
@@ -60,37 +60,79 @@
assert a == 3L
def test_compare(self):
- BIG = 1L << 9999
- assert 0 == 0L
- assert not (0 != 0L)
- assert 0L == 0
- assert not (0L != 0)
- assert not (0 == BIG)
- assert 0 != BIG
- assert not (BIG == 0)
- assert BIG != 0
- assert not (0L == BIG)
- assert 0L != BIG
- assert 0 <= 0L
- assert not (0 < 0L)
- assert 0 <= BIG
- assert 0 < BIG
- assert not (BIG <= 0)
- assert not (BIG < 0)
- assert 0L <= 0L
- assert not (0L < 0L)
- assert 0L <= BIG
- assert 0L < BIG
- assert not (BIG <= 0L)
- assert not (BIG < 0L)
- assert not (0 <= -BIG)
- assert not (0 < -BIG)
- assert -BIG <= 0
- assert -BIG < 0
- assert not (0L <= -BIG)
- assert not (0L < -BIG)
- assert -BIG <= 0L
- assert -BIG < 0L
+ for BIG in (1L, 1L << 62, 1L << 9999):
+ assert 0 == 0L
+ assert not (0 != 0L)
+ assert 0L == 0
+ assert not (0L != 0)
+ assert not (0 == BIG)
+ assert 0 != BIG
+ assert not (BIG == 0)
+ assert BIG != 0
+ assert not (0L == BIG)
+ assert 0L != BIG
+ assert 0 <= 0L
+ assert not (0 < 0L)
+ assert 0 <= BIG
+ assert 0 < BIG
+ assert not (BIG <= 0)
+ assert not (BIG < 0)
+ assert 0L <= 0L
+ assert not (0L < 0L)
+ assert 0L <= BIG
+ assert 0L < BIG
+ assert not (BIG <= 0L)
+ assert not (BIG < 0L)
+ assert not (0 <= -BIG)
+ assert not (0 < -BIG)
+ assert -BIG <= 0
+ assert -BIG < 0
+ assert not (0L <= -BIG)
+ assert not (0L < -BIG)
+ assert -BIG <= 0L
+ assert -BIG < 0L
+ #
+ assert not (BIG < int(BIG))
+ assert (BIG <= int(BIG))
+ assert (BIG == int(BIG))
+ assert not (BIG != int(BIG))
+ assert not (BIG > int(BIG))
+ assert (BIG >= int(BIG))
+ #
+ assert (BIG < int(BIG)+1)
+ assert (BIG <= int(BIG)+1)
+ assert not (BIG == int(BIG)+1)
+ assert (BIG != int(BIG)+1)
+ assert not (BIG > int(BIG)+1)
+ assert not (BIG >= int(BIG)+1)
+ #
+ assert not (BIG < int(BIG)-1)
+ assert not (BIG <= int(BIG)-1)
+ assert not (BIG == int(BIG)-1)
+ assert (BIG != int(BIG)-1)
+ assert (BIG > int(BIG)-1)
+ assert (BIG >= int(BIG)-1)
+ #
+ assert not (int(BIG) < BIG)
+ assert (int(BIG) <= BIG)
+ assert (int(BIG) == BIG)
+ assert not (int(BIG) != BIG)
+ assert not (int(BIG) > BIG)
+ assert (int(BIG) >= BIG)
+ #
+ assert not (int(BIG)+1 < BIG)
+ assert not (int(BIG)+1 <= BIG)
+ assert not (int(BIG)+1 == BIG)
+ assert (int(BIG)+1 != BIG)
+ assert (int(BIG)+1 > BIG)
+ assert (int(BIG)+1 >= BIG)
+ #
+ assert (int(BIG)-1 < BIG)
+ assert (int(BIG)-1 <= BIG)
+ assert not (int(BIG)-1 == BIG)
+ assert (int(BIG)-1 != BIG)
+ assert not (int(BIG)-1 > BIG)
+ assert not (int(BIG)-1 >= BIG)
def test_conversion(self):
class long2(long):
Modified: pypy/trunk/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/rarithmetic.py (original)
+++ pypy/trunk/pypy/rlib/rarithmetic.py Wed Mar 24 16:01:00 2010
@@ -307,7 +307,7 @@
if val > klass.MASK>>1 or val < -(klass.MASK>>1)-1:
raise OverflowError("%s does not fit in signed %d-bit integer"%(val, klass.BITS))
if val < 0:
- val = - ((-val) & klass.MASK)
+ val = ~ ((~val) & klass.MASK)
return super(signed_int, klass).__new__(klass, val)
typemap = {}
Modified: pypy/trunk/pypy/rlib/rbigint.py
==============================================================================
--- pypy/trunk/pypy/rlib/rbigint.py (original)
+++ pypy/trunk/pypy/rlib/rbigint.py Wed Mar 24 16:01:00 2010
@@ -49,6 +49,7 @@
class rbigint(object):
"""This is a reimplementation of longs using a list of digits."""
+ # XXX relace the list of ints with a list of rffi.INTs, maybe
def __init__(self, digits=None, sign=0):
if digits is None or len(digits) == 0:
@@ -272,13 +273,13 @@
return False
def le(self, other):
- return self.lt(other) or self.eq(other)
+ return not other.lt(self)
def gt(self, other):
- return other.le(self)
+ return other.lt(self)
def ge(self, other):
- return other.lt(self)
+ return not self.lt(other)
def hash(self):
return _hash(self)
Modified: pypy/trunk/pypy/rlib/rmarshal.py
==============================================================================
--- pypy/trunk/pypy/rlib/rmarshal.py (original)
+++ pypy/trunk/pypy/rlib/rmarshal.py Wed Mar 24 16:01:00 2010
@@ -6,7 +6,7 @@
from pypy.annotation.signature import annotation
from pypy.annotation.listdef import ListDef, TooLateForChange
from pypy.tool.pairtype import pair, pairtype
-from pypy.rlib.rarithmetic import formatd, r_longlong, intmask
+from pypy.rlib.rarithmetic import formatd, r_longlong, intmask, LONG_BIT
from pypy.rlib.rarithmetic import break_up_float, parts_to_float
from pypy.rlib.unroll import unrolling_iterable
@@ -151,8 +151,12 @@
add_loader(annmodel.s_Bool, load_bool)
def dump_int(buf, x):
- buf.append(TYPE_INT)
- w_long(buf, x)
+ # only use TYPE_INT on 32-bit platforms
+ if LONG_BIT > 32:
+ dump_longlong(buf, r_longlong(x))
+ else:
+ buf.append(TYPE_INT)
+ w_long(buf, x)
add_dumper(annmodel.SomeInteger(), dump_int)
def load_int_nonneg(loader):
@@ -163,9 +167,14 @@
add_loader(annmodel.SomeInteger(nonneg=True), load_int_nonneg)
def load_int(loader):
- if readchr(loader) != TYPE_INT:
- raise ValueError("expected an int")
- return readlong(loader)
+ r = readchr(loader)
+ if LONG_BIT > 32 and r == TYPE_INT64:
+ x = readlong(loader) & 0xFFFFFFFF
+ x |= readlong(loader) << 32
+ return x
+ if r == TYPE_INT:
+ return readlong(loader)
+ raise ValueError("expected an int")
add_loader(annmodel.SomeInteger(), load_int)
def dump_longlong(buf, x):
Modified: pypy/trunk/pypy/rlib/rstack.py
==============================================================================
--- pypy/trunk/pypy/rlib/rstack.py (original)
+++ pypy/trunk/pypy/rlib/rstack.py Wed Mar 24 16:01:00 2010
@@ -38,8 +38,9 @@
stack_too_big = rffi.llexternal('LL_stack_too_big', [], rffi.INT,
compilation_info=compilation_info,
_nowrapper=True,
- _callable=lambda: 0,
+ _callable=lambda: _zero,
sandboxsafe=True)
+_zero = rffi.cast(rffi.INT, 0)
def stack_check():
if rffi.cast(lltype.Signed, stack_too_big()):
Modified: pypy/trunk/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rarithmetic.py (original)
+++ pypy/trunk/pypy/rlib/test/test_rarithmetic.py Wed Mar 24 16:01:00 2010
@@ -197,6 +197,10 @@
x = intmask(tp(5))
assert (type(x), x) == (int, 5)
+def test_bug_creating_r_int():
+ minint = -sys.maxint-1
+ assert r_int(r_int(minint)) == minint
+
def test_ovfcheck():
one = 1
x = sys.maxint
Modified: pypy/trunk/pypy/rlib/test/test_rbigint.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rbigint.py (original)
+++ pypy/trunk/pypy/rlib/test/test_rbigint.py Wed Mar 24 16:01:00 2010
@@ -106,7 +106,7 @@
assert rbigint.fromrarith_int(r_uint(17)).eq(rbigint([17], 1))
assert rbigint.fromrarith_int(r_uint(BASE-1)).eq(rbigint([intmask(BASE-1)], 1))
assert rbigint.fromrarith_int(r_uint(BASE)).eq(rbigint([0, 1], 1))
- assert rbigint.fromrarith_int(r_uint(BASE**2)).eq(rbigint([0], 0))
+ #assert rbigint.fromrarith_int(r_uint(BASE**2)).eq(rbigint([0], 0))
assert rbigint.fromrarith_int(r_uint(sys.maxint)).eq(
rbigint.fromint(sys.maxint))
assert rbigint.fromrarith_int(r_uint(sys.maxint+1)).eq(
@@ -193,6 +193,14 @@
f2 = rbigint.fromlong(y)
assert (x < y) == f1.lt(f2)
+ def test_order(self):
+ f6 = rbigint.fromint(6)
+ f7 = rbigint.fromint(7)
+ assert (f6.lt(f6), f6.lt(f7), f7.lt(f6)) == (0,1,0)
+ assert (f6.le(f6), f6.le(f7), f7.le(f6)) == (1,1,0)
+ assert (f6.gt(f6), f6.gt(f7), f7.gt(f6)) == (0,0,1)
+ assert (f6.ge(f6), f6.ge(f7), f7.ge(f6)) == (1,0,1)
+
def test_int_conversion(self):
f1 = rbigint.fromlong(12332)
f2 = rbigint.fromint(12332)
@@ -465,9 +473,12 @@
def test_args_from_rarith_int(self):
from pypy.rpython.tool.rfficache import platform
+ from pypy.rlib.rarithmetic import r_int
classlist = platform.numbertype_to_rclass.values()
fnlist = []
for r in classlist:
+ if r is r_int: # and also r_longlong on 64-bit
+ continue
if r is int:
mask = sys.maxint*2+1
signed = True
Modified: pypy/trunk/pypy/rlib/test/test_rmarshal.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rmarshal.py (original)
+++ pypy/trunk/pypy/rlib/test/test_rmarshal.py Wed Mar 24 16:01:00 2010
@@ -2,7 +2,7 @@
import marshal
from pypy.rlib.rmarshal import *
from pypy.annotation import model as annmodel
-from pypy.rlib.rarithmetic import formatd
+from pypy.rlib.rarithmetic import formatd, LONG_BIT
types_that_can_be_none = [
[int],
@@ -17,6 +17,10 @@
assert marshal.loads(''.join(buf)) == 5
buf = []
+ get_marshaller(int)(buf, -555)
+ assert marshal.loads(''.join(buf)) == -555
+
+ buf = []
get_marshaller(float)(buf, 3.25)
assert marshal.loads(''.join(buf)) == 3.25
@@ -37,6 +41,15 @@
assert marshal.loads(''.join(buf)) == 0x12380000007
buf = []
+ get_marshaller(r_longlong)(buf, r_longlong(-0x12380000007))
+ assert marshal.loads(''.join(buf)) == -0x12380000007
+
+ if LONG_BIT > 32:
+ buf = []
+ get_marshaller(int)(buf, -0x12340000007)
+ assert marshal.loads(''.join(buf)) == -0x12340000007
+
+ buf = []
get_marshaller([int])(buf, [2, 5, -7])
assert marshal.loads(''.join(buf)) == [2, 5, -7]
@@ -54,6 +67,9 @@
buf = 'i\x05\x00\x00\x00'
assert get_unmarshaller(int)(buf) == 5
+ buf = 'i\x00\xf0\xff\xff'
+ assert get_unmarshaller(int)(buf) == -4096
+
buf = 'f\x043.25'
assert get_unmarshaller(float)(buf) == 3.25
@@ -75,6 +91,16 @@
buf = 'I\x07\x00\x00\x80\x23\x01\x00\x00'
assert get_unmarshaller(r_longlong)(buf) == 0x12380000007
+ buf = 'I\x00\x00\x01\x83\x80\x00\x00\x97'
+ assert get_unmarshaller(r_longlong)(buf) == -7566046822028738560L
+
+ if LONG_BIT > 32:
+ buf = 'I\x07\x00\x00\x80\x23\x01\x00\x00'
+ assert get_unmarshaller(int)(buf) == 0x12380000007
+
+ buf = 'I\x00\x00\x01\x83\x80\x00\x00\x97'
+ assert get_unmarshaller(int)(buf) == -7566046822028738560
+
buf = ('[\x03\x00\x00\x00i\x02\x00\x00\x00i\x05\x00\x00\x00'
'i\xf9\xff\xff\xff')
assert get_unmarshaller([int])(buf) == [2, 5, -7]
@@ -98,10 +124,18 @@
return ''.join(buf)
res = interpret(f, [])
res = ''.join(res.chars)
- assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00i\x05\x00\x00\x00'
- 's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
- 'i\x07\x00\x00\x00s\x05\x00\x00\x00world'
- 'f\x061e+100')
+ if LONG_BIT == 32:
+ assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00i\x05\x00\x00\x00'
+ 's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
+ 'i\x07\x00\x00\x00s\x05\x00\x00\x00world'
+ 'f\x061e+100')
+ else:
+ assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00'
+ 'I\x05\x00\x00\x00\x00\x00\x00\x00'
+ 's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
+ 'I\x07\x00\x00\x00\x00\x00\x00\x00'
+ 's\x05\x00\x00\x00world'
+ 'f\x061e+100')
def test_llinterp_unmarshal():
from pypy.rpython.test.test_llinterp import interpret
Modified: pypy/trunk/pypy/rlib/test/test_rstruct.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rstruct.py (original)
+++ pypy/trunk/pypy/rlib/test/test_rstruct.py Wed Mar 24 16:01:00 2010
@@ -1,12 +1,14 @@
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rlib.rstruct.runpack import runpack
+from pypy.rlib.rarithmetic import LONG_BIT
import struct
class BaseTestRStruct(BaseRtypingTest):
def test_unpack(self):
+ pad = '\x00' * (LONG_BIT//8-1) # 3 or 7 null bytes
def fn():
- return runpack('sll', 'a\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00')[1]
+ return runpack('sll', 'a'+pad+'\x03'+pad+'\x04'+pad)[1]
assert fn() == 3
assert self.interpret(fn, []) == 3
Modified: pypy/trunk/pypy/rpython/lltypesystem/llgroup.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/llgroup.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/llgroup.py Wed Mar 24 16:01:00 2010
@@ -50,9 +50,11 @@
if LONG_BIT == 32:
+ HALFSHIFT = 16
HALFWORD = rffi.USHORT
r_halfword = rffi.r_ushort
else:
+ HALFSHIFT = 32
HALFWORD = rffi.UINT
r_halfword = rffi.r_uint
@@ -97,7 +99,7 @@
'&~0xFFFF' or with a direct masking like '&0x10000' (resp. on 64-bit
platform, with '&~0xFFFFFFFF' or '&0x100000000').
"""
- MASK = (1<<(LONG_BIT//2))-1 # 0xFFFF or 0xFFFFFFFF
+ MASK = (1<<HALFSHIFT)-1 # 0xFFFF or 0xFFFFFFFF
def annotation(self):
from pypy.annotation import model
Modified: pypy/trunk/pypy/rpython/lltypesystem/test/test_llgroup.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/test/test_llgroup.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/test/test_llgroup.py Wed Mar 24 16:01:00 2010
@@ -67,10 +67,11 @@
test.build()
grpptr = test.grpptr
g1x = [test.g1a, test.g1b]
- cs1 = CombinedSymbolic(test.g1b, 0x450000)
- cs2 = CombinedSymbolic(test.g1b, 0x410000)
- assert llop.extract_ushort(rffi.USHORT, cs1) is test.g1b
- assert cs1 & ~0xFFFF == 0x450000
+ MASK = CombinedSymbolic.MASK
+ cs1 = CombinedSymbolic(test.g1b, 0x45 << HALFSHIFT)
+ cs2 = CombinedSymbolic(test.g1b, 0x41 << HALFSHIFT)
+ assert llop.extract_ushort(HALFWORD, cs1) is test.g1b
+ assert cs1 & ~MASK == 0x45 << HALFSHIFT
cslist = [cs1, cs2]
#
def f():
@@ -99,11 +100,11 @@
assert p.x == expected[i]
#
for i in range(2):
- s = llop.extract_ushort(rffi.USHORT, cslist[i])
+ s = llop.extract_ushort(HALFWORD, cslist[i])
p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, s)
assert p == test.p1b
- assert cslist[0] & ~0xFFFF == 0x450000
- assert cslist[1] & ~0xFFFF == 0x410000
+ assert cslist[0] & ~MASK == 0x45 << HALFSHIFT
+ assert cslist[1] & ~MASK == 0x41 << HALFSHIFT
#
return 42
return f
Modified: pypy/trunk/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/generation.py (original)
+++ pypy/trunk/pypy/rpython/memory/gc/generation.py Wed Mar 24 16:01:00 2010
@@ -8,9 +8,11 @@
from pypy.rlib.objectmodel import free_non_gc_object
from pypy.rlib.debug import ll_assert
from pypy.rlib.debug import debug_print, debug_start, debug_stop
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, LONG_BIT
from pypy.rpython.lltypesystem.lloperation import llop
+WORD = LONG_BIT // 8
+
# The following flag is never set on young objects, i.e. the ones living
# in the nursery. It is initially set on all prebuilt and old objects,
# and gets cleared by the write_barrier() when we write in them a
@@ -47,10 +49,10 @@
nursery_hash_base = -1
def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
- nursery_size=128,
- min_nursery_size=128,
+ nursery_size=32*WORD,
+ min_nursery_size=32*WORD,
auto_nursery_size=False,
- space_size=4096,
+ space_size=1024*WORD,
max_space_size=sys.maxint//2+1):
SemiSpaceGC.__init__(self, config, chunk_size = chunk_size,
space_size = space_size,
Modified: pypy/trunk/pypy/rpython/memory/gc/hybrid.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/hybrid.py (original)
+++ pypy/trunk/pypy/rpython/memory/gc/hybrid.py Wed Mar 24 16:01:00 2010
@@ -1,6 +1,6 @@
import sys
from pypy.rpython.memory.gc.semispace import SemiSpaceGC
-from pypy.rpython.memory.gc.generation import GenerationGC
+from pypy.rpython.memory.gc.generation import GenerationGC, WORD
from pypy.rpython.memory.gc.semispace import GCFLAG_EXTERNAL, GCFLAG_FORWARDED
from pypy.rpython.memory.gc.semispace import GCFLAG_HASHMASK
from pypy.rpython.memory.gc.generation import GCFLAG_NO_YOUNG_PTRS
@@ -89,8 +89,8 @@
# condition: large_object <= large_object_gcptrs < min_nursery_size/4
def __init__(self, *args, **kwds):
- large_object = kwds.pop('large_object', 24)
- large_object_gcptrs = kwds.pop('large_object_gcptrs', 32)
+ large_object = kwds.pop('large_object', 6*WORD)
+ large_object_gcptrs = kwds.pop('large_object_gcptrs', 8*WORD)
self.generation3_collect_threshold = kwds.pop(
'generation3_collect_threshold', GENERATION3_COLLECT_THRESHOLD)
GenerationGC.__init__(self, *args, **kwds)
Modified: pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py (original)
+++ pypy/trunk/pypy/rpython/memory/gc/test/test_direct.py Wed Mar 24 16:01:00 2010
@@ -9,6 +9,9 @@
import py
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.memory.gctypelayout import TypeLayoutBuilder
+from pypy.rlib.rarithmetic import LONG_BIT
+
+WORD = LONG_BIT // 8
ADDR_ARRAY = lltype.Array(llmemory.Address)
S = lltype.GcForwardReference()
@@ -378,11 +381,11 @@
class TestHybridGC(TestGenerationGC):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
- GC_PARAMS = {'space_size': 192,
- 'min_nursery_size': 48,
- 'nursery_size': 48,
- 'large_object': 12,
- 'large_object_gcptrs': 12,
+ GC_PARAMS = {'space_size': 48*WORD,
+ 'min_nursery_size': 12*WORD,
+ 'nursery_size': 12*WORD,
+ 'large_object': 3*WORD,
+ 'large_object_gcptrs': 3*WORD,
'generation3_collect_threshold': 5,
}
Modified: pypy/trunk/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/trunk/pypy/rpython/memory/test/test_gc.py Wed Mar 24 16:01:00 2010
@@ -1,7 +1,6 @@
import py
import sys
-#from pypy.rpython.memory.support import INT_SIZE
from pypy.rpython.memory import gcwrapper
from pypy.rpython.memory.test import snippet
from pypy.rpython.test.test_llinterp import get_interpreter
@@ -12,6 +11,10 @@
from pypy.rlib.objectmodel import compute_unique_id, keepalive_until_here
from pypy.rlib import rgc
from pypy.rlib.rstring import StringBuilder
+from pypy.rlib.rarithmetic import LONG_BIT
+
+WORD = LONG_BIT // 8
+
def stdout_ignore_ll_functions(msg):
strmsg = str(msg)
@@ -629,7 +632,7 @@
GC_CAN_SHRINK_ARRAY = True
class TestGrowingSemiSpaceGC(TestSemiSpaceGC):
- GC_PARAMS = {'space_size': 64}
+ GC_PARAMS = {'space_size': 16*WORD}
class TestGenerationalGC(TestSemiSpaceGC):
from pypy.rpython.memory.gc.generation import GenerationGC as GCClass
@@ -641,7 +644,7 @@
py.test.skip("Not implemented yet")
class TestMarkCompactGCGrowing(TestMarkCompactGC):
- GC_PARAMS = {'space_size': 64}
+ GC_PARAMS = {'space_size': 16*WORD}
class TestHybridGC(TestGenerationalGC):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
@@ -716,11 +719,11 @@
GC_CAN_MOVE = False # with this size of heap, stuff gets allocated
# in 3rd gen.
GC_CANNOT_MALLOC_NONMOVABLE = False
- GC_PARAMS = {'space_size': 192,
- 'min_nursery_size': 48,
- 'nursery_size': 48,
- 'large_object': 12,
- 'large_object_gcptrs': 12,
+ GC_PARAMS = {'space_size': 48*WORD,
+ 'min_nursery_size': 12*WORD,
+ 'nursery_size': 12*WORD,
+ 'large_object': 3*WORD,
+ 'large_object_gcptrs': 3*WORD,
'generation3_collect_threshold': 5,
}
Modified: pypy/trunk/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/trunk/pypy/rpython/memory/test/test_transformed_gc.py Wed Mar 24 16:01:00 2010
@@ -1,10 +1,10 @@
import py
import sys
-import struct, inspect
+import inspect
from pypy.translator.c import gc
from pypy.annotation import model as annmodel
from pypy.annotation import policy as annpolicy
-from pypy.rpython.lltypesystem import lltype, llmemory, llarena, rffi
+from pypy.rpython.lltypesystem import lltype, llmemory, llarena, rffi, llgroup
from pypy.rpython.memory.gctransform import framework
from pypy.rpython.lltypesystem.lloperation import llop, void
from pypy.rpython.memory.gc.marksweep import X_CLONE, X_POOL, X_POOL_PTR
@@ -14,8 +14,9 @@
from pypy import conftest
from pypy.rlib.rstring import StringBuilder
from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib.rarithmetic import LONG_BIT
-INT_SIZE = struct.calcsize("i") # only for estimates
+WORD = LONG_BIT // 8
def rtype(func, inputtypes, specialize=True, gcname='ref', stacklessgc=False,
@@ -219,7 +220,7 @@
run, statistics = self.runner("llinterp_lists", statistics=True)
run([])
heap_size = self.heap_usage(statistics)
- assert heap_size < 16000 * INT_SIZE / 4 # xxx
+ assert heap_size < 16000 * WORD / 4 # xxx
def define_llinterp_tuples(cls):
def malloc_a_lot():
@@ -239,7 +240,7 @@
run, statistics = self.runner("llinterp_tuples", statistics=True)
run([])
heap_size = self.heap_usage(statistics)
- assert heap_size < 16000 * INT_SIZE / 4 # xxx
+ assert heap_size < 16000 * WORD / 4 # xxx
def skipdefine_global_list(cls):
gl = []
@@ -275,7 +276,7 @@
res = run([100, 0])
assert res == len(''.join([str(x) for x in range(100)]))
heap_size = self.heap_usage(statistics)
- assert heap_size < 16000 * INT_SIZE / 4 # xxx
+ assert heap_size < 16000 * WORD / 4 # xxx
def define_nongc_static_root(cls):
T1 = lltype.GcStruct("C", ('x', lltype.Signed))
@@ -687,7 +688,7 @@
def f():
from pypy.rpython.lltypesystem import rffi
alist = [A() for i in range(50)]
- idarray = lltype.malloc(rffi.INTP.TO, len(alist), flavor='raw')
+ idarray = lltype.malloc(rffi.LONGP.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
@@ -753,7 +754,7 @@
graph = graphof(translator, g)
for op in graph.startblock.operations:
if op.opname == 'do_malloc_fixedsize_clear':
- op.args = [Constant(type_id, rffi.USHORT),
+ op.args = [Constant(type_id, llgroup.HALFWORD),
Constant(llmemory.sizeof(P), lltype.Signed),
Constant(True, lltype.Bool), # can_collect
Constant(False, lltype.Bool), # has_finalizer
@@ -790,7 +791,7 @@
graph = graphof(translator, g)
for op in graph.startblock.operations:
if op.opname == 'do_malloc_fixedsize_clear':
- op.args = [Constant(type_id, rffi.USHORT),
+ op.args = [Constant(type_id, llgroup.HALFWORD),
Constant(llmemory.sizeof(P), lltype.Signed),
Constant(True, lltype.Bool), # can_collect
Constant(False, lltype.Bool), # has_finalizer
@@ -883,7 +884,7 @@
gcname = "marksweep"
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
- GC_PARAMS = {'start_heap_size': 4096 }
+ GC_PARAMS = {'start_heap_size': 1024*WORD }
root_stack_depth = 200
@@ -1121,7 +1122,7 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.marksweep import PrintingMarkSweepGC as GCClass
- GC_PARAMS = {'start_heap_size': 4096 }
+ GC_PARAMS = {'start_heap_size': 1024*WORD }
root_stack_depth = 200
class TestSemiSpaceGC(GenericMovingGCTests):
@@ -1131,7 +1132,7 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.semispace import SemiSpaceGC as GCClass
- GC_PARAMS = {'space_size': 2048}
+ GC_PARAMS = {'space_size': 512*WORD}
root_stack_depth = 200
class TestMarkCompactGC(GenericMovingGCTests):
@@ -1143,7 +1144,7 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.markcompact import MarkCompactGC as GCClass
- GC_PARAMS = {'space_size': 2048}
+ GC_PARAMS = {'space_size': 512*WORD}
root_stack_depth = 200
class TestGenerationGC(GenericMovingGCTests):
@@ -1154,8 +1155,8 @@
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.generation import GenerationGC as \
GCClass
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 128}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 32*WORD}
root_stack_depth = 200
def define_weakref_across_minor_collection(cls):
@@ -1351,8 +1352,8 @@
self.__ready = False # collecting here is expected
GenerationGC._teardown(self)
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 512}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 128*WORD}
root_stack_depth = 200
def define_working_nursery(cls):
@@ -1382,9 +1383,9 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 128,
- 'large_object': 32}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 32*WORD,
+ 'large_object': 8*WORD}
root_stack_depth = 200
def define_ref_from_rawmalloced_to_regular(cls):
@@ -1522,7 +1523,7 @@
gcname = "marksweep"
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
- GC_PARAMS = {'start_heap_size': 4096 }
+ GC_PARAMS = {'start_heap_size': 1024*WORD }
root_stack_depth = 200
class TestHybridTaggedPointerGC(TaggedPointerGCTests):
@@ -1532,6 +1533,6 @@
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.generation import GenerationGC as \
GCClass
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 128}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 32*WORD}
root_stack_depth = 200
Modified: pypy/trunk/pypy/translator/c/gcc/test/conftest.py
==============================================================================
--- pypy/trunk/pypy/translator/c/gcc/test/conftest.py (original)
+++ pypy/trunk/pypy/translator/c/gcc/test/conftest.py Wed Mar 24 16:01:00 2010
@@ -1,9 +1,9 @@
import py
from pypy.jit.backend import detect_cpu
-class Directory(py.test.collect.Directory):
+class Module(py.test.collect.Module):
def collect(self):
cpu = detect_cpu.autodetect()
if cpu != 'x86':
py.test.skip("x86 directory skipped: cpu is %r" % (cpu,))
- return super(Directory, self).collect()
+ return super(Module, self).collect()
Modified: pypy/trunk/pypy/translator/c/node.py
==============================================================================
--- pypy/trunk/pypy/translator/c/node.py (original)
+++ pypy/trunk/pypy/translator/c/node.py Wed Mar 24 16:01:00 2010
@@ -992,18 +992,13 @@
forward_cdecl(ctype, self.name, self.db.standalone,
self.is_thread_local()))
yield '#include "src/llgroup.h"'
+ yield 'PYPY_GROUP_CHECK_SIZE(%s)' % (self.name,)
for i, member in enumerate(self.obj.members):
structnode = self.db.getcontainernode(member)
yield '#define %s %s.member%d' % (structnode.name,
self.name, i)
yield ''
- def startupcode(self):
- count = len(self.obj.members)
- if count == 0:
- return []
- return ['PYPY_GROUP_CHECK_SIZE(%s, member%d);' % (self.name, count-1)]
-
def initializationexpr(self):
self._fix_members()
lines = ['{']
Modified: pypy/trunk/pypy/translator/c/primitive.py
==============================================================================
--- pypy/trunk/pypy/translator/c/primitive.py (original)
+++ pypy/trunk/pypy/translator/c/primitive.py Wed Mar 24 16:01:00 2010
@@ -148,9 +148,8 @@
if isinstance(value, Symbolic):
if isinstance(value, llgroup.GroupMemberOffset):
groupnode = db.getcontainernode(value.grpptr._as_obj())
- return 'GROUP_MEMBER_OFFSET(%s, %s, member%s)' % (
+ return 'GROUP_MEMBER_OFFSET(%s, member%s)' % (
cdecl(groupnode.implementationtypename, ''),
- groupnode.name,
value.index,
)
else:
Modified: pypy/trunk/pypy/translator/c/src/llgroup.h
==============================================================================
--- pypy/trunk/pypy/translator/c/src/llgroup.h (original)
+++ pypy/trunk/pypy/translator/c/src/llgroup.h Wed Mar 24 16:01:00 2010
@@ -11,7 +11,7 @@
typedef unsigned short pypy_halfword_t;
-#define GROUP_MEMBER_OFFSET(grouptype, groupname, membername) \
+#define GROUP_MEMBER_OFFSET(grouptype, membername) \
((unsigned short)(((long)&((grouptype*)NULL)->membername) / 4))
#define _OP_GET_GROUP_MEMBER(groupptr, compactoffset) \
@@ -22,33 +22,31 @@
/* A macro to crash at compile-time if sizeof(group) is too large.
Uses a hack that I've found on some random forum. Haaaaaaaaaackish. */
-#define PYPY_GROUP_CHECK_SIZE(groupname, lastname) \
- { typedef char group_##groupname##_is_too_large[ \
- 2*(sizeof(groupname) <= 65536*4)-1]; }
+#define PYPY_GROUP_CHECK_SIZE(groupname) \
+ typedef char group_##groupname##_is_too_large[ \
+ 2*(sizeof(groupname) <= 65536*4)-1];
#else /******************************************************/
/* On 64-bit platforms, a CombinedSymbolic is two UINTs, and the lower
- one stores a real pointer to the group memeber. The limitation is
- that this pointer must fit inside 32-bit, i.e. the whole group must
- be located in the first 32 bits of address space. */
+ one is an 32-bit offset from the start of the group. */
typedef unsigned int pypy_halfword_t;
-#define GROUP_MEMBER_OFFSET(grouptype, groupname, membername) \
- ((long)(&groupname.membername))
+#define GROUP_MEMBER_OFFSET(grouptype, membername) \
+ offsetof(grouptype, membername)
#define _OP_GET_GROUP_MEMBER(groupptr, compactoffset) \
- ((long)compactoffset)
+ (((char*)groupptr) + (long)compactoffset)
#define _OP_GET_NEXT_GROUP_MEMBER(groupptr, compactoffset, skipoffset) \
- ((long)compactoffset + skipoffset)
+ (((char*)groupptr) + skipoffset + (long)compactoffset)
-/* A macro to check at run-time if the group is below the 32-bit limit. */
-#define PYPY_GROUP_CHECK_SIZE(groupname, lastname) \
- if ((unsigned long)(&groupname.lastname) > 0xFFFFFFFF) \
- error = "group " #groupname " is not located in the " \
- "initial 32 bits of address space"
+/* A macro to crash at compile-time if sizeof(group) is too large.
+ Uses a hack that I've found on some random forum. Haaaaaaaaaackish. */
+#define PYPY_GROUP_CHECK_SIZE(groupname) \
+ typedef char group_##groupname##_is_too_large[ \
+ 2*(sizeof(groupname) <= 4294967296L)-1];
#endif /*****************************************************/
Modified: pypy/trunk/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/trunk/pypy/translator/c/test/test_lltyped.py Wed Mar 24 16:01:00 2010
@@ -732,14 +732,17 @@
('z4', Signed), ('u4', Signed))
goffsets = []
for i in range(4096 + toobig):
- goffsets.append(grp.add_member(malloc(S1, immortal=True)))
+ ofs = grp.add_member(malloc(S1, immortal=True))
+ goffsets.append(llgroup.CombinedSymbolic(ofs, 0))
grpptr = grp._as_ptr()
def f(n):
- p = llop.get_group_member(Ptr(S1), grpptr, goffsets[n])
+ o = llop.extract_ushort(llgroup.HALFWORD, goffsets[n])
+ p = llop.get_group_member(Ptr(S1), grpptr, o)
p.x = 5
for i in range(len(goffsets)):
if i != n:
- q = llop.get_group_member(Ptr(S1), grpptr, goffsets[i])
+ o = llop.extract_ushort(llgroup.HALFWORD, goffsets[i])
+ q = llop.get_group_member(Ptr(S1), grpptr, o)
q.x = 666
return p.x
if toobig:
More information about the Pypy-commit
mailing list