[pypy-commit] pypy default: Merge default heads
Author: Julian Berman Branch: Changeset: r95867:60fa14799cf4 Date: 2019-02-06 12:06 +0100 http://bitbucket.org/pypy/pypy/changeset/60fa14799cf4/ Log:Merge default heads diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -5,6 +5,10 @@ .. this is a revision shortly after release-pypy-7.0.0 .. startrev: 481c69f7d81f +.. branch: zlib-copying-redux + +Fix calling copy on already-flushed compressobjs. + .. branch: zlib-copying The zlib module's compressobj and decompressobj now expose copy methods diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py --- a/pypy/module/zlib/interp_zlib.py +++ b/pypy/module/zlib/interp_zlib.py @@ -175,6 +175,11 @@ try: self.lock() try: +if not self.stream: +raise oefmt( +space.w_ValueError, +"Compressor was already flushed", +) copied = rzlib.deflateCopy(self.stream) finally: self.unlock() @@ -318,9 +323,6 @@ try: self.lock() try: -if not self.stream: -raise zlib_error(space, - "decompressor object already flushed") copied = rzlib.inflateCopy(self.stream) finally: self.unlock() diff --git a/pypy/module/zlib/test/test_zlib.py b/pypy/module/zlib/test/test_zlib.py --- a/pypy/module/zlib/test/test_zlib.py +++ b/pypy/module/zlib/test/test_zlib.py @@ -307,7 +307,8 @@ assert (d1 + from_copy) == (d1 + from_decompressor) -def test_unsuccessful_decompress_copy(self): +def test_cannot_copy_decompressor_with_stream_in_inconsistent_state(self): +if self.runappdirect: skip("can't run with -A") decompressor = self.zlib.decompressobj() self.intentionally_break_a_z_stream(zobj=decompressor) raises(self.zlib.error, decompressor.copy) @@ -341,7 +342,13 @@ assert (d1 + from_copy) == (d1 + from_compressor) -def test_unsuccessful_compress_copy(self): +def test_cannot_copy_compressor_with_stream_in_inconsistent_state(self): +if self.runappdirect: skip("can't run with -A") compressor = self.zlib.compressobj() self.intentionally_break_a_z_stream(zobj=compressor) raises(self.zlib.error, compressor.copy) + +def test_cannot_copy_compressor_with_flushed_stream(self): +compressor = self.zlib.compressobj() +compressor.flush() +raises(ValueError, compressor.copy) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Merge default
Author: Julian Berman Branch: Changeset: r95866:24f1b599a64d Date: 2019-02-06 11:59 +0100 http://bitbucket.org/pypy/pypy/changeset/24f1b599a64d/ Log:Merge default diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -5,6 +5,10 @@ .. this is a revision shortly after release-pypy-7.0.0 .. startrev: 481c69f7d81f +.. branch: zlib-copying-redux + +Fix calling copy on already-flushed compressobjs. + .. branch: zlib-copying The zlib module's compressobj and decompressobj now expose copy methods diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py --- a/pypy/module/zlib/interp_zlib.py +++ b/pypy/module/zlib/interp_zlib.py @@ -175,6 +175,11 @@ try: self.lock() try: +if not self.stream: +raise oefmt( +space.w_ValueError, +"Compressor was already flushed", +) copied = rzlib.deflateCopy(self.stream) finally: self.unlock() @@ -318,9 +323,6 @@ try: self.lock() try: -if not self.stream: -raise zlib_error(space, - "decompressor object already flushed") copied = rzlib.inflateCopy(self.stream) finally: self.unlock() diff --git a/pypy/module/zlib/test/test_zlib.py b/pypy/module/zlib/test/test_zlib.py --- a/pypy/module/zlib/test/test_zlib.py +++ b/pypy/module/zlib/test/test_zlib.py @@ -307,7 +307,8 @@ assert (d1 + from_copy) == (d1 + from_decompressor) -def test_unsuccessful_decompress_copy(self): +def test_cannot_copy_decompressor_with_stream_in_inconsistent_state(self): +if self.runappdirect: skip("can't run with -A") decompressor = self.zlib.decompressobj() self.intentionally_break_a_z_stream(zobj=decompressor) raises(self.zlib.error, decompressor.copy) @@ -341,7 +342,13 @@ assert (d1 + from_copy) == (d1 + from_compressor) -def test_unsuccessful_compress_copy(self): +def test_cannot_copy_compressor_with_stream_in_inconsistent_state(self): +if self.runappdirect: skip("can't run with -A") compressor = self.zlib.compressobj() self.intentionally_break_a_z_stream(zobj=compressor) raises(self.zlib.error, compressor.copy) + +def test_cannot_copy_compressor_with_flushed_stream(self): +compressor = self.zlib.compressobj() +compressor.flush() +raises(ValueError, compressor.copy) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Merge default
Author: Laurence TrattBranch: Changeset: r91363:cfe544728497 Date: 2017-05-22 15:23 +0200 http://bitbucket.org/pypy/pypy/changeset/cfe544728497/ Log:Merge default diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py --- a/lib_pypy/_ctypes/function.py +++ b/lib_pypy/_ctypes/function.py @@ -1,4 +1,3 @@ - from _ctypes.basics import _CData, _CDataMeta, cdata_from_address from _ctypes.primitive import SimpleType, _SimpleCData from _ctypes.basics import ArgumentError, keepalive_key @@ -9,13 +8,16 @@ import sys import traceback -try: from __pypy__ import builtinify -except ImportError: builtinify = lambda f: f + +try: +from __pypy__ import builtinify +except ImportError: +builtinify = lambda f: f # XXX this file needs huge refactoring I fear -PARAMFLAG_FIN = 0x1 -PARAMFLAG_FOUT = 0x2 +PARAMFLAG_FIN = 0x1 +PARAMFLAG_FOUT = 0x2 PARAMFLAG_FLCID = 0x4 PARAMFLAG_COMBINED = PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID @@ -24,9 +26,9 @@ PARAMFLAG_FIN, PARAMFLAG_FIN | PARAMFLAG_FOUT, PARAMFLAG_FIN | PARAMFLAG_FLCID -) +) -WIN64 = sys.platform == 'win32' and sys.maxint == 2**63 - 1 +WIN64 = sys.platform == 'win32' and sys.maxint == 2 ** 63 - 1 def get_com_error(errcode, riid, pIunk): @@ -35,6 +37,7 @@ from _ctypes import COMError return COMError(errcode, None, None) + @builtinify def call_function(func, args): "Only for debugging so far: So that we can call CFunction instances" @@ -94,14 +97,9 @@ "item %d in _argtypes_ has no from_param method" % ( i + 1,)) self._argtypes_ = list(argtypes) -self._check_argtypes_for_fastpath() + argtypes = property(_getargtypes, _setargtypes) -def _check_argtypes_for_fastpath(self): -if all([hasattr(argtype, '_ffiargshape_') for argtype in self._argtypes_]): -fastpath_cls = make_fastpath_subclass(self.__class__) -fastpath_cls.enable_fastpath_maybe(self) - def _getparamflags(self): return self._paramflags @@ -126,27 +124,26 @@ raise TypeError( "paramflags must be a sequence of (int [,string [,value]]) " "tuples" -) +) if not isinstance(flag, int): raise TypeError( "paramflags must be a sequence of (int [,string [,value]]) " "tuples" -) +) _flag = flag & PARAMFLAG_COMBINED if _flag == PARAMFLAG_FOUT: typ = self._argtypes_[idx] if getattr(typ, '_ffiargshape_', None) not in ('P', 'z', 'Z'): raise TypeError( "'out' parameter %d must be a pointer type, not %s" -% (idx+1, type(typ).__name__) -) +% (idx + 1, type(typ).__name__) +) elif _flag not in VALID_PARAMFLAGS: raise TypeError("paramflag value %d not supported" % flag) self._paramflags = paramflags paramflags = property(_getparamflags, _setparamflags) - def _getrestype(self): return self._restype_ @@ -156,7 +153,7 @@ from ctypes import c_int restype = c_int if not (isinstance(restype, _CDataMeta) or restype is None or -callable(restype)): +callable(restype)): raise TypeError("restype must be a type, a callable, or None") self._restype_ = restype @@ -168,15 +165,18 @@ def _geterrcheck(self): return getattr(self, '_errcheck_', None) + def _seterrcheck(self, errcheck): if not callable(errcheck): raise TypeError("The errcheck attribute must be callable") self._errcheck_ = errcheck + def _delerrcheck(self): try: del self._errcheck_ except AttributeError: pass + errcheck = property(_geterrcheck, _seterrcheck, _delerrcheck) def _ffishapes(self, args, restype): @@ -188,7 +188,7 @@ raise TypeError("invalid result type for callback function") restype = restype._ffiargshape_ else: -restype = 'O' # void +restype = 'O' # void return argtypes, restype def _set_address(self, address): @@ -201,7 +201,7 @@ def __init__(self, *args): self.name = None -self._objects = {keepalive_key(0):self} +self._objects = {keepalive_key(0): self} self._needs_free = True # Empty function object -- this is needed for casts @@ -222,10 +222,8 @@ if self._argtypes_ is None: self._argtypes_ = [] self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype) -
[pypy-commit] pypy default: merge default
Author: Tim FelgentreffBranch: Changeset: r89901:c613943ef39a Date: 2017-02-02 11:07 +0100 http://bitbucket.org/pypy/pypy/changeset/c613943ef39a/ Log:merge default diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py --- a/lib_pypy/_ctypes/basics.py +++ b/lib_pypy/_ctypes/basics.py @@ -102,7 +102,11 @@ % (len(buf) + offset, size + offset)) raw_addr = buf._pypy_raw_address() result = self.from_address(raw_addr) -result._ensure_objects()[''] = obj +objects = result._ensure_objects() +if objects is not None: +objects[''] = obj +else: # case e.g. of a primitive type like c_int +result._objects = obj return result def from_buffer_copy(self, obj, offset=0): diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py --- a/pypy/interpreter/function.py +++ b/pypy/interpreter/function.py @@ -198,10 +198,21 @@ def getdict(self, space): if self.w_func_dict is None: +if not self.can_change_code: +raise oefmt(space.w_AttributeError, +"cannot set extra attributes on built-in functions") self.w_func_dict = space.newdict(instance=True) return self.w_func_dict +def getdictvalue(self, space, attr): +if not self.can_change_code: +return None +return W_Root.getdictvalue(self, space, attr) + def setdict(self, space, w_dict): +if not self.can_change_code: +raise oefmt(space.w_AttributeError, +"cannot set __dict__ on built-in functions") if not space.isinstance_w(w_dict, space.w_dict): raise oefmt(space.w_TypeError, "setting function's dictionary to a non-dict") @@ -660,7 +671,7 @@ Function.__init__(self, func.space, func.code, func.w_func_globals, func.defs_w, func.closure, func.name) self.w_doc = func.w_doc -self.w_func_dict = func.w_func_dict +#self.w_func_dict = func.w_func_dict---nowadays, always None self.w_module = func.w_module def descr_builtinfunction__new__(space, w_subtype): diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py --- a/pypy/interpreter/test/test_function.py +++ b/pypy/interpreter/test/test_function.py @@ -95,8 +95,16 @@ def test_write_code_builtin_forbidden(self): def f(*args): return 42 -raises(TypeError, "dir.func_code = f.func_code") -raises(TypeError, "list.append.im_func.func_code = f.func_code") +raises(TypeError, "dir.func_code = f.func_code") +raises(TypeError, "list.append.im_func.func_code = f.func_code") + +def test_write_extra_attributes_builtin_forbidden(self): +raises(AttributeError, "dir.abcd = 5") +raises(AttributeError, "list.append.im_func.efgh = 6") +raises(AttributeError, "dir.__dict__") +raises(AttributeError, "dir.__dict__ = {}") +c = all.__call__ # this should work +assert c([4, 5, 6]) is True def test_set_module_to_name_eagerly(self): skip("fails on PyPy but works on CPython. Unsure we want to care") diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -122,12 +122,120 @@ hints={'nolength': True})) class W_ArrayBase(W_Root): -_attrs_ = ('space', 'len', 'allocated', '_lifeline_') # no buffer +_attrs_ = ('space', 'len', 'allocated', '_lifeline_', '_buffer') def __init__(self, space): self.space = space self.len = 0 self.allocated = 0 +self._buffer = lltype.nullptr(rffi.CCHARP.TO) + +@rgc.must_be_light_finalizer +def __del__(self): +if self._buffer: +lltype.free(self._buffer, flavor='raw') + +def setlen(self, size, zero=False, overallocate=True): +if size > 0: +if size > self.allocated or size < self.allocated / 2: +if overallocate: +if size < 9: +some = 3 +else: +some = 6 +some += size >> 3 +else: +some = 0 +self.allocated = size + some +byte_size = self.allocated * self.itemsize +if zero: +new_buffer = lltype.malloc( +rffi.CCHARP.TO, byte_size, flavor='raw', +add_memory_pressure=True, zero=True) +else: +new_buffer = lltype.malloc( +rffi.CCHARP.TO, byte_size, flavor='raw', +add_memory_pressure=True) +
[pypy-commit] pypy default: merge default
Author: Carl Friedrich BolzBranch: Changeset: r87724:b9ac5226fa5c Date: 2016-10-12 17:45 +0200 http://bitbucket.org/pypy/pypy/changeset/b9ac5226fa5c/ Log:merge default diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py b/rpython/jit/metainterp/optimizeopt/optimizer.py --- a/rpython/jit/metainterp/optimizeopt/optimizer.py +++ b/rpython/jit/metainterp/optimizeopt/optimizer.py @@ -734,7 +734,7 @@ modifier = resume.ResumeDataVirtualAdder(self, descr, op, self.trace, self.resumedata_memo) try: -newboxes = modifier.finish(self, pendingfields) +newboxes = modifier.finish(pendingfields) if (newboxes is not None and len(newboxes) > self.metainterp_sd.options.failargs_limit): raise resume.TagOverflow diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py --- a/rpython/jit/metainterp/resume.py +++ b/rpython/jit/metainterp/resume.py @@ -165,7 +165,7 @@ class NumberingState(object): def __init__(self, size): self.liveboxes = {} -self.current = [0] * size +self.current = [rffi.cast(rffi.SHORT, 0)] * size self._pos = 0 self.num_boxes = 0 self.num_virtuals = 0 @@ -179,6 +179,9 @@ assert rffi.cast(lltype.Signed, short) == item return self.append_short(short) +def create_numbering(self): +return resumecode.create_numbering(self.current) + class ResumeDataLoopMemo(object): def __init__(self, metainterp_sd): @@ -229,12 +232,12 @@ # env numbering -def _number_boxes(self, iter, arr, optimizer, state): +def _number_boxes(self, iter, arr, optimizer, numb_state): """ Number boxes from one snapshot """ -num_boxes = state.num_boxes -num_virtuals = state.num_virtuals -liveboxes = state.liveboxes +num_boxes = numb_state.num_boxes +num_virtuals = numb_state.num_virtuals +liveboxes = numb_state.liveboxes for item in arr: box = iter.get(rffi.cast(lltype.Signed, item)) box = optimizer.get_box_replacement(box) @@ -258,34 +261,34 @@ tagged = tag(num_boxes, TAGBOX) num_boxes += 1 liveboxes[box] = tagged -state.append_short(tagged) -state.num_boxes = num_boxes -state.num_virtuals = num_virtuals +numb_state.append_short(tagged) +numb_state.num_boxes = num_boxes +numb_state.num_virtuals = num_virtuals def number(self, optimizer, position, trace): snapshot_iter = trace.get_snapshot_iter(position) -state = NumberingState(snapshot_iter.size) +numb_state = NumberingState(snapshot_iter.size) arr = snapshot_iter.vable_array -state.append_int(len(arr)) -self._number_boxes(snapshot_iter, arr, optimizer, state) +numb_state.append_int(len(arr)) +self._number_boxes(snapshot_iter, arr, optimizer, numb_state) arr = snapshot_iter.vref_array n = len(arr) assert not (n & 1) -state.append_int(n >> 1) +numb_state.append_int(n >> 1) -self._number_boxes(snapshot_iter, arr, optimizer, state) +self._number_boxes(snapshot_iter, arr, optimizer, numb_state) for snapshot in snapshot_iter.framestack: jitcode_index, pc = snapshot_iter.unpack_jitcode_pc(snapshot) -state.append_int(jitcode_index) -state.append_int(pc) -self._number_boxes(snapshot_iter, snapshot.box_array, optimizer, state) +numb_state.append_int(jitcode_index) +numb_state.append_int(pc) +self._number_boxes( +snapshot_iter, snapshot.box_array, optimizer, numb_state) -numb = resumecode.create_numbering(state.current) -return numb, state.liveboxes, state.num_virtuals +return numb_state # caching for virtuals and boxes inside them @@ -418,7 +421,8 @@ _, tagbits = untag(tagged) return tagbits == TAGVIRTUAL -def finish(self, optimizer, pending_setfields=[]): +def finish(self, pending_setfields=[]): +optimizer = self.optimizer # compute the numbering storage = self.storage # make sure that nobody attached resume data to this guard yet @@ -426,12 +430,12 @@ resume_position = self.guard_op.rd_resume_position assert resume_position >= 0 # count stack depth -numb, liveboxes_from_env, num_virtuals = self.memo.number(optimizer, -resume_position, self.optimizer.trace) -self.liveboxes_from_env = liveboxes_from_env +numb_state = self.memo.number(optimizer, +resume_position, optimizer.trace) +self.liveboxes_from_env = liveboxes_from_env = numb_state.liveboxes +
[pypy-commit] pypy default: merge default
Author: Carl Friedrich BolzBranch: Changeset: r84026:616e8202f53f Date: 2016-04-29 11:17 +0300 http://bitbucket.org/pypy/pypy/changeset/616e8202f53f/ Log:merge default 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 @@ -277,7 +277,7 @@ def copy(self, obj): result = Object() result.space = self.space -result._init_empty(self) +result._mapdict_init_empty(self) return result def length(self): @@ -286,7 +286,7 @@ def set_terminator(self, obj, terminator): result = Object() result.space = self.space -result._init_empty(terminator) +result._mapdict_init_empty(terminator) return result def remove_dict_entries(self, obj): @@ -304,7 +304,7 @@ def materialize_r_dict(self, space, obj, dict_w): result = Object() result.space = space -result._init_empty(self.devolved_dict_terminator) +result._mapdict_init_empty(self.devolved_dict_terminator) return result @@ -417,11 +417,6 @@ def __repr__(self): return "" % (self.name, self.index, self.storageindex, self.back) -def _become(w_obj, new_obj): -# this is like the _become method, really, but we cannot use that due to -# RPython reasons -w_obj._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) - class MapAttrCache(object): def __init__(self, space): SIZE = 1 << space.config.objspace.std.methodcachesizeexp @@ -457,16 +452,13 @@ # everything that's needed to use mapdict for a user subclass at all. # This immediately makes slots possible. -# assumes presence of _init_empty, _mapdict_read_storage, +# assumes presence of _mapdict_init_empty, _mapdict_read_storage, # _mapdict_write_storage, _mapdict_storage_length, # _set_mapdict_storage_and_map # _ # methods needed for mapdict -def _become(self, new_obj): -self._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) - def _get_mapdict_map(self): return jit.promote(self.map) def _set_mapdict_map(self, map): @@ -482,7 +474,7 @@ def setclass(self, space, w_cls): new_obj = self._get_mapdict_map().set_terminator(self, w_cls.terminator) -self._become(new_obj) +self._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) def user_setup(self, space, w_subtype): from pypy.module.__builtin__.interp_classobj import W_InstanceObject @@ -490,7 +482,7 @@ assert (not self.typedef.hasdict or isinstance(w_subtype.terminator, NoDictTerminator) or self.typedef is W_InstanceObject.typedef) -self._init_empty(w_subtype.terminator) +self._mapdict_init_empty(w_subtype.terminator) # methods needed for slots @@ -508,7 +500,7 @@ new_obj = self._get_mapdict_map().delete(self, "slot", index) if new_obj is None: return False -self._become(new_obj) +self._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) return True @@ -549,7 +541,7 @@ new_obj = self._get_mapdict_map().delete(self, attrname, DICT) if new_obj is None: return False -self._become(new_obj) +self._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) return True def getdict(self, space): @@ -599,7 +591,7 @@ assert flag class MapdictStorageMixin(object): -def _init_empty(self, map): +def _mapdict_init_empty(self, map): from rpython.rlib.debug import make_sure_not_resized self.map = map self.storage = make_sure_not_resized([None] * map.size_estimate()) @@ -643,7 +635,7 @@ rangenmin1 = unroll.unrolling_iterable(range(nmin1)) valnmin1 = "_value%s" % nmin1 class subcls(object): -def _init_empty(self, map): +def _mapdict_init_empty(self, map): for i in rangenmin1: setattr(self, "_value%s" % i, None) setattr(self, valnmin1, erase_item(None)) @@ -731,7 +723,7 @@ def get_empty_storage(self): w_result = Object() terminator = self.space.fromcache(get_terminator_for_dicts) -w_result._init_empty(terminator) +w_result._mapdict_init_empty(terminator) return self.erase(w_result) def switch_to_object_strategy(self, w_dict): @@ -811,7 +803,7 @@ def clear(self, w_dict): w_obj = self.unerase(w_dict.dstorage) new_obj = w_obj._get_mapdict_map().remove_dict_entries(w_obj) -_become(w_obj, new_obj) +w_obj._set_mapdict_storage_and_map(new_obj.storage, new_obj.map) def popitem(self, w_dict): curr = self.unerase(w_dict.dstorage)._get_mapdict_map().search(DICT) @@ -836,7 +828,7 @@ def
[pypy-commit] pypy default: merge default
Author: Nikolay ZinovBranch: Changeset: r82187:e418c04f44ad Date: 2016-02-12 19:28 +0300 http://bitbucket.org/pypy/pypy/changeset/e418c04f44ad/ Log:merge default diff too long, truncating to 2000 out of 2205 lines diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO --- a/lib_pypy/cffi.egg-info/PKG-INFO +++ b/lib_pypy/cffi.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cffi -Version: 1.5.0 +Version: 1.5.1 Summary: Foreign Function Interface for Python calling C code. Home-page: http://cffi.readthedocs.org Author: Armin Rigo, Maciej Fijalkowski diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py --- a/lib_pypy/cffi/__init__.py +++ b/lib_pypy/cffi/__init__.py @@ -4,8 +4,8 @@ from .api import FFI, CDefError, FFIError from .ffiplatform import VerificationError, VerificationMissing -__version__ = "1.5.0" -__version_info__ = (1, 5, 0) +__version__ = "1.5.1" +__version_info__ = (1, 5, 1) # The verifier module file names are based on the CRC32 of a string that # contains the following version number. It may be older than __version__ diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h --- a/lib_pypy/cffi/_cffi_include.h +++ b/lib_pypy/cffi/_cffi_include.h @@ -231,6 +231,12 @@ ((got_nonpos) == (expected <= 0) && \ (got) == (unsigned long long)expected) +#ifdef MS_WIN32 +# define _cffi_stdcall __stdcall +#else +# define _cffi_stdcall /* nothing */ +#endif + #ifdef __cplusplus } #endif diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h new file mode 100644 --- /dev/null +++ b/lib_pypy/cffi/_embedding.h @@ -0,0 +1,517 @@ + +/* Support code for embedding */ + +#if defined(_MSC_VER) +# define CFFI_DLLEXPORT __declspec(dllexport) +#elif defined(__GNUC__) +# define CFFI_DLLEXPORT __attribute__((visibility("default"))) +#else +# define CFFI_DLLEXPORT /* nothing */ +#endif + + +/* There are two global variables of type _cffi_call_python_fnptr: + + * _cffi_call_python, which we declare just below, is the one called + by ``extern "Python"`` implementations. + + * _cffi_call_python_org, which on CPython is actually part of the + _cffi_exports[] array, is the function pointer copied from + _cffi_backend. + + After initialization is complete, both are equal. However, the + first one remains equal to &_cffi_start_and_call_python until the + very end of initialization, when we are (or should be) sure that + concurrent threads also see a completely initialized world, and + only then is it changed. +*/ +#undef _cffi_call_python +typedef void (*_cffi_call_python_fnptr)(struct _cffi_externpy_s *, char *); +static void _cffi_start_and_call_python(struct _cffi_externpy_s *, char *); +static _cffi_call_python_fnptr _cffi_call_python = &_cffi_start_and_call_python; + + +#ifndef _MSC_VER + /* --- Assuming a GCC not infinitely old --- */ +# define cffi_compare_and_swap(l,o,n) __sync_bool_compare_and_swap(l,o,n) +# define cffi_write_barrier() __sync_synchronize() +# if !defined(__amd64__) && !defined(__x86_64__) && \ + !defined(__i386__) && !defined(__i386) +# define cffi_read_barrier() __sync_synchronize() +# else +# define cffi_read_barrier() (void)0 +# endif +#else + /* --- Windows threads version --- */ +# include +# define cffi_compare_and_swap(l,o,n) \ + (InterlockedCompareExchangePointer(l,n,o) == (o)) +# define cffi_write_barrier() InterlockedCompareExchange(&_cffi_dummy,0,0) +# define cffi_read_barrier() (void)0 +static volatile LONG _cffi_dummy; +#endif + +#ifdef WITH_THREAD +# ifndef _MSC_VER +# include + static pthread_mutex_t _cffi_embed_startup_lock; +# else + static CRITICAL_SECTION _cffi_embed_startup_lock; +# endif + static char _cffi_embed_startup_lock_ready = 0; +#endif + +static void _cffi_acquire_reentrant_mutex(void) +{ +static void *volatile lock = NULL; + +while (!cffi_compare_and_swap(, NULL, (void *)1)) { +/* should ideally do a spin loop instruction here, but + hard to do it portably and doesn't really matter I + think: pthread_mutex_init() should be very fast, and + this is only run at start-up anyway. */ +} + +#ifdef WITH_THREAD +if (!_cffi_embed_startup_lock_ready) { +# ifndef _MSC_VER +pthread_mutexattr_t attr; +pthread_mutexattr_init(); +pthread_mutexattr_settype(, PTHREAD_MUTEX_RECURSIVE); +pthread_mutex_init(&_cffi_embed_startup_lock, ); +# else +InitializeCriticalSection(&_cffi_embed_startup_lock); +# endif +_cffi_embed_startup_lock_ready = 1; +} +#endif + +while (!cffi_compare_and_swap(, (void *)1, NULL)) +; + +#ifndef _MSC_VER +pthread_mutex_lock(&_cffi_embed_startup_lock); +#else +EnterCriticalSection(&_cffi_embed_startup_lock); +#endif +} + +static void
[pypy-commit] pypy default: merge default
Author: Tim Felgentreff timfelgentr...@gmail.com Branch: Changeset: r78410:b22f13cfe74d Date: 2015-07-02 11:52 +0200 http://bitbucket.org/pypy/pypy/changeset/b22f13cfe74d/ Log:merge default diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py --- a/pypy/module/imp/importing.py +++ b/pypy/module/imp/importing.py @@ -349,11 +349,14 @@ w_all = try_getattr(space, w_mod, space.wrap('__all__')) if w_all is not None: fromlist_w = space.fixedview(w_all) -else: -# this only runs if fromlist_w != ['*'] -for w_name in fromlist_w: -if try_getattr(space, w_mod, w_name) is None: -return None +else: +fromlist_w = [] +# from x import * with x already imported and no x.__all__ +# always succeeds without doing more imports. It will +# just copy everything from x.__dict__ as it is now. +for w_name in fromlist_w: +if try_getattr(space, w_mod, w_name) is None: +return None return w_mod return first @@ -391,12 +394,12 @@ w_all = try_getattr(space, w_mod, w('__all__')) if w_all is not None: fromlist_w = space.fixedview(w_all) -else: -# this only runs if fromlist_w != ['*'] -for w_name in fromlist_w: -if try_getattr(space, w_mod, w_name) is None: -load_part(space, w_path, prefix, space.str0_w(w_name), - w_mod, tentative=1) +else: +fromlist_w = [] +for w_name in fromlist_w: +if try_getattr(space, w_mod, w_name) is None: +load_part(space, w_path, prefix, space.str0_w(w_name), + w_mod, tentative=1) return w_mod else: return first diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -66,6 +66,14 @@ b = insubpackage = 1, ) setuppkg(pkg.pkg2, a='', b='') +setuppkg(pkg.withall, + __init__ = __all__ = ['foobar'], + foobar= found = 123) +setuppkg(pkg.withoutall, + __init__ = , + foobar= found = 123) +setuppkg(pkg.bogusall, + __init__ = __all__ = 42) setuppkg(pkg_r, inpkg = import x.y) setuppkg(pkg_r.x) setuppkg(x, y='') @@ -677,6 +685,32 @@ import imp raises(ValueError, imp.load_module, , , , [1, 2, 3, 4]) +def test_import_star_finds_submodules_with___all__(self): +for case in [not-imported-yet, already-imported]: +d = {} +exec from pkg.withall import * in d +assert d[foobar].found == 123 + +def test_import_star_does_not_find_submodules_without___all__(self): +for case in [not-imported-yet, already-imported]: +d = {} +exec from pkg.withoutall import * in d +assert foobar not in d +import pkg.withoutall.foobar # - import it here only +for case in [not-imported-yet, already-imported]: +d = {} +exec from pkg.withoutall import * in d +assert d[foobar].found == 123 + +def test_import_star_with_bogus___all__(self): +for case in [not-imported-yet, already-imported]: +try: +exec from pkg.bogusall import * in {} +except TypeError: +pass# 'int' object does not support indexing +else: +raise AssertionError(should have failed) + class TestAbi: def test_abi_tag(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: Changeset: r77307:bd704034a4b5 Date: 2015-05-13 08:10 +0200 http://bitbucket.org/pypy/pypy/changeset/bd704034a4b5/ Log:merge default diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py --- a/pypy/module/micronumpy/concrete.py +++ b/pypy/module/micronumpy/concrete.py @@ -519,6 +519,9 @@ return self.__class__(self.start, new_strides, new_backstrides, new_shape, self, orig_array) +def sort(self, space, w_axis, w_order): +from .selection import sort_array +return sort_array(self, space, w_axis, w_order) class NonWritableSliceArray(SliceArray): def descr_setitem(self, space, orig_array, w_index, w_value): diff --git a/pypy/module/micronumpy/selection.py b/pypy/module/micronumpy/selection.py --- a/pypy/module/micronumpy/selection.py +++ b/pypy/module/micronumpy/selection.py @@ -120,7 +120,7 @@ ArgSort = make_timsort_class(arg_getitem, arg_setitem, arg_length, arg_getitem_slice, arg_lt) -def argsort(arr, space, w_axis, itemsize): +def argsort(arr, space, w_axis): if w_axis is space.w_None: # note that it's fine ot pass None here as we're not going # to pass the result around (None is the link to base in slices) @@ -138,7 +138,7 @@ if len(arr.get_shape()) == 1: for i in range(arr.get_size()): raw_storage_setitem(storage, i * INT_SIZE, i) -r = Repr(INT_SIZE, itemsize, arr.get_size(), arr_storage, +r = Repr(INT_SIZE, arr.strides[0], arr.get_size(), arr_storage, storage, 0, arr.start) ArgSort(r).sort() else: @@ -174,8 +174,7 @@ itemtype = arr.dtype.itemtype for tp in all_types: if isinstance(itemtype, tp[0]): -return cache._lookup(tp)(arr, space, w_axis, - itemtype.get_element_size()) +return cache._lookup(tp)(arr, space, w_axis) # XXX this should probably be changed raise oefmt(space.w_NotImplementedError, sorting of non-numeric types '%s' is not implemented, @@ -272,7 +271,7 @@ ArgSort = make_timsort_class(arg_getitem, arg_setitem, arg_length, arg_getitem_slice, arg_lt) -def sort(arr, space, w_axis, itemsize): +def sort(arr, space, w_axis): if w_axis is space.w_None: # note that it's fine to pass None here as we're not going # to pass the result around (None is the link to base in slices) @@ -284,7 +283,7 @@ axis = space.int_w(w_axis) with arr as storage: if len(arr.get_shape()) == 1: -r = Repr(itemsize, arr.get_size(), storage, +r = Repr(arr.strides[0], arr.get_size(), storage, arr.start) ArgSort(r).sort() else: @@ -313,8 +312,7 @@ sorting of non-native byteorder not supported yet) for tp in all_types: if isinstance(itemtype, tp[0]): -return cache._lookup(tp)(arr, space, w_axis, - itemtype.get_element_size()) +return cache._lookup(tp)(arr, space, w_axis) # XXX this should probably be changed raise oefmt(space.w_NotImplementedError, sorting of non-numeric types '%s' is not implemented, diff --git a/pypy/module/micronumpy/test/test_selection.py b/pypy/module/micronumpy/test/test_selection.py --- a/pypy/module/micronumpy/test/test_selection.py +++ b/pypy/module/micronumpy/test/test_selection.py @@ -82,6 +82,13 @@ #assert (a == b).all(), \ #'a,orig,dtype %r,%r,%r' % (a,c,dtype) +def test_sort_noncontiguous(self): +from numpy import array +x = array([[2, 10], [1, 11]]) +assert (x[:, 0].argsort() == [1, 0]).all() +x[:, 0].sort() +assert (x == [[1, 10], [2, 11]]).all() + # tests from numpy/tests/test_multiarray.py def test_sort_corner_cases(self): # test ordering for floats and complex containing nans. It is only ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r76386:58059c786617 Date: 2015-03-15 21:41 +0100 http://bitbucket.org/pypy/pypy/changeset/58059c786617/ Log:merge default diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -11,3 +11,4 @@ 32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.2=3.1 32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.3.1 10f1b29a2bd21f837090286174a9ca030b8680b2 release-2.5.0 +8e24dac0b8e2db30d46d59f2c4daa3d4aaab7861 release-2.5.1 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: Changeset: r75491:c5c8fff7c426 Date: 2015-01-23 10:40 +0100 http://bitbucket.org/pypy/pypy/changeset/c5c8fff7c426/ Log:merge default diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -97,14 +97,22 @@ _nowrapper=True, c_type='int') def get_saved_errno(): -Return the saved value of the errno. This value is saved after a call -to an llexternal function with 'save_err RFFI_ERRNO_AFTER != 0'. +Return the value of the saved errno. +This value is saved after a call to a C function, if it was declared +with the flag llexternal(..., save_err=rffi.RFFI_SAVE_ERRNO). +Functions without that flag don't change the saved errno. + from rpython.rlib import rthread return intmask(rthread.tlfield_rpy_errno.getraw()) def set_saved_errno(errno): -Set the saved value of the errno. This value will be used by a -following llexternal function with 'save_err RFFI_ERRNO_BEFORE != 0'. +Set the value of the saved errno. This value will be used to +initialize the real errno just before calling the following C function, +provided it was declared llexternal(..., save_err=RFFI_READSAVED_ERRNO). +Note also that it is more common to want the real errno to be initially +zero; for that case, use llexternal(..., save_err=RFFI_ZERO_ERRNO_BEFORE) +and then you don't need set_saved_errno(0). + from rpython.rlib import rthread rthread.tlfield_rpy_errno.setraw(rffi.cast(INT, errno)) diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py --- a/rpython/rlib/rwin32.py +++ b/rpython/rlib/rwin32.py @@ -124,10 +124,24 @@ _nowrapper=True, sandboxsafe=True) def GetLastError_saved(): +Return the value of the saved LastError. +The C-level GetLastError() is saved there after a call to a C +function, if that C function was declared with the flag +llexternal(..., save_err=rffi.RFFI_SAVE_LASTERROR). +Functions without that flag don't change the saved LastError. +Alternatively, if the function was declared RFFI_SAVE_WSALASTERROR, +then the value of the C-level WSAGetLastError() is saved instead +(into the same saved LastError variable). + from rpython.rlib import rthread return rffi.cast(lltype.Signed, rthread.tlfield_rpy_lasterror.getraw()) def SetLastError_saved(err): +Set the value of the saved LastError. This value will be used in +a call to the C-level SetLastError() just before calling the +following C function, provided it was declared +llexternal(..., save_err=RFFI_READSAVED_LASTERROR). + from rpython.rlib import rthread rthread.tlfield_rpy_lasterror.setraw(rffi.cast(DWORD, err)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: Changeset: r75463:eef53f795276 Date: 2015-01-21 18:22 +0100 http://bitbucket.org/pypy/pypy/changeset/eef53f795276/ Log:merge default diff too long, truncating to 2000 out of 23420 lines diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -28,7 +28,7 @@ DEALINGS IN THE SOFTWARE. -PyPy Copyright holders 2003-2014 +PyPy Copyright holders 2003-2015 --- Except when otherwise stated (look for LICENSE files or information at diff --git a/lib-python/2.7/collections.py b/lib-python/2.7/collections.py --- a/lib-python/2.7/collections.py +++ b/lib-python/2.7/collections.py @@ -17,6 +17,10 @@ except ImportError: assert '__pypy__' not in _sys.builtin_module_names newdict = lambda _ : {} +try: +from __pypy__ import reversed_dict +except ImportError: +reversed_dict = lambda d: reversed(d.keys()) try: from thread import get_ident as _get_ident @@ -29,142 +33,35 @@ class OrderedDict(dict): -'Dictionary that remembers insertion order' -# An inherited dict maps keys to values. -# The inherited dict provides __getitem__, __len__, __contains__, and get. -# The remaining methods are order-aware. -# Big-O running times for all methods are the same as regular dictionaries. +'''Dictionary that remembers insertion order. -# The internal self.__map dict maps keys to links in a doubly linked list. -# The circular doubly linked list starts and ends with a sentinel element. -# The sentinel element never gets deleted (this simplifies the algorithm). -# Each link is stored as a list of length three: [PREV, NEXT, KEY]. +In PyPy all dicts are ordered anyway. This is mostly useful as a +placeholder to mean this dict must be ordered even on CPython. -def __init__(self, *args, **kwds): -'''Initialize an ordered dictionary. The signature is the same as -regular dictionaries, but keyword arguments are not recommended because -their insertion order is arbitrary. - -''' -if len(args) 1: -raise TypeError('expected at most 1 arguments, got %d' % len(args)) -try: -self.__root -except AttributeError: -self.__root = root = [] # sentinel node -root[:] = [root, root, None] -self.__map = {} -self.__update(*args, **kwds) - -def __setitem__(self, key, value, dict_setitem=dict.__setitem__): -'od.__setitem__(i, y) == od[i]=y' -# Setting a new item creates a new link at the end of the linked list, -# and the inherited dictionary is updated with the new key/value pair. -if key not in self: -root = self.__root -last = root[0] -last[1] = root[0] = self.__map[key] = [last, root, key] -return dict_setitem(self, key, value) - -def __delitem__(self, key, dict_delitem=dict.__delitem__): -'od.__delitem__(y) == del od[y]' -# Deleting an existing item uses self.__map to find the link which gets -# removed by updating the links in the predecessor and successor nodes. -dict_delitem(self, key) -link_prev, link_next, _ = self.__map.pop(key) -link_prev[1] = link_next# update link_prev[NEXT] -link_next[0] = link_prev# update link_next[PREV] - -def __iter__(self): -'od.__iter__() == iter(od)' -# Traverse the linked list in order. -root = self.__root -curr = root[1] # start at the first node -while curr is not root: -yield curr[2] # yield the curr[KEY] -curr = curr[1] # move to next node +Known difference: iterating over an OrderedDict which is being +concurrently modified raises RuntimeError in PyPy. In CPython +instead we get some behavior that appears reasonable in some +cases but is nonsensical in other cases. This is officially +forbidden by the CPython docs, so we forbid it explicitly for now. +''' def __reversed__(self): -'od.__reversed__() == reversed(od)' -# Traverse the linked list in reverse order. -root = self.__root -curr = root[0] # start at the last node -while curr is not root: -yield curr[2] # yield the curr[KEY] -curr = curr[0] # move to previous node - -def clear(self): -'od.clear() - None. Remove all items from od.' -root = self.__root -root[:] = [root, root, None] -self.__map.clear() -dict.clear(self) - -# -- the following methods do not depend on the
[pypy-commit] pypy default: merge default into branch
Author: Wim Lavrijsen wlavrij...@lbl.gov Branch: Changeset: r70893:822c0b8d758b Date: 2014-04-23 12:46 -0700 http://bitbucket.org/pypy/pypy/changeset/822c0b8d758b/ Log:merge default into branch diff --git a/pypy/doc/release-2.3.0.rst b/pypy/doc/release-2.3.0.rst new file mode 100644 --- /dev/null +++ b/pypy/doc/release-2.3.0.rst @@ -0,0 +1,88 @@ +=== +PyPy 2.3 - TODO +=== + +We're pleased to announce PyPy 2.3, which targets version 2.7.6 of the Python +language. This release updates the stdlib from 2.7.3, jumping directly to 2.7.6. + +This release also contains several bugfixes and performance improvements. + +You can download the PyPy 2.3 release here: + +http://pypy.org/download.html + +We would like to thank our donors for the continued support of the PyPy +project. We showed quite a bit of progress on all three projects (see below) +and we're slowly running out of funds. +Please consider donating more so we can finish those projects! The three +projects are: + +* Py3k (supporting Python 3.x): the release PyPy3 2.2 is imminent. + +* STM (software transactional memory): a preview will be released very soon, + as soon as we fix a few bugs + +* NumPy: the work done is included in the PyPy 2.2 release. More details below. + +.. _`Raspberry Pi Foundation`: http://www.raspberrypi.org + +What is PyPy? += + +PyPy is a very compliant Python interpreter, almost a drop-in replacement for +CPython 2.7. It's fast (`pypy 2.2 and cpython 2.7.2`_ performance comparison) +due to its integrated tracing JIT compiler. + +This release supports x86 machines running Linux 32/64, Mac OS X 64, Windows +32, or ARM (ARMv6 or ARMv7, with VFPv3). + +Work on the native Windows 64 is still stalling, we would welcome a volunteer +to handle that. + +.. _`pypy 2.2 and cpython 2.7.2`: http://speed.pypy.org + +Highlights +== + +* Our Garbage Collector is now incremental. It should avoid almost + all pauses due to a major collection taking place. Previously, it + would pause the program (rarely) to walk all live objects, which + could take arbitrarily long if your process is using a whole lot of + RAM. Now the same work is done in steps. This should make PyPy + more responsive, e.g. in games. There are still other pauses, from + the GC and the JIT, but they should be on the order of 5 + milliseconds each. + +* The JIT counters for hot code were never reset, which meant that a + process running for long enough would eventually JIT-compile more + and more rarely executed code. Not only is it useless to compile + such code, but as more compiled code means more memory used, this + gives the impression of a memory leak. This has been tentatively + fixed by decreasing the counters from time to time. + +* NumPy has been split: now PyPy only contains the core module, called + ``_numpypy``. The ``numpy`` module itself has been moved to + ``https://bitbucket.org/pypy/numpy`` and ``numpypy`` disappeared. + You need to install NumPy separately with a virtualenv: + ``pip install git+https://bitbucket.org/pypy/numpy.git``; + or directly: + ``git clone https://bitbucket.org/pypy/numpy.git``; + ``cd numpy``; ``pypy setup.py install``. + +* non-inlined calls have less overhead + +* Things that use ``sys.set_trace`` are now JITted (like coverage) + +* JSON decoding is now very fast (JSON encoding was already very fast) + +* various buffer copying methods experience speedups (like list-of-ints to + ``int[]`` buffer from cffi) + +* We finally wrote (hopefully) all the missing ``os.xxx()`` functions, + including ``os.startfile()`` on Windows and a handful of rare ones + on Posix. + +* numpy has a rudimentary C API that cooperates with ``cpyext`` + +Cheers, +Armin Rigo and Maciej Fijalkowski diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py --- a/pypy/module/cppyy/converter.py +++ b/pypy/module/cppyy/converter.py @@ -6,7 +6,7 @@ from rpython.rlib.rarithmetic import r_singlefloat from rpython.rlib import jit_libffi, rfloat -from pypy.module._rawffi.interp_rawffi import unpack_simple_shape +from pypy.module._rawffi.interp_rawffi import letter2tp from pypy.module._rawffi.array import W_Array, W_ArrayInstance from pypy.module.cppyy import helper, capi, ffitypes @@ -132,7 +132,7 @@ def __getattr__(self, name): if name.startswith('array_'): typecode = name[len('array_'):] -arr = self.space.interp_w(W_Array, unpack_simple_shape(self.space, self.space.wrap(typecode))) +arr = self.space.interp_w(W_Array, letter2tp(self.space, typecode)) setattr(self, name, arr) return arr raise AttributeError(name) @@ -409,7 +409,7 @@ if ptrval == 0: from pypy.module.cppyy import interp_cppyy return interp_cppyy.get_nullptr(space) -arr = space.interp_w(W_Array,
[pypy-commit] pypy default: merge default into branch
Author: Matti Picus matti.pi...@gmail.com Branch: Changeset: r70673:bace5e5bd016 Date: 2014-04-16 23:10 +0300 http://bitbucket.org/pypy/pypy/changeset/bace5e5bd016/ Log:merge default into branch diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -23,6 +23,7 @@ 'set_string_function': 'appbridge.set_string_function', 'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo', +'nditer': 'nditer.nditer', } for c in ['MAXDIMS', 'CLIP', 'WRAP', 'RAISE']: interpleveldefs[c] = 'space.wrap(constants.%s)' % c diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py --- a/pypy/module/micronumpy/concrete.py +++ b/pypy/module/micronumpy/concrete.py @@ -458,6 +458,13 @@ return SliceArray(self.start, new_strides, new_backstrides, new_shape, self, orig_array) +def readonly(self): +return NonWritableSlice(self.start, self.strides, self.backstrides, self.shape, self.parent, self.orig_arr, self.dtype) + +class NonWritableSlice(SliceArray): +def descr_setitem(self, space, orig_array, w_index, w_value): +raise OperationError(space.w_ValueError, space.wrap( +assignment destination is read-only)) class VoidBoxStorage(BaseConcreteArray): def __init__(self, size, dtype): diff --git a/pypy/module/micronumpy/iterators.py b/pypy/module/micronumpy/iterators.py --- a/pypy/module/micronumpy/iterators.py +++ b/pypy/module/micronumpy/iterators.py @@ -42,6 +42,7 @@ from rpython.rlib import jit from pypy.module.micronumpy import support +from pypy.module.micronumpy.strides import calc_strides from pypy.module.micronumpy.base import W_NDimArray @@ -142,6 +143,37 @@ def setitem(self, elem): self.array.setitem(self.offset, elem) +class SliceIterator(ArrayIter): +def __init__(self, arr, strides, backstrides, shape, order=C, +backward=False, dtype=None): +if dtype is None: +dtype = arr.implementation.dtype +self.dtype = dtype +self.arr = arr +if backward: +self.slicesize = shape[0] +self.gap = [support.product(shape[1:]) * dtype.elsize] +strides = strides[1:] +backstrides = backstrides[1:] +shape = shape[1:] +strides.reverse() +backstrides.reverse() +shape.reverse() +size = support.product(shape) +else: +shape = [support.product(shape)] +strides, backstrides = calc_strides(shape, dtype, order) +size = 1 +self.slicesize = support.product(shape) +self.gap = strides + +ArrayIter.__init__(self, arr.implementation, size, shape, strides, backstrides) + +def getslice(self): +from pypy.module.micronumpy.concrete import SliceArray +retVal = SliceArray(self.offset, self.gap, self.backstrides, +[self.slicesize], self.arr.implementation, self.arr, self.dtype) +return retVal def AxisIter(array, shape, axis, cumulative): strides = array.get_strides() diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py new file mode 100644 --- /dev/null +++ b/pypy/module/micronumpy/nditer.py @@ -0,0 +1,577 @@ +from pypy.interpreter.baseobjspace import W_Root +from pypy.interpreter.typedef import TypeDef, GetSetProperty +from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault +from pypy.interpreter.error import OperationError +from pypy.module.micronumpy.base import W_NDimArray, convert_to_array +from pypy.module.micronumpy.strides import (calculate_broadcast_strides, + shape_agreement, shape_agreement_multiple) +from pypy.module.micronumpy.iterators import ArrayIter, SliceIterator +from pypy.module.micronumpy.concrete import SliceArray +from pypy.module.micronumpy.descriptor import decode_w_dtype +from pypy.module.micronumpy import ufuncs + + +class AbstractIterator(object): +def done(self): +raise NotImplementedError(Abstract Class) + +def next(self): +raise NotImplementedError(Abstract Class) + +def getitem(self, space, array): +raise NotImplementedError(Abstract Class) + +class IteratorMixin(object): +_mixin_ = True +def __init__(self, it, op_flags): +self.it = it +self.op_flags = op_flags + +def done(self): +return self.it.done() + +def next(self): +self.it.next() + +def getitem(self, space, array): +return self.op_flags.get_it_item[self.index](space, array, self.it) + +def setitem(self, space, array, val): +xxx + +class BoxIterator(IteratorMixin, AbstractIterator): +index = 0 + +class ExternalLoopIterator(IteratorMixin, AbstractIterator): +index = 1 + +def
[pypy-commit] pypy default: merge default
Author: Antonio Cuni anto.c...@gmail.com Branch: Changeset: r66676:04a26a17138a Date: 2013-08-30 18:09 +0200 http://bitbucket.org/pypy/pypy/changeset/04a26a17138a/ Log:merge default diff --git a/lib-python/2.7/uuid.py b/lib-python/2.7/uuid.py --- a/lib-python/2.7/uuid.py +++ b/lib-python/2.7/uuid.py @@ -44,6 +44,8 @@ UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') +import struct + __author__ = 'Ka-Ping Yee p...@zesty.ca' RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [ @@ -142,7 +144,8 @@ if bytes is not None: if len(bytes) != 16: raise ValueError('bytes is not a 16-char string') -int = long(('%02x'*16) % tuple(map(ord, bytes)), 16) +int = (struct.unpack('Q', bytes[:8])[0] 64 | + struct.unpack('Q', bytes[8:])[0]) if fields is not None: if len(fields) != 6: raise ValueError('fields is not a 6-tuple') diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -40,9 +40,9 @@ # for all computations. See the book for algorithms for converting between # proleptic Gregorian ordinals and many other calendar systems. -_DAYS_IN_MONTH = [None, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] +_DAYS_IN_MONTH = [-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] -_DAYS_BEFORE_MONTH = [None] +_DAYS_BEFORE_MONTH = [-1] dbm = 0 for dim in _DAYS_IN_MONTH[1:]: _DAYS_BEFORE_MONTH.append(dbm) diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -75,3 +75,12 @@ .. branch: reflex-support .. branch: numpypy-inplace-op .. branch: rewritten-loop-logging + +.. branch: nobold-backtrace +Work on improving UnionError messages and stack trace displays. + +.. branch: improve-errors-again +More improvements and refactorings of error messages. + +.. branch: improve-errors-again2 +Unbreak tests in rlib. diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py --- a/pypy/module/micronumpy/interp_boxes.py +++ b/pypy/module/micronumpy/interp_boxes.py @@ -396,6 +396,8 @@ class W_UnicodeBox(W_CharacterBox): def descr__new__unicode_box(space, w_subtype, w_arg): +raise OperationError(space.w_NotImplementedError, space.wrap(Unicode is not supported yet)) + from pypy.module.micronumpy.interp_dtype import new_unicode_dtype arg = space.unicode_w(unicode_from_object(space, w_arg)) 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 @@ -88,13 +88,27 @@ w_res = W_NDimArray.from_shape(space, res_shape, self.get_dtype(), w_instance=self) return loop.getitem_filter(w_res, self, arr) -def setitem_filter(self, space, idx, val): +def setitem_filter(self, space, idx, value): +from pypy.module.micronumpy.interp_boxes import Box +val = value if len(idx.get_shape()) 1 and idx.get_shape() != self.get_shape(): raise OperationError(space.w_ValueError, space.wrap(boolean index array should have 1 dimension)) if idx.get_size() self.get_size(): raise OperationError(space.w_ValueError, space.wrap(index out of range for array)) +idx_iter = idx.create_iter(self.get_shape()) +size = loop.count_all_true_iter(idx_iter, self.get_shape(), idx.get_dtype()) +if len(val.get_shape()) 0 and val.get_shape()[0] 1 and size val.get_shape()[0]: +raise OperationError(space.w_ValueError, space.wrap(NumPy boolean array indexing assignment +cannot assign %d input values to +the %d output values where the mask is true % (val.get_shape()[0],size))) +if val.get_shape() == [1]: +box = val.descr_getitem(space, space.wrap(0)) +assert isinstance(box, Box) +val = W_NDimArray(scalar.Scalar(val.get_dtype(), box)) +elif val.get_shape() == [0]: +val.implementation.dtype = self.implementation.dtype loop.setitem_filter(self, idx, val) def _prepare_array_index(self, space, w_index): diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py --- a/pypy/module/micronumpy/loop.py +++ b/pypy/module/micronumpy/loop.py @@ -318,23 +318,27 @@ lefti.next() return result -count_all_true_driver = jit.JitDriver(name = 'numpy_count', - greens = ['shapelen', 'dtype'], - reds = 'auto') def count_all_true(arr): -s = 0 if arr.is_scalar(): return
[pypy-commit] pypy default: Merge default
Author: Taavi Burns taavi.bu...@gmail.com Branch: Changeset: r66119:4e153d9db4c5 Date: 2013-08-13 11:41 -0400 http://bitbucket.org/pypy/pypy/changeset/4e153d9db4c5/ Log:Merge default diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -140,6 +140,7 @@ (deg2rad, radians), (rad2deg, degrees), (reciprocal, reciprocal), +(rint, rint), (sign, sign), (signbit, signbit), (sin, sin), diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py --- a/pypy/module/micronumpy/interp_ufuncs.py +++ b/pypy/module/micronumpy/interp_ufuncs.py @@ -620,6 +620,7 @@ (positive, pos, 1), (negative, neg, 1), (absolute, abs, 1, {complex_to_float: True}), +(rint, rint, 1), (sign, sign, 1, {promote_bools: True}), (signbit, signbit, 1, {bool_result: True, allow_complex: False}), diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py --- a/pypy/module/micronumpy/test/test_ufuncs.py +++ b/pypy/module/micronumpy/test/test_ufuncs.py @@ -255,6 +255,22 @@ for i in range(3): assert c[i] == a[i] * b[i] +def test_rint(self): +from numpypy import array, complex, rint, isnan + +nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'), float('-inf') + +reference = array([ninf, -2., -1., -0., 0., 0., 0., 1., 2., inf]) +a = array([ninf, -1.5, -1., -0.5, -0., 0., 0.5, 1., 1.5, inf]) +b = rint(a) +for i in range(len(a)): +assert b[i] == reference[i] +assert isnan(rint(nan)) +assert isnan(rint(nnan)) + +assert rint(complex(inf, 1.5)) == complex(inf, 2.) +assert rint(complex(0.5, inf)) == complex(0., inf) + def test_sign(self): from numpypy import array, sign, dtype diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -307,6 +307,13 @@ def min(self, v1, v2): return min(v1, v2) +@simple_unary_op +def rint(self, v): +if isfinite(v): +return rfloat.round_double(v, 0, half_even=True) +else: +return v + class NonNativePrimitive(Primitive): _mixin_ = True @@ -1392,11 +1399,14 @@ def round(self, v, decimals=0): ans = list(self.for_computation(self.unbox(v))) if isfinite(ans[0]): -ans[0] = rfloat.round_double(ans[0], decimals, half_even=True) +ans[0] = rfloat.round_double(ans[0], decimals, half_even=True) if isfinite(ans[1]): -ans[1] = rfloat.round_double(ans[1], decimals, half_even=True) +ans[1] = rfloat.round_double(ans[1], decimals, half_even=True) return self.box_complex(ans[0], ans[1]) +def rint(self, v): +return self.round(v) + # No floor, ceil, trunc in numpy for complex #@simple_unary_op #def floor(self, v): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: Changeset: r64902:d0cfac47ecad Date: 2013-06-13 18:25 +0200 http://bitbucket.org/pypy/pypy/changeset/d0cfac47ecad/ Log:merge default diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -3,3 +3,6 @@ d8ac7d23d3ec5f9a0fa1264972f74a010dbfd07f release-1.6 ff4af8f318821f7f5ca998613a60fca09aa137da release-1.7 07e08e9c885ca67d89bcc304e45a32346daea2fa release-2.0-beta-1 +9b623bc48b5950cf07184462a0e48f2c4df0d720 pypy-2.1-beta1-arm +9b623bc48b5950cf07184462a0e48f2c4df0d720 pypy-2.1-beta1-arm +ab0dd631c22015ed88e583d9fdd4c43eebf0be21 pypy-2.1-beta1-arm diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -218,6 +218,7 @@ Impara, Germany Change Maker, Sweden University of California Berkeley, USA +Google Inc. The PyPy Logo as used by http://speed.pypy.org and others was created by Samuel Reis and is distributed on terms of Creative Commons Share Alike diff --git a/lib_pypy/_tkinter/__init__.py b/lib_pypy/_tkinter/__init__.py new file mode 100644 --- /dev/null +++ b/lib_pypy/_tkinter/__init__.py @@ -0,0 +1,43 @@ +# _tkinter package -- low-level interface to libtk and libtcl. +# +# This is an internal module, applications should import Tkinter instead. +# +# This version is based on cffi, and is a translation of _tkinter.c +# from CPython, version 2.7.4. + +class TclError(Exception): +pass + +from .tklib import tklib, tkffi +from .app import TkApp + +TK_VERSION = tkffi.string(tklib.get_tk_version()) +TCL_VERSION = tkffi.string(tklib.get_tcl_version()) + +READABLE = tklib.TCL_READABLE +WRITABLE = tklib.TCL_WRITABLE +EXCEPTION = tklib.TCL_EXCEPTION + +def create(screenName=None, baseName=None, className=None, + interactive=False, wantobjects=False, wantTk=True, + sync=False, use=None): +return TkApp(screenName, baseName, className, + interactive, wantobjects, wantTk, sync, use) + +def _flatten(item): +def _flatten1(output, item, depth): +if depth 1000: +raise ValueError(nesting too deep in _flatten) +if not isinstance(item, (list, tuple)): +raise TypeError(argument must be sequence) +# copy items to output tuple +for o in item: +if isinstance(o, (list, tuple)): +_flatten1(output, o, depth + 1) +elif o is not None: +output.append(o) + +result = [] +_flatten1(result, item, 0) +return tuple(result) + diff --git a/lib_pypy/_tkinter/app.py b/lib_pypy/_tkinter/app.py new file mode 100644 --- /dev/null +++ b/lib_pypy/_tkinter/app.py @@ -0,0 +1,389 @@ +# The TkApp class. + +from .tklib import tklib, tkffi +from . import TclError +from .tclobj import TclObject, FromObj, AsObj, TypeCache + +import sys + +def varname_converter(input): +if isinstance(input, TclObject): +return input.string +return input + + +def Tcl_AppInit(app): +if tklib.Tcl_Init(app.interp) == tklib.TCL_ERROR: +app.raiseTclError() +skip_tk_init = tklib.Tcl_GetVar( +app.interp, _tkinter_skip_tk_init, tklib.TCL_GLOBAL_ONLY) +if skip_tk_init and tkffi.string(skip_tk_init) == 1: +return + +if tklib.Tk_Init(app.interp) == tklib.TCL_ERROR: +app.raiseTclError() + +class _CommandData(object): +def __new__(cls, app, name, func): +self = object.__new__(cls) +self.app = app +self.name = name +self.func = func +handle = tkffi.new_handle(self) +app._commands[name] = handle # To keep the command alive +return tkffi.cast(ClientData, handle) + +@tkffi.callback(Tcl_CmdProc) +def PythonCmd(clientData, interp, argc, argv): +self = tkffi.from_handle(clientData) +assert self.app.interp == interp +try: +args = [tkffi.string(arg) for arg in argv[1:argc]] +result = self.func(*args) +obj = AsObj(result) +tklib.Tcl_SetObjResult(interp, obj) +except: +self.app.errorInCmd = True +self.app.exc_info = sys.exc_info() +return tklib.TCL_ERROR +else: +return tklib.TCL_OK + +@tkffi.callback(Tcl_CmdDeleteProc) +def PythonCmdDelete(clientData): +self = tkffi.from_handle(clientData) +app = self.app +del app._commands[self.name] +return + + +class TkApp(object): +def __new__(cls, screenName, baseName, className, +interactive, wantobjects, wantTk, sync, use): +if not wantobjects: +raise NotImplementedError(wantobjects=True only) +self = object.__new__(cls) +self.interp = tklib.Tcl_CreateInterp() +self._wantobjects = wantobjects +self.threaded = bool(tklib.Tcl_GetVar2Ex( +self.interp, tcl_platform, threaded, +tklib.TCL_GLOBAL_ONLY)) +self.thread_id = tklib.Tcl_GetCurrentThread() +self.dispatching = False +
[pypy-commit] pypy default: Merge default
Author: Romain Guillebert romain...@gmail.com Branch: Changeset: r64542:4668b8d8a921 Date: 2013-05-24 17:10 +0200 http://bitbucket.org/pypy/pypy/changeset/4668b8d8a921/ Log:Merge default ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r62701:8b0ce43d0de4 Date: 2013-03-23 12:01 -0700 http://bitbucket.org/pypy/pypy/changeset/8b0ce43d0de4/ Log:merge default diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1520,9 +1520,9 @@ dummy_lock = DummyLock() -## Table describing the regular part of the interface of object spaces, -## namely all methods which only take w_ arguments and return a w_ result -## (if any). Note: keep in sync with rpython.flowspace.operation.Table. +# Table describing the regular part of the interface of object spaces, +# namely all methods which only take w_ arguments and return a w_ result +# (if any). ObjSpace.MethodTable = [ # method name # symbol # number of arguments # special method name(s) diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py b/rpython/jit/metainterp/optimizeopt/unroll.py --- a/rpython/jit/metainterp/optimizeopt/unroll.py +++ b/rpython/jit/metainterp/optimizeopt/unroll.py @@ -180,7 +180,7 @@ if self.boxes_created_this_iteration is not None: for box in self.inputargs: -self.boxes_created_this_iteration[box] = True +self.boxes_created_this_iteration[box] = None short_boxes = ShortBoxes(self.optimizer, inputargs, self.boxes_created_this_iteration) @@ -241,7 +241,7 @@ for box in self.inputargs: if box in seen: continue -seen[box] = True +seen[box] = None preamble_value = exported_state.exported_values[box] value = self.optimizer.getvalue(box) value.import_from(preamble_value, self.optimizer) @@ -291,7 +291,7 @@ i = 0 while i len(newoperations): op = newoperations[i] -self.boxes_created_this_iteration[op.result] = True +self.boxes_created_this_iteration[op.result] = None args = op.getarglist() if op.is_guard(): args = args + op.getfailargs() @@ -363,7 +363,7 @@ else: op = newoperations[i] -self.boxes_created_this_iteration[op.result] = True +self.boxes_created_this_iteration[op.result] = None args = op.getarglist() if op.is_guard(): args = args + op.getfailargs() @@ -471,7 +471,7 @@ #self.optimizer.loop.logops.repr_of_resop(op)) optimizer.send_extra_operation(op) -seen[op.result] = True +seen[op.result] = None if op.is_ovf(): guard = ResOperation(rop.GUARD_NO_OVERFLOW, [], None) optimizer.send_extra_operation(guard) @@ -498,7 +498,7 @@ value_guards = [] self.short.append(op) -self.short_seen[op.result] = True +self.short_seen[op.result] = None if emit and self.short_inliner: newop = self.short_inliner.inline_op(op) self.optimizer.send_extra_operation(newop) diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py b/rpython/jit/metainterp/optimizeopt/virtualstate.py --- a/rpython/jit/metainterp/optimizeopt/virtualstate.py +++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py @@ -76,32 +76,32 @@ if self.position in renum: if renum[self.position] == other.position: return True -bad[self] = True -bad[other] = True +bad[self] = None +bad[other] = None return False renum[self.position] = other.position if not self._generalization_of(other): -bad[self] = True -bad[other] = True +bad[self] = None +bad[other] = None return False assert isinstance(other, AbstractVirtualStructStateInfo) assert len(self.fielddescrs) == len(self.fieldstate) assert len(other.fielddescrs) == len(other.fieldstate) if len(self.fielddescrs) != len(other.fielddescrs): -bad[self] = True -bad[other] = True +bad[self] = None +bad[other] = None return False for i in range(len(self.fielddescrs)): if other.fielddescrs[i] is not self.fielddescrs[i]: -bad[self] = True -bad[other] = True +bad[self] = None +bad[other] = None return False if not self.fieldstate[i].generalization_of(other.fieldstate[i], renum, bad): -bad[self] = True -bad[other] = True +bad[self] = None +bad[other] = None return False return True @@ -167,23 +167,23 @@
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r57680:993a0159055a Date: 2012-09-30 00:14 +0200 http://bitbucket.org/pypy/pypy/changeset/993a0159055a/ Log:merge default diff --git a/pypy/doc/arm.rst b/pypy/doc/arm.rst --- a/pypy/doc/arm.rst +++ b/pypy/doc/arm.rst @@ -23,7 +23,7 @@ The tools required to cross translate from a Linux based host to an ARM based Linux target are: -- A checkout of PyPy's arm-backend-2 branch. +- A checkout of PyPy (default branch). - The GCC ARM cross compiler (on Ubuntu it is the ``gcc-arm-linux-gnueabi package``) but other toolchains should also work. - Scratchbox 2, a cross-compilation engine (``scratchbox2`` Ubuntu package). - A 32-bit PyPy or Python. @@ -147,4 +147,4 @@ return 0 def target(*args): - return main, None \ No newline at end of file + return main, None diff --git a/pypy/jit/backend/model.py b/pypy/jit/backend/model.py --- a/pypy/jit/backend/model.py +++ b/pypy/jit/backend/model.py @@ -131,13 +131,13 @@ def get_latest_value_float(self, index): Returns the value for the index'th argument to the last executed operation (from 'fail_args' if it was a guard, -or from 'args' if it was a FINISH). Returns a float. +or from 'args' if it was a FINISH). Returns a FLOATSTORAGE. raise NotImplementedError def get_latest_value_ref(self, index): Returns the value for the index'th argument to the last executed operation (from 'fail_args' if it was a guard, -or from 'args' if it was a FINISH). Returns a ptr or an obj. +or from 'args' if it was a FINISH). Returns a GCREF. raise NotImplementedError def get_latest_value_count(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r55208:c6d48bfb9d2f Date: 2012-05-29 18:58 +0200 http://bitbucket.org/pypy/pypy/changeset/c6d48bfb9d2f/ Log:merge default diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py --- a/pypy/rlib/rwin32.py +++ b/pypy/rlib/rwin32.py @@ -371,7 +371,7 @@ if sig == CTRL_C_EVENT or sig == CTRL_BREAK_EVENT: if GenerateConsoleCtrlEvent(sig, pid) == 0: raise lastWindowsError('os_kill failed generating event') -return 0 +return handle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) if handle == NULL_HANDLE: raise lastWindowsError('os_kill failed opening process') ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Antonio Cuni anto.c...@gmail.com Branch: Changeset: r52835:c6b3b1bc1eee Date: 2012-02-24 09:59 +0100 http://bitbucket.org/pypy/pypy/changeset/c6b3b1bc1eee/ Log:merge default diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -328,7 +328,7 @@ raise modname = self.str_w(w_modname) mod = self.interpclass_w(w_mod) -if isinstance(mod, Module): +if isinstance(mod, Module) and not mod.startup_called: self.timer.start(startup + modname) mod.init(self) self.timer.stop(startup + modname) diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py --- a/pypy/interpreter/test/test_objspace.py +++ b/pypy/interpreter/test/test_objspace.py @@ -322,3 +322,14 @@ space.ALL_BUILTIN_MODULES.pop() del space._builtinmodule_list mods = space.get_builtinmodule_to_install() + +def test_dont_reload_builtin_mods_on_startup(self): +from pypy.tool.option import make_config, make_objspace +config = make_config(None) +space = make_objspace(config) +w_executable = space.wrap('executable') +assert space.str_w(space.getattr(space.sys, w_executable)) == 'py.py' +space.setattr(space.sys, w_executable, space.wrap('foobar')) +assert space.str_w(space.getattr(space.sys, w_executable)) == 'foobar' +space.startup() +assert space.str_w(space.getattr(space.sys, w_executable)) == 'foobar' diff --git a/pypy/interpreter/test/test_zpy.py b/pypy/interpreter/test/test_zpy.py --- a/pypy/interpreter/test/test_zpy.py +++ b/pypy/interpreter/test/test_zpy.py @@ -17,14 +17,14 @@ def test_executable(): Ensures sys.executable points to the py.py script # TODO : watch out for spaces/special chars in pypypath -output = run(sys.executable, pypypath, +output = run(sys.executable, pypypath, '-S', -c, import sys;print sys.executable) assert output.splitlines()[-1] == pypypath def test_special_names(): Test the __name__ and __file__ special global names cmd = print __name__; print '__file__' in globals() -output = run(sys.executable, pypypath, '-c', cmd) +output = run(sys.executable, pypypath, '-S', '-c', cmd) assert output.splitlines()[-2] == '__main__' assert output.splitlines()[-1] == 'False' @@ -33,24 +33,24 @@ tmpfile.write(print __name__; print __file__\n) tmpfile.close() -output = run(sys.executable, pypypath, tmpfilepath) +output = run(sys.executable, pypypath, '-S', tmpfilepath) assert output.splitlines()[-2] == '__main__' assert output.splitlines()[-1] == str(tmpfilepath) def test_argv_command(): Some tests on argv # test 1 : no arguments -output = run(sys.executable, pypypath, +output = run(sys.executable, pypypath, '-S', -c, import sys;print sys.argv) assert output.splitlines()[-1] == str(['-c']) # test 2 : some arguments after -output = run(sys.executable, pypypath, +output = run(sys.executable, pypypath, '-S', -c, import sys;print sys.argv, hello) assert output.splitlines()[-1] == str(['-c','hello']) # test 3 : additionnal pypy parameters -output = run(sys.executable, pypypath, +output = run(sys.executable, pypypath, '-S', -O, -c, import sys;print sys.argv, hello) assert output.splitlines()[-1] == str(['-c','hello']) @@ -65,15 +65,15 @@ tmpfile.close() # test 1 : no arguments -output = run(sys.executable, pypypath, tmpfilepath) +output = run(sys.executable, pypypath, '-S', tmpfilepath) assert output.splitlines()[-1] == str([tmpfilepath]) # test 2 : some arguments after -output = run(sys.executable, pypypath, tmpfilepath, hello) +output = run(sys.executable, pypypath, '-S', tmpfilepath, hello) assert output.splitlines()[-1] == str([tmpfilepath,'hello']) # test 3 : additionnal pypy parameters -output = run(sys.executable, pypypath, -O, tmpfilepath, hello) +output = run(sys.executable, pypypath, '-S', -O, tmpfilepath, hello) assert output.splitlines()[-1] == str([tmpfilepath,'hello']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r52126:ad2705041965 Date: 2012-02-06 11:35 +0200 http://bitbucket.org/pypy/pypy/changeset/ad2705041965/ Log:merge default diff --git a/pypy/module/pypyjit/test_pypy_c/test_call.py b/pypy/module/pypyjit/test_pypy_c/test_call.py --- a/pypy/module/pypyjit/test_pypy_c/test_call.py +++ b/pypy/module/pypyjit/test_pypy_c/test_call.py @@ -27,6 +27,7 @@ ... p53 = call_assembler(..., descr=...) guard_not_forced(descr=...) +keepalive(...) guard_no_exception(descr=...) ... ) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r52055:e7d6f39ba721 Date: 2012-02-03 12:46 +0200 http://bitbucket.org/pypy/pypy/changeset/e7d6f39ba721/ Log:merge default diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -1,11 +1,13 @@ import py + +from pypy.conftest import gettestobjspace, option +from pypy.interpreter.error import OperationError +from pypy.module.micronumpy import signature +from pypy.module.micronumpy.appbridge import get_appbridge_cache +from pypy.module.micronumpy.interp_iter import Chunk +from pypy.module.micronumpy.interp_numarray import W_NDimArray, shape_agreement from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest -from pypy.module.micronumpy.interp_numarray import W_NDimArray, shape_agreement -from pypy.module.micronumpy.interp_iter import Chunk -from pypy.module.micronumpy import signature -from pypy.interpreter.error import OperationError -from pypy.conftest import gettestobjspace class MockDtype(object): @@ -1169,7 +1171,7 @@ for obj in [float, bool, int]: assert ones(1, dtype=obj).itemsize == dtype(obj).itemsize assert (ones(1) + ones(1)).itemsize == 8 -assert array(1).itemsize == 8 +assert array(1.0).itemsize == 8 assert ones(1)[:].itemsize == 8 def test_nbytes(self): @@ -1179,7 +1181,7 @@ assert ones((2, 2)).nbytes == 32 assert ones((2, 2))[1:,].nbytes == 16 assert (ones(1) + ones(1)).nbytes == 8 -assert array(3).nbytes == 8 +assert array(3.0).nbytes == 8 class AppTestMultiDim(BaseNumpyAppTest): @@ -1759,10 +1761,11 @@ assert len(a) == 8 assert arange(False, True, True).dtype is dtype(int) -from pypy.module.micronumpy.appbridge import get_appbridge_cache class AppTestRepr(BaseNumpyAppTest): def setup_class(cls): +if option.runappdirect: +py.test.skip(Can't be run directly.) BaseNumpyAppTest.setup_class.im_func(cls) cache = get_appbridge_cache(cls.space) cls.old_array_repr = cache.w_array_repr @@ -1776,6 +1779,8 @@ assert str(array([1, 2, 3])) == 'array([1, 2, 3])' def teardown_class(cls): +if option.runappdirect: +return cache = get_appbridge_cache(cls.space) cache.w_array_repr = cls.old_array_repr cache.w_array_str = cls.old_array_str ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r48916:cc101bad6f60 Date: 2011-11-08 12:08 +0100 http://bitbucket.org/pypy/pypy/changeset/cc101bad6f60/ Log:merge default ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r48818:5a19f9787d6b Date: 2011-11-06 11:14 +0100 http://bitbucket.org/pypy/pypy/changeset/5a19f9787d6b/ Log:merge default diff --git a/lib-python/conftest.py b/lib-python/conftest.py --- a/lib-python/conftest.py +++ b/lib-python/conftest.py @@ -201,7 +201,7 @@ RegrTest('test_difflib.py'), RegrTest('test_dircache.py', core=True), RegrTest('test_dis.py'), -RegrTest('test_distutils.py'), +RegrTest('test_distutils.py', skip=True), RegrTest('test_dl.py', skip=True), RegrTest('test_doctest.py', usemodules=thread), RegrTest('test_doctest2.py'), diff --git a/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py b/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py --- a/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py +++ b/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py @@ -1,6 +1,5 @@ import unittest from ctypes import * -from ctypes.test import xfail class MyInt(c_int): def __cmp__(self, other): @@ -27,7 +26,6 @@ self.assertEqual(None, cb()) -@xfail def test_int_callback(self): args = [] def func(arg): diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -17,7 +17,7 @@ if len(f) == 3: if (not hasattr(tp, '_type_') or not isinstance(tp._type_, str) -or tp._type_ not in iIhHbBlL): +or tp._type_ not in iIhHbBlLqQ): #XXX: are those all types? # we just dont get the type name # in the interp levle thrown TypeError diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -247,7 +247,6 @@ CONST_1 = ConstInt(1) CVAL_ZERO= ConstantValue(CONST_0) CVAL_ZERO_FLOAT = ConstantValue(Const._new(0.0)) -CVAL_UNINITIALIZED_ZERO = ConstantValue(CONST_0) llhelper.CVAL_NULLREF = ConstantValue(llhelper.CONST_NULL) oohelper.CVAL_NULLREF = ConstantValue(oohelper.CONST_NULL) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -4123,6 +4123,38 @@ self.optimize_strunicode_loop(ops, expected) +def test_str_concat_constant_lengths(self): +ops = +[i0] +p0 = newstr(1) +strsetitem(p0, 0, i0) +p1 = newstr(0) +p2 = call(0, p0, p1, descr=strconcatdescr) +i1 = call(0, p2, p0, descr=strequaldescr) +finish(i1) + +expected = +[i0] +finish(1) + +self.optimize_strunicode_loop(ops, expected) + +def test_str_concat_constant_lengths_2(self): +ops = +[i0] +p0 = newstr(0) +p1 = newstr(1) +strsetitem(p1, 0, i0) +p2 = call(0, p0, p1, descr=strconcatdescr) +i1 = call(0, p2, p1, descr=strequaldescr) +finish(i1) + +expected = +[i0] +finish(1) + +self.optimize_strunicode_loop(ops, expected) + def test_str_slice_1(self): ops = [p1, i1, i2] @@ -4883,6 +4915,27 @@ def test_plain_virtual_string_copy_content(self): ops = +[i1] +p0 = newstr(6) +copystrcontent(shello!, p0, 0, 0, 6) +p1 = call(0, p0, sabc123, descr=strconcatdescr) +i0 = strgetitem(p1, i1) +finish(i0) + +expected = +[i1] +p0 = newstr(6) +copystrcontent(shello!, p0, 0, 0, 6) +p1 = newstr(12) +copystrcontent(p0, p1, 0, 0, 6) +copystrcontent(sabc123, p1, 0, 6, 6) +i0 = strgetitem(p1, i1) +finish(i0) + +self.optimize_strunicode_loop(ops, expected) + +def test_plain_virtual_string_copy_content_2(self): +ops = [] p0 = newstr(6) copystrcontent(shello!, p0, 0, 0, 6) @@ -4894,10 +4947,7 @@ [] p0 = newstr(6) copystrcontent(shello!, p0, 0, 0, 6) -p1 = newstr(12) -copystrcontent(p0, p1, 0, 0, 6) -copystrcontent(sabc123, p1, 0, 6, 6) -i0 = strgetitem(p1, 0) +i0 = strgetitem(p0, 0) finish(i0) self.optimize_strunicode_loop(ops, expected) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -2168,13 +2168,13 @@ ops = [p0, i0, p1, i1,
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r48717:8ecb5f0cd990 Date: 2011-11-03 20:47 +0100 http://bitbucket.org/pypy/pypy/changeset/8ecb5f0cd990/ Log:merge default diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py --- a/pypy/jit/metainterp/optimizeopt/heap.py +++ b/pypy/jit/metainterp/optimizeopt/heap.py @@ -146,8 +146,6 @@ newresult = result.clonebox() optimizer.make_constant(newresult, result) result = newresult -if result is op.getarg(0): # FIXME: Unsupported corner case?? -continue getop = ResOperation(rop.GETARRAYITEM_GC, [op.getarg(0), op.getarg(1)], result, op.getdescr()) shortboxes.add_potential(getop, synthetic=True) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7450,6 +7450,55 @@ self.optimize_loop(ops, expected) +def test_setarrayitem_p0_p0(self): +ops = +[i0, i1] +p0 = escape() +setarrayitem_gc(p0, 2, p0, descr=arraydescr) +jump(i0, i1) + +expected = +[i0, i1] +p0 = escape() +setarrayitem_gc(p0, 2, p0, descr=arraydescr) +jump(i0, i1) + +self.optimize_loop(ops, expected) + +def test_setfield_p0_p0(self): +ops = +[i0, i1] +p0 = escape() +setfield_gc(p0, p0, descr=arraydescr) +jump(i0, i1) + +expected = +[i0, i1] +p0 = escape() +setfield_gc(p0, p0, descr=arraydescr) +jump(i0, i1) + +self.optimize_loop(ops, expected) + +def test_setfield_p0_p1_p0(self): +ops = +[i0, i1] +p0 = escape() +p1 = escape() +setfield_gc(p0, p1, descr=adescr) +setfield_gc(p1, p0, descr=bdescr) +jump(i0, i1) + +expected = +[i0, i1] +p0 = escape() +p1 = escape() +setfield_gc(p0, p1, descr=adescr) +setfield_gc(p1, p0, descr=bdescr) +jump(i0, i1) + +self.optimize_loop(ops, expected) + class TestLLtype(OptimizeOptTest, LLtypeMixin): pass diff --git a/pypy/jit/metainterp/optimizeopt/virtualstate.py b/pypy/jit/metainterp/optimizeopt/virtualstate.py --- a/pypy/jit/metainterp/optimizeopt/virtualstate.py +++ b/pypy/jit/metainterp/optimizeopt/virtualstate.py @@ -551,6 +551,7 @@ optimizer.produce_potential_short_preamble_ops(self) self.short_boxes = {} +self.short_boxes_in_production = {} for box in self.potential_ops.keys(): try: @@ -606,6 +607,10 @@ return if isinstance(box, Const): return +if box in self.short_boxes_in_production: +raise BoxNotProducable +self.short_boxes_in_production[box] = True + if box in self.potential_ops: ops = self.prioritized_alternatives(box) produced_one = False diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -312,10 +312,11 @@ class W_XRange(Wrappable): -def __init__(self, space, start, len, step): +def __init__(self, space, start, stop, step): self.space = space self.start = start -self.len = len +self.stop = stop +self.len = get_len_of_range(space, start, stop, step) self.step = step def descr_new(space, w_subtype, w_start, w_stop=None, w_step=1): @@ -325,9 +326,8 @@ start, stop = 0, start else: stop = _toint(space, w_stop) -howmany = get_len_of_range(space, start, stop, step) obj = space.allocate_instance(W_XRange, w_subtype) -W_XRange.__init__(obj, space, start, howmany, step) +W_XRange.__init__(obj, space, start, stop, step) return space.wrap(obj) def descr_repr(self): @@ -357,12 +357,12 @@ def descr_iter(self): return self.space.wrap(W_XRangeIterator(self.space, self.start, -self.len, self.step)) +self.stop, self.step)) def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step return self.space.wrap(W_XRangeIterator(self.space, lastitem, -self.len, -self.step)) +self.start - 1, -self.step)) def descr_reduce(self): space =
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r48432:f5825eff38c3 Date: 2011-10-25 15:41 +0200 http://bitbucket.org/pypy/pypy/changeset/f5825eff38c3/ Log:merge default diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py --- a/pypy/jit/backend/x86/assembler.py +++ b/pypy/jit/backend/x86/assembler.py @@ -1276,8 +1276,8 @@ genop_int_ne = _cmpop(NE, NE) genop_int_gt = _cmpop(G, L) genop_int_ge = _cmpop(GE, LE) -genop_ptr_eq = genop_int_eq -genop_ptr_ne = genop_int_ne +genop_ptr_eq = genop_instance_ptr_eq = genop_int_eq +genop_ptr_ne = genop_instance_ptr_ne = genop_int_ne genop_float_lt = _cmpop_float('B', 'A') genop_float_le = _cmpop_float('BE', 'AE') @@ -1297,8 +1297,8 @@ genop_guard_int_ne = _cmpop_guard(NE, NE, E, E) genop_guard_int_gt = _cmpop_guard(G, L, LE, GE) genop_guard_int_ge = _cmpop_guard(GE, LE, L, G) -genop_guard_ptr_eq = genop_guard_int_eq -genop_guard_ptr_ne = genop_guard_int_ne +genop_guard_ptr_eq = genop_guard_instance_ptr_eq = genop_guard_int_eq +genop_guard_ptr_ne = genop_guard_instance_ptr_ne = genop_guard_int_ne genop_guard_uint_gt = _cmpop_guard(A, B, BE, AE) genop_guard_uint_lt = _cmpop_guard(B, A, AE, BE) diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py --- a/pypy/jit/backend/x86/regalloc.py +++ b/pypy/jit/backend/x86/regalloc.py @@ -651,8 +651,8 @@ consider_uint_lt = _consider_compop consider_uint_le = _consider_compop consider_uint_ge = _consider_compop -consider_ptr_eq = _consider_compop -consider_ptr_ne = _consider_compop +consider_ptr_eq = consider_instance_ptr_eq = _consider_compop +consider_ptr_ne = consider_instance_ptr_ne = _consider_compop def _consider_float_op(self, op): loc1 = self.xrm.loc(op.getarg(1)) 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 @@ -800,6 +800,9 @@ def _is_gc(self, v): return getattr(getattr(v.concretetype, TO, None), _gckind, ?) == 'gc' +def _is_rclass_instance(self, v): +return lltype._castdepth(v.concretetype.TO, rclass.OBJECT) = 0 + def _rewrite_cmp_ptrs(self, op): if self._is_gc(op.args[0]): return op @@ -817,11 +820,21 @@ return self._rewrite_equality(op, 'int_is_true') def rewrite_op_ptr_eq(self, op): -op1 = self._rewrite_equality(op, 'ptr_iszero') +prefix = '' +if self._is_rclass_instance(op.args[0]): +assert self._is_rclass_instance(op.args[1]) +op = SpaceOperation('instance_ptr_eq', op.args, op.result) +prefix = 'instance_' +op1 = self._rewrite_equality(op, prefix + 'ptr_iszero') return self._rewrite_cmp_ptrs(op1) def rewrite_op_ptr_ne(self, op): -op1 = self._rewrite_equality(op, 'ptr_nonzero') +prefix = '' +if self._is_rclass_instance(op.args[0]): +assert self._is_rclass_instance(op.args[1]) +op = SpaceOperation('instance_ptr_ne', op.args, op.result) +prefix = 'instance_' +op1 = self._rewrite_equality(op, prefix + 'ptr_nonzero') return self._rewrite_cmp_ptrs(op1) rewrite_op_ptr_iszero = _rewrite_cmp_ptrs 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 @@ -576,10 +576,10 @@ assert op1.args == [v2] def test_ptr_eq(): -v1 = varoftype(rclass.OBJECTPTR) -v2 = varoftype(rclass.OBJECTPTR) +v1 = varoftype(lltype.Ptr(rstr.STR)) +v2 = varoftype(lltype.Ptr(rstr.STR)) v3 = varoftype(lltype.Bool) -c0 = const(lltype.nullptr(rclass.OBJECT)) +c0 = const(lltype.nullptr(rstr.STR)) # for opname, reducedname in [('ptr_eq', 'ptr_iszero'), ('ptr_ne', 'ptr_nonzero')]: @@ -598,6 +598,31 @@ assert op1.opname == reducedname assert op1.args == [v2] +def test_instance_ptr_eq(): +v1 = varoftype(rclass.OBJECTPTR) +v2 = varoftype(rclass.OBJECTPTR) +v3 = varoftype(lltype.Bool) +c0 = const(lltype.nullptr(rclass.OBJECT)) + +for opname, newopname, reducedname in [ +('ptr_eq', 'instance_ptr_eq', 'instance_ptr_iszero'), +('ptr_ne', 'instance_ptr_ne', 'instance_ptr_nonzero') +]: +op = SpaceOperation(opname, [v1, v2], v3) +op1 = Transformer().rewrite_operation(op) +assert op1.opname == newopname +assert op1.args == [v1, v2] + +op = SpaceOperation(opname, [v1, c0], v3) +op1 = Transformer().rewrite_operation(op) +assert op1.opname == reducedname +assert op1.args == [v1] + +op = SpaceOperation(opname, [c0, v1], v3) +op1 =
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r48277:39882f1dfd15 Date: 2011-10-20 19:50 +0200 http://bitbucket.org/pypy/pypy/changeset/39882f1dfd15/ Log:merge default diff --git a/lib_pypy/pyrepl/readline.py b/lib_pypy/pyrepl/readline.py --- a/lib_pypy/pyrepl/readline.py +++ b/lib_pypy/pyrepl/readline.py @@ -395,9 +395,21 @@ _wrapper.f_in = f_in _wrapper.f_out = f_out -if hasattr(sys, '__raw_input__'):# PyPy -_old_raw_input = sys.__raw_input__ +if '__pypy__' in sys.builtin_module_names:# PyPy + +def _old_raw_input(prompt=''): +# sys.__raw_input__() is only called when stdin and stdout are +# as expected and are ttys. If it is the case, then get_reader() +# should not really fail in _wrapper.raw_input(). If it still +# does, then we will just cancel the redirection and call again +# the built-in raw_input(). +try: +del sys.__raw_input__ +except AttributeError: +pass +return raw_input(prompt) sys.__raw_input__ = _wrapper.raw_input + else: # this is not really what readline.c does. Better than nothing I guess import __builtin__ diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -72,6 +72,7 @@ del working_modules['fcntl'] # LOCK_NB not defined del working_modules[_minimal_curses] del working_modules[termios] +del working_modules[_multiprocessing] # depends on rctime diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py --- a/pypy/jit/metainterp/optimizeopt/rewrite.py +++ b/pypy/jit/metainterp/optimizeopt/rewrite.py @@ -106,10 +106,9 @@ self.make_equal_to(op.result, v1) else: self.emit_operation(op) - -# Synthesize the reverse ops for optimize_default to reuse -self.pure(rop.INT_ADD, [op.result, op.getarg(1)], op.getarg(0)) -self.pure(rop.INT_SUB, [op.getarg(0), op.result], op.getarg(1)) +# Synthesize the reverse ops for optimize_default to reuse +self.pure(rop.INT_ADD, [op.result, op.getarg(1)], op.getarg(0)) +self.pure(rop.INT_SUB, [op.getarg(0), op.result], op.getarg(1)) def optimize_INT_ADD(self, op): v1 = self.getvalue(op.getarg(0)) @@ -122,10 +121,9 @@ self.make_equal_to(op.result, v1) else: self.emit_operation(op) - -# Synthesize the reverse op for optimize_default to reuse -self.pure(rop.INT_SUB, [op.result, op.getarg(1)], op.getarg(0)) -self.pure(rop.INT_SUB, [op.result, op.getarg(0)], op.getarg(1)) +# Synthesize the reverse op for optimize_default to reuse +self.pure(rop.INT_SUB, [op.result, op.getarg(1)], op.getarg(0)) +self.pure(rop.INT_SUB, [op.result, op.getarg(0)], op.getarg(1)) def optimize_INT_MUL(self, op): v1 = self.getvalue(op.getarg(0)) @@ -141,13 +139,13 @@ self.make_constant_int(op.result, 0) else: for lhs, rhs in [(v1, v2), (v2, v1)]: -# x (x -1) == 0 is a quick test for power of 2 -if (lhs.is_constant() and -(lhs.box.getint() (lhs.box.getint() - 1)) == 0): -new_rhs = ConstInt(highest_bit(lhs.box.getint())) -op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs]) -break - +if lhs.is_constant(): +x = lhs.box.getint() +# x (x - 1) == 0 is a quick test for power of 2 +if x (x - 1) == 0: +new_rhs = ConstInt(highest_bit(lhs.box.getint())) +op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs]) +break self.emit_operation(op) def optimize_UINT_FLOORDIV(self, op): @@ -462,6 +460,14 @@ self.optimizer.opaque_pointers[value] = True self.make_equal_to(op.result, value) +def optimize_CAST_PTR_TO_INT(self, op): +self.pure(rop.CAST_INT_TO_PTR, [op.result], op.getarg(0)) +self.emit_operation(op) + +def optimize_CAST_INT_TO_PTR(self, op): +self.pure(rop.CAST_PTR_TO_INT, [op.result], op.getarg(0)) +self.emit_operation(op) + dispatch_opt = make_dispatcher_method(OptRewrite, 'optimize_', default=OptRewrite.emit_operation) optimize_guards = _findall(OptRewrite, 'optimize_', 'GUARD') diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -234,6 +234,30 @@ % expected_value
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r47840:f4baf68db210 Date: 2011-10-06 04:05 +0200 http://bitbucket.org/pypy/pypy/changeset/f4baf68db210/ Log:merge default diff --git a/pypy/module/__pypy__/interp_builders.py b/pypy/module/__pypy__/interp_builders.py --- a/pypy/module/__pypy__/interp_builders.py +++ b/pypy/module/__pypy__/interp_builders.py @@ -40,6 +40,12 @@ self.builder = None return w_s +def descr_len(self, space): +if self.builder is None: +raise OperationError(space.w_ValueError, + space.wrap('no lenght of built builder')) +return space.wrap(self.builder.getlength()) + W_Builder.__name__ = W_%s % name W_Builder.typedef = TypeDef(name, __new__ = interp2app(func_with_new_name( @@ -48,6 +54,7 @@ append = interp2app(W_Builder.descr_append), append_slice = interp2app(W_Builder.descr_append_slice), build = interp2app(W_Builder.descr_build), +__len__ = interp2app(W_Builder.descr_len), ) W_Builder.typedef.acceptable_as_base_class = False return W_Builder diff --git a/pypy/module/__pypy__/test/test_builders.py b/pypy/module/__pypy__/test/test_builders.py --- a/pypy/module/__pypy__/test/test_builders.py +++ b/pypy/module/__pypy__/test/test_builders.py @@ -38,7 +38,9 @@ b = StringBuilder() b.append(abc) b.append(123) +assert len(b) == 6 b.append(you and me) s = b.build() +raises(ValueError, len, b) assert s == abc123you and me -raises(ValueError, b.build) \ No newline at end of file +raises(ValueError, b.build) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r47569:af517c41faff Date: 2011-09-23 19:45 +0200 http://bitbucket.org/pypy/pypy/changeset/af517c41faff/ Log:merge default diff --git a/pypy/interpreter/pyparser/future.py b/pypy/interpreter/pyparser/future.py --- a/pypy/interpreter/pyparser/future.py +++ b/pypy/interpreter/pyparser/future.py @@ -225,14 +225,16 @@ raise DoneException self.consume_whitespace() -def consume_whitespace(self): +def consume_whitespace(self, newline_ok=False): while 1: c = self.getc() if c in whitespace: self.pos += 1 continue -elif c == '\\': -self.pos += 1 +elif c == '\\' or newline_ok: +slash = c == '\\' +if slash: +self.pos += 1 c = self.getc() if c == '\n': self.pos += 1 @@ -243,8 +245,10 @@ if self.getc() == '\n': self.pos += 1 self.atbol() +elif slash: +raise DoneException else: -raise DoneException +return else: return @@ -281,7 +285,7 @@ return else: self.pos += 1 -self.consume_whitespace() +self.consume_whitespace(paren_list) if paren_list and self.getc() == ')': self.pos += 1 return # Handles trailing comma inside parenthesis diff --git a/pypy/interpreter/pyparser/test/test_futureautomaton.py b/pypy/interpreter/pyparser/test/test_futureautomaton.py --- a/pypy/interpreter/pyparser/test/test_futureautomaton.py +++ b/pypy/interpreter/pyparser/test/test_futureautomaton.py @@ -3,7 +3,7 @@ from pypy.tool import stdlib___future__ as fut def run(s): -f = future.FutureAutomaton(future.futureFlags_2_5, s) +f = future.FutureAutomaton(future.futureFlags_2_7, s) try: f.start() except future.DoneException: @@ -113,6 +113,14 @@ assert f.lineno == 1 assert f.col_offset == 0 +def test_paren_with_newline(): +s = 'from __future__ import (division,\nabsolute_import)\n' +f = run(s) +assert f.pos == len(s) +assert f.flags == (fut.CO_FUTURE_DIVISION | fut.CO_FUTURE_ABSOLUTE_IMPORT) +assert f.lineno == 1 +assert f.col_offset == 0 + def test_multiline(): s = 'abc #def\n #ghi\nfrom __future__ import (division as b, generators,)\nfrom __future__ import with_statement\n' f = run(s) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r47304:27862000e92d Date: 2011-09-16 18:21 +0200 http://bitbucket.org/pypy/pypy/changeset/27862000e92d/ Log:merge default 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 @@ -359,26 +359,43 @@ return _str_join_many_items(space, w_self, list_w, size) -def _str_join_many_items(space, w_self, list_w, size): -self = w_self._value +from pypy.rlib.jit import JitDriver + +one = JitDriver(greens = [], reds = ['size', 'reslen', 'self', 'list_w']) +two = JitDriver(greens = [], reds = ['i', 'size', 'list_w', 'sb', 'self', + 'w_self']) + +def _str_join_compute_reslen(space, self, list_w, size): reslen = len(self) * (size - 1) for i in range(size): +one.jit_merge_point(size = size, reslen = reslen, +self = self, list_w = list_w) w_s = list_w[i] if not space.isinstance_w(w_s, space.w_str): if space.isinstance_w(w_s, space.w_unicode): -# we need to rebuild w_list here, because the original -# w_list might be an iterable which we already consumed -w_list = space.newlist(list_w) -w_u = space.call_function(space.w_unicode, w_self) -return space.call_method(w_u, join, w_list) +return -1 raise operationerrfmt( space.w_TypeError, sequence item %d: expected string, %s found, i, space.type(w_s).getname(space)) reslen += len(space.str_w(w_s)) +return reslen + +def _str_join_many_items(space, w_self, list_w, size): +self = w_self._value + +reslen = _str_join_compute_reslen(space, self, list_w, size) +if reslen == -1: +# we need to rebuild w_list here, because the original +# w_list might be an iterable which we already consumed +w_list = space.newlist(list_w) +w_u = space.call_function(space.w_unicode, w_self) +return space.call_method(w_u, join, w_list) sb = StringBuilder(reslen) for i in range(size): +two.jit_merge_point(size=size, i=i, sb=sb, list_w=list_w, self=self, +w_self=w_self) if self and i != 0: sb.append(self) sb.append(space.str_w(list_w[i])) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Carl Friedrich Bolz cfb...@gmx.de Branch: Changeset: r46984:1b70e84ac93b Date: 2011-09-01 15:31 +0200 http://bitbucket.org/pypy/pypy/changeset/1b70e84ac93b/ Log:merge default diff --git a/pypy/doc/stackless.rst b/pypy/doc/stackless.rst --- a/pypy/doc/stackless.rst +++ b/pypy/doc/stackless.rst @@ -209,6 +209,8 @@ * Automatic unlimited stack (must be emulated__ so far) +* Support for other CPUs than x86 and x86-64 + .. __: `recursion depth limit`_ (*) Pickling, as well as changing threads, could be implemented by using @@ -217,9 +219,8 @@ hard switch (like now) when the C stack contains non-trivial C frames to save, and a soft switch (like previously) when it contains only simple calls from Python to Python. Soft-switched continulets would -also consume a bit less RAM, at the possible expense of making the -switch a bit slower (unsure about that; what is the Stackless Python -experience?). +also consume a bit less RAM, and the switch might be a bit faster too +(unsure about that; what is the Stackless Python experience?). Recursion depth limit ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Antonio Cuni anto.c...@gmail.com Branch: Changeset: r46023:a5b76d2cd38c Date: 2011-07-27 18:43 +0200 http://bitbucket.org/pypy/pypy/changeset/a5b76d2cd38c/ Log:merge default diff --git a/pypy/jit/codewriter/regalloc.py b/pypy/jit/codewriter/regalloc.py --- a/pypy/jit/codewriter/regalloc.py +++ b/pypy/jit/codewriter/regalloc.py @@ -1,129 +1,8 @@ -import sys -from pypy.objspace.flow.model import Variable -from pypy.tool.algo.color import DependencyGraph -from pypy.tool.algo.unionfind import UnionFind +from pypy.tool.algo import regalloc from pypy.jit.metainterp.history import getkind from pypy.jit.codewriter.flatten import ListOfKind + def perform_register_allocation(graph, kind): -Perform register allocation for the Variables of the given 'kind' -in the 'graph'. -regalloc = RegAllocator(graph, kind) -regalloc.make_dependencies() -regalloc.coalesce_variables() -regalloc.find_node_coloring() -return regalloc - - -class RegAllocator(object): -DEBUG_REGALLOC = False - -def __init__(self, graph, kind): -self.graph = graph -self.kind = kind - -def make_dependencies(self): -dg = DependencyGraph() -for block in self.graph.iterblocks(): -# Compute die_at = {Variable: index_of_operation_with_last_usage} -die_at = dict.fromkeys(block.inputargs, 0) -for i, op in enumerate(block.operations): -for v in op.args: -if isinstance(v, Variable): -die_at[v] = i -elif isinstance(v, ListOfKind): -for v1 in v: -if isinstance(v1, Variable): -die_at[v1] = i -if op.result is not None: -die_at[op.result] = i + 1 -if isinstance(block.exitswitch, tuple): -for x in block.exitswitch: -die_at.pop(x, None) -else: -die_at.pop(block.exitswitch, None) -for link in block.exits: -for v in link.args: -die_at.pop(v, None) -die_at = [(value, key) for (key, value) in die_at.items()] -die_at.sort() -die_at.append((sys.maxint,)) -# Done. XXX the code above this line runs 3 times -# (for kind in KINDS) to produce the same result... -livevars = [v for v in block.inputargs - if getkind(v.concretetype) == self.kind] -# Add the variables of this block to the dependency graph -for i, v in enumerate(livevars): -dg.add_node(v) -for j in range(i): -dg.add_edge(livevars[j], v) -livevars = set(livevars) -die_index = 0 -for i, op in enumerate(block.operations): -while die_at[die_index][0] == i: -try: -livevars.remove(die_at[die_index][1]) -except KeyError: -pass -die_index += 1 -if (op.result is not None and -getkind(op.result.concretetype) == self.kind): -dg.add_node(op.result) -for v in livevars: -if getkind(v.concretetype) == self.kind: -dg.add_edge(v, op.result) -livevars.add(op.result) -self._depgraph = dg - -def coalesce_variables(self): -self._unionfind = UnionFind() -pendingblocks = list(self.graph.iterblocks()) -while pendingblocks: -block = pendingblocks.pop() -# Aggressively try to coalesce each source variable with its -# target. We start from the end of the graph instead of -# from the beginning. This is a bit arbitrary, but the idea -# is that the end of the graph runs typically more often -# than the start, given that we resume execution from the -# middle during blackholing. -for link in block.exits: -if link.last_exception is not None: -self._depgraph.add_node(link.last_exception) -if link.last_exc_value is not None: -self._depgraph.add_node(link.last_exc_value) -for i, v in enumerate(link.args): -self._try_coalesce(v, link.target.inputargs[i]) - -def _try_coalesce(self, v, w): -if isinstance(v, Variable) and getkind(v.concretetype) == self.kind: -assert getkind(w.concretetype) == self.kind -dg = self._depgraph -uf = self._unionfind -v0 = uf.find_rep(v) -w0 = uf.find_rep(w) -if v0 is not w0 and v0 not in dg.neighbours[w0]: -_, rep, _ = uf.union(v0, w0) -assert uf.find_rep(v0) is
[pypy-commit] pypy default: merge default
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r45945:70435a5564da Date: 2011-07-24 18:46 +0200 http://bitbucket.org/pypy/pypy/changeset/70435a5564da/ Log:merge default diff --git a/pypy/rpython/lltypesystem/rdict.py b/pypy/rpython/lltypesystem/rdict.py --- a/pypy/rpython/lltypesystem/rdict.py +++ b/pypy/rpython/lltypesystem/rdict.py @@ -501,9 +501,6 @@ ENTRY = ENTRIES.OF entry = d.entries[i] if ENTRIES.must_clear_key: -key = entry.key # careful about destructor side effects: - # keep key alive until entry.value has also - # been zeroed (if it must be) entry.key = lltype.nullptr(ENTRY.key.TO) if ENTRIES.must_clear_value: entry.value = lltype.nullptr(ENTRY.value.TO) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r45795:95a8a9907969 Date: 2011-07-21 09:55 +0200 http://bitbucket.org/pypy/pypy/changeset/95a8a9907969/ Log:merge default diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -15,14 +15,19 @@ # ufuncs 'abs': 'interp_ufuncs.absolute', 'absolute': 'interp_ufuncs.absolute', +'add': 'interp_ufuncs.add', 'copysign': 'interp_ufuncs.copysign', +'divide': 'interp_ufuncs.divide', 'exp': 'interp_ufuncs.exp', +'fabs': 'interp_ufuncs.fabs', 'floor': 'interp_ufuncs.floor', 'maximum': 'interp_ufuncs.maximum', 'minimum': 'interp_ufuncs.minimum', +'multiply': 'interp_ufuncs.multiply', 'negative': 'interp_ufuncs.negative', 'reciprocal': 'interp_ufuncs.reciprocal', 'sign': 'interp_ufuncs.sign', +'subtract': 'interp_ufuncs.subtract', 'sin': 'interp_ufuncs.sin', 'cos': 'interp_ufuncs.cos', 'tan': 'interp_ufuncs.tan', diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py --- a/pypy/module/micronumpy/compile.py +++ b/pypy/module/micronumpy/compile.py @@ -3,7 +3,7 @@ It should not be imported by the module itself -from pypy.module.micronumpy.interp_numarray import FloatWrapper, SingleDimArray +from pypy.module.micronumpy.interp_numarray import FloatWrapper, SingleDimArray, BaseArray class BogusBytecode(Exception): pass @@ -18,6 +18,14 @@ def wrap(self, x): return x +def issequence_w(self, w_obj): +# Completley wrong in the general case, but good enough for this. +return isinstance(w_obj, BaseArray) + +def float_w(self, w_obj): +assert isinstance(w_obj, float) +return w_obj + def numpy_compile(bytecode, array_size): space = TrivialSpace() stack = [] 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 @@ -2,6 +2,8 @@ from pypy.interpreter.error import OperationError, operationerrfmt from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty +from pypy.module.micronumpy.interp_support import Signature +from pypy.module.micronumpy import interp_ufuncs from pypy.objspace.std.floatobject import float2string as float2string_orig from pypy.rlib import jit from pypy.rlib.rfloat import DTSF_STR_PRECISION @@ -26,16 +28,6 @@ slice_driver1 = jit.JitDriver(greens=['signature'], reds=['i', 'j', 'step', 'stop', 'self', 'arr']) slice_driver2 = jit.JitDriver(greens=['signature'], reds=['i', 'j', 'step', 'stop', 'self', 'arr']) -class Signature(object): -def __init__(self): -self.transitions = {} - -def transition(self, target): -if target in self.transitions: -return self.transitions[target] -self.transitions[target] = new = Signature() -return new - def pos(v): return v def neg(v): @@ -44,16 +36,8 @@ return abs(v) def add(v1, v2): return v1 + v2 -def sub(v1, v2): -return v1 - v2 def mul(v1, v2): return v1 * v2 -def div(v1, v2): -return v1 / v2 -def power(v1, v2): -return math.pow(v1, v2) -def mod(v1, v2): -return math.fmod(v1, v2) def maximum(v1, v2): return max(v1, v2) def minimum(v1, v2): @@ -91,51 +75,30 @@ descr_neg = _unop_impl(neg) descr_abs = _unop_impl(absolute) -def _binop_impl(function): -signature = Signature() +def _binop_impl(w_ufunc): def impl(self, space, w_other): -w_other = convert_to_array(space, w_other) -new_sig = self.signature.transition(signature) -res = Call2( -function, -self, -w_other, -new_sig.transition(w_other.signature) -) -w_other.invalidates.append(res) -self.invalidates.append(res) -return space.wrap(res) -return func_with_new_name(impl, binop_%s_impl % function.__name__) +return w_ufunc(space, self, w_other) +return func_with_new_name(impl, binop_%s_impl % w_ufunc.__name__) -descr_add = _binop_impl(add) -descr_sub = _binop_impl(sub) -descr_mul = _binop_impl(mul) -descr_div = _binop_impl(div) -descr_pow = _binop_impl(power) -descr_mod = _binop_impl(mod) +descr_add = _binop_impl(interp_ufuncs.add) +descr_sub = _binop_impl(interp_ufuncs.subtract) +descr_mul = _binop_impl(interp_ufuncs.multiply) +descr_div = _binop_impl(interp_ufuncs.divide) +descr_pow = _binop_impl(interp_ufuncs.power) +descr_mod = _binop_impl(interp_ufuncs.mod) -def _binop_right_impl(function): -signature =
[pypy-commit] pypy default: merge default
Author: Maciej Fijalkowski fij...@gmail.com Branch: Changeset: r44902:bb4fee3d2de9 Date: 2011-06-13 09:46 +0200 http://bitbucket.org/pypy/pypy/changeset/bb4fee3d2de9/ Log:merge default 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 @@ -46,7 +46,7 @@ def invalidated(self): for arr in self.invalidates: arr.force_if_needed() -self.invalidates = [] +del self.invalidates[:] def _binop_impl(function): signature = Signature() @@ -83,16 +83,23 @@ def descr_len(self, space): return self.get_concrete().descr_len(space) -@unwrap_spec(item=int) -def descr_getitem(self, space, item): -return self.get_concrete().descr_getitem(space, item) +def descr_getitem(self, space, w_idx): +# TODO: indexation by tuples +start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) +if step == 0: +# Single index +return space.wrap(self.get_concrete().getitem(start)) +else: +# Slice +res = SingleDimSlice(start, stop, step, slice_length, self, self.signature.transition(SingleDimSlice.static_signature)) +return space.wrap(res) + @unwrap_spec(item=int, value=float) def descr_setitem(self, space, item, value): self.invalidated() return self.get_concrete().descr_setitem(space, item, value) - class FloatWrapper(BaseArray): Intermediate class representing a float literal. @@ -119,6 +126,10 @@ self.forced_result = None self.signature = signature +def _del_sources(self): +# Function for deleting references to source arrays, to allow garbage-collecting them +raise NotImplementedError + def compute(self): i = 0 signature = self.signature @@ -135,6 +146,7 @@ def force_if_needed(self): if self.forced_result is None: self.forced_result = self.compute() +self._del_sources() def get_concrete(self): self.force_if_needed() @@ -145,6 +157,13 @@ return self.forced_result.eval(i) return self._eval(i) +def find_size(self): +if self.forced_result is not None: +# The result has been computed and sources may be unavailable +return self.forced_result.find_size() +return self._find_size() + + class Call1(VirtualArray): _immutable_fields_ = [function, values] @@ -153,7 +172,10 @@ self.function = function self.values = values -def find_size(self): +def _del_sources(self): +self.values = None + +def _find_size(self): return self.values.find_size() def _eval(self, i): @@ -170,7 +192,11 @@ self.left = left self.right = right -def find_size(self): +def _del_sources(self): +self.left = None +self.right = None + +def _find_size(self): try: return self.left.find_size() except ValueError: @@ -181,6 +207,53 @@ lhs, rhs = self.left.eval(i), self.right.eval(i) return self.function(lhs, rhs) +class ViewArray(BaseArray): + +Class for representing views of arrays, they will reflect changes of parrent arrays. Example: slices + +_immutable_fields_ = [parent] +def __init__(self, parent, signature): +BaseArray.__init__(self) +self.signature = signature +self.parent = parent +self.invalidates = parent.invalidates + +def get_concrete(self): +return self # in fact, ViewArray never gets concrete as it never stores data. This implementation is needed for BaseArray getitem/setitem to work, can be refactored. + +def eval(self, i): +return self.parent.eval(self.calc_index(i)) + +def getitem(self, item): +return self.parent.getitem(self.calc_index(item)) + +@unwrap_spec(item=int, value=float) +def descr_setitem(self, space, item, value): +return self.parent.descr_setitem(space, self.calc_index(item), value) + +def descr_len(self, space): +return space.wrap(self.find_size()) + +def calc_index(self, item): +raise NotImplementedError + +class SingleDimSlice(ViewArray): +_immutable_fields_ = [start, stop, step, size] +static_signature = Signature() + +def __init__(self, start, stop, step, slice_length, parent, signature): +ViewArray.__init__(self, parent, signature) +self.start = start +self.stop = stop +self.step = step +self.size = slice_length + +def find_size(self): +return self.size + +def calc_index(self, item): +return (self.start + item * self.step) + class SingleDimArray(BaseArray): signature = Signature() @@