[pypy-commit] pypy small-unroll-improvements: fix translation - turns out a mixin doesn't work
Author: Carl Friedrich Bolz Branch: small-unroll-improvements Changeset: r70647:f96b890d7ea5 Date: 2014-04-16 09:57 +0200 http://bitbucket.org/pypy/pypy/changeset/f96b890d7ea5/ Log:fix translation - turns out a mixin doesn't work 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 @@ -506,8 +506,7 @@ s.debug_print("", seen, bad, metainterp_sd) -class VirtualStateConstructor(object): -import_from_mixin(VirtualVisitor) +class VirtualStateConstructor(VirtualVisitor): def __init__(self, optimizer): self.fieldboxes = {} 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 @@ -268,14 +268,15 @@ _frame_info_placeholder = (None, 0, 0) -class ResumeDataVirtualAdder(object): -import_from_mixin(VirtualVisitor) +class ResumeDataVirtualAdder(VirtualVisitor): def __init__(self, storage, memo): self.storage = storage self.memo = memo def make_virtual_info(self, value, fieldnums): +from rpython.jit.metainterp.optimizeopt.virtualize import AbstractVirtualValue +assert isinstance(value, AbstractVirtualValue) assert fieldnums is not None vinfo = value._cached_vinfo if vinfo is not None and vinfo.equals(fieldnums): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix for 6dac6407412f. Very obscure.
Author: Armin Rigo Branch: Changeset: r70648:a82950d1732e Date: 2014-04-16 10:32 +0200 http://bitbucket.org/pypy/pypy/changeset/a82950d1732e/ Log:Fix for 6dac6407412f. Very obscure. diff --git a/pypy/module/__pypy__/app_signal.py b/pypy/module/__pypy__/app_signal.py --- a/pypy/module/__pypy__/app_signal.py +++ b/pypy/module/__pypy__/app_signal.py @@ -1,4 +1,9 @@ -import __pypy__.thread +import thread +# ^^ relative import of __pypy__.thread. Note that some tests depend on +# this (test_enable_signals in test_signal.py) to work properly, +# otherwise they get caught in some deadlock waiting for the import +# lock... + class SignalsEnabled(object): '''A context manager to use in non-main threads: @@ -8,7 +13,7 @@ that is within a "with signals_enabled:". This other thread should be ready to handle unexpected exceptions that the signal handler might raise --- notably KeyboardInterrupt.''' -__enter__ = __pypy__.thread._signals_enter -__exit__ = __pypy__.thread._signals_exit +__enter__ = thread._signals_enter +__exit__ = thread._signals_exit signals_enabled = SignalsEnabled() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix link (thanks Ryan on pull request #229)
Author: Armin Rigo Branch: Changeset: r70649:6fbffc03e832 Date: 2014-04-16 11:22 +0200 http://bitbucket.org/pypy/pypy/changeset/6fbffc03e832/ Log:Fix link (thanks Ryan on pull request #229) diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst --- a/pypy/doc/faq.rst +++ b/pypy/doc/faq.rst @@ -318,7 +318,7 @@ To read more about the RPython limitations read the `RPython description`_. -.. _`RPython description`: coding-guide.html#restricted-python +.. _`RPython description`: coding-guide.html#rpython-definition --- Does RPython have anything to do with Zope's Restricted Python? ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Yet another attempt to unravel the mess that 6dac6407412f exposed.
Author: Armin Rigo Branch: Changeset: r70650:867cc494a9fa Date: 2014-04-16 11:10 + http://bitbucket.org/pypy/pypy/changeset/867cc494a9fa/ Log:Yet another attempt to unravel the mess that 6dac6407412f exposed. This makes space.allocate_lock() raise CannotHaveLock if we're translating. Translation passes again. diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -337,6 +337,9 @@ return 'internal subclass of %s' % (Class.__name__,) wrappable_class_name._annspecialcase_ = 'specialize:memo' +class CannotHaveLock(Exception): +"""Raised by space.allocate_lock() if we're translating.""" + # class ObjSpace(object): @@ -663,6 +666,11 @@ def __allocate_lock(self): from rpython.rlib.rthread import allocate_lock, error +# hack: we can't have prebuilt locks if we're translating. +# In this special situation we should just not lock at all +# (translation is not multithreaded anyway). +if not we_are_translated() and self.config.translating: +raise CannotHaveLock() try: return allocate_lock() except error: diff --git a/pypy/module/_file/interp_stream.py b/pypy/module/_file/interp_stream.py --- a/pypy/module/_file/interp_stream.py +++ b/pypy/module/_file/interp_stream.py @@ -4,7 +4,7 @@ from rpython.rlib.streamio import StreamErrors from pypy.interpreter.error import OperationError -from pypy.interpreter.baseobjspace import ObjSpace, W_Root +from pypy.interpreter.baseobjspace import ObjSpace, W_Root, CannotHaveLock from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gateway import interp2app from pypy.interpreter.streamutil import wrap_streamerror, wrap_oserror_as_ioerror @@ -33,19 +33,24 @@ def _try_acquire_lock(self): # this function runs with the GIL acquired so there is no race # condition in the creation of the lock -if self.slock is None: -self.slock = self.space.allocate_lock() me = self.space.getexecutioncontext() # used as thread ident if self.slockowner is me: return False# already acquired by the current thread -self.slock.acquire(True) +try: +if self.slock is None: +self.slock = self.space.allocate_lock() +except CannotHaveLock: +pass +else: +self.slock.acquire(True) assert self.slockowner is None self.slockowner = me return True def _release_lock(self): self.slockowner = None -self.slock.release() +if self.slock is not None: +self.slock.release() def lock(self): if not self._try_acquire_lock(): 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 @@ -8,7 +8,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, generic_new_descr from pypy.interpreter.error import OperationError, oefmt -from pypy.interpreter.baseobjspace import W_Root +from pypy.interpreter.baseobjspace import W_Root, CannotHaveLock from pypy.interpreter.eval import Code from pypy.interpreter.pycode import PyCode from rpython.rlib import streamio, jit @@ -753,26 +753,14 @@ me = self.space.getexecutioncontext() # used as thread ident return self.lockowner is me -def _can_have_lock(self): -# hack: we can't have self.lock != None during translation, -# because prebuilt lock objects are not allowed. In this -# special situation we just don't lock at all (translation is -# not multithreaded anyway). -if we_are_translated(): -return True # we need a lock at run-time -elif self.space.config.translating: -assert self.lock is None -return False -else: -return True # in py.py - def acquire_lock(self): # this function runs with the GIL acquired so there is no race # condition in the creation of the lock if self.lock is None: -if not self._can_have_lock(): +try: +self.lock = self.space.allocate_lock() +except CannotHaveLock: return -self.lock = self.space.allocate_lock() me = self.space.getexecutioncontext() # used as thread ident if self.lockowner is me: pass# already acquired by the current thread @@ -790,7 +778,7 @@ # Too bad. This situation can occur if a fork() occurred # with the import lock held, and we're the child. return -if not self._can_have_lock(): +if self.lock
[pypy-commit] pypy issue1514: Apply pypy-import.diff3 from issue1514. Change the logic a bit
Author: Armin Rigo Branch: issue1514 Changeset: r70652:f96656bbecc9 Date: 2014-04-16 14:44 +0200 http://bitbucket.org/pypy/pypy/changeset/f96656bbecc9/ Log:Apply pypy-import.diff3 from issue1514. Change the logic a bit to be closer to the original (in particular, add the object to sys.modules even if it's not a W_Module). diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -440,10 +440,11 @@ return name -def getbuiltinmodule(self, name, force_init=False): +def getbuiltinmodule(self, name, force_init=False, reuse=True): w_name = self.wrap(name) w_modules = self.sys.get('modules') if not force_init: +assert reuse try: return self.getitem(w_modules, w_name) except OperationError, e: @@ -459,9 +460,20 @@ "getbuiltinmodule() called with non-builtin module %s", name) else: -# Initialize the module +# Add the module to sys.modules and initialize the module +# The order is important to avoid recursions. from pypy.interpreter.module import Module if isinstance(w_mod, Module): +if not reuse and w_mod.startup_called: +# create a copy of the module. (see issue1514) +# eventlet patcher relies on this behaviour. +w_mod2 = self.wrap(Module(self, w_name)) +self.setitem(w_modules, w_name, w_mod2) +w_mod.getdict(self) # unlazy w_initialdict +self.call_method(w_mod2.getdict(self), 'update', + w_mod.w_initialdict) +return w_mod2 +# w_mod.init(self) # Add the module to sys.modules 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 @@ -579,7 +579,8 @@ return space.call_method(find_info.w_loader, "load_module", w_modulename) if find_info.modtype == C_BUILTIN: -return space.getbuiltinmodule(find_info.filename, force_init=True) +return space.getbuiltinmodule(find_info.filename, force_init=True, + reuse=reuse) if find_info.modtype in (PY_SOURCE, PY_COMPILED, C_EXTENSION, PKG_DIRECTORY): w_mod = None diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py --- a/pypy/module/imp/test/test_app.py +++ b/pypy/module/imp/test/test_app.py @@ -203,7 +203,6 @@ def test_builtin_reimport(self): # from https://bugs.pypy.org/issue1514 -skip("fix me") import sys, marshal old = marshal.loads @@ -223,7 +222,6 @@ # taken from https://bugs.pypy.org/issue1514, with extra cases # that show a difference with CPython: we can get on CPython # several module objects for the same built-in module :-( -skip("several built-in module objects: not supported by pypy") import sys, marshal old = marshal.loads 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 @@ -578,7 +578,6 @@ assert hasattr(time, 'clock') def test_reimport_builtin_simple_case_2(self): -skip("fix me") import sys, time time.foo = "bar" del sys.modules['time'] @@ -586,7 +585,6 @@ assert not hasattr(time, 'foo') def test_reimport_builtin(self): -skip("fix me") import sys, time oldpath = sys.path time.tzset = "" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue1514: A branch to run the tests in
Author: Armin Rigo Branch: issue1514 Changeset: r70651:7b0312827183 Date: 2014-04-16 14:39 +0200 http://bitbucket.org/pypy/pypy/changeset/7b0312827183/ Log:A branch to run the tests in ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: someone forgot those
Author: Maciej Fijalkowski Branch: Changeset: r70653:6c60fdb521ad Date: 2014-04-16 14:48 +0200 http://bitbucket.org/pypy/pypy/changeset/6c60fdb521ad/ Log:someone forgot those 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 @@ -97,6 +97,7 @@ self.indices = [0] * len(self.shape_m1) self.offset = self.array.start +@jit.unroll_safe def next(self): self.index += 1 for i in xrange(self.ndim_m1, -1, -1): @@ -108,6 +109,7 @@ self.indices[i] = 0 self.offset -= self.backstrides[i] +@jit.unroll_safe def next_skip_x(self, step): assert step >= 0 if step == 0: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: a more questionable unrolling here
Author: Maciej Fijalkowski Branch: Changeset: r70654:054e2cc2266a Date: 2014-04-16 15:13 +0200 http://bitbucket.org/pypy/pypy/changeset/054e2cc2266a/ Log:a more questionable unrolling here 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 @@ -442,6 +442,7 @@ return v1 % v2 @simple_binary_op +@jit.unroll_iff(lambda self, v1, v2: jit.isconstant(v2)) def pow(self, v1, v2): if v2 < 0: return 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue1514: hg merge default
Author: Armin Rigo Branch: issue1514 Changeset: r70655:8edf0636e375 Date: 2014-04-16 15:27 +0200 http://bitbucket.org/pypy/pypy/changeset/8edf0636e375/ Log:hg merge default diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -337,6 +337,9 @@ return 'internal subclass of %s' % (Class.__name__,) wrappable_class_name._annspecialcase_ = 'specialize:memo' +class CannotHaveLock(Exception): +"""Raised by space.allocate_lock() if we're translating.""" + # class ObjSpace(object): @@ -675,6 +678,11 @@ def __allocate_lock(self): from rpython.rlib.rthread import allocate_lock, error +# hack: we can't have prebuilt locks if we're translating. +# In this special situation we should just not lock at all +# (translation is not multithreaded anyway). +if not we_are_translated() and self.config.translating: +raise CannotHaveLock() try: return allocate_lock() except error: diff --git a/pypy/module/_file/interp_stream.py b/pypy/module/_file/interp_stream.py --- a/pypy/module/_file/interp_stream.py +++ b/pypy/module/_file/interp_stream.py @@ -4,7 +4,7 @@ from rpython.rlib.streamio import StreamErrors from pypy.interpreter.error import OperationError -from pypy.interpreter.baseobjspace import ObjSpace, W_Root +from pypy.interpreter.baseobjspace import ObjSpace, W_Root, CannotHaveLock from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gateway import interp2app from pypy.interpreter.streamutil import wrap_streamerror, wrap_oserror_as_ioerror @@ -33,19 +33,24 @@ def _try_acquire_lock(self): # this function runs with the GIL acquired so there is no race # condition in the creation of the lock -if self.slock is None: -self.slock = self.space.allocate_lock() me = self.space.getexecutioncontext() # used as thread ident if self.slockowner is me: return False# already acquired by the current thread -self.slock.acquire(True) +try: +if self.slock is None: +self.slock = self.space.allocate_lock() +except CannotHaveLock: +pass +else: +self.slock.acquire(True) assert self.slockowner is None self.slockowner = me return True def _release_lock(self): self.slockowner = None -self.slock.release() +if self.slock is not None: +self.slock.release() def lock(self): if not self._try_acquire_lock(): 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 @@ -8,7 +8,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, generic_new_descr from pypy.interpreter.error import OperationError, oefmt -from pypy.interpreter.baseobjspace import W_Root +from pypy.interpreter.baseobjspace import W_Root, CannotHaveLock from pypy.interpreter.eval import Code from pypy.interpreter.pycode import PyCode from rpython.rlib import streamio, jit @@ -754,26 +754,14 @@ me = self.space.getexecutioncontext() # used as thread ident return self.lockowner is me -def _can_have_lock(self): -# hack: we can't have self.lock != None during translation, -# because prebuilt lock objects are not allowed. In this -# special situation we just don't lock at all (translation is -# not multithreaded anyway). -if we_are_translated(): -return True # we need a lock at run-time -elif self.space.config.translating: -assert self.lock is None -return False -else: -return True # in py.py - def acquire_lock(self): # this function runs with the GIL acquired so there is no race # condition in the creation of the lock if self.lock is None: -if not self._can_have_lock(): +try: +self.lock = self.space.allocate_lock() +except CannotHaveLock: return -self.lock = self.space.allocate_lock() me = self.space.getexecutioncontext() # used as thread ident if self.lockowner is me: pass# already acquired by the current thread @@ -791,7 +779,7 @@ # Too bad. This situation can occur if a fork() occurred # with the import lock held, and we're the child. return -if not self._can_have_lock(): +if self.lock is None: # CannotHaveLock occurred return space = self.space raise OperationError(space.w_RuntimeError, diff --git
[pypy-commit] pypy default: Unsure of this fix, but should help fix translation
Author: Armin Rigo Branch: Changeset: r70656:28f12116ef3d Date: 2014-04-16 15:53 +0200 http://bitbucket.org/pypy/pypy/changeset/28f12116ef3d/ Log:Unsure of this fix, but should help fix translation 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 @@ -442,7 +442,7 @@ return v1 % v2 @simple_binary_op -@jit.unroll_iff(lambda self, v1, v2: jit.isconstant(v2)) +@jit.look_inside_iff(lambda self, v1, v2: jit.isconstant(v2)) def pow(self, v1, v2): if v2 < 0: return 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue1514: hg merge default
Author: Armin Rigo Branch: issue1514 Changeset: r70657:faf6b124f8f7 Date: 2014-04-16 15:53 +0200 http://bitbucket.org/pypy/pypy/changeset/faf6b124f8f7/ Log:hg merge default 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 @@ -442,7 +442,7 @@ return v1 % v2 @simple_binary_op -@jit.unroll_iff(lambda self, v1, v2: jit.isconstant(v2)) +@jit.look_inside_iff(lambda self, v1, v2: jit.isconstant(v2)) def pow(self, v1, v2): if v2 < 0: return 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix the skipping condition (it was "skip always" by mistake)
Author: Armin Rigo Branch: Changeset: r70658:3a448de2c18d Date: 2014-04-16 16:02 +0200 http://bitbucket.org/pypy/pypy/changeset/3a448de2c18d/ Log:Fix the skipping condition (it was "skip always" by mistake) diff --git a/rpython/rlib/test/test_rlocale.py b/rpython/rlib/test/test_rlocale.py --- a/rpython/rlib/test/test_rlocale.py +++ b/rpython/rlib/test/test_rlocale.py @@ -37,7 +37,7 @@ assert isinstance(grouping, str) def test_libintl(): -if sys.platform != "darwin" or not sys.platform.startswith("linux"): +if sys.platform != "darwin" and not sys.platform.startswith("linux"): py.test.skip("there is (maybe) no libintl here") _gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP) res = _gettext("1234") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: jit.isconstant(float)
Author: Armin Rigo Branch: Changeset: r70659:31fa36a1d761 Date: 2014-04-16 16:20 +0200 http://bitbucket.org/pypy/pypy/changeset/31fa36a1d761/ Log:jit.isconstant(float) diff --git a/rpython/jit/metainterp/blackhole.py b/rpython/jit/metainterp/blackhole.py --- a/rpython/jit/metainterp/blackhole.py +++ b/rpython/jit/metainterp/blackhole.py @@ -887,6 +887,10 @@ def bhimpl_int_isconstant(x): return False +@arguments("f", returns="i") +def bhimpl_float_isconstant(x): +return False + @arguments("r", returns="i") def bhimpl_ref_isconstant(x): return False diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py --- a/rpython/jit/metainterp/pyjitpl.py +++ b/rpython/jit/metainterp/pyjitpl.py @@ -1169,7 +1169,9 @@ def _opimpl_isconstant(self, box): return ConstInt(isinstance(box, Const)) -opimpl_int_isconstant = opimpl_ref_isconstant = _opimpl_isconstant +opimpl_int_isconstant = _opimpl_isconstant +opimpl_ref_isconstant = _opimpl_isconstant +opimpl_float_isconstant = _opimpl_isconstant @arguments("box") def _opimpl_isvirtual(self, box): diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -3329,6 +3329,25 @@ assert res == main(1, 10, 2) self.check_resops(call=0) +def test_look_inside_iff_const_float(self): +@look_inside_iff(lambda arg: isconstant(arg)) +def f(arg): +return arg + 0.5 + +driver = JitDriver(greens = [], reds = ['n', 'total']) + +def main(n): +total = 0.0 +while n > 0: +driver.jit_merge_point(n=n, total=total) +total = f(total) +n -= 1 +return total + +res = self.meta_interp(main, [10], enable_opts='') +assert res == 5.0 +self.check_resops(call=1) + def test_look_inside_iff_virtual(self): # There's no good reason for this to be look_inside_iff, but it's a test! @look_inside_iff(lambda arg, n: isvirtual(arg)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue1514: hg merge default
Author: Armin Rigo Branch: issue1514 Changeset: r70660:aed75d5736d6 Date: 2014-04-16 16:20 +0200 http://bitbucket.org/pypy/pypy/changeset/aed75d5736d6/ Log:hg merge default diff --git a/rpython/jit/metainterp/blackhole.py b/rpython/jit/metainterp/blackhole.py --- a/rpython/jit/metainterp/blackhole.py +++ b/rpython/jit/metainterp/blackhole.py @@ -887,6 +887,10 @@ def bhimpl_int_isconstant(x): return False +@arguments("f", returns="i") +def bhimpl_float_isconstant(x): +return False + @arguments("r", returns="i") def bhimpl_ref_isconstant(x): return False diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py --- a/rpython/jit/metainterp/pyjitpl.py +++ b/rpython/jit/metainterp/pyjitpl.py @@ -1169,7 +1169,9 @@ def _opimpl_isconstant(self, box): return ConstInt(isinstance(box, Const)) -opimpl_int_isconstant = opimpl_ref_isconstant = _opimpl_isconstant +opimpl_int_isconstant = _opimpl_isconstant +opimpl_ref_isconstant = _opimpl_isconstant +opimpl_float_isconstant = _opimpl_isconstant @arguments("box") def _opimpl_isvirtual(self, box): diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -3329,6 +3329,25 @@ assert res == main(1, 10, 2) self.check_resops(call=0) +def test_look_inside_iff_const_float(self): +@look_inside_iff(lambda arg: isconstant(arg)) +def f(arg): +return arg + 0.5 + +driver = JitDriver(greens = [], reds = ['n', 'total']) + +def main(n): +total = 0.0 +while n > 0: +driver.jit_merge_point(n=n, total=total) +total = f(total) +n -= 1 +return total + +res = self.meta_interp(main, [10], enable_opts='') +assert res == 5.0 +self.check_resops(call=1) + def test_look_inside_iff_virtual(self): # There's no good reason for this to be look_inside_iff, but it's a test! @look_inside_iff(lambda arg, n: isvirtual(arg)) diff --git a/rpython/rlib/test/test_rlocale.py b/rpython/rlib/test/test_rlocale.py --- a/rpython/rlib/test/test_rlocale.py +++ b/rpython/rlib/test/test_rlocale.py @@ -37,7 +37,7 @@ assert isinstance(grouping, str) def test_libintl(): -if sys.platform != "darwin" or not sys.platform.startswith("linux"): +if sys.platform != "darwin" and not sys.platform.startswith("linux"): py.test.skip("there is (maybe) no libintl here") _gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP) res = _gettext("1234") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: hg merge issue1514
Author: Armin Rigo Branch: Changeset: r70665:c2c709110379 Date: 2014-04-16 17:38 +0200 http://bitbucket.org/pypy/pypy/changeset/c2c709110379/ Log:hg merge issue1514 Support strange manipulations of sys.modules (thanks yamt) involving deleting built-in modules from sys.modules and reimporting them. Required by eventlet. diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -443,10 +443,11 @@ return name -def getbuiltinmodule(self, name, force_init=False): +def getbuiltinmodule(self, name, force_init=False, reuse=True): w_name = self.wrap(name) w_modules = self.sys.get('modules') if not force_init: +assert reuse try: return self.getitem(w_modules, w_name) except OperationError, e: @@ -462,9 +463,20 @@ "getbuiltinmodule() called with non-builtin module %s", name) else: -# Initialize the module +# Add the module to sys.modules and initialize the module +# The order is important to avoid recursions. from pypy.interpreter.module import Module if isinstance(w_mod, Module): +if not reuse and w_mod.startup_called: +# create a copy of the module. (see issue1514) +# eventlet patcher relies on this behaviour. +w_mod2 = self.wrap(Module(self, w_name)) +self.setitem(w_modules, w_name, w_mod2) +w_mod.getdict(self) # unlazy w_initialdict +self.call_method(w_mod2.getdict(self), 'update', + w_mod.w_initialdict) +return w_mod2 +# w_mod.init(self) # Add the module to sys.modules 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 @@ -579,7 +579,8 @@ return space.call_method(find_info.w_loader, "load_module", w_modulename) if find_info.modtype == C_BUILTIN: -return space.getbuiltinmodule(find_info.filename, force_init=True) +return space.getbuiltinmodule(find_info.filename, force_init=True, + reuse=reuse) if find_info.modtype in (PY_SOURCE, PY_COMPILED, C_EXTENSION, PKG_DIRECTORY): w_mod = None diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py --- a/pypy/module/imp/test/test_app.py +++ b/pypy/module/imp/test/test_app.py @@ -203,7 +203,6 @@ def test_builtin_reimport(self): # from https://bugs.pypy.org/issue1514 -skip("fix me") import sys, marshal old = marshal.loads @@ -223,7 +222,6 @@ # taken from https://bugs.pypy.org/issue1514, with extra cases # that show a difference with CPython: we can get on CPython # several module objects for the same built-in module :-( -skip("several built-in module objects: not supported by pypy") import sys, marshal old = marshal.loads 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 @@ -578,7 +578,6 @@ assert hasattr(time, 'clock') def test_reimport_builtin_simple_case_2(self): -skip("fix me") import sys, time time.foo = "bar" del sys.modules['time'] @@ -586,7 +585,6 @@ assert not hasattr(time, 'foo') def test_reimport_builtin(self): -skip("fix me") import sys, time oldpath = sys.path time.tzset = "" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stmgc-c7: Kill what remains of the previous approach to abort_info
Author: Armin Rigo Branch: stmgc-c7 Changeset: r70663:de599561d2a5 Date: 2014-04-16 17:32 +0200 http://bitbucket.org/pypy/pypy/changeset/de599561d2a5/ Log:Kill what remains of the previous approach to abort_info diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py --- a/pypy/interpreter/executioncontext.py +++ b/pypy/interpreter/executioncontext.py @@ -56,10 +56,6 @@ return frame def enter(self, frame): -if self.space.config.translation.stm: - if not self.space.config.translation.jit: # XXX -from pypy.module.thread.stm import enter_frame -enter_frame(self, frame) frame.f_backref = self.topframeref self.topframeref = jit.virtual_ref(frame) @@ -81,11 +77,6 @@ frame_vref() jit.virtual_ref_finish(frame_vref, frame) -if self.space.config.translation.stm: - if not self.space.config.translation.jit: # XXX -from pypy.module.thread.stm import leave_frame -leave_frame(self, frame) - # def c_call_trace(self, frame, w_func, args=None): diff --git a/pypy/module/thread/stm.py b/pypy/module/thread/stm.py --- a/pypy/module/thread/stm.py +++ b/pypy/module/thread/stm.py @@ -41,21 +41,6 @@ if not we_are_translated() and not hasattr(ec, '_thread_local_dicts'): initialize_execution_context(ec) -@jit.dont_look_inside # XXX: handle abort_info_push in JIT -def enter_frame(ec, frame): -"""Called from ExecutionContext.enter().""" -if frame.hide(): -return -rstm.abort_info_push(frame.pycode, ('[', 'co_filename', 'co_name', -'co_firstlineno', 'co_lnotab')) -rstm.abort_info_push(frame, ('last_instr', ']')) - -def leave_frame(ec, frame): -"""Called from ExecutionContext.leave().""" -if frame.hide(): -return -rstm.abort_info_pop(2) - class STMThreadLocals(BaseThreadLocals): diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py --- a/rpython/rlib/rstm.py +++ b/rpython/rlib/rstm.py @@ -80,18 +80,6 @@ def is_atomic(): return llop.stm_get_atomic(lltype.Signed) -def abort_info_push(instance, fieldnames): -"Special-cased below." - -@dont_look_inside -def abort_info_pop(count): -if we_are_translated(): -llop.stm_abort_info_pop(lltype.Void, count) - -@dont_look_inside -def charp_inspect_abort_info(): -return llop.stm_inspect_abort_info(rffi.CCHARP) - @dont_look_inside def abort_and_retry(): llop.stm_abort_and_retry(lltype.Void) @@ -161,58 +149,6 @@ # -class AbortInfoPush(ExtRegistryEntry): -_about_ = abort_info_push - -def compute_result_annotation(self, s_instance, s_fieldnames): -from rpython.annotator.model import SomeInstance -assert isinstance(s_instance, SomeInstance) -assert s_fieldnames.is_constant() -assert isinstance(s_fieldnames.const, tuple) # tuple of names - -def specialize_call(self, hop): -fieldnames = hop.args_s[1].const -lst = [] -v_instance = hop.inputarg(hop.args_r[0], arg=0) -for fieldname in fieldnames: -if fieldname == '[': -lst.append(-2)# start of sublist -continue -if fieldname == ']': -lst.append(-1)# end of sublist -continue -fieldname = 'inst_' + fieldname -extraofs = None -STRUCT = v_instance.concretetype.TO -while not hasattr(STRUCT, fieldname): -STRUCT = STRUCT.super -TYPE = getattr(STRUCT, fieldname) -if TYPE == lltype.Signed: -kind = 1 -elif TYPE == lltype.Unsigned: -kind = 2 -elif TYPE == lltype.Ptr(rstr.STR): -kind = 3 -extraofs = llmemory.offsetof(rstr.STR, 'chars') -else: -raise NotImplementedError( -"abort_info_push(%s, %r): field of type %r" -% (STRUCT.__name__, fieldname, TYPE)) -lst.append(kind) -lst.append(llmemory.offsetof(STRUCT, fieldname)) -if extraofs is not None: -lst.append(extraofs) -lst.append(0) -ARRAY = rffi.CArray(lltype.Signed) -array = lltype.malloc(ARRAY, len(lst), flavor='raw', immortal=True) -for i in range(len(lst)): -array[i] = lst[i] -c_array = hop.inputconst(lltype.Ptr(ARRAY), array) -hop.exception_cannot_occur() -hop.genop('stm_abort_info_push', [v_instance, c_array]) - -# - class ThreadLocalReference(object): _COUNT = 1 ___ pypy-commit mailing list pypy-commit@python.or
[pypy-commit] pypy stmgc-c7: Use stm stack markers
Author: Armin Rigo Branch: stmgc-c7 Changeset: r70661:7ea6e9a3e2b8 Date: 2014-04-16 17:30 +0200 http://bitbucket.org/pypy/pypy/changeset/7ea6e9a3e2b8/ Log:Use stm stack markers diff --git a/rpython/jit/backend/x86/assembler.py b/rpython/jit/backend/x86/assembler.py --- a/rpython/jit/backend/x86/assembler.py +++ b/rpython/jit/backend/x86/assembler.py @@ -859,11 +859,18 @@ # (ebp is a writeable object and does not need a write-barrier # again (ensured by the code calling the loop)) self.mc.MOV(ebx, self.heap_shadowstack_top()) -self.mc.MOV_mr((self.SEGMENT_NO, ebx.value, 0), ebp.value) - # MOV [ebx], ebp if self.cpu.gc_ll_descr.stm: +self.mc.MOV_mi((self.SEGMENT_NO, ebx.value, 0), + rstm.STM_STACK_MARKER_NEW) # MOV [ebx], MARKER_NEW +self.mc.MOV_mr((self.SEGMENT_NO, ebx.value, WORD), + ebp.value) # MOV [ebx+WORD], ebp self.mc.MOV_sr(STM_OLD_SHADOWSTACK, ebx.value) -self.mc.ADD_ri(ebx.value, WORD) + # MOV [esp+xx], ebx +self.mc.ADD_ri(ebx.value, 2 * WORD) +else: +self.mc.MOV_mr((self.SEGMENT_NO, ebx.value, 0), + ebp.value) # MOV [ebx], ebp +self.mc.ADD_ri(ebx.value, WORD) self.mc.MOV(self.heap_shadowstack_top(), ebx) # MOV [rootstacktop], ebx def _call_footer_shadowstack(self): diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py --- a/rpython/rlib/rstm.py +++ b/rpython/rlib/rstm.py @@ -12,6 +12,8 @@ TID = rffi.UINT tid_offset = CFlexSymbolic('offsetof(struct rpyobj_s, tid)') stm_nb_segments = CFlexSymbolic('STM_NB_SEGMENTS') +stm_stack_marker_new = CFlexSymbolic('STM_STACK_MARKER_NEW') +stm_stack_marker_old = CFlexSymbolic('STM_STACK_MARKER_OLD') adr_nursery_free = CFlexSymbolic('((long)&STM_SEGMENT->nursery_current)') adr_nursery_top = CFlexSymbolic('((long)&STM_SEGMENT->nursery_end)') adr_pypy_stm_nursery_low_fill_mark = ( ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stmgc-c7: import stmgc/918b1901b1f9
Author: Armin Rigo Branch: stmgc-c7 Changeset: r70662:4ca36098b3de Date: 2014-04-16 17:31 +0200 http://bitbucket.org/pypy/pypy/changeset/4ca36098b3de/ Log:import stmgc/918b1901b1f9 diff --git a/rpython/translator/stm/src_stm/revision b/rpython/translator/stm/src_stm/revision --- a/rpython/translator/stm/src_stm/revision +++ b/rpython/translator/stm/src_stm/revision @@ -1,1 +1,1 @@ -a158a889e78b +918b1901b1f9 diff --git a/rpython/translator/stm/src_stm/stm/gcpage.c b/rpython/translator/stm/src_stm/stm/gcpage.c --- a/rpython/translator/stm/src_stm/stm/gcpage.c +++ b/rpython/translator/stm/src_stm/stm/gcpage.c @@ -380,8 +380,8 @@ struct stm_shadowentry_s *current = tl->shadowstack; struct stm_shadowentry_s *base = tl->shadowstack_base; while (current-- != base) { -assert(current->ss != (object_t *)-1); -mark_visit_object(current->ss, segment_base); +if (((uintptr_t)current->ss) > STM_STACK_MARKER_OLD) +mark_visit_object(current->ss, segment_base); } mark_visit_object(tl->thread_local_obj, segment_base); diff --git a/rpython/translator/stm/src_stm/stm/nursery.c b/rpython/translator/stm/src_stm/stm/nursery.c --- a/rpython/translator/stm/src_stm/stm/nursery.c +++ b/rpython/translator/stm/src_stm/stm/nursery.c @@ -157,10 +157,32 @@ stm_thread_local_t *tl = STM_SEGMENT->running_thread; struct stm_shadowentry_s *current = tl->shadowstack; struct stm_shadowentry_s *base = tl->shadowstack_base; -while (current-- != base) { -assert(current->ss != (object_t *)-1); -minor_trace_if_young(¤t->ss); +while (1) { +--current; +OPT_ASSERT(current >= base); + +switch ((uintptr_t)current->ss) { + +case 0: /* NULL */ +continue; + +case STM_STACK_MARKER_NEW: +/* the marker was not already seen: mark it as seen, + but continue looking more deeply in the shadowstack */ +current->ss = (object_t *)STM_STACK_MARKER_OLD; +continue; + +case STM_STACK_MARKER_OLD: +/* the marker was already seen: we can stop the + root stack tracing at this point */ +goto interrupt; + +default: +/* the stack entry is a regular pointer */ +minor_trace_if_young(¤t->ss); +} } + interrupt: minor_trace_if_young(&tl->thread_local_obj); } diff --git a/rpython/translator/stm/src_stm/stm/setup.c b/rpython/translator/stm/src_stm/stm/setup.c --- a/rpython/translator/stm/src_stm/stm/setup.c +++ b/rpython/translator/stm/src_stm/stm/setup.c @@ -154,11 +154,13 @@ struct stm_shadowentry_s *s = (struct stm_shadowentry_s *)start; tl->shadowstack = s; tl->shadowstack_base = s; +STM_PUSH_ROOT(*tl, STM_STACK_MARKER_OLD); } static void _done_shadow_stack(stm_thread_local_t *tl) { -assert(tl->shadowstack >= tl->shadowstack_base); +assert(tl->shadowstack > tl->shadowstack_base); +assert(tl->shadowstack_base->ss == (object_t *)STM_STACK_MARKER_OLD); char *start = (char *)tl->shadowstack_base; _shadowstack_trap_page(start, PROT_READ | PROT_WRITE); diff --git a/rpython/translator/stm/src_stm/stm/timing.c b/rpython/translator/stm/src_stm/stm/timing.c --- a/rpython/translator/stm/src_stm/stm/timing.c +++ b/rpython/translator/stm/src_stm/stm/timing.c @@ -71,7 +71,7 @@ s_mutex_lock(); fprintf(stderr, "thread %p:\n", tl); for (i = 0; i < _STM_TIME_N; i++) { -fprintf(stderr, "%-24s %9u %.3f s\n", +fprintf(stderr, "%-24s %9u %8.3f s\n", timer_names[i], tl->events[i], (double)tl->timing[i]); } s_mutex_unlock(); diff --git a/rpython/translator/stm/src_stm/stmgc.h b/rpython/translator/stm/src_stm/stmgc.h --- a/rpython/translator/stm/src_stm/stmgc.h +++ b/rpython/translator/stm/src_stm/stmgc.h @@ -265,6 +265,8 @@ #define STM_PUSH_ROOT(tl, p) ((tl).shadowstack++->ss = (object_t *)(p)) #define STM_POP_ROOT(tl, p)((p) = (typeof(p))((--(tl).shadowstack)->ss)) #define STM_POP_ROOT_RET(tl) ((--(tl).shadowstack)->ss) +#define STM_STACK_MARKER_NEW 1 +#define STM_STACK_MARKER_OLD 2 /* Every thread needs to have a corresponding stm_thread_local_t ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue1514: ready for merge
Author: Armin Rigo Branch: issue1514 Changeset: r70664:3dff2f025058 Date: 2014-04-16 17:36 +0200 http://bitbucket.org/pypy/pypy/changeset/3dff2f025058/ Log:ready for merge ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: silence import RuntimeWarning
Author: Brian Kearns Branch: Changeset: r70666:e370d5d04364 Date: 2014-04-16 12:18 -0400 http://bitbucket.org/pypy/pypy/changeset/e370d5d04364/ Log:silence import RuntimeWarning diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py --- a/pypy/module/micronumpy/app_numpy.py +++ b/pypy/module/micronumpy/app_numpy.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import math import _numpypy ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix whatsnew
Author: Brian Kearns Branch: Changeset: r70667:db4a8be80c49 Date: 2014-04-16 12:43 -0400 http://bitbucket.org/pypy/pypy/changeset/db4a8be80c49/ Log:fix whatsnew 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 @@ -133,4 +133,7 @@ .. branch: ast-issue1673 fix ast classes __dict__ are always empty problem and fix the ast deepcopy issue when -there is missing field \ No newline at end of file +there is missing field + +.. branch: issue1514 +Fix issues with reimporting builtin modules ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: update micronumpy test_zjit
Author: Brian Kearns Branch: Changeset: r70668:5191bc7c4184 Date: 2014-04-16 13:26 -0400 http://bitbucket.org/pypy/pypy/changeset/5191bc7c4184/ Log:update micronumpy test_zjit diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -482,16 +482,19 @@ assert result == 1.0 self.check_trace_count(1) self.check_simple_loop({ -'call': 2, -'getfield_gc': 2, -'guard_no_exception': 2, +'getarrayitem_gc': 4, +'getfield_gc': 4, 'guard_not_invalidated': 1, -'guard_true': 1, +'guard_true': 3, +'int_add': 6, 'int_gt': 1, +'int_lt': 2, 'int_sub': 1, 'jump': 1, 'raw_load': 1, 'raw_store': 1, +'setarrayitem_gc': 2, +'setfield_gc': 4, }) def define_dot(): @@ -506,36 +509,43 @@ result = self.run("dot") assert result == 184 self.check_trace_count(3) -self.check_simple_loop({'float_add': 1, -'float_mul': 1, -'guard_not_invalidated': 1, -'guard_true': 1, -'int_add': 3, -'int_lt': 1, -'jump': 1, -'raw_load': 2}) -self.check_resops({'arraylen_gc': 1, - 'call': 3, - 'float_add': 2, - 'float_mul': 2, - 'getfield_gc': 26, - 'getfield_gc_pure': 24, - 'guard_class': 4, - 'guard_false': 2, - 'guard_no_exception': 3, - 'guard_nonnull': 12, - 'guard_nonnull_class': 4, - 'guard_not_invalidated': 2, - 'guard_true': 9, - 'guard_value': 4, - 'int_add': 6, - 'int_ge': 3, - 'int_lt': 4, - 'jump': 3, - 'new_array': 1, - 'raw_load': 6, - 'raw_store': 1, - 'setfield_gc': 3}) +self.check_simple_loop({ +'float_add': 1, +'float_mul': 1, +'guard_not_invalidated': 1, +'guard_true': 1, +'int_add': 3, +'int_lt': 1, +'jump': 1, +'raw_load': 2, +}) +self.check_resops({ +'arraylen_gc': 1, +'float_add': 2, +'float_mul': 2, +'getarrayitem_gc': 11, +'getarrayitem_gc_pure': 15, +'getfield_gc': 35, +'getfield_gc_pure': 39, +'guard_class': 4, +'guard_false': 14, +'guard_nonnull': 12, +'guard_nonnull_class': 4, +'guard_not_invalidated': 2, +'guard_true': 13, +'guard_value': 4, +'int_add': 25, +'int_ge': 4, +'int_le': 8, +'int_lt': 11, +'int_sub': 4, +'jump': 3, +'new_array': 1, +'raw_load': 6, +'raw_store': 1, +'setarrayitem_gc': 8, +'setfield_gc': 15, +}) def define_argsort(): return """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: eliminate duplicate getarrayitem_gc in numpy iterator next
Author: Brian Kearns Branch: Changeset: r70669:4b3a31de60d3 Date: 2014-04-16 18:22 -0400 http://bitbucket.org/pypy/pypy/changeset/4b3a31de60d3/ Log:eliminate duplicate getarrayitem_gc in numpy iterator next 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 @@ -101,8 +101,9 @@ def next(self): self.index += 1 for i in xrange(self.ndim_m1, -1, -1): -if self.indices[i] < self.shape_m1[i]: -self.indices[i] += 1 +idx = self.indices[i] +if idx < self.shape_m1[i]: +self.indices[i] = idx + 1 self.offset += self.strides[i] break else: @@ -116,8 +117,9 @@ return self.index += step for i in xrange(self.ndim_m1, -1, -1): -if self.indices[i] < (self.shape_m1[i] + 1) - step: -self.indices[i] += step +idx = self.indices[i] +if idx < (self.shape_m1[i] + 1) - step: +self.indices[i] = idx + step self.offset += self.strides[i] * step break else: diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -482,7 +482,7 @@ assert result == 1.0 self.check_trace_count(1) self.check_simple_loop({ -'getarrayitem_gc': 4, +'getarrayitem_gc': 2, 'getfield_gc': 4, 'guard_not_invalidated': 1, 'guard_true': 3, @@ -523,7 +523,7 @@ 'arraylen_gc': 1, 'float_add': 2, 'float_mul': 2, -'getarrayitem_gc': 11, +'getarrayitem_gc': 7, 'getarrayitem_gc_pure': 15, 'getfield_gc': 35, 'getfield_gc_pure': 39, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: os.path.isdir calls nt.isdir on win32 which is not rpython after PyWin is installed to host python
Author: Matti Picus Branch: Changeset: r70672:5494b1aac76f Date: 2014-04-16 06:07 +0300 http://bitbucket.org/pypy/pypy/changeset/5494b1aac76f/ Log:os.path.isdir calls nt.isdir on win32 which is not rpython after PyWin is installed to host python 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 @@ -2,7 +2,7 @@ Implementation of the interpreter-level default import logic. """ -import sys, os, stat +import sys, os, stat, genericpath from pypy.interpreter.module import Module from pypy.interpreter.gateway import interp2app, unwrap_spec @@ -522,7 +522,8 @@ path = space.str0_w(w_pathitem) filepart = os.path.join(path, partname) -if os.path.isdir(filepart) and case_ok(filepart): +# os.path.isdir on win32 is not rpython when pywin32 installed +if genericpath.isdir(filepart) and case_ok(filepart): initfile = os.path.join(filepart, '__init__') modtype, _, _ = find_modtype(space, initfile) if modtype in (PY_SOURCE, PY_COMPILED): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpypy-nditer: implement op_dtypes
Author: Matti Picus Branch: numpypy-nditer Changeset: r70671:0dca5996f880 Date: 2014-04-16 23:10 +0300 http://bitbucket.org/pypy/pypy/changeset/0dca5996f880/ Log:implement op_dtypes diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py --- a/pypy/module/micronumpy/nditer.py +++ b/pypy/module/micronumpy/nditer.py @@ -7,6 +7,7 @@ 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 @@ -201,8 +202,8 @@ else: raise NotImplementedError('not implemented yet') -def get_iter(space, order, arr, shape): -imp = arr.implementation +def get_iter(space, order, arr, shape, dtype): +imp = arr.implementation.astype(space, dtype) backward = is_backward(imp, order) if (imp.strides[0] < imp.strides[-1] and not backward) or \ (imp.strides[0] > imp.strides[-1] and backward): @@ -291,8 +292,13 @@ if not space.is_none(w_op_axes): self.set_op_axes(space, w_op_axes) if not space.is_none(w_op_dtypes): -raise OperationError(space.w_NotImplementedError, space.wrap( -'nditer op_dtypes kwarg not implemented yet')) +w_seq_as_list = space.listview(w_op_dtypes) +self.dtypes = [decode_w_dtype(space, w_elem) for w_elem in w_seq_as_list] +if len(self.dtypes) != len(self.seq): +raise OperationError(space.w_ValueError, space.wrap( +"op_dtypes must be a tuple/list matching the number of ops")) +else: +self.dtypes = [] self.iters=[] outargs = [i for i in range(len(self.seq)) \ if self.seq[i] is None or self.op_flags[i].rw == 'w'] @@ -304,7 +310,7 @@ shape=out_shape) if len(outargs) > 0: # Make None operands writeonly and flagged for allocation -out_dtype = None +out_dtype = self.dtypes[0] if len(self.dtypes) > 0 else None for i in range(len(self.seq)): if self.seq[i] is None: self.op_flags[i].get_it_item = (get_readwrite_item, @@ -331,6 +337,19 @@ else: backward = self.order != self.tracked_index self.index_iter = IndexIterator(iter_shape, backward=backward) +if len(self.dtypes) > 0: +# Make sure dtypes make sense +for i in range(len(self.seq)): +selfd = self.dtypes[i] +seq_d = self.seq[i].get_dtype() +if not selfd: +self.dtypes[i] = seq_d +elif selfd != seq_d and not 'r' in self.op_flags[i].tmp_copy: +raise OperationError(space.w_TypeError, space.wrap( +"Iterator operand required copying or buffering")) +else: +#copy them from seq +self.dtypes = [s.get_dtype() for s in self.seq] if self.external_loop: for i in range(len(self.seq)): self.iters.append(ExternalLoopIterator(get_external_loop_iter(space, self.order, @@ -338,7 +357,8 @@ else: for i in range(len(self.seq)): self.iters.append(BoxIterator(get_iter(space, self.order, -self.seq[i], iter_shape), self.op_flags[i])) +self.seq[i], iter_shape, self.dtypes[i]), + self.op_flags[i])) def set_op_axes(self, space, w_op_axes): if space.len_w(w_op_axes) != len(self.seq): diff --git a/pypy/module/micronumpy/test/test_nditer.py b/pypy/module/micronumpy/test/test_nditer.py --- a/pypy/module/micronumpy/test/test_nditer.py +++ b/pypy/module/micronumpy/test/test_nditer.py @@ -140,11 +140,7 @@ def test_op_dtype(self): from numpy import arange, nditer, sqrt, array -import sys a = arange(6).reshape(2,3) - 3 -if '__pypy__' in sys.builtin_module_names: -raises(NotImplementedError, nditer, a, op_dtypes=['complex']) -skip('nditer op_dtypes kwarg not implemented yet') exc = raises(TypeError, nditer, a, op_dtypes=['complex']) assert str(exc.value).startswith("Iterator operand required copying or buffering") r = [] @@ -154,7 +150,7 @@ assert abs((array(r) - [1.73205080757j, 1.41421356237j, 1j, 0j, 1+0j, 1.41421356237+0j]).sum()) < 1e-5 r = [] -for x in nditer(a, flags=['buffered'], +for x in nditer(a, op_flags=['copy'], op_dtypes=['complex128']): r.append(sqrt(x)) assert abs((array(r) - [1.73205080757j, 1.41421356237j,
[pypy-commit] pypy default: merge default into branch
Author: Matti Picus 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 parse_op_arg(space
[pypy-commit] pypy numpypy-nditer: disable 'external_loop' and 'buffering' flags pending future refactor, fix translation
Author: Matti Picus Branch: numpypy-nditer Changeset: r70670:873c97659fd1 Date: 2014-04-16 05:57 +0300 http://bitbucket.org/pypy/pypy/changeset/873c97659fd1/ Log:disable 'external_loop' and 'buffering' flags pending future refactor, fix translation diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py --- a/pypy/module/micronumpy/nditer.py +++ b/pypy/module/micronumpy/nditer.py @@ -155,8 +155,12 @@ 'expected string or Unicode object, %s found' % typename)) item = space.str_w(w_item) if item == 'external_loop': +raise OperationError(space.w_NotImplementedError, space.wrap( +'nditer external_loop not implemented yet')) nditer.external_loop = True elif item == 'buffered': +raise OperationError(space.w_NotImplementedError, space.wrap( +'nditer buffered not implemented yet')) # For numpy compatability nditer.buffered = True elif item == 'c_index': @@ -307,7 +311,7 @@ get_readwrite_slice) self.op_flags[i].allocate = True continue -if self.op_flags[i] == 'w': +if self.op_flags[i].rw == 'w': continue out_dtype = ufuncs.find_binop_result_dtype(space, self.seq[i].get_dtype(), out_dtype) @@ -348,7 +352,7 @@ l = axis_len elif axis_len != l: raise OperationError(space.w_ValueError, space.wrap("Each entry of op_axes must have the same size")) -self.op_axes.append([space.int_w(x) if not space.is_none(x) else space.w_None for x in space.listview(w_axis)]) +self.op_axes.append([space.int_w(x) if not space.is_none(x) else -1 for x in space.listview(w_axis)]) if l == -1: raise OperationError(space.w_ValueError, space.wrap("If op_axes is provided, at least one list of axes must be contained within it")) raise Exception('xxx TODO') @@ -441,7 +445,7 @@ l_w = [] for op in self.seq: l_w.append(op.descr_view(space)) -return space.newlist(l_w) +return space.newlist(l_w) def descr_get_dtypes(self, space): res = [None] * len(self.seq) diff --git a/pypy/module/micronumpy/test/test_nditer.py b/pypy/module/micronumpy/test/test_nditer.py --- a/pypy/module/micronumpy/test/test_nditer.py +++ b/pypy/module/micronumpy/test/test_nditer.py @@ -38,6 +38,10 @@ def test_external_loop(self): from numpy import arange, nditer, array a = arange(24).reshape(2, 3, 4) +import sys +if '__pypy__' in sys.builtin_module_names: +raises(NotImplementedError, nditer, a, flags=['external_loop']) +skip('nditer external_loop not implmented') r = [] n = 0 for x in nditer(a, flags=['external_loop']): @@ -115,13 +119,17 @@ it[0] = it.multi_index[1] - it.multi_index[0] it.iternext() assert (a == [[0, 1, 2], [-1, 0, 1]]).all() -b = zeros((2, 3)) -exc = raises(ValueError, nditer, b, flags=['c_index', 'external_loop']) -assert str(exc.value).startswith("Iterator flag EXTERNAL_LOOP cannot") +# b = zeros((2, 3)) +# exc = raises(ValueError, nditer, b, flags=['c_index', 'external_loop']) +# assert str(exc.value).startswith("Iterator flag EXTERNAL_LOOP cannot") def test_buffered(self): from numpy import arange, nditer, array a = arange(6).reshape(2,3) +import sys +if '__pypy__' in sys.builtin_module_names: +raises(NotImplementedError, nditer, a, flags=['buffered']) +skip('nditer buffered not implmented') r = [] for x in nditer(a, flags=['external_loop', 'buffered'], order='F'): r.append(x) @@ -189,6 +197,10 @@ def test_outarg(self): from numpy import nditer, zeros, arange +import sys +if '__pypy__' in sys.builtin_module_names: +raises(NotImplementedError, nditer, [1, 2], flags=['external_loop']) +skip('nditer external_loop not implmented') def square1(a): it = nditer([a, None]) @@ -215,6 +227,10 @@ def test_outer_product(self): from numpy import nditer, arange a = arange(3) +import sys +if '__pypy__' in sys.builtin_module_names: +raises(NotImplementedError, nditer, a, flags=['external_loop']) +skip('nditer external_loop not implmented') b = arange(8).reshape(2,4) it = nditer([a, b, None], flags=['external_loop'], op_axes=[[0, -1, -1], [-1, 0, 1], None]) ___ pypy-commit mailing list pypy-c
[pypy-commit] pypy default: revert part of 310dcc241b1f: go back to having the module in sys.modules before
Author: Philip Jenvey Branch: Changeset: r70674:a7023a962605 Date: 2014-04-16 16:17 -0700 http://bitbucket.org/pypy/pypy/changeset/a7023a962605/ Log:revert part of 310dcc241b1f: go back to having the module in sys.modules before init, otherwise py3k runs into trouble while bootstrapping sys with the new reloading fix diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -462,26 +462,23 @@ raise oefmt(self.w_SystemError, "getbuiltinmodule() called with non-builtin module %s", name) -else: -# Add the module to sys.modules and initialize the module -# The order is important to avoid recursions. -from pypy.interpreter.module import Module -if isinstance(w_mod, Module): -if not reuse and w_mod.startup_called: -# create a copy of the module. (see issue1514) -# eventlet patcher relies on this behaviour. -w_mod2 = self.wrap(Module(self, w_name)) -self.setitem(w_modules, w_name, w_mod2) -w_mod.getdict(self) # unlazy w_initialdict -self.call_method(w_mod2.getdict(self), 'update', - w_mod.w_initialdict) -return w_mod2 -# -w_mod.init(self) -# Add the module to sys.modules +# Add the module to sys.modules and initialize the module. The +# order is important to avoid recursions. +from pypy.interpreter.module import Module +if isinstance(w_mod, Module): +if not reuse and w_mod.startup_called: +# create a copy of the module. (see issue1514) eventlet +# patcher relies on this behaviour. +w_mod2 = self.wrap(Module(self, w_name)) +self.setitem(w_modules, w_name, w_mod2) +w_mod.getdict(self) # unlazy w_initialdict +self.call_method(w_mod2.getdict(self), 'update', + w_mod.w_initialdict) +return w_mod2 self.setitem(w_modules, w_name, w_mod) -return w_mod +w_mod.init(self) +return w_mod def get_builtinmodule_to_install(self): """NOT_RPYTHON""" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge upstream
Author: Philip Jenvey Branch: Changeset: r70676:c7c7b54e61a0 Date: 2014-04-16 16:34 -0700 http://bitbucket.org/pypy/pypy/changeset/c7c7b54e61a0/ Log:merge upstream 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 @@ -2,7 +2,7 @@ Implementation of the interpreter-level default import logic. """ -import sys, os, stat +import sys, os, stat, genericpath from pypy.interpreter.module import Module from pypy.interpreter.gateway import interp2app, unwrap_spec @@ -522,7 +522,8 @@ path = space.str0_w(w_pathitem) filepart = os.path.join(path, partname) -if os.path.isdir(filepart) and case_ok(filepart): +# os.path.isdir on win32 is not rpython when pywin32 installed +if genericpath.isdir(filepart) and case_ok(filepart): initfile = os.path.join(filepart, '__init__') modtype, _, _ = find_modtype(space, initfile) if modtype in (PY_SOURCE, PY_COMPILED): 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.micronum
[pypy-commit] pypy default: Backed out merge changeset: bace5e5bd016
Author: Matti Picus Branch: Changeset: r70677:6dbec8d4abec Date: 2014-04-17 02:35 +0300 http://bitbucket.org/pypy/pypy/changeset/6dbec8d4abec/ Log:Backed out merge changeset: bace5e5bd016 Backed out merge revision to its first parent (5494b1aac76f) 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,7 +23,6 @@ '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,13 +458,6 @@ 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,7 +42,6 @@ """ 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 @@ -143,37 +142,6 @@ 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 deleted file mode 100644 --- a/pypy/module/micronumpy/nditer.py +++ /dev/null @@ -1,577 +0,0 @@ -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 Extern
[pypy-commit] pypy default: merge heads - back out premature merge of nditer
Author: Matti Picus Branch: Changeset: r70678:16be85246762 Date: 2014-04-17 02:38 +0300 http://bitbucket.org/pypy/pypy/changeset/16be85246762/ Log:merge heads - back out premature merge of nditer diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -462,26 +462,23 @@ raise oefmt(self.w_SystemError, "getbuiltinmodule() called with non-builtin module %s", name) -else: -# Add the module to sys.modules and initialize the module -# The order is important to avoid recursions. -from pypy.interpreter.module import Module -if isinstance(w_mod, Module): -if not reuse and w_mod.startup_called: -# create a copy of the module. (see issue1514) -# eventlet patcher relies on this behaviour. -w_mod2 = self.wrap(Module(self, w_name)) -self.setitem(w_modules, w_name, w_mod2) -w_mod.getdict(self) # unlazy w_initialdict -self.call_method(w_mod2.getdict(self), 'update', - w_mod.w_initialdict) -return w_mod2 -# -w_mod.init(self) -# Add the module to sys.modules +# Add the module to sys.modules and initialize the module. The +# order is important to avoid recursions. +from pypy.interpreter.module import Module +if isinstance(w_mod, Module): +if not reuse and w_mod.startup_called: +# create a copy of the module. (see issue1514) eventlet +# patcher relies on this behaviour. +w_mod2 = self.wrap(Module(self, w_name)) +self.setitem(w_modules, w_name, w_mod2) +w_mod.getdict(self) # unlazy w_initialdict +self.call_method(w_mod2.getdict(self), 'update', + w_mod.w_initialdict) +return w_mod2 self.setitem(w_modules, w_name, w_mod) -return w_mod +w_mod.init(self) +return w_mod def get_builtinmodule_to_install(self): """NOT_RPYTHON""" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix whatsnew
Author: Brian Kearns Branch: Changeset: r70679:cf13db4663c3 Date: 2014-04-16 19:48 -0400 http://bitbucket.org/pypy/pypy/changeset/cf13db4663c3/ Log:fix whatsnew 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 @@ -137,3 +137,5 @@ .. branch: issue1514 Fix issues with reimporting builtin modules + +.. branch: numpypy-nditer ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: enable another test_zjit
Author: Brian Kearns Branch: Changeset: r70680:dd3c87c0ab56 Date: 2014-04-16 21:18 -0400 http://bitbucket.org/pypy/pypy/changeset/dd3c87c0ab56/ Log:enable another test_zjit diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -94,14 +94,26 @@ a -> 3 """ -def test_floatadd(self): +def test_float_add(self): result = self.run("float_add") assert result == 3 + 3 -py.test.skip("don't run for now") -self.check_simple_loop({"raw_load": 1, "float_add": 1, -"raw_store": 1, "int_add": 1, -"int_ge": 1, "guard_false": 1, "jump": 1, -'arraylen_gc': 1}) +self.check_trace_count(1) +self.check_simple_loop({ +'float_add': 1, +'getarrayitem_gc': 3, +'getfield_gc': 7, +'guard_false': 1, +'guard_not_invalidated': 1, +'guard_true': 3, +'int_add': 9, +'int_ge': 1, +'int_lt': 3, +'jump': 1, +'raw_load': 2, +'raw_store': 1, +'setarrayitem_gc': 3, +'setfield_gc': 6, +}) def define_sum(): return """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test with tzname rather than tzset for win32 compat
Author: Brian Kearns Branch: Changeset: r70681:19e7e8192d2e Date: 2014-04-16 23:36 -0400 http://bitbucket.org/pypy/pypy/changeset/19e7e8192d2e/ Log:test with tzname rather than tzset for win32 compat 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 @@ -587,17 +587,17 @@ def test_reimport_builtin(self): import sys, time oldpath = sys.path -time.tzset = "" +time.tzname = "" del sys.modules['time'] import time as time1 assert sys.modules['time'] is time1 -assert time.tzset == "" +assert time.tzname == "" -reload(time1) # don't leave a broken time.tzset behind +reload(time1) # don't leave a broken time.tzname behind import time -assert time.tzset != "" +assert time.tzname != "" def test_reload_infinite(self): import infinite_reload ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: add a test_zjit for pow
Author: Brian Kearns Branch: Changeset: r70683:f2bdd3baf2d1 Date: 2014-04-17 01:26 -0400 http://bitbucket.org/pypy/pypy/changeset/f2bdd3baf2d1/ Log:add a test_zjit for pow 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 @@ -388,6 +388,8 @@ w_res = w_lhs.descr_mul(interp.space, w_rhs) elif self.name == '-': w_res = w_lhs.descr_sub(interp.space, w_rhs) +elif self.name == '**': +w_res = w_lhs.descr_pow(interp.space, w_rhs) elif self.name == '->': if isinstance(w_rhs, FloatObject): w_rhs = IntObject(int(w_rhs.floatval)) @@ -622,7 +624,7 @@ (':', 'colon'), ('\w+', 'identifier'), ('\]', 'array_right'), -('(->)|[\+\-\*\/]', 'operator'), +('(->)|[\+\-\*\/]+', 'operator'), ('=', 'assign'), (',', 'comma'), ('\|', 'pipe'), diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -115,6 +115,38 @@ 'setfield_gc': 6, }) +def define_pow(): +return """ +a = |30| ** 2 +a -> 3 +""" + +def test_pow(self): +result = self.run("pow") +assert result == 3 ** 2 +self.check_trace_count(1) +self.check_simple_loop({ +'call': 3, +'float_add': 1, +'float_eq': 3, +'float_mul': 2, +'float_ne': 1, +'getarrayitem_gc': 3, +'getfield_gc': 7, +'guard_false': 4, +'guard_not_invalidated': 1, +'guard_true': 5, +'int_add': 9, +'int_ge': 1, +'int_is_true': 1, +'int_lt': 3, +'jump': 1, +'raw_load': 2, +'raw_store': 1, +'setarrayitem_gc': 3, +'setfield_gc': 6, +}) + def define_sum(): return """ a = |30| ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: support astype in micronumpy compile
Author: Brian Kearns Branch: Changeset: r70682:be03fa07697d Date: 2014-04-17 01:22 -0400 http://bitbucket.org/pypy/pypy/changeset/be03fa07697d/ Log:support astype in micronumpy compile 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 @@ -37,7 +37,7 @@ "unegative", "flat", "tostring","count_nonzero", "argsort"] TWO_ARG_FUNCTIONS = ["dot", 'take'] -TWO_ARG_FUNCTIONS_OR_NONE = ['view'] +TWO_ARG_FUNCTIONS_OR_NONE = ['view', 'astype'] THREE_ARG_FUNCTIONS = ['where'] class W_TypeObject(W_Root): @@ -596,6 +596,8 @@ arg = self.args[1].execute(interp) if self.name == 'view': w_res = arr.descr_view(interp.space, arg) +elif self.name == 'astype': +w_res = arr.descr_astype(interp.space, arg) else: assert False else: diff --git a/pypy/module/micronumpy/test/test_compile.py b/pypy/module/micronumpy/test/test_compile.py --- a/pypy/module/micronumpy/test/test_compile.py +++ b/pypy/module/micronumpy/test/test_compile.py @@ -319,3 +319,14 @@ ''') results = interp.results[0] assert isinstance(results, W_NDimArray) + +def test_astype_dtype(self): +interp = self.run(''' +a = [1, 0, 3, 0] +b = int +c = astype(a, b) +c +''') +results = interp.results[0] +assert isinstance(results, W_NDimArray) +assert results.get_dtype().is_int() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit