[pypy-commit] pypy py3.5: Don't wrap codec exceptions when they have an attribute or more arguments.
Author: Amaury Forgeot d'ArcBranch: py3.5 Changeset: r88148:9abb6079ac04 Date: 2016-11-05 17:27 +0100 http://bitbucket.org/pypy/pypy/changeset/9abb6079ac04/ Log:Don't wrap codec exceptions when they have an attribute or more arguments. Move the code to errors.py because it relies on implementation details. diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py --- a/pypy/interpreter/error.py +++ b/pypy/interpreter/error.py @@ -344,6 +344,42 @@ finally: self._context_recorded = True +# A simplified version of _PyErr_TrySetFromCause, which returns a +# new exception of the same class, but with another error message. +# This only works for exceptions which have just a single message, +# and no other attribute. +# Otherwise the same OperationError is returned. +def try_set_from_cause(self, space, message): +from pypy.module.exceptions.interp_exceptions import W_BaseException +self.normalize_exception(space) +w_value = self.get_w_value(space) +if not isinstance(w_value, W_BaseException): +return self +exc = w_value +# "args" should be empty or contain a single string +if len(exc.args_w) == 0: +pass +elif len(exc.args_w) == 1: +if not space.isinstance_w(exc.args_w[0], space.w_unicode): +return self +else: +return self +# No instance attribute. +if exc.w_dict and space.is_true(exc.w_dict): +return self +# Try to create the new exception. +try: +new_error = oefmt(space.type(w_value), + "%s (%T: %S)", message, w_value, w_value) +new_error.w_cause = w_value +new_error.normalize_exception(space) +# Copy the traceback, but it does not escape. +new_error.set_traceback(self._application_traceback) +except OperationError: +# Return the original error +return self +return new_error + def _break_context_cycle(space, w_value, w_context): """Break reference cycles in the __context__ chain. diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py --- a/pypy/module/_codecs/interp_codecs.py +++ b/pypy/module/_codecs/interp_codecs.py @@ -415,23 +415,11 @@ state.codec_error_registry[error] = space.wrap(interp2app(globals()[name])) -# A simplified version of the incredibly complex CPython function -# _PyErr_TrySetFromCause, which returns a new exception with another -# error message. Subclasses of UnicodeErrors are returned inchanged, -# but this is only a side-effect: they cannot be constructed with a -# simple message. def _wrap_codec_error(space, operr, action, encoding): -w_exc = operr.get_w_value(space) -try: -new_operr = oefmt(space.type(w_exc), - "%s with '%s' codec failed (%T: %S)", - action, encoding, w_exc, w_exc) -new_operr.w_cause = w_exc -new_operr.normalize_exception(space) -except OperationError: -# Return the original error -return operr -return new_operr +# Note that UnicodeErrors are not wrapped and returned as is, +# "thanks to" a limitation of try_set_from_cause. +message = "%s with '%s' codec failed" % (action, encoding) +return operr.try_set_from_cause(space, message) def _call_codec(space, w_decoder, w_obj, action, encoding, errors): try: diff --git a/pypy/module/_codecs/test/test_codecs.py b/pypy/module/_codecs/test/test_codecs.py --- a/pypy/module/_codecs/test/test_codecs.py +++ b/pypy/module/_codecs/test/test_codecs.py @@ -380,11 +380,12 @@ import _codecs def search_function(encoding): def f(input, errors="strict"): -raise RuntimeError('should be wrapped') +raise to_raise if encoding == 'test.failingenc': return (f, f, None, None) return None _codecs.register(search_function) +to_raise = RuntimeError('should be wrapped') exc = raises(RuntimeError, b"hello".decode, "test.failingenc") assert str(exc.value) == ( "decoding with 'test.failingenc' codec failed " @@ -393,6 +394,14 @@ assert str(exc.value) == ( "encoding with 'test.failingenc' codec failed " "(RuntimeError: should be wrapped)") +# +to_raise.attr = "don't wrap" +exc = raises(RuntimeError, u"hello".encode, "test.failingenc") +assert exc.value == to_raise +# +to_raise = RuntimeError("Should", "Not", "Wrap") +exc = raises(RuntimeError, u"hello".encode, "test.failingenc") +assert exc.value == to_raise def test_cpytest_decode(self): import codecs
[pypy-commit] pypy py3.5: Codec error handlers *may* return bytes for the replacement string, but most standard ones don't.
Author: Amaury Forgeot d'ArcBranch: py3.5 Changeset: r88149:0562516d347e Date: 2016-11-05 21:22 +0100 http://bitbucket.org/pypy/pypy/changeset/0562516d347e/ Log:Codec error handlers *may* return bytes for the replacement string, but most standard ones don't. diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py --- a/pypy/module/_codecs/interp_codecs.py +++ b/pypy/module/_codecs/interp_codecs.py @@ -1,9 +1,9 @@ from rpython.rlib import jit from rpython.rlib.objectmodel import we_are_translated -from rpython.rlib.rstring import StringBuilder, UnicodeBuilder +from rpython.rlib.rstring import UnicodeBuilder from rpython.rlib.runicode import ( code_to_unichr, MAXUNICODE, -raw_unicode_escape_helper, raw_unicode_escape_helper) +raw_unicode_escape_helper_unicode) from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault @@ -247,7 +247,7 @@ start = space.int_w(space.getattr(w_exc, space.wrap('start'))) w_end = space.getattr(w_exc, space.wrap('end')) end = space.int_w(w_end) -builder = StringBuilder() +builder = UnicodeBuilder() pos = start while pos < end: code = ord(obj[pos]) @@ -257,11 +257,11 @@ code |= ord(obj[pos+1]) & 0x03FF code += 0x1 pos += 1 -builder.append("
[pypy-commit] pypy.org extradoc: update the values
Author: Armin RigoBranch: extradoc Changeset: r814:021ba7394e6b Date: 2016-11-05 19:29 +0100 http://bitbucket.org/pypy/pypy.org/changeset/021ba7394e6b/ Log:update the values diff --git a/don1.html b/don1.html --- a/don1.html +++ b/don1.html @@ -15,7 +15,7 @@ - $66246 of $105000 (63.1%) + $66265 of $105000 (63.1%) @@ -23,7 +23,7 @@ This donation goes towards supporting Python 3 in PyPy. Current status: -we have $3549 left +we have $3567 left in the account. Read proposal ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Issue #2426: reverse the order of 'a.__dict__'. Gives a more
Author: Armin RigoBranch: Changeset: r88147:714537112a18 Date: 2016-11-05 16:04 +0100 http://bitbucket.org/pypy/pypy/changeset/714537112a18/ Log:Issue #2426: reverse the order of 'a.__dict__'. Gives a more natural-looking order, and should help performance of copy.copy() diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py --- a/pypy/objspace/std/mapdict.py +++ b/pypy/objspace/std/mapdict.py @@ -830,65 +830,83 @@ new_obj = map.materialize_r_dict(space, obj, dict_w) obj._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) + +class IteratorMixin(object): + +def _init(self, strategy, w_dict): +w_obj = strategy.unerase(w_dict.dstorage) +self.w_obj = w_obj +self.orig_map = curr_map = w_obj._get_mapdict_map() +# We enumerate non-lazily the attributes, and store them in the +# 'attrs' list. We then walk that list in opposite order. This +# gives an ordering that is more natural (roughly corresponding +# to oldest-first) than the one we get in the direct algorithm +# (from leaves to root, looks like backward order). See issue +# #2426: it should improve the performance of code like +# copy.copy(). +attrs = [] +while True: +curr_map = curr_map.search(DICT) +if curr_map is None: +break +attrs.append(curr_map.name) +curr_map = curr_map.back +self.attrs = attrs + + class MapDictIteratorKeys(BaseKeyIterator): +objectmodel.import_from_mixin(IteratorMixin) + def __init__(self, space, strategy, w_dict): BaseKeyIterator.__init__(self, space, strategy, w_dict) -w_obj = strategy.unerase(w_dict.dstorage) -self.w_obj = w_obj -self.orig_map = self.curr_map = w_obj._get_mapdict_map() +self._init(strategy, w_dict) def next_key_entry(self): assert isinstance(self.w_dict.get_strategy(), MapDictStrategy) if self.orig_map is not self.w_obj._get_mapdict_map(): return None -if self.curr_map: -curr_map = self.curr_map.search(DICT) -if curr_map: -self.curr_map = curr_map.back -attr = curr_map.name -w_attr = self.space.wrap(attr) -return w_attr +attrs = self.attrs +if len(attrs) > 0: +attr = attrs.pop() +w_attr = self.space.wrap(attr) +return w_attr return None class MapDictIteratorValues(BaseValueIterator): +objectmodel.import_from_mixin(IteratorMixin) + def __init__(self, space, strategy, w_dict): BaseValueIterator.__init__(self, space, strategy, w_dict) -w_obj = strategy.unerase(w_dict.dstorage) -self.w_obj = w_obj -self.orig_map = self.curr_map = w_obj._get_mapdict_map() +self._init(strategy, w_dict) def next_value_entry(self): assert isinstance(self.w_dict.get_strategy(), MapDictStrategy) if self.orig_map is not self.w_obj._get_mapdict_map(): return None -if self.curr_map: -curr_map = self.curr_map.search(DICT) -if curr_map: -self.curr_map = curr_map.back -attr = curr_map.name -return self.w_obj.getdictvalue(self.space, attr) +attrs = self.attrs +if len(attrs) > 0: +attr = attrs.pop() +return self.w_obj.getdictvalue(self.space, attr) return None class MapDictIteratorItems(BaseItemIterator): +objectmodel.import_from_mixin(IteratorMixin) + def __init__(self, space, strategy, w_dict): BaseItemIterator.__init__(self, space, strategy, w_dict) -w_obj = strategy.unerase(w_dict.dstorage) -self.w_obj = w_obj -self.orig_map = self.curr_map = w_obj._get_mapdict_map() +self._init(strategy, w_dict) def next_item_entry(self): assert isinstance(self.w_dict.get_strategy(), MapDictStrategy) if self.orig_map is not self.w_obj._get_mapdict_map(): return None, None -if self.curr_map: -curr_map = self.curr_map.search(DICT) -if curr_map: -self.curr_map = curr_map.back -attr = curr_map.name -w_attr = self.space.wrap(attr) -return w_attr, self.w_obj.getdictvalue(self.space, attr) +attrs = self.attrs +if len(attrs) > 0: +attr = attrs.pop() +w_attr = self.space.wrap(attr) +return w_attr, self.w_obj.getdictvalue(self.space, attr) return None, None diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py --- a/pypy/objspace/std/test/test_mapdict.py +++ b/pypy/objspace/std/test/test_mapdict.py @@ -1183,6 +1183,20 @@ got = a.method() assert got == 43 +
[pypy-commit] pypy default: Issue #2428: Fix for an issue with ctypes (showing up as
Author: Armin RigoBranch: Changeset: r88146:f59244e00341 Date: 2016-11-05 15:41 +0100 http://bitbucket.org/pypy/pypy/changeset/f59244e00341/ Log:Issue #2428: Fix for an issue with ctypes (showing up as platform.uname() on recent Windows) diff --git a/pypy/module/_rawffi/alt/interp_funcptr.py b/pypy/module/_rawffi/alt/interp_funcptr.py --- a/pypy/module/_rawffi/alt/interp_funcptr.py +++ b/pypy/module/_rawffi/alt/interp_funcptr.py @@ -339,6 +339,9 @@ "No symbol %s found in library %s", name, self.name) return space.wrap(address_as_uint) +def getidentifier(self, space): +return space.wrap(self.cdll.getidentifier()) + @unwrap_spec(name='str_or_None', mode=int) def descr_new_cdll(space, w_type, name, mode=-1): return space.wrap(W_CDLL(space, name, mode)) @@ -349,6 +352,8 @@ __new__ = interp2app(descr_new_cdll), getfunc = interp2app(W_CDLL.getfunc), getaddressindll = interp2app(W_CDLL.getaddressindll), +__int__ = interp2app(W_CDLL.getidentifier), +__long__= interp2app(W_CDLL.getidentifier), ) class W_WinDLL(W_CDLL): diff --git a/pypy/module/_rawffi/alt/test/test_funcptr.py b/pypy/module/_rawffi/alt/test/test_funcptr.py --- a/pypy/module/_rawffi/alt/test/test_funcptr.py +++ b/pypy/module/_rawffi/alt/test/test_funcptr.py @@ -643,3 +643,11 @@ f_name = libfoo.getfunc('AAA_first_ordinal_function', [], types.sint) f_ordinal = libfoo.getfunc(1, [], types.sint) assert f_name.getaddr() == f_ordinal.getaddr() + +def test_cdll_as_integer(self): +import _rawffi +from _rawffi.alt import CDLL +libfoo = CDLL(self.libfoo_name) +A = _rawffi.Array('i') +a = A(1, autofree=True) +a[0] = libfoo # should cast libfoo to int/long automatically diff --git a/rpython/rlib/libffi.py b/rpython/rlib/libffi.py --- a/rpython/rlib/libffi.py +++ b/rpython/rlib/libffi.py @@ -457,6 +457,9 @@ def getaddressindll(self, name): return dlsym(self.lib, name) +def getidentifier(self): +return rffi.cast(lltype.Unsigned, self.lib) + if os.name == 'nt': class WinDLL(CDLL): def getpointer(self, name, argtypes, restype, flags=FUNCFLAG_STDCALL): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: Don't pollute the namespace with 'CTypeDescrObject'
Author: Armin RigoBranch: Changeset: r2805:9308471c132a Date: 2016-11-05 10:36 +0100 http://bitbucket.org/cffi/cffi/changeset/9308471c132a/ Log:Don't pollute the namespace with 'CTypeDescrObject' diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h --- a/cffi/_cffi_include.h +++ b/cffi/_cffi_include.h @@ -141,9 +141,9 @@ #define _cffi_to_c_char \ ((int(*)(PyObject *))_cffi_exports[9]) #define _cffi_from_c_pointer \ -((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10]) +((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[10]) #define _cffi_to_c_pointer \ -((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11]) +((char *(*)(PyObject *, struct _cffi_ctypedescr *))_cffi_exports[11]) #define _cffi_get_struct_layout \ not used any more #define _cffi_restore_errno \ @@ -153,11 +153,11 @@ #define _cffi_from_c_char\ ((PyObject *(*)(char))_cffi_exports[15]) #define _cffi_from_c_deref \ -((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16]) +((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[16]) #define _cffi_to_c \ -((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17]) +((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[17]) #define _cffi_from_c_struct \ -((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18]) +((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18]) #define _cffi_to_c_wchar_t \ ((wchar_t(*)(PyObject *))_cffi_exports[19]) #define _cffi_from_c_wchar_t \ @@ -167,21 +167,22 @@ #define _cffi_to_c__Bool \ ((_Bool(*)(PyObject *))_cffi_exports[22]) #define _cffi_prepare_pointer_call_argument \ -((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23]) +((Py_ssize_t(*)(struct _cffi_ctypedescr *, \ +PyObject *, char **))_cffi_exports[23]) #define _cffi_convert_array_from_object \ -((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24]) +((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[24]) #define _CFFI_CPIDX 25 #define _cffi_call_python\ ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX]) #define _CFFI_NUM_EXPORTS 26 -typedef struct _ctypedescr CTypeDescrObject; +struct _cffi_ctypedescr; static void *_cffi_exports[_CFFI_NUM_EXPORTS]; #define _cffi_type(index) ( \ assertuintptr_t)_cffi_types[index]) & 1) == 0), \ -(CTypeDescrObject *)_cffi_types[index]) +(struct _cffi_ctypedescr *)_cffi_types[index]) static PyObject *_cffi_init(const char *module_name, Py_ssize_t version, const struct _cffi_type_context_s *ctx) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: skip vector test on x86 32bit
Author: Richard PlanggerBranch: Changeset: r88145:6b8216508ada Date: 2016-11-05 07:34 +0100 http://bitbucket.org/pypy/pypy/changeset/6b8216508ada/ Log:skip vector test on x86 32bit diff --git a/rpython/jit/metainterp/test/test_resoperation.py b/rpython/jit/metainterp/test/test_resoperation.py --- a/rpython/jit/metainterp/test/test_resoperation.py +++ b/rpython/jit/metainterp/test/test_resoperation.py @@ -1,5 +1,7 @@ import py +import pytest import re +import sys from rpython.jit.metainterp import resoperation as rop from rpython.jit.metainterp.history import AbstractDescr, AbstractFailDescr from rpython.jit.metainterp.history import ConstInt @@ -96,6 +98,7 @@ (rop.rop.CAST_SINGLEFLOAT_TO_FLOAT, [VARI], {'from': 4, 'to': 8}), (rop.rop.CAST_FLOAT_TO_SINGLEFLOAT, [VARF], {'from': 8, 'to': 4}), ]) +@pytest.mark.skipif("sys.maxint == 2**31-1") def test_cast_ops(opnum, args, kwargs): op = rop.ResOperation(opnum, args) assert op.is_typecast() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit