Author: Armin Rigo <[email protected]>
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 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:
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
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -153,6 +153,9 @@
     def __exit__(self, *args):
         self.release()
 
+    def _cleanup_(self):
+        raise Exception("seeing a prebuilt rpython.rlib.rthread.Lock instance")
+
 # ____________________________________________________________
 #
 # Stack size
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to