Author: Ronny Pfannschmidt <[email protected]>
Branch: stdlib-unification
Changeset: r54907:b4c7d0e64cc7
Date: 2012-05-06 14:44 +0200
http://bitbucket.org/pypy/pypy/changeset/b4c7d0e64cc7/

Log:    merge from default

diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst
--- a/pypy/doc/cppyy.rst
+++ b/pypy/doc/cppyy.rst
@@ -51,8 +51,15 @@
 `Download`_ a binary or install from `source`_.
 Some Linux and Mac systems may have ROOT provided in the list of scientific
 software of their packager.
-A current, standalone version of Reflex should be provided at some point,
-once the dependencies and general packaging have been thought out.
+If, however, you prefer a standalone version of Reflex, the best is to get
+this `recent snapshot`_, and install like so::
+
+    $ tar jxf reflex-2012-05-02.tar.bz2
+    $ cd reflex-2012-05-02
+    $ build/autogen
+    $ ./configure <usual set of options such as --prefix>
+    $ make && make install
+
 Also, make sure you have a version of `gccxml`_ installed, which is most
 easily provided by the packager of your system.
 If you read up on gccxml, you'll probably notice that it is no longer being
@@ -61,12 +68,13 @@
 
 .. _`Download`: http://root.cern.ch/drupal/content/downloading-root
 .. _`source`: http://root.cern.ch/drupal/content/installing-root-source
+.. _`recent snapshot`: http://cern.ch/wlav/reflex-2012-05-02.tar.bz2
 .. _`gccxml`: http://www.gccxml.org
 
 Next, get the `PyPy sources`_, select the reflex-support branch, and build
 pypy-c.
 For the build to succeed, the ``$ROOTSYS`` environment variable must point to
-the location of your ROOT installation::
+the location of your ROOT (or standalone Reflex) installation::
 
     $ hg clone https://bitbucket.org/pypy/pypy
     $ cd pypy
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1652,8 +1652,6 @@
     'UnicodeTranslateError',
     'ValueError',
     'ZeroDivisionError',
-    'UnicodeEncodeError',
-    'UnicodeDecodeError',
     ]
     
 if sys.platform.startswith("win"):
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1290,10 +1290,6 @@
                                w(self.valuestackdepth)])
 
     def handle(self, frame, unroller):
-        next_instr = self.really_handle(frame, unroller)   # JIT hack
-        return r_uint(next_instr)
-
-    def really_handle(self, frame, unroller):
         """ Purely abstract method
         """
         raise NotImplementedError
@@ -1305,17 +1301,17 @@
     _opname = 'SETUP_LOOP'
     handling_mask = SBreakLoop.kind | SContinueLoop.kind
 
-    def really_handle(self, frame, unroller):
+    def handle(self, frame, unroller):
         if isinstance(unroller, SContinueLoop):
             # re-push the loop block without cleaning up the value stack,
             # and jump to the beginning of the loop, stored in the
             # exception's argument
             frame.append_block(self)
-            return unroller.jump_to
+            return r_uint(unroller.jump_to)
         else:
             # jump to the end of the loop
             self.cleanupstack(frame)
-            return self.handlerposition
+            return r_uint(self.handlerposition)
 
 
 class ExceptBlock(FrameBlock):
@@ -1325,7 +1321,7 @@
     _opname = 'SETUP_EXCEPT'
     handling_mask = SApplicationException.kind
 
-    def really_handle(self, frame, unroller):
+    def handle(self, frame, unroller):
         # push the exception to the value stack for inspection by the
         # exception handler (the code after the except:)
         self.cleanupstack(frame)
@@ -1340,7 +1336,7 @@
         frame.pushvalue(operationerr.get_w_value(frame.space))
         frame.pushvalue(operationerr.w_type)
         frame.last_exception = operationerr
-        return self.handlerposition   # jump to the handler
+        return r_uint(self.handlerposition)   # jump to the handler
 
 
 class FinallyBlock(FrameBlock):
@@ -1361,7 +1357,7 @@
         frame.pushvalue(frame.space.w_None)
         frame.pushvalue(frame.space.w_None)
 
-    def really_handle(self, frame, unroller):
+    def handle(self, frame, unroller):
         # any abnormal reason for unrolling a finally: triggers the end of
         # the block unrolling and the entering the finally: handler.
         # see comments in cleanup().
@@ -1369,18 +1365,18 @@
         frame.pushvalue(frame.space.wrap(unroller))
         frame.pushvalue(frame.space.w_None)
         frame.pushvalue(frame.space.w_None)
-        return self.handlerposition   # jump to the handler
+        return r_uint(self.handlerposition)   # jump to the handler
 
 
 class WithBlock(FinallyBlock):
 
     _immutable_ = True
 
-    def really_handle(self, frame, unroller):
+    def handle(self, frame, unroller):
         if (frame.space.full_exceptions and
             isinstance(unroller, SApplicationException)):
             unroller.operr.normalize_exception(frame.space)
-        return FinallyBlock.really_handle(self, frame, unroller)
+        return FinallyBlock.handle(self, frame, unroller)
 
 block_classes = {'SETUP_LOOP': LoopBlock,
                  'SETUP_EXCEPT': ExceptBlock,
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
@@ -652,7 +652,11 @@
             arrayvalue.make_len_gt(MODE_UNICODE, op.getdescr(), 
indexvalue.box.getint())
         self.optimize_default(op)
 
-
+    # These are typically removed already by OptRewrite, but it can be
+    # dissabled and unrolling emits some SAME_AS ops to setup the
+    # optimizier state. These needs to always be optimized out.
+    def optimize_SAME_AS(self, op):
+        self.make_equal_to(op.result, self.getvalue(op.getarg(0)))
 
 
 dispatch_opt = make_dispatcher_method(Optimizer, 'optimize_',
diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py 
b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -335,9 +335,13 @@
                                       
             args[short_inputargs[i]] = jmp_to_short_args[i]
         self.short_inliner = Inliner(short_inputargs, jmp_to_short_args)
-        for op in self.short[1:]:
+        i = 1
+        while i < len(self.short):
+            # Note that self.short might be extended during this loop
+            op = self.short[i]
             newop = self.short_inliner.inline_op(op)
             self.optimizer.send_extra_operation(newop)
+            i += 1
 
         # Import boxes produced in the preamble but used in the loop
         newoperations = self.optimizer.get_newoperations()
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
@@ -6,6 +6,7 @@
 import re
 
 from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
+from pypy.interpreter.error import OperationError
 from pypy.module.micronumpy import interp_boxes
 from pypy.module.micronumpy.interp_dtype import get_dtype_cache
 from pypy.module.micronumpy.interp_numarray import (Scalar, BaseArray,
@@ -39,11 +40,11 @@
 THREE_ARG_FUNCTIONS = ['where']
 
 class FakeSpace(object):
-    w_ValueError = None
-    w_TypeError = None
-    w_IndexError = None
-    w_OverflowError = None
-    w_NotImplementedError = None
+    w_ValueError = "ValueError"
+    w_TypeError = "TypeError"
+    w_IndexError = "IndexError"
+    w_OverflowError = "OverflowError"
+    w_NotImplementedError = "NotImplementedError"
     w_None = None
 
     w_bool = "bool"
@@ -126,8 +127,13 @@
             return w_obj.intval
         elif isinstance(w_obj, FloatObject):
             return int(w_obj.floatval)
+        elif isinstance(w_obj, SliceObject):
+            raise OperationError(self.w_TypeError, self.wrap("slice."))
         raise NotImplementedError
 
+    def index(self, w_obj):
+        return self.wrap(self.int_w(w_obj))
+
     def str_w(self, w_obj):
         if isinstance(w_obj, StringObject):
             return w_obj.v
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
@@ -350,12 +350,31 @@
         if shape_len == 1:
             if space.isinstance_w(w_idx, space.w_int):
                 return True
+
+            try:
+                value = space.int_w(space.index(w_idx))
+                return True
+            except OperationError:
+                pass
+
+            try:
+                value = space.int_w(w_idx)
+                return True
+            except OperationError:
+                pass
+
             if space.isinstance_w(w_idx, space.w_slice):
                 return False
         elif (space.isinstance_w(w_idx, space.w_slice) or
               space.isinstance_w(w_idx, space.w_int)):
             return False
-        lgt = space.len_w(w_idx)
+
+        try:
+            lgt = space.len_w(w_idx)
+        except OperationError:
+            raise OperationError(space.w_IndexError,
+                                 space.wrap("index must be either an int or a 
sequence."))
+
         if lgt > shape_len:
             raise OperationError(space.w_IndexError,
                                  space.wrap("invalid index"))
@@ -1030,8 +1049,21 @@
 
     @jit.unroll_safe
     def _index_of_single_item(self, space, w_idx):
-        if space.isinstance_w(w_idx, space.w_int):
-            idx = space.int_w(w_idx)
+        is_valid = False
+        try:
+            idx = space.int_w(space.index(w_idx))
+            is_valid = True
+        except OperationError:
+            pass
+
+        if not is_valid:
+            try:
+                idx = space.int_w(w_idx)
+                is_valid = True
+            except OperationError:
+                pass
+
+        if is_valid:
             if idx < 0:
                 idx = self.shape[0] + idx
             if idx < 0 or idx >= self.shape[0]:
diff --git a/pypy/module/micronumpy/test/test_base.py 
b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -10,6 +10,7 @@
 import sys
 
 class BaseNumpyAppTest(object):
+    @classmethod
     def setup_class(cls):
         if option.runappdirect:
             if '__pypy__' not in sys.builtin_module_names:
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
@@ -8,7 +8,6 @@
 from pypy.module.micronumpy.interp_numarray import W_NDimArray, shape_agreement
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 
-
 class MockDtype(object):
     class itemtype(object):
         @staticmethod
@@ -195,6 +194,36 @@
         assert _to_coords(13, 'F') == [1, 0, 2]
 
 class AppTestNumArray(BaseNumpyAppTest):
+    def w_CustomIndexObject(self, index):
+        class CustomIndexObject(object):
+            def __init__(self, index):
+                self.index = index
+            def __index__(self):
+                return self.index
+
+        return CustomIndexObject(index)
+
+    def w_CustomIndexIntObject(self, index, value):
+        class CustomIndexIntObject(object):
+            def __init__(self, index, value):
+                self.index = index
+                self.value = value
+            def __index__(self):
+                return self.index
+            def __int__(self):
+                return self.value
+
+        return CustomIndexIntObject(index, value)
+
+    def w_CustomIntObject(self, value):
+        class CustomIntObject(object):
+            def __init__(self, value):
+                self.value = value
+            def __index__(self):
+                return self.value
+
+        return CustomIntObject(value)
+
     def test_ndarray(self):
         from _numpypy import ndarray, array, dtype
 
@@ -329,6 +358,28 @@
         assert a[1, 3] == 8
         assert a.T[1, 2] == 11
 
+    def test_getitem_obj_index(self):
+        from _numpypy import arange
+
+        a = arange(10)
+
+        assert a[self.CustomIndexObject(1)] == 1
+
+    def test_getitem_obj_prefer_index_to_int(self):
+        from _numpypy import arange
+
+        a = arange(10)
+
+
+        assert a[self.CustomIndexIntObject(0, 1)] == 0
+
+    def test_getitem_obj_int(self):
+        from _numpypy import arange
+
+        a = arange(10)
+
+        assert a[self.CustomIntObject(1)] == 1
+
     def test_setitem(self):
         from _numpypy import array
         a = array(range(5))
@@ -348,6 +399,48 @@
         for i in xrange(5):
             assert a[i] == i
 
+    def test_setitem_obj_index(self):
+        from _numpypy import arange
+
+        a = arange(10)
+
+        a[self.CustomIndexObject(1)] = 100
+        assert a[1] == 100
+
+    def test_setitem_obj_prefer_index_to_int(self):
+        from _numpypy import arange
+
+        a = arange(10)
+
+        a[self.CustomIndexIntObject(0, 1)] = 100
+        assert a[0] == 100
+
+    def test_setitem_obj_int(self):
+        from _numpypy import arange
+
+        a = arange(10)
+
+        a[self.CustomIntObject(1)] = 100
+
+        assert a[1] == 100
+
+    def test_access_swallow_exception(self):
+        class ErrorIndex(object):
+            def __index__(self):
+                return 1 / 0
+
+        class ErrorInt(object):
+            def __int__(self):
+                return 1 / 0
+
+        # numpy will swallow errors in __int__ and __index__ and
+        # just raise IndexError.
+
+        from _numpypy import arange
+        a = arange(10)
+        raises(IndexError, "a[ErrorIndex()] == 0")
+        raises(IndexError, "a[ErrorInt()] == 0")
+
     def test_setslice_array(self):
         from _numpypy import array
         a = array(range(5))
diff --git a/pypy/module/thread/gil.py b/pypy/module/thread/gil.py
--- a/pypy/module/thread/gil.py
+++ b/pypy/module/thread/gil.py
@@ -5,7 +5,7 @@
 # This module adds a global lock to an object space.
 # If multiple threads try to execute simultaneously in this space,
 # all but one will be blocked.  The other threads get a chance to run
-# from time to time, using the hook yield_thread().
+# from time to time, using the periodic action GILReleaseAction.
 
 from pypy.module.thread import ll_thread as thread
 from pypy.module.thread.error import wrap_thread_error
@@ -51,8 +51,6 @@
             self.gil_ready = False
             self.setup_threads(space)
 
-    def yield_thread(self):
-        do_yield_thread()
 
 class GILReleaseAction(PeriodicAsyncAction):
     """An action called every sys.checkinterval bytecodes.  It releases
diff --git a/pypy/module/thread/test/test_gil.py 
b/pypy/module/thread/test/test_gil.py
--- a/pypy/module/thread/test/test_gil.py
+++ b/pypy/module/thread/test/test_gil.py
@@ -55,7 +55,7 @@
                 assert state.datalen3 == len(state.data)
                 assert state.datalen4 == len(state.data)
                 debug_print(main, i, state.datalen4)
-                state.threadlocals.yield_thread()
+                gil.do_yield_thread()
                 assert i == j
                 j += 1
         def bootstrap():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to