Author: Richard Plangger <planri...@gmail.com> Branch: ppc-vsx-support Changeset: r88029:189e9af37446 Date: 2016-11-01 14:21 +0100 http://bitbucket.org/pypy/pypy/changeset/189e9af37446/
Log: merge default diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -106,8 +106,10 @@ # So we create a few interp-level subclasses of W_XxxObject, which add # some combination of features. This is done using mapdict. -# we need two subclasses of the app-level type, one to add mapdict, and then one -# to add del to not slow down the GC. +# Note that nowadays, we need not "a few" but only one subclass. It +# adds mapdict, which flexibly allows all features. We handle the +# presence or absence of an app-level '__del__' by calling +# register_finalizer() or not. @specialize.memo() def get_unique_interplevel_subclass(space, cls): diff --git a/pypy/module/cpyext/test/test_ztranslation.py b/pypy/module/cpyext/test/test_ztranslation.py deleted file mode 100644 --- a/pypy/module/cpyext/test/test_ztranslation.py +++ /dev/null @@ -1,4 +0,0 @@ -from pypy.objspace.fake.checkmodule import checkmodule - -def test_cpyext_translates(): - checkmodule('cpyext', '_rawffi', translate_startup=False) diff --git a/pypy/module/micronumpy/test/test_ztranslation.py b/pypy/module/micronumpy/test/test_ztranslation.py deleted file mode 100644 --- a/pypy/module/micronumpy/test/test_ztranslation.py +++ /dev/null @@ -1,4 +0,0 @@ -from pypy.objspace.fake.checkmodule import checkmodule - -def test_numpy_translates(): - checkmodule('micronumpy') diff --git a/pypy/module/struct/formatiterator.py b/pypy/module/struct/formatiterator.py --- a/pypy/module/struct/formatiterator.py +++ b/pypy/module/struct/formatiterator.py @@ -1,3 +1,5 @@ +from rpython.rlib.rarithmetic import (r_uint, r_ulonglong, r_longlong, + maxint, intmask) from rpython.rlib import jit from rpython.rlib.objectmodel import specialize from rpython.rlib.rstring import StringBuilder @@ -148,7 +150,20 @@ @specialize.argtype(1) def appendobj(self, value): - self.result_w.append(self.space.wrap(value)) + # CPython tries hard to return int objects whenever it can, but + # space.wrap returns a long if we pass a r_uint, r_ulonglong or + # r_longlong. So, we need special care in those cases. + is_unsigned = (isinstance(value, r_uint) or + isinstance(value, r_ulonglong)) + if is_unsigned and value <= maxint: + w_value = self.space.wrap(intmask(value)) + elif isinstance(value, r_longlong) and -maxint-1 <= value <= maxint: + w_value = self.space.wrap(intmask(value)) + else: + # generic type, just use space.wrap + w_value = self.space.wrap(value) + # + self.result_w.append(w_value) def get_pos(self): return self.pos diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py --- a/pypy/module/struct/test/test_struct.py +++ b/pypy/module/struct/test/test_struct.py @@ -431,6 +431,20 @@ def test_overflow(self): raises(self.struct.error, self.struct.pack, 'i', 1<<65) + def test_unpack_fits_into_int(self): + import sys + for fmt in 'ILQq': + # check that we return an int, if it fits + buf = self.struct.pack(fmt, 42) + val, = self.struct.unpack(fmt, buf) + assert val == 42 + assert type(val) is int + # + # check that we return a long, if it doesn't fit into an int + buf = self.struct.pack('Q', sys.maxint+1) + val, = self.struct.unpack('Q', buf) + assert val == sys.maxint+1 + assert type(val) is long class AppTestStructBuffer(object): spaceconfig = dict(usemodules=['struct', '__pypy__']) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit