Author: Alex Gaynor <[email protected]>
Branch: numpy-full-fromstring
Changeset: r50529:d0c17d270f6c
Date: 2011-12-15 02:52 -0500
http://bitbucket.org/pypy/pypy/changeset/d0c17d270f6c/
Log: merged default
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -190,8 +190,8 @@
def is_w(self, space, w_other):
return self is w_other
- def unique_id(self, space):
- return space.wrap(compute_unique_id(self))
+ def immutable_unique_id(self, space):
+ return None
def str_w(self, space):
w_msg = typed_unwrap_error_msg(space, "string", self)
@@ -706,7 +706,10 @@
return w_two.is_w(self, w_one)
def id(self, w_obj):
- return w_obj.unique_id(self)
+ w_result = w_obj.immutable_unique_id(self)
+ if w_result is None:
+ w_result = self.wrap(compute_unique_id(w_obj))
+ return w_result
def hash_w(self, w_obj):
"""shortcut for space.int_w(space.hash(w_obj))"""
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -54,7 +54,11 @@
# Hash support
def default_identity_hash(space, w_obj):
- return space.wrap(compute_identity_hash(w_obj))
+ w_unique_id = w_obj.immutable_unique_id(space)
+ if w_unique_id is None: # common case
+ return space.wrap(compute_identity_hash(w_obj))
+ else:
+ return space.hash(w_unique_id)
# ____________________________________________________________
#
diff --git a/pypy/jit/codewriter/jtransform.py
b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -498,27 +498,29 @@
else:
log.WARNING('ignoring hint %r at %r' % (hints, self.graph))
+ def _rewrite_raw_malloc(self, op, name, args):
+ d = op.args[1].value.copy()
+ d.pop('flavor')
+ add_memory_pressure = d.pop('add_memory_pressure', False)
+ zero = d.pop('zero', False)
+ track_allocation = d.pop('track_allocation', True)
+ if d:
+ raise UnsupportedMallocFlags(d)
+ TYPE = op.args[0].value
+ if zero:
+ name += '_zero'
+ if add_memory_pressure:
+ name += '_add_memory_pressure'
+ if not track_allocation:
+ name += '_no_track_allocation'
+ return self._do_builtin_call(op, name, args,
+ extra = (TYPE,),
+ extrakey = TYPE)
+
def rewrite_op_malloc_varsize(self, op):
if op.args[1].value['flavor'] == 'raw':
- d = op.args[1].value.copy()
- d.pop('flavor')
- add_memory_pressure = d.pop('add_memory_pressure', False)
- zero = d.pop('zero', False)
- track_allocation = d.pop('track_allocation', True)
- if d:
- raise UnsupportedMallocFlags(d)
- ARRAY = op.args[0].value
- name = 'raw_malloc'
- if zero:
- name += '_zero'
- if add_memory_pressure:
- name += '_add_memory_pressure'
- if not track_allocation:
- name += '_no_track_allocation'
- return self._do_builtin_call(op, name,
- [op.args[2]],
- extra = (ARRAY,),
- extrakey = ARRAY)
+ return self._rewrite_raw_malloc(op, 'raw_malloc_varsize',
+ [op.args[2]])
if op.args[0].value == rstr.STR:
return SpaceOperation('newstr', [op.args[2]], op.result)
elif op.args[0].value == rstr.UNICODE:
@@ -531,11 +533,18 @@
op.result)
def rewrite_op_free(self, op):
- flags = op.args[1].value
- assert flags['flavor'] == 'raw'
- ARRAY = op.args[0].concretetype.TO
- return self._do_builtin_call(op, 'raw_free', [op.args[0]],
- extra = (ARRAY,), extrakey = ARRAY)
+ d = op.args[1].value.copy()
+ assert d['flavor'] == 'raw'
+ d.pop('flavor')
+ track_allocation = d.pop('track_allocation', True)
+ if d:
+ raise UnsupportedMallocFlags(d)
+ STRUCT = op.args[0].concretetype.TO
+ name = 'raw_free'
+ if not track_allocation:
+ name += '_no_track_allocation'
+ return self._do_builtin_call(op, name, [op.args[0]],
+ extra = (STRUCT,), extrakey = STRUCT)
def rewrite_op_getarrayitem(self, op):
ARRAY = op.args[0].concretetype.TO
@@ -736,6 +745,9 @@
return [op0, op1]
def rewrite_op_malloc(self, op):
+ if op.args[1].value['flavor'] == 'raw':
+ return self._rewrite_raw_malloc(op, 'raw_malloc_fixedsize', [])
+ #
assert op.args[1].value == {'flavor': 'gc'}
STRUCT = op.args[0].value
vtable = heaptracker.get_vtable_for_gcstruct(self.cpu, STRUCT)
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -599,26 +599,75 @@
return p
return _ll_0_alloc_with_del
- def build_raw_malloc_builder(zero=False, add_memory_pressure=False,
track_allocation=True):
- def build_ll_1_raw_malloc(ARRAY):
- def _ll_1_raw_malloc(n):
- return lltype.malloc(ARRAY, n, flavor='raw', zero=zero,
add_memory_pressure=add_memory_pressure)
- return _ll_1_raw_malloc
- return build_ll_1_raw_malloc
+ def build_raw_malloc_varsize_builder(zero=False,
+ add_memory_pressure=False,
+ track_allocation=True):
+ def build_ll_1_raw_malloc_varsize(ARRAY):
+ def _ll_1_raw_malloc_varsize(n):
+ return lltype.malloc(ARRAY, n, flavor='raw', zero=zero,
+ add_memory_pressure=add_memory_pressure,
+ track_allocation=track_allocation)
+ return _ll_1_raw_malloc_varsize
+ return build_ll_1_raw_malloc_varsize
- build_ll_1_raw_malloc = build_raw_malloc_builder()
- build_ll_1_raw_malloc_zero = build_raw_malloc_builder(zero=True)
- build_ll_1_raw_malloc_zero_add_memory_pressure =
build_raw_malloc_builder(zero=True, add_memory_pressure=True)
- build_ll_1_raw_malloc_add_memory_pressure =
build_raw_malloc_builder(add_memory_pressure=True)
- build_ll_1_raw_malloc_no_track_allocation =
build_raw_malloc_builder(track_allocation=False)
- build_ll_1_raw_malloc_zero_no_track_allocation =
build_raw_malloc_builder(zero=True, track_allocation=False)
- build_ll_1_raw_malloc_zero_add_memory_pressure_no_track_allocation =
build_raw_malloc_builder(zero=True, add_memory_pressure=True,
track_allocation=False)
- build_ll_1_raw_malloc_add_memory_pressure_no_track_allocation =
build_raw_malloc_builder(add_memory_pressure=True, track_allocation=False)
+ build_ll_1_raw_malloc_varsize = (
+ build_raw_malloc_varsize_builder())
+ build_ll_1_raw_malloc_varsize_zero = (
+ build_raw_malloc_varsize_builder(zero=True))
+ build_ll_1_raw_malloc_varsize_zero_add_memory_pressure = (
+ build_raw_malloc_varsize_builder(zero=True, add_memory_pressure=True))
+ build_ll_1_raw_malloc_varsize_add_memory_pressure = (
+ build_raw_malloc_varsize_builder(add_memory_pressure=True))
+ build_ll_1_raw_malloc_varsize_no_track_allocation = (
+ build_raw_malloc_varsize_builder(track_allocation=False))
+ build_ll_1_raw_malloc_varsize_zero_no_track_allocation = (
+ build_raw_malloc_varsize_builder(zero=True, track_allocation=False))
+ build_ll_1_raw_malloc_varsize_zero_add_memory_pressure_no_track_allocation
= (
+ build_raw_malloc_varsize_builder(zero=True, add_memory_pressure=True,
track_allocation=False))
+ build_ll_1_raw_malloc_varsize_add_memory_pressure_no_track_allocation = (
+ build_raw_malloc_varsize_builder(add_memory_pressure=True,
track_allocation=False))
- def build_ll_1_raw_free(ARRAY):
- def _ll_1_raw_free(p):
- lltype.free(p, flavor='raw')
- return _ll_1_raw_free
+ def build_raw_malloc_fixedsize_builder(zero=False,
+ add_memory_pressure=False,
+ track_allocation=True):
+ def build_ll_0_raw_malloc_fixedsize(STRUCT):
+ def _ll_0_raw_malloc_fixedsize():
+ return lltype.malloc(STRUCT, flavor='raw', zero=zero,
+ add_memory_pressure=add_memory_pressure,
+ track_allocation=track_allocation)
+ return _ll_0_raw_malloc_fixedsize
+ return build_ll_0_raw_malloc_fixedsize
+
+ build_ll_0_raw_malloc_fixedsize = (
+ build_raw_malloc_fixedsize_builder())
+ build_ll_0_raw_malloc_fixedsize_zero = (
+ build_raw_malloc_fixedsize_builder(zero=True))
+ build_ll_0_raw_malloc_fixedsize_zero_add_memory_pressure = (
+ build_raw_malloc_fixedsize_builder(zero=True,
add_memory_pressure=True))
+ build_ll_0_raw_malloc_fixedsize_add_memory_pressure = (
+ build_raw_malloc_fixedsize_builder(add_memory_pressure=True))
+ build_ll_0_raw_malloc_fixedsize_no_track_allocation = (
+ build_raw_malloc_fixedsize_builder(track_allocation=False))
+ build_ll_0_raw_malloc_fixedsize_zero_no_track_allocation = (
+ build_raw_malloc_fixedsize_builder(zero=True, track_allocation=False))
+
build_ll_0_raw_malloc_fixedsize_zero_add_memory_pressure_no_track_allocation = (
+ build_raw_malloc_fixedsize_builder(zero=True,
add_memory_pressure=True, track_allocation=False))
+ build_ll_0_raw_malloc_fixedsize_add_memory_pressure_no_track_allocation = (
+ build_raw_malloc_fixedsize_builder(add_memory_pressure=True,
track_allocation=False))
+
+ def build_raw_free_builder(track_allocation=True):
+ def build_ll_1_raw_free(ARRAY):
+ def _ll_1_raw_free(p):
+ lltype.free(p, flavor='raw',
+ track_allocation=track_allocation)
+ return _ll_1_raw_free
+ return build_ll_1_raw_free
+
+ build_ll_1_raw_free = (
+ build_raw_free_builder())
+ build_ll_1_raw_free_no_track_allocation = (
+ build_raw_free_builder(track_allocation=False))
+
class OOtypeHelpers:
diff --git a/pypy/jit/codewriter/test/test_codewriter.py
b/pypy/jit/codewriter/test/test_codewriter.py
--- a/pypy/jit/codewriter/test/test_codewriter.py
+++ b/pypy/jit/codewriter/test/test_codewriter.py
@@ -217,7 +217,7 @@
cw.make_jitcodes(verbose=True)
#
s = jitdriver_sd.mainjitcode.dump()
- assert 'residual_call_ir_i $<* fn _ll_1_raw_malloc__Signed>' in s
+ assert 'residual_call_ir_i $<* fn _ll_1_raw_malloc_varsize__Signed>' in s
assert 'setarrayitem_raw_i' in s
assert 'getarrayitem_raw_i' in s
assert 'residual_call_ir_v $<* fn _ll_1_raw_free__arrayPtr>' in s
diff --git a/pypy/jit/codewriter/test/test_jtransform.py
b/pypy/jit/codewriter/test/test_jtransform.py
--- a/pypy/jit/codewriter/test/test_jtransform.py
+++ b/pypy/jit/codewriter/test/test_jtransform.py
@@ -550,7 +550,7 @@
tr = Transformer(FakeCPU(), FakeResidualCallControl())
op0, op1 = tr.rewrite_operation(op)
assert op0.opname == 'residual_call_ir_i'
- assert op0.args[0].value == 'raw_malloc' # pseudo-function as a str
+ assert op0.args[0].value == 'raw_malloc_varsize' # pseudo-function as a str
assert op1.opname == '-live-'
assert op1.args == []
@@ -564,7 +564,7 @@
tr = Transformer(FakeCPU(), FakeResidualCallControl())
op0, op1 = tr.rewrite_operation(op)
assert op0.opname == 'residual_call_ir_i'
- assert op0.args[0].value == 'raw_malloc_zero' # pseudo-function as a str
+ assert op0.args[0].value == 'raw_malloc_varsize_zero' # pseudo-fn as a str
assert op1.opname == '-live-'
assert op1.args == []
@@ -578,6 +578,35 @@
tr = Transformer(FakeCPU(), FakeResidualCallControl())
py.test.raises(UnsupportedMallocFlags, tr.rewrite_operation, op)
+def test_raw_malloc_fixedsize():
+ S = lltype.Struct('dummy', ('x', lltype.Signed))
+ v = varoftype(lltype.Ptr(S))
+ flags = Constant({'flavor': 'raw', 'zero': True}, lltype.Void)
+ op = SpaceOperation('malloc', [Constant(S, lltype.Void), flags], v)
+ tr = Transformer(FakeCPU(), FakeResidualCallControl())
+ op0, op1 = tr.rewrite_operation(op)
+ assert op0.opname == 'residual_call_r_i'
+ assert op0.args[0].value == 'raw_malloc_fixedsize_zero' #pseudo-fn as a str
+ assert op1.opname == '-live-'
+ assert op1.args == []
+
+def test_raw_free():
+ S = lltype.Struct('dummy', ('x', lltype.Signed))
+ for flag in [True, False]:
+ flags = Constant({'flavor': 'raw', 'track_allocation': flag},
+ lltype.Void)
+ op = SpaceOperation('free', [varoftype(lltype.Ptr(S)), flags],
+ varoftype(lltype.Void))
+ tr = Transformer(FakeCPU(), FakeResidualCallControl())
+ op0, op1 = tr.rewrite_operation(op)
+ assert op0.opname == 'residual_call_ir_v'
+ if flag:
+ pseudo_op_name = 'raw_free'
+ else:
+ pseudo_op_name = 'raw_free_no_track_allocation'
+ assert op0.args[0].value == pseudo_op_name # pseudo-function as a str
+ assert op1.opname == '-live-'
+
def test_rename_on_links():
v1 = Variable()
v2 = Variable(); v2.concretetype = llmemory.Address
diff --git a/pypy/jit/metainterp/test/test_rawmem.py
b/pypy/jit/metainterp/test/test_rawmem.py
--- a/pypy/jit/metainterp/test/test_rawmem.py
+++ b/pypy/jit/metainterp/test/test_rawmem.py
@@ -8,7 +8,7 @@
VOID_TP = lltype.Array(lltype.Void, hints={"nolength": True,
"uncast_on_llgraph": True})
class A(object):
def __init__(self, x):
- self.storage = rffi.cast(lltype.Ptr(VOID_TP), x)\
+ self.storage = rffi.cast(lltype.Ptr(VOID_TP), x)
def f(n):
x = lltype.malloc(TP, n, flavor="raw", zero=True)
@@ -19,4 +19,14 @@
lltype.free(x, flavor="raw")
return s
res = self.interp_operations(f, [10])
- assert res == 1.0
\ No newline at end of file
+
+ def test_fixed_size_malloc(self):
+ TIMEVAL = lltype.Struct('dummy', ('tv_sec', rffi.LONG), ('tv_usec',
rffi.LONG))
+ def f():
+ p = lltype.malloc(TIMEVAL, flavor='raw')
+ lltype.free(p, flavor='raw')
+ return 42
+ res = self.interp_operations(f, [])
+ assert res == 42
+ self.check_operations_history({'call': 2, 'guard_no_exception': 1,
+ 'finish': 1})
diff --git a/pypy/module/_ssl/test/test_ssl.py
b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -161,11 +161,16 @@
def test_shutdown(self):
import socket, ssl, sys, gc
- if sys.platform == 'darwin':
- skip("get also on CPython: error: [Errno 0]")
ss = socket.ssl(self.s)
ss.write("hello\n")
- assert ss.shutdown() is self.s._sock
+ try:
+ result = ss.shutdown()
+ except socket.error, e:
+ # xxx obscure case; throwing errno 0 is pretty odd...
+ if e.errno == 0:
+ skip("Shutdown raised errno 0. CPython does this too")
+ raise
+ assert result is self.s._sock
raises(ssl.SSLError, ss.write, "hello\n")
del ss; gc.collect()
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -581,6 +581,7 @@
def descr_get_dtype(self, space):
return space.wrap(self.find_dtype())
+ @jit.unroll_safe
def descr_get_shape(self, space):
return space.newtuple([space.wrap(i) for i in self.shape])
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -656,7 +656,11 @@
os.fsync(f) # <- should also work with a file, or anything
finally: # with a fileno() method
f.close()
- raises(OSError, os.fsync, fd)
+ try:
+ # May not raise anything with a buggy libc (or eatmydata)
+ os.fsync(fd)
+ except OSError:
+ pass
raises(ValueError, os.fsync, -1)
if hasattr(os, 'fdatasync'):
@@ -668,7 +672,11 @@
os.fdatasync(fd)
finally:
f.close()
- raises(OSError, os.fdatasync, fd)
+ try:
+ # May not raise anything with a buggy libc (or eatmydata)
+ os.fdatasync(fd)
+ except OSError:
+ pass
raises(ValueError, os.fdatasync, -1)
if hasattr(os, 'fchdir'):
diff --git a/pypy/objspace/std/complexobject.py
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -31,9 +31,9 @@
imag2 = float2longlong(imag2)
return real1 == real2 and imag1 == imag2
- def unique_id(self, space):
+ def immutable_unique_id(self, space):
if self.user_overridden_class:
- return W_Object.unique_id(self, space)
+ return None
from pypy.rlib.longlong2float import float2longlong
from pypy.objspace.std.model import IDTAG_COMPLEX as tag
real = space.float_w(space.getattr(self, space.wrap("real")))
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -34,9 +34,9 @@
two = float2longlong(space.float_w(w_other))
return one == two
- def unique_id(self, space):
+ def immutable_unique_id(self, space):
if self.user_overridden_class:
- return W_Object.unique_id(self, space)
+ return None
from pypy.rlib.longlong2float import float2longlong
from pypy.objspace.std.model import IDTAG_FLOAT as tag
val = float2longlong(space.float_w(self))
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -26,9 +26,9 @@
return self is w_other
return space.int_w(self) == space.int_w(w_other)
- def unique_id(self, space):
+ def immutable_unique_id(self, space):
if self.user_overridden_class:
- return W_Object.unique_id(self, space)
+ return None
from pypy.objspace.std.model import IDTAG_INT as tag
b = space.bigint_w(self)
b = b.lshift(3).or_(rbigint.fromint(tag))
diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -18,9 +18,9 @@
return self is w_other
return space.bigint_w(self).eq(space.bigint_w(w_other))
- def unique_id(self, space):
+ def immutable_unique_id(self, space):
if self.user_overridden_class:
- return W_Object.unique_id(self, space)
+ return None
from pypy.objspace.std.model import IDTAG_LONG as tag
b = space.bigint_w(self)
b = b.lshift(3).or_(rbigint.fromint(tag))
diff --git a/pypy/objspace/std/stringobject.py
b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -32,9 +32,9 @@
return False
return space.str_w(self) is space.str_w(w_other)
- def unique_id(self, space):
+ def immutable_unique_id(self, space):
if self.user_overridden_class:
- return W_Object.unique_id(self, space)
+ return None
return space.wrap(compute_unique_id(space.str_w(self)))
diff --git a/pypy/objspace/std/test/test_obj.py
b/pypy/objspace/std/test/test_obj.py
--- a/pypy/objspace/std/test/test_obj.py
+++ b/pypy/objspace/std/test/test_obj.py
@@ -253,6 +253,12 @@
y = 2j
assert id(x) != id(y)
+ def test_object_hash_immutable(self):
+ x = 42
+ y = 40
+ y += 2
+ assert object.__hash__(x) == object.__hash__(y)
+
def test_isinstance_shortcut():
from pypy.objspace.std import objspace
diff --git a/pypy/objspace/std/unicodeobject.py
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -32,9 +32,9 @@
return False
return space.unicode_w(self) is space.unicode_w(w_other)
- def unique_id(self, space):
+ def immutable_unique_id(self, space):
if self.user_overridden_class:
- return W_Object.unique_id(self, space)
+ return None
return space.wrap(compute_unique_id(space.unicode_w(self)))
diff --git a/pypy/rpython/lltypesystem/rffi.py
b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -16,6 +16,7 @@
from pypy.rpython.annlowlevel import llhelper
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
+from pypy.rlib import jit
from pypy.rpython.lltypesystem import llmemory
import os, sys
@@ -249,8 +250,7 @@
wrapper = func_with_new_name(wrapper, name)
if calling_conv != "c":
- from pypy.rlib.jit import dont_look_inside
- wrapper = dont_look_inside(wrapper)
+ wrapper = jit.dont_look_inside(wrapper)
return wrapper
@@ -697,6 +697,8 @@
return b.build()
# str -> char*
+ # Can't inline this because of the raw address manipulation.
+ @jit.dont_look_inside
def get_nonmovingbuffer(data):
"""
Either returns a non-moving copy or performs neccessary pointer
@@ -717,6 +719,8 @@
get_nonmovingbuffer._annenforceargs_ = [strtype]
# (str, char*) -> None
+ # Can't inline this because of the raw address manipulation.
+ @jit.dont_look_inside
def free_nonmovingbuffer(data, buf):
"""
Either free a non-moving buffer or keep the original storage alive.
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit