[pypy-commit] pypy less-stringly-ops: hg merge default

rlamy noreply at buildbot.pypy.org
Sun Sep 22 21:24:58 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r67063:25e171ca825f
Date: 2013-09-22 20:24 +0100
http://bitbucket.org/pypy/pypy/changeset/25e171ca825f/

Log:	hg merge default

diff too long, truncating to 2000 out of 5610 lines

diff --git a/lib-python/2.7/argparse.py b/lib-python/2.7/argparse.py
--- a/lib-python/2.7/argparse.py
+++ b/lib-python/2.7/argparse.py
@@ -1780,7 +1780,19 @@
             # error if this argument is not allowed with other previously
             # seen arguments, assuming that actions that use the default
             # value don't really count as "present"
-            if argument_values is not action.default:
+
+            # XXX PyPy bug-to-bug compatibility: "is" on primitive types
+            # is not consistent in CPython.  We'll assume it is close
+            # enough for ints (which is true only for "small ints"), but
+            # for floats and longs and complexes we'll go for the option
+            # of forcing "is" to say False, like it usually does on
+            # CPython.  A fix is pending on CPython trunk
+            # (http://bugs.python.org/issue18943) but that might change
+            # the details of the semantics and so not be applied to 2.7.
+            # See the line AA below.
+
+            if (argument_values is not action.default or
+                    type(argument_values) in (float, long, complex)):  # AA
                 seen_non_default_actions.add(action)
                 for conflict_action in action_conflicts.get(action, []):
                     if conflict_action in seen_non_default_actions:
diff --git a/lib-python/2.7/uuid.py b/lib-python/2.7/uuid.py
--- a/lib-python/2.7/uuid.py
+++ b/lib-python/2.7/uuid.py
@@ -128,10 +128,10 @@
         """
 
         if hex is not None:
-            if (bytes is not None or bytes_le is not None or fields is not None
-                    or int is not None):
-                raise TypeError('if the hex argument is given, bytes, bytes_le, fields,'
-                                ' and int need to be None')
+            if (bytes is not None or bytes_le is not None or
+                    fields is not None or int is not None):
+                raise TypeError('if the hex argument is given, bytes,'
+                                ' bytes_le, fields,  and int need to be None')
             hex = hex.replace('urn:', '').replace('uuid:', '')
             hex = hex.strip('{}').replace('-', '')
             if len(hex) != 32:
@@ -139,8 +139,8 @@
             int = long(hex, 16)
         elif bytes_le is not None:
             if bytes is not None or fields is not None or int is not None:
-                raise TypeError('if the bytes_le argument is given, bytes, fields,'
-                                ' and int need to be None')
+                raise TypeError('if the bytes_le argument is given, bytes,'
+                                ' fields, and int need to be None')
             if len(bytes_le) != 16:
                 raise ValueError('bytes_le is not a 16-char string')
             bytes = (bytes_le[3] + bytes_le[2] + bytes_le[1] + bytes_le[0] +
@@ -150,15 +150,16 @@
                    struct.unpack('>Q', bytes[8:])[0])
         elif bytes is not None:
             if fields is not None or int is not None:
-                raise TypeError('if the bytes argument is given, fields'
-                                ' and int need to be None')
+                raise TypeError('if the bytes argument is given, fields '
+                                'and int need to be None')
             if len(bytes) != 16:
                 raise ValueError('bytes is not a 16-char string')
             int = (struct.unpack('>Q', bytes[:8])[0] << 64 |
                    struct.unpack('>Q', bytes[8:])[0])
         elif fields is not None:
             if int is not None:
-                raise TypeError('if the fields argument is given, int needs to be None')
+                raise TypeError('if the fields argument is given, int needs'
+                                ' to be None')
             if len(fields) != 6:
                 raise ValueError('fields is not a 6-tuple')
             (time_low, time_mid, time_hi_version,
diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py
--- a/lib_pypy/_curses.py
+++ b/lib_pypy/_curses.py
@@ -1,6 +1,9 @@
 """Reimplementation of the standard extension module '_curses' using cffi."""
 
 import sys
+if sys.platform == 'win32':
+    #This module does not exist in windows
+    raise ImportError('No module named _curses')
 from functools import wraps
 
 from cffi import FFI
diff --git a/lib_pypy/_tkinter/__init__.py b/lib_pypy/_tkinter/__init__.py
--- a/lib_pypy/_tkinter/__init__.py
+++ b/lib_pypy/_tkinter/__init__.py
@@ -22,6 +22,7 @@
 READABLE = tklib.TCL_READABLE
 WRITABLE = tklib.TCL_WRITABLE
 EXCEPTION = tklib.TCL_EXCEPTION
+DONT_WAIT = tklib.TCL_DONT_WAIT
 
 def create(screenName=None, baseName=None, className=None,
            interactive=False, wantobjects=False, wantTk=True,
diff --git a/lib_pypy/_tkinter/app.py b/lib_pypy/_tkinter/app.py
--- a/lib_pypy/_tkinter/app.py
+++ b/lib_pypy/_tkinter/app.py
@@ -4,7 +4,23 @@
 from . import TclError
 from .tclobj import TclObject, FromObj, AsObj, TypeCache
 
+import contextlib
 import sys
+import threading
+import time
+
+
+class _DummyLock(object):
+    "A lock-like object that does not do anything"
+    def acquire(self):
+        pass
+    def release(self):
+        pass
+    def __enter__(self):
+        pass
+    def __exit__(self, *exc):
+        pass
+
 
 def varname_converter(input):
     if isinstance(input, TclObject):
@@ -37,17 +53,18 @@
     def PythonCmd(clientData, interp, argc, argv):
         self = tkffi.from_handle(clientData)
         assert self.app.interp == interp
-        try:
-            args = [tkffi.string(arg) for arg in argv[1:argc]]
-            result = self.func(*args)
-            obj = AsObj(result)
-            tklib.Tcl_SetObjResult(interp, obj)
-        except:
-            self.app.errorInCmd = True
-            self.app.exc_info = sys.exc_info()
-            return tklib.TCL_ERROR
-        else:
-            return tklib.TCL_OK
+        with self.app._tcl_lock_released():
+            try:
+                args = [tkffi.string(arg) for arg in argv[1:argc]]
+                result = self.func(*args)
+                obj = AsObj(result)
+                tklib.Tcl_SetObjResult(interp, obj)
+            except:
+                self.app.errorInCmd = True
+                self.app.exc_info = sys.exc_info()
+                return tklib.TCL_ERROR
+            else:
+                return tklib.TCL_OK
 
     @tkffi.callback("Tcl_CmdDeleteProc")
     def PythonCmdDelete(clientData):
@@ -58,6 +75,8 @@
 
 
 class TkApp(object):
+    _busywaitinterval = 0.02  # 20ms.
+
     def __new__(cls, screenName, baseName, className,
                 interactive, wantobjects, wantTk, sync, use):
         if not wantobjects:
@@ -73,6 +92,12 @@
         self.quitMainLoop = False
         self.errorInCmd = False
 
+        if not self.threaded:
+            # TCL is not thread-safe, calls needs to be serialized.
+            self._tcl_lock = threading.Lock()
+        else:
+            self._tcl_lock = _DummyLock()
+
         self._typeCache = TypeCache()
         self._commands = {}
 
@@ -133,6 +158,13 @@
         if self.threaded and self.thread_id != tklib.Tcl_GetCurrentThread():
             raise RuntimeError("Calling Tcl from different appartment")
 
+    @contextlib.contextmanager
+    def _tcl_lock_released(self):
+        "Context manager to temporarily release the tcl lock."
+        self._tcl_lock.release()
+        yield
+        self._tcl_lock.acquire()
+
     def loadtk(self):
         # We want to guard against calling Tk_Init() multiple times
         err = tklib.Tcl_Eval(self.interp, "info exists     tk_version")
@@ -159,22 +191,25 @@
         flags=tklib.TCL_LEAVE_ERR_MSG
         if global_only:
             flags |= tklib.TCL_GLOBAL_ONLY
-        res = tklib.Tcl_GetVar2Ex(self.interp, name1, name2, flags)
-        if not res:
-            self.raiseTclError()
-        assert self._wantobjects
-        return FromObj(self, res)
+        with self._tcl_lock:
+            res = tklib.Tcl_GetVar2Ex(self.interp, name1, name2, flags)
+            if not res:
+                self.raiseTclError()
+            assert self._wantobjects
+            return FromObj(self, res)
 
     def _setvar(self, name1, value, global_only=False):
         name1 = varname_converter(name1)
+        # XXX Acquire tcl lock???
         newval = AsObj(value)
         flags=tklib.TCL_LEAVE_ERR_MSG
         if global_only:
             flags |= tklib.TCL_GLOBAL_ONLY
-        res = tklib.Tcl_SetVar2Ex(self.interp, name1, tkffi.NULL,
-                                  newval, flags)
-        if not res:
-            self.raiseTclError()
+        with self._tcl_lock:
+            res = tklib.Tcl_SetVar2Ex(self.interp, name1, tkffi.NULL,
+                                      newval, flags)
+            if not res:
+                self.raiseTclError()
 
     def _unsetvar(self, name1, name2=None, global_only=False):
         name1 = varname_converter(name1)
@@ -183,9 +218,10 @@
         flags=tklib.TCL_LEAVE_ERR_MSG
         if global_only:
             flags |= tklib.TCL_GLOBAL_ONLY
-        res = tklib.Tcl_UnsetVar2(self.interp, name1, name2, flags)
-        if res == tklib.TCL_ERROR:
-            self.raiseTclError()
+        with self._tcl_lock:
+            res = tklib.Tcl_UnsetVar2(self.interp, name1, name2, flags)
+            if res == tklib.TCL_ERROR:
+                self.raiseTclError()
 
     def getvar(self, name1, name2=None):
         return self._var_invoke(self._getvar, name1, name2)
@@ -219,9 +255,10 @@
         if self.threaded and self.thread_id != tklib.Tcl_GetCurrentThread():
             raise NotImplementedError("Call from another thread")
 
-        res = tklib.Tcl_CreateCommand(
-            self.interp, cmdName, _CommandData.PythonCmd,
-            clientData, _CommandData.PythonCmdDelete)
+        with self._tcl_lock:
+            res = tklib.Tcl_CreateCommand(
+                self.interp, cmdName, _CommandData.PythonCmd,
+                clientData, _CommandData.PythonCmdDelete)
         if not res:
             raise TclError("can't create Tcl command")
 
@@ -229,7 +266,8 @@
         if self.threaded and self.thread_id != tklib.Tcl_GetCurrentThread():
             raise NotImplementedError("Call from another thread")
 
-        res = tklib.Tcl_DeleteCommand(self.interp, cmdName)
+        with self._tcl_lock:
+            res = tklib.Tcl_DeleteCommand(self.interp, cmdName)
         if res == -1:
             raise TclError("can't delete Tcl command")
 
@@ -256,11 +294,12 @@
                 tklib.Tcl_IncrRefCount(obj)
                 objects[i] = obj
 
-            res = tklib.Tcl_EvalObjv(self.interp, argc, objects, flags)
-            if res == tklib.TCL_ERROR:
-                self.raiseTclError()
-            else:
-                result = self._callResult()
+            with self._tcl_lock:
+                res = tklib.Tcl_EvalObjv(self.interp, argc, objects, flags)
+                if res == tklib.TCL_ERROR:
+                    self.raiseTclError()
+                else:
+                    result = self._callResult()
         finally:
             for obj in objects:
                 if obj:
@@ -280,17 +319,19 @@
 
     def eval(self, script):
         self._check_tcl_appartment()
-        res = tklib.Tcl_Eval(self.interp, script)
-        if res == tklib.TCL_ERROR:
-            self.raiseTclError()
-        return tkffi.string(tklib.Tcl_GetStringResult(self.interp))
+        with self._tcl_lock:
+            res = tklib.Tcl_Eval(self.interp, script)
+            if res == tklib.TCL_ERROR:
+                self.raiseTclError()
+            return tkffi.string(tklib.Tcl_GetStringResult(self.interp))
 
     def evalfile(self, filename):
         self._check_tcl_appartment()
-        res = tklib.Tcl_EvalFile(self.interp, filename)
-        if res == tklib.TCL_ERROR:
-            self.raiseTclError()
-        return tkffi.string(tklib.Tcl_GetStringResult(self.interp))
+        with self._tcl_lock:
+            res = tklib.Tcl_EvalFile(self.interp, filename)
+            if res == tklib.TCL_ERROR:
+                self.raiseTclError()
+            return tkffi.string(tklib.Tcl_GetStringResult(self.interp))
 
     def split(self, arg):
         if isinstance(arg, tuple):
@@ -375,7 +416,10 @@
             if self.threaded:
                 result = tklib.Tcl_DoOneEvent(0)
             else:
-                raise NotImplementedError("TCL configured without threads")
+                with self._tcl_lock:
+                    result = tklib.Tcl_DoOneEvent(tklib.TCL_DONT_WAIT)
+                if result == 0:
+                    time.sleep(self._busywaitinterval)
 
             if result < 0:
                 break
diff --git a/lib_pypy/_tkinter/tklib.py b/lib_pypy/_tkinter/tklib.py
--- a/lib_pypy/_tkinter/tklib.py
+++ b/lib_pypy/_tkinter/tklib.py
@@ -1,6 +1,7 @@
 # C bindings with libtcl and libtk.
 
 from cffi import FFI
+import sys
 
 tkffi = FFI()
 
@@ -18,6 +19,8 @@
 #define TCL_EVAL_DIRECT ...
 #define TCL_EVAL_GLOBAL ...
 
+#define TCL_DONT_WAIT ...
+
 typedef unsigned short Tcl_UniChar;
 typedef ... Tcl_Interp;
 typedef ...* Tcl_ThreadId;
@@ -102,6 +105,17 @@
 int Tk_GetNumMainWindows();
 """)
 
+# XXX find a better way to detect paths
+# XXX pick up CPPFLAGS and LDFLAGS and add to these paths?
+if sys.platform.startswith("openbsd"):
+    incdirs = ['/usr/local/include/tcl8.5', '/usr/local/include/tk8.5', '/usr/X11R6/include']
+    linklibs = ['tk85', 'tcl85']
+    libdirs = ['/usr/local/lib', '/usr/X11R6/lib']
+else:
+    incdirs=['/usr/include/tcl']
+    linklibs=['tcl', 'tk']
+    libdirs = []
+
 tklib = tkffi.verify("""
 #include <tcl.h>
 #include <tk.h>
@@ -109,6 +123,7 @@
 char *get_tk_version() { return TK_VERSION; }
 char *get_tcl_version() { return TCL_VERSION; }
 """,
-include_dirs=['/usr/include/tcl'],
-libraries=['tcl', 'tk'],
+include_dirs=incdirs,
+libraries=linklibs,
+library_dirs = libdirs
 )
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,5 +4,5 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "0.7"
-__version_info__ = (0, 7)
+__version__ = "0.7.2"
+__version_info__ = (0, 7, 2)
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -54,7 +54,8 @@
             # _cffi_backend.so compiled.
             import _cffi_backend as backend
             from . import __version__
-            assert backend.__version__ == __version__
+            assert (backend.__version__ == __version__ or
+                    backend.__version__ == __version__[:3])
             # (If you insist you can also try to pass the option
             # 'backend=backend_ctypes.CTypesBackend()', but don't
             # rely on it!  It's probably not going to work well.)
diff --git a/lib_pypy/cffi/commontypes.py b/lib_pypy/cffi/commontypes.py
--- a/lib_pypy/cffi/commontypes.py
+++ b/lib_pypy/cffi/commontypes.py
@@ -30,7 +30,9 @@
         elif result in model.PrimitiveType.ALL_PRIMITIVE_TYPES:
             result = model.PrimitiveType(result)
         else:
-            assert commontype != result
+            if commontype == result:
+                raise api.FFIError("Unsupported type: %r.  Please file a bug "
+                                   "if you think it should be." % (commontype,))
             result = resolve_common_type(result)   # recursively
         assert isinstance(result, model.BaseTypeByIdentity)
         _CACHE[commontype] = result
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -290,13 +290,26 @@
                 # assume a primitive type.  get it from .names, but reduce
                 # synonyms to a single chosen combination
                 names = list(type.names)
-                if names == ['signed'] or names == ['unsigned']:
-                    names.append('int')
-                if names[0] == 'signed' and names != ['signed', 'char']:
-                    names.pop(0)
-                if (len(names) > 1 and names[-1] == 'int'
-                        and names != ['unsigned', 'int']):
-                    names.pop()
+                if names != ['signed', 'char']:    # keep this unmodified
+                    prefixes = {}
+                    while names:
+                        name = names[0]
+                        if name in ('short', 'long', 'signed', 'unsigned'):
+                            prefixes[name] = prefixes.get(name, 0) + 1
+                            del names[0]
+                        else:
+                            break
+                    # ignore the 'signed' prefix below, and reorder the others
+                    newnames = []
+                    for prefix in ('unsigned', 'short', 'long'):
+                        for i in range(prefixes.get(prefix, 0)):
+                            newnames.append(prefix)
+                    if not names:
+                        names = ['int']    # implicitly
+                    if names == ['int']:   # but kill it if 'short' or 'long'
+                        if 'short' in prefixes or 'long' in prefixes:
+                            names = []
+                    names = newnames + names
                 ident = ' '.join(names)
                 if ident == 'void':
                     return model.void_type
@@ -500,8 +513,8 @@
                 self._partial_length = True
                 return None
         #
-        raise api.FFIError("unsupported non-constant or "
-                           "not immediately constant expression")
+        raise api.FFIError("unsupported expression: expected a "
+                           "simple numeric constant")
 
     def _build_enum_type(self, explicit_name, decls):
         if decls is not None:
diff --git a/lib_pypy/cffi/vengine_gen.py b/lib_pypy/cffi/vengine_gen.py
--- a/lib_pypy/cffi/vengine_gen.py
+++ b/lib_pypy/cffi/vengine_gen.py
@@ -61,7 +61,9 @@
     def load_library(self):
         # import it with the CFFI backend
         backend = self.ffi._backend
-        module = backend.load_library(self.verifier.modulefilename)
+        # needs to make a path that contains '/', on Posix
+        filename = os.path.join(os.curdir, self.verifier.modulefilename)
+        module = backend.load_library(filename)
         #
         # call loading_gen_struct() to get the struct layout inferred by
         # the C compiler
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -356,7 +356,7 @@
   attempt to point newcomers at existing alternatives, which are more
   mainstream and where they will get help from many people.*
 
-  *If anybody seriously wants to promote RPython anyway, he is welcome
+  *If anybody seriously wants to promote RPython anyway, they are welcome
   to: we won't actively resist such a plan.  There are a lot of things
   that could be done to make RPython a better Java-ish language for
   example, starting with supporting non-GIL-based multithreading, but we
@@ -396,8 +396,8 @@
 patch the generated machine code.
 
 So the position of the core PyPy developers is that if anyone wants to
-make an N+1'th attempt with LLVM, he is welcome, and he will receive a
-bit of help on the IRC channel, but he is left with the burden of proof
+make an N+1'th attempt with LLVM, they are welcome, and will be happy to
+provide help in the IRC channel, but they are left with the burden of proof
 that it works.
 
 ----------------------
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
@@ -80,6 +80,9 @@
 .. branch: reflex-support
 .. branch: numpypy-inplace-op
 .. branch: rewritten-loop-logging
+.. branch: no-release-gil
+.. branch: safe-win-mmap
+.. branch: boolean-indexing-cleanup
 
 .. branch: nobold-backtrace
 Work on improving UnionError messages and stack trace displays.
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -77,12 +77,12 @@
         raise NotImplementedError("only for interp-level user subclasses "
                                   "from typedef.py")
 
-    def getname(self, space, default='?'):
+    def getname(self, space):
         try:
             return space.str_w(space.getattr(self, space.wrap('__name__')))
         except OperationError, e:
             if e.match(space, space.w_TypeError) or e.match(space, space.w_AttributeError):
-                return default
+                return '?'
             raise
 
     def getaddrstring(self, space):
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -482,17 +482,16 @@
                 space.abstract_isinstance_w(w_firstarg, self.w_class)):
             pass  # ok
         else:
-            clsdescr = self.w_class.getname(space, "")
-            if clsdescr:
+            clsdescr = self.w_class.getname(space)
+            if clsdescr and clsdescr != '?':
                 clsdescr += " instance"
             else:
                 clsdescr = "instance"
             if w_firstarg is None:
                 instdescr = "nothing"
             else:
-                instname = space.abstract_getclass(w_firstarg).getname(space,
-                                                                       "")
-                if instname:
+                instname = space.abstract_getclass(w_firstarg).getname(space)
+                if instname and instname != '?':
                     instdescr = instname + " instance"
                 else:
                     instdescr = "instance"
diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -128,7 +128,7 @@
 
     def type(self, obj):
         class Type:
-            def getname(self, space, default='?'):
+            def getname(self, space):
                 return type(obj).__name__
         return Type()
 
diff --git a/pypy/module/__pypy__/interp_time.py b/pypy/module/__pypy__/interp_time.py
--- a/pypy/module/__pypy__/interp_time.py
+++ b/pypy/module/__pypy__/interp_time.py
@@ -48,11 +48,11 @@
 
     c_clock_gettime = rffi.llexternal("clock_gettime",
         [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
-        compilation_info=CConfig._compilation_info_, threadsafe=False
+        compilation_info=CConfig._compilation_info_, releasegil=False
     )
     c_clock_getres = rffi.llexternal("clock_getres",
         [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
-        compilation_info=CConfig._compilation_info_, threadsafe=False
+        compilation_info=CConfig._compilation_info_, releasegil=False
     )
 
     @unwrap_spec(clk_id="c_int")
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -54,6 +54,13 @@
         if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK:
             raise OperationError(space.w_SystemError,
                 space.wrap("libffi failed to build this callback"))
+        #
+        # We must setup the GIL here, in case the callback is invoked in
+        # some other non-Pythonic thread.  This is the same as cffi on
+        # CPython.
+        if space.config.translation.thread:
+            from pypy.module.thread.os_thread import setup_threads
+            setup_threads(space)
 
     def get_closure(self):
         return rffi.cast(clibffi.FFI_CLOSUREP, self._cdata)
diff --git a/pypy/module/_minimal_curses/fficurses.py b/pypy/module/_minimal_curses/fficurses.py
--- a/pypy/module/_minimal_curses/fficurses.py
+++ b/pypy/module/_minimal_curses/fficurses.py
@@ -26,6 +26,9 @@
 def try_ldflags():
     yield ExternalCompilationInfo(libraries=['curses'])
     yield ExternalCompilationInfo(libraries=['curses', 'tinfo'])
+    yield ExternalCompilationInfo(libraries=['ncurses'])
+    yield ExternalCompilationInfo(libraries=['ncurses'],
+                                  library_dirs=['/usr/lib64'])
 
 def try_tools():
     try:
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -28,7 +28,7 @@
         'CreateSemaphoreA', [rffi.VOIDP, rffi.LONG, rffi.LONG, rwin32.LPCSTR],
         rwin32.HANDLE)
     _CloseHandle = rwin32.winexternal('CloseHandle', [rwin32.HANDLE],
-        rwin32.BOOL, threadsafe=False)
+        rwin32.BOOL, releasegil=False)
     _ReleaseSemaphore = rwin32.winexternal(
         'ReleaseSemaphore', [rwin32.HANDLE, rffi.LONG, rffi.LONGP],
         rwin32.BOOL)
@@ -82,8 +82,8 @@
     _sem_open = external('sem_open',
                          [rffi.CCHARP, rffi.INT, rffi.INT, rffi.UINT],
                          SEM_T)
-    # tread sem_close as not threadsafe for now to be able to use the __del__
-    _sem_close = external('sem_close', [SEM_T], rffi.INT, threadsafe=False)
+    # sem_close is releasegil=False to be able to use it in the __del__
+    _sem_close = external('sem_close', [SEM_T], rffi.INT, releasegil=False)
     _sem_unlink = external('sem_unlink', [rffi.CCHARP], rffi.INT)
     _sem_wait = external('sem_wait', [SEM_T], rffi.INT)
     _sem_trywait = external('sem_trywait', [SEM_T], rffi.INT)
diff --git a/pypy/module/_pypyjson/test/test__pypyjson.py b/pypy/module/_pypyjson/test/test__pypyjson.py
--- a/pypy/module/_pypyjson/test/test__pypyjson.py
+++ b/pypy/module/_pypyjson/test/test__pypyjson.py
@@ -1,5 +1,5 @@
 # -*- encoding: utf-8 -*-
-import py
+import py, sys
 from pypy.module._pypyjson.interp_decoder import JSONDecoder
 
 def test_skip_whitespace():
@@ -16,6 +16,9 @@
 class AppTest(object):
     spaceconfig = {"objspace.usemodules._pypyjson": True}
 
+    def setup_class(cls):
+        cls.w_run_on_16bit = cls.space.wrap(sys.maxunicode == 65535)
+
     def test_raise_on_unicode(self):
         import _pypyjson
         raises(TypeError, _pypyjson.loads, u"42")
@@ -178,11 +181,11 @@
         raises(ValueError, "_pypyjson.loads('[1: 2]')")
         raises(ValueError, "_pypyjson.loads('[1, 2')")
         raises(ValueError, """_pypyjson.loads('["extra comma",]')""")
-        
+
     def test_unicode_surrogate_pair(self):
+        if self.run_on_16bit:
+            skip("XXX fix me or mark definitely skipped")
         import _pypyjson
         expected = u'z\U0001d120x'
         res = _pypyjson.loads('"z\\ud834\\udd20x"')
         assert res == expected
-
-
diff --git a/pypy/module/_weakref/interp__weakref.py b/pypy/module/_weakref/interp__weakref.py
--- a/pypy/module/_weakref/interp__weakref.py
+++ b/pypy/module/_weakref/interp__weakref.py
@@ -175,8 +175,8 @@
             state = '; dead'
         else:
             typename = space.type(w_obj).getname(space)
-            objname = w_obj.getname(space, '')
-            if objname:
+            objname = w_obj.getname(space)
+            if objname and objname != '?':
                 state = "; to '%s' (%s)" % (typename, objname)
             else:
                 state = "; to '%s'" % (typename,)
diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -144,12 +144,12 @@
 BZ2_bzCompressInit = external('BZ2_bzCompressInit', [bz_stream, rffi.INT,
                               rffi.INT, rffi.INT], rffi.INT)
 BZ2_bzCompressEnd = external('BZ2_bzCompressEnd', [bz_stream], rffi.INT,
-                             threadsafe=False)
+                             releasegil=False)
 BZ2_bzCompress = external('BZ2_bzCompress', [bz_stream, rffi.INT], rffi.INT)
 BZ2_bzDecompressInit = external('BZ2_bzDecompressInit', [bz_stream, rffi.INT,
                                                          rffi.INT], rffi.INT)
 BZ2_bzDecompressEnd = external('BZ2_bzDecompressEnd', [bz_stream], rffi.INT,
-                               threadsafe=False)
+                               releasegil=False)
 BZ2_bzDecompress = external('BZ2_bzDecompress', [bz_stream], rffi.INT)
 
 def _catch_bz2_error(space, bzerror):
diff --git a/pypy/module/cppyy/capi/builtin_capi.py b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -27,7 +27,7 @@
 _c_num_scopes = rffi.llexternal(
     "cppyy_num_scopes",
     [C_SCOPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_num_scopes(space, cppscope):
     return _c_num_scopes(cppscope.handle)
@@ -41,28 +41,28 @@
 _c_resolve_name = rffi.llexternal(
     "cppyy_resolve_name",
     [rffi.CCHARP], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_resolve_name(space, name):
     return charp2str_free(space, _c_resolve_name(name))
 _c_get_scope_opaque = rffi.llexternal(
     "cppyy_get_scope",
     [rffi.CCHARP], C_SCOPE,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_get_scope_opaque(space, name):
     return _c_get_scope_opaque(name)
 _c_get_template = rffi.llexternal(
     "cppyy_get_template",
     [rffi.CCHARP], C_TYPE,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_get_template(space, name):
     return _c_get_template(name)
 _c_actual_class = rffi.llexternal(
     "cppyy_actual_class",
     [C_TYPE, C_OBJECT], C_TYPE,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_actual_class(space, cppclass, cppobj):
     return _c_actual_class(cppclass.handle, cppobj)
@@ -71,21 +71,21 @@
 _c_allocate = rffi.llexternal(
     "cppyy_allocate",
     [C_TYPE], C_OBJECT,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci)
 def c_allocate(space, cppclass):
     return _c_allocate(cppclass.handle)
 _c_deallocate = rffi.llexternal(
     "cppyy_deallocate",
     [C_TYPE, C_OBJECT], lltype.Void,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci)
 def c_deallocate(space, cppclass, cppobject):
     _c_deallocate(cppclass.handle, cppobject)
 _c_destruct = rffi.llexternal(
     "cppyy_destruct",
     [C_TYPE, C_OBJECT], lltype.Void,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_destruct(space, cppclass, cppobject):
     _c_destruct(cppclass.handle, cppobject)
@@ -94,63 +94,63 @@
 _c_call_v = rffi.llexternal(
     "cppyy_call_v",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], lltype.Void,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_v(space, cppmethod, cppobject, nargs, args):
     _c_call_v(cppmethod, cppobject, nargs, args)
 _c_call_b = rffi.llexternal(
     "cppyy_call_b",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.UCHAR,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_b(space, cppmethod, cppobject, nargs, args):
     return _c_call_b(cppmethod, cppobject, nargs, args)
 _c_call_c = rffi.llexternal(
     "cppyy_call_c",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.CHAR,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_c(space, cppmethod, cppobject, nargs, args):
     return _c_call_c(cppmethod, cppobject, nargs, args)
 _c_call_h = rffi.llexternal(
     "cppyy_call_h",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.SHORT,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_h(space, cppmethod, cppobject, nargs, args):
     return _c_call_h(cppmethod, cppobject, nargs, args)
 _c_call_i = rffi.llexternal(
     "cppyy_call_i",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.INT,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_i(space, cppmethod, cppobject, nargs, args):
     return _c_call_i(cppmethod, cppobject, nargs, args)
 _c_call_l = rffi.llexternal(
     "cppyy_call_l",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONG,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_l(space, cppmethod, cppobject, nargs, args):
     return _c_call_l(cppmethod, cppobject, nargs, args)
 _c_call_ll = rffi.llexternal(
     "cppyy_call_ll",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONGLONG,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_ll(space, cppmethod, cppobject, nargs, args):
     return _c_call_ll(cppmethod, cppobject, nargs, args)
 _c_call_f = rffi.llexternal(
     "cppyy_call_f",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.FLOAT,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_f(space, cppmethod, cppobject, nargs, args):
     return _c_call_f(cppmethod, cppobject, nargs, args)
 _c_call_d = rffi.llexternal(
     "cppyy_call_d",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.DOUBLE,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_d(space, cppmethod, cppobject, nargs, args):
     return _c_call_d(cppmethod, cppobject, nargs, args)
@@ -158,14 +158,14 @@
 _c_call_r = rffi.llexternal(
     "cppyy_call_r",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.VOIDP,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_r(space, cppmethod, cppobject, nargs, args):
     return _c_call_r(cppmethod, cppobject, nargs, args)
 _c_call_s = rffi.llexternal(
     "cppyy_call_s",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.CCHARP,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_s(space, cppmethod, cppobject, nargs, args):
     return _c_call_s(cppmethod, cppobject, nargs, args)
@@ -173,14 +173,14 @@
 _c_constructor = rffi.llexternal(
     "cppyy_constructor",
     [C_METHOD, C_TYPE, rffi.INT, rffi.VOIDP], C_OBJECT,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_constructor(space, cppmethod, cppobject, nargs, args):
     return _c_constructor(cppmethod, cppobject, nargs, args)
 _c_call_o = rffi.llexternal(
     "cppyy_call_o",
     [C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP, C_TYPE], rffi.LONG,
-    threadsafe=ts_call,
+    releasegil=ts_call,
     compilation_info=backend.eci)
 def c_call_o(space, method, cppobj, nargs, args, cppclass):
     return _c_call_o(method, cppobj, nargs, args, cppclass.handle)
@@ -188,7 +188,7 @@
 _c_get_methptr_getter = rffi.llexternal(
     "cppyy_get_methptr_getter",
     [C_SCOPE, C_INDEX], C_METHPTRGETTER_PTR,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci,
     elidable_function=True)
 def c_get_methptr_getter(space, cppscope, index):
@@ -198,21 +198,21 @@
 _c_allocate_function_args = rffi.llexternal(
     "cppyy_allocate_function_args",
     [rffi.SIZE_T], rffi.VOIDP,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci)
 def c_allocate_function_args(space, size):
     return _c_allocate_function_args(size)
 _c_deallocate_function_args = rffi.llexternal(
     "cppyy_deallocate_function_args",
     [rffi.VOIDP], lltype.Void,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci)
 def c_deallocate_function_args(space, args):
     _c_deallocate_function_args(args)
 _c_function_arg_sizeof = rffi.llexternal(
     "cppyy_function_arg_sizeof",
     [], rffi.SIZE_T,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci,
     elidable_function=True)
 def c_function_arg_sizeof(space):
@@ -220,7 +220,7 @@
 _c_function_arg_typeoffset = rffi.llexternal(
     "cppyy_function_arg_typeoffset",
     [], rffi.SIZE_T,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci,
     elidable_function=True)
 def c_function_arg_typeoffset(space):
@@ -230,14 +230,14 @@
 _c_is_namespace = rffi.llexternal(
     "cppyy_is_namespace",
     [C_SCOPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_is_namespace(space, scope):
     return _c_is_namespace(scope)
 _c_is_enum = rffi.llexternal(
     "cppyy_is_enum",
     [rffi.CCHARP], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_is_enum(space, name):
     return _c_is_enum(name)
@@ -246,42 +246,42 @@
 _c_final_name = rffi.llexternal(
     "cppyy_final_name",
     [C_TYPE], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_final_name(space, cpptype):
     return charp2str_free(space, _c_final_name(cpptype))
 _c_scoped_final_name = rffi.llexternal(
     "cppyy_scoped_final_name",
     [C_TYPE], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_scoped_final_name(space, cpptype):
     return charp2str_free(space, _c_scoped_final_name(cpptype))
 _c_has_complex_hierarchy = rffi.llexternal(
     "cppyy_has_complex_hierarchy",
     [C_TYPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_has_complex_hierarchy(space, cpptype):
     return _c_has_complex_hierarchy(cpptype)
 _c_num_bases = rffi.llexternal(
     "cppyy_num_bases",
     [C_TYPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_num_bases(space, cppclass):
     return _c_num_bases(cppclass.handle)
 _c_base_name = rffi.llexternal(
     "cppyy_base_name",
     [C_TYPE, rffi.INT], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_base_name(space, cppclass, base_index):
     return charp2str_free(space, _c_base_name(cppclass.handle, base_index))
 _c_is_subtype = rffi.llexternal(
     "cppyy_is_subtype",
     [C_TYPE, C_TYPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci,
     elidable_function=True)
 @jit.elidable_promote('2')
@@ -293,7 +293,7 @@
 _c_base_offset = rffi.llexternal(
     "cppyy_base_offset",
     [C_TYPE, C_TYPE, C_OBJECT, rffi.INT], rffi.SIZE_T,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci,
     elidable_function=True)
 @jit.elidable_promote('1,2,4')
@@ -308,21 +308,21 @@
 _c_num_methods = rffi.llexternal(
     "cppyy_num_methods",
     [C_SCOPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_num_methods(space, cppscope):
     return _c_num_methods(cppscope.handle)
 _c_method_index_at = rffi.llexternal(
     "cppyy_method_index_at",
     [C_SCOPE, rffi.INT], C_INDEX,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_index_at(space, cppscope, imethod):
     return _c_method_index_at(cppscope.handle, imethod)
 _c_method_indices_from_name = rffi.llexternal(
     "cppyy_method_indices_from_name",
     [C_SCOPE, rffi.CCHARP], C_INDEX_ARRAY,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_indices_from_name(space, cppscope, name):
     indices = _c_method_indices_from_name(cppscope.handle, name)
@@ -341,49 +341,49 @@
 _c_method_name = rffi.llexternal(
     "cppyy_method_name",
     [C_SCOPE, C_INDEX], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_name(space, cppscope, index):
     return charp2str_free(space, _c_method_name(cppscope.handle, index))
 _c_method_result_type = rffi.llexternal(
     "cppyy_method_result_type",
     [C_SCOPE, C_INDEX], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_result_type(space, cppscope, index):
     return charp2str_free(space, _c_method_result_type(cppscope.handle, index))
 _c_method_num_args = rffi.llexternal(
     "cppyy_method_num_args",
     [C_SCOPE, C_INDEX], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_num_args(space, cppscope, index):
     return _c_method_num_args(cppscope.handle, index)
 _c_method_req_args = rffi.llexternal(
     "cppyy_method_req_args",
     [C_SCOPE, C_INDEX], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_req_args(space, cppscope, index):
     return _c_method_req_args(cppscope.handle, index)
 _c_method_arg_type = rffi.llexternal(
     "cppyy_method_arg_type",
     [C_SCOPE, C_INDEX, rffi.INT], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_arg_type(space, cppscope, index, arg_index):
     return charp2str_free(space, _c_method_arg_type(cppscope.handle, index, arg_index))
 _c_method_arg_default = rffi.llexternal(
     "cppyy_method_arg_default",
     [C_SCOPE, C_INDEX, rffi.INT], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_arg_default(space, cppscope, index, arg_index):
     return charp2str_free(space, _c_method_arg_default(cppscope.handle, index, arg_index))
 _c_method_signature = rffi.llexternal(
     "cppyy_method_signature",
     [C_SCOPE, C_INDEX], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_signature(space, cppscope, index):
     return charp2str_free(space, _c_method_signature(cppscope.handle, index))
@@ -391,19 +391,19 @@
 _c_method_is_template = rffi.llexternal(
     "cppyy_method_is_template",
     [C_SCOPE, C_INDEX], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_method_is_template(space, cppscope, index):
     return _c_method_is_template(cppscope.handle, index)
 _c_method_num_template_args = rffi.llexternal(
     "cppyy_method_num_template_args",
     [C_SCOPE, C_INDEX], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 _c_method_template_arg_name = rffi.llexternal(
     "cppyy_method_template_arg_name",
     [C_SCOPE, C_INDEX, C_INDEX], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_template_args(space, cppscope, index):
     nargs = _c_method_num_template_args(cppscope.handle, index)
@@ -415,14 +415,14 @@
 _c_get_method = rffi.llexternal(
     "cppyy_get_method",
     [C_SCOPE, C_INDEX], C_METHOD,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_get_method(space, cppscope, index):
     return _c_get_method(cppscope.handle, index)
 _c_get_global_operator = rffi.llexternal(
     "cppyy_get_global_operator",
     [C_SCOPE, C_SCOPE, C_SCOPE, rffi.CCHARP], WLAVC_INDEX,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_get_global_operator(space, nss, lc, rc, op):
     if nss is not None:
@@ -433,14 +433,14 @@
 _c_is_constructor = rffi.llexternal(
     "cppyy_is_constructor",
     [C_TYPE, C_INDEX], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_is_constructor(space, cppclass, index):
     return _c_is_constructor(cppclass.handle, index)
 _c_is_staticmethod = rffi.llexternal(
     "cppyy_is_staticmethod",
     [C_TYPE, C_INDEX], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_is_staticmethod(space, cppclass, index):
     return _c_is_staticmethod(cppclass.handle, index)
@@ -449,28 +449,28 @@
 _c_num_datamembers = rffi.llexternal(
     "cppyy_num_datamembers",
     [C_SCOPE], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_num_datamembers(space, cppscope):
     return _c_num_datamembers(cppscope.handle)
 _c_datamember_name = rffi.llexternal(
     "cppyy_datamember_name",
     [C_SCOPE, rffi.INT], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_datamember_name(space, cppscope, datamember_index):
     return charp2str_free(space, _c_datamember_name(cppscope.handle, datamember_index))
 _c_datamember_type = rffi.llexternal(
     "cppyy_datamember_type",
     [C_SCOPE, rffi.INT], rffi.CCHARP,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_datamember_type(space, cppscope, datamember_index):
     return charp2str_free(space, _c_datamember_type(cppscope.handle, datamember_index))
 _c_datamember_offset = rffi.llexternal(
     "cppyy_datamember_offset",
     [C_SCOPE, rffi.INT], rffi.SIZE_T,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_datamember_offset(space, cppscope, datamember_index):
     return _c_datamember_offset(cppscope.handle, datamember_index)
@@ -478,7 +478,7 @@
 _c_datamember_index = rffi.llexternal(
     "cppyy_datamember_index",
     [C_SCOPE, rffi.CCHARP], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_datamember_index(space, cppscope, name):
     return _c_datamember_index(cppscope.handle, name)
@@ -487,14 +487,14 @@
 _c_is_publicdata = rffi.llexternal(
     "cppyy_is_publicdata",
     [C_SCOPE, rffi.INT], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_is_publicdata(space, cppscope, datamember_index):
     return _c_is_publicdata(cppscope.handle, datamember_index)
 _c_is_staticdata = rffi.llexternal(
     "cppyy_is_staticdata",
     [C_SCOPE, rffi.INT], rffi.INT,
-    threadsafe=ts_reflect,
+    releasegil=ts_reflect,
     compilation_info=backend.eci)
 def c_is_staticdata(space, cppscope, datamember_index):
     return _c_is_staticdata(cppscope.handle, datamember_index)
@@ -503,21 +503,21 @@
 _c_strtoll = rffi.llexternal(
     "cppyy_strtoll",
     [rffi.CCHARP], rffi.LONGLONG,
-    threadsafe=ts_helper,
+    releasegil=ts_helper,
     compilation_info=backend.eci)
 def c_strtoll(space, svalue):
     return _c_strtoll(svalue)
 _c_strtoull = rffi.llexternal(
     "cppyy_strtoull",
     [rffi.CCHARP], rffi.ULONGLONG,
-    threadsafe=ts_helper,
+    releasegil=ts_helper,
     compilation_info=backend.eci)
 def c_strtoull(space, svalue):
     return _c_strtoull(svalue)
 c_free = rffi.llexternal(
     "cppyy_free",
     [rffi.VOIDP], lltype.Void,
-    threadsafe=ts_memory,
+    releasegil=ts_memory,
     compilation_info=backend.eci)
 
 def charp2str_free(space, charp):
@@ -529,7 +529,7 @@
 _c_charp2stdstring = rffi.llexternal(
     "cppyy_charp2stdstring",
     [rffi.CCHARP], C_OBJECT,
-    threadsafe=ts_helper,
+    releasegil=ts_helper,
     compilation_info=backend.eci)
 def c_charp2stdstring(space, svalue):
     charp = rffi.str2charp(svalue)
@@ -539,14 +539,14 @@
 _c_stdstring2stdstring = rffi.llexternal(
     "cppyy_stdstring2stdstring",
     [C_OBJECT], C_OBJECT,
-    threadsafe=ts_helper,
+    releasegil=ts_helper,
     compilation_info=backend.eci)
 def c_stdstring2stdstring(space, cppobject):
     return _c_stdstring2stdstring(cppobject)
 _c_assign2stdstring = rffi.llexternal(
     "cppyy_assign2stdstring",
     [C_OBJECT, rffi.CCHARP], lltype.Void,
-    threadsafe=ts_helper,
+    releasegil=ts_helper,
     compilation_info=backend.eci)
 def c_assign2stdstring(space, cppobject, svalue):
     charp = rffi.str2charp(svalue)
@@ -555,7 +555,7 @@
 _c_free_stdstring = rffi.llexternal(
     "cppyy_free_stdstring",
     [C_OBJECT], lltype.Void,
-    threadsafe=ts_helper,
+    releasegil=ts_helper,
     compilation_info=backend.eci)
 def c_free_stdstring(space, cppobject):
     _c_free_stdstring(cppobject)
diff --git a/pypy/module/cppyy/capi/cint_capi.py b/pypy/module/cppyy/capi/cint_capi.py
--- a/pypy/module/cppyy/capi/cint_capi.py
+++ b/pypy/module/cppyy/capi/cint_capi.py
@@ -60,7 +60,7 @@
 _c_load_dictionary = rffi.llexternal(
     "cppyy_load_dictionary",
     [rffi.CCHARP], rdynload.DLLHANDLE,
-    threadsafe=False,
+    releasegil=False,
     compilation_info=eci)
 
 def c_load_dictionary(name):
@@ -84,7 +84,7 @@
 _ttree_Branch = rffi.llexternal(
     "cppyy_ttree_Branch",
     [rffi.VOIDP, rffi.CCHARP, rffi.CCHARP, rffi.VOIDP, rffi.INT, rffi.INT], rffi.LONG,
-    threadsafe=False,
+    releasegil=False,
     compilation_info=eci)
 
 @unwrap_spec(args_w='args_w')
@@ -158,7 +158,7 @@
 c_ttree_GetEntry = rffi.llexternal(
     "cppyy_ttree_GetEntry",
     [rffi.VOIDP, rffi.LONGLONG], rffi.LONGLONG,
-    threadsafe=False,
+    releasegil=False,
     compilation_info=eci)
 
 @unwrap_spec(args_w='args_w')
diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -241,7 +241,6 @@
     it is necessary to serialize calls to this function."""
     if not space.config.translation.thread:
         raise NoThreads
-    rthread.gc_thread_prepare()
     # PyThreadState_Get will allocate a new execution context,
     # we need to protect gc and other globals with the GIL.
     rffi.aroundstate.after()
diff --git a/pypy/module/crypt/interp_crypt.py b/pypy/module/crypt/interp_crypt.py
--- a/pypy/module/crypt/interp_crypt.py
+++ b/pypy/module/crypt/interp_crypt.py
@@ -8,7 +8,7 @@
 else:
     eci = ExternalCompilationInfo(libraries=['crypt'])
 c_crypt = rffi.llexternal('crypt', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP,
-                          compilation_info=eci, threadsafe=False)
+                          compilation_info=eci, releasegil=False)
 
 @unwrap_spec(word=str, salt=str)
 def crypt(space, word, salt):
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -316,7 +316,8 @@
         self.storage = storage
 
     def create_iter(self, shape=None, backward_broadcast=False):
-        if shape is None or shape == self.get_shape():
+        if shape is None or \
+           support.product(shape) <= support.product(self.get_shape()):
             return iter.ConcreteArrayIterator(self)
         r = calculate_broadcast_strides(self.get_strides(),
                                         self.get_backstrides(),
@@ -385,7 +386,8 @@
         loop.fill(self, box.convert_to(self.dtype))
 
     def create_iter(self, shape=None, backward_broadcast=False):
-        if shape is not None and shape != self.get_shape():
+        if shape is not None and shape != self.get_shape() and \
+           support.product(shape) > support.product(self.get_shape()):
             r = calculate_broadcast_strides(self.get_strides(),
                                             self.get_backstrides(),
                                             self.get_shape(), shape,
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -88,28 +88,22 @@
         w_res = W_NDimArray.from_shape(space, res_shape, self.get_dtype(), w_instance=self)
         return loop.getitem_filter(w_res, self, arr)
 
-    def setitem_filter(self, space, idx, value):
-        from pypy.module.micronumpy.interp_boxes import Box
-        val = value
+    def setitem_filter(self, space, idx, val):
         if len(idx.get_shape()) > 1 and idx.get_shape() != self.get_shape():
             raise OperationError(space.w_ValueError,
                                  space.wrap("boolean index array should have 1 dimension"))
         if idx.get_size() > self.get_size():
             raise OperationError(space.w_ValueError,
                                  space.wrap("index out of range for array"))
-        idx_iter = idx.create_iter(self.get_shape())
-        size = loop.count_all_true_iter(idx_iter, self.get_shape(), idx.get_dtype())
-        if len(val.get_shape()) > 0 and val.get_shape()[0] > 1 and size > val.get_shape()[0]:
+        idx_iter = idx.create_iter()
+        size = loop.count_all_true_iter(idx_iter, idx.get_shape(), idx.get_dtype())
+        if size > val.get_size() and val.get_size() > 1:
             raise OperationError(space.w_ValueError, space.wrap("NumPy boolean array indexing assignment "
                                                                 "cannot assign %d input values to "
-                                                                "the %d output values where the mask is true" % (val.get_shape()[0],size)))
-        if val.get_shape() == [1]:
-            box = val.descr_getitem(space, space.wrap(0))
-            assert isinstance(box, Box)
-            val = W_NDimArray(scalar.Scalar(val.get_dtype(), box))
-        elif val.get_shape() == [0]:
+                                                                "the %d output values where the mask is true" % (val.get_size(), size)))
+        if val.get_shape() == [0]:
             val.implementation.dtype = self.implementation.dtype
-        loop.setitem_filter(self, idx, val)
+        loop.setitem_filter(self, idx, val, size)
 
     def _prepare_array_index(self, space, w_index):
         if isinstance(w_index, W_NDimArray):
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -372,11 +372,14 @@
                                                 'index_dtype'],
                                       reds = 'auto')
 
-def setitem_filter(arr, index, value):
+def setitem_filter(arr, index, value, size):
     arr_iter = arr.create_iter()
-    index_iter = index.create_iter(arr.get_shape())
-    value_iter = value.create_iter()
     shapelen = len(arr.get_shape())
+    if shapelen > 1 and len(index.get_shape()) < 2:
+        index_iter = index.create_iter(arr.get_shape(), backward_broadcast=True)
+    else:
+        index_iter = index.create_iter()
+    value_iter = value.create_iter([size])
     index_dtype = index.get_dtype()
     arr_dtype = arr.get_dtype()
     while not index_iter.done():
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -776,7 +776,13 @@
 
     def test_unicode_boxes(self):
         from numpypy import unicode_
-        assert isinstance(unicode_(3), unicode)
+        try:
+            u = unicode_(3)
+        except NotImplementedError, e:
+            if e.message.find('not supported yet') >= 0:
+                skip('unicode box not implemented')
+        else:
+            assert isinstance(u, unicode)
 
     def test_character_dtype(self):
         from numpypy import array, character
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
@@ -2355,11 +2355,16 @@
     def test_array_indexing_bool_specialcases(self):
         from numpypy import arange, array
         a = arange(6)
-        try:
-            a[a < 3] = [1, 2]
-            assert False, "Should not work"
-        except ValueError:
-            pass
+        exc = raises(ValueError,'a[a < 3] = [1, 2]')
+        assert exc.value[0].find('cannot assign') >= 0
+        b = arange(4).reshape(2, 2) + 10
+        a[a < 4] = b
+        assert (a == [10, 11, 12, 13, 4, 5]).all()
+        b += 10
+        c = arange(8).reshape(2, 2, 2)
+        a[a > 9] = c[:, :, 1]
+        assert (c[:, :, 1] == [[1, 3], [5, 7]]).all()
+        assert (a == [1, 3, 5, 7, 4, 5]).all()
         a = arange(6)
         a[a > 3] = array([15])
         assert (a == [0, 1, 2, 3, 15, 15]).all()
diff --git a/pypy/module/operator/__init__.py b/pypy/module/operator/__init__.py
--- a/pypy/module/operator/__init__.py
+++ b/pypy/module/operator/__init__.py
@@ -50,6 +50,7 @@
         '__concat__' : 'concat',
         '__contains__' : 'contains',
         'sequenceIncludes' : 'contains',
+        '__index__' : 'index',
         '__delitem__' : 'delitem',
         '__div__' : 'div',
         '__eq__' : 'eq',
diff --git a/pypy/module/operator/test/test_operator.py b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -190,3 +190,9 @@
         assert methodcaller("method", 4)(x) == (4, 3)
         assert methodcaller("method", 4, 5)(x) == (4, 5)
         assert methodcaller("method", 4, arg2=42)(x) == (4, 42)
+
+    def test_index(self):
+        import operator
+        assert operator.index(42) == 42
+        assert operator.__index__(42) == 42
+        raises(TypeError, operator.index, "abc")
diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -356,7 +356,7 @@
 XML_ParserCreateNS = expat_external(
     'XML_ParserCreateNS', [rffi.CCHARP, rffi.CHAR], XML_Parser)
 XML_ParserFree = expat_external(
-    'XML_ParserFree', [XML_Parser], lltype.Void, threadsafe=False)
+    'XML_ParserFree', [XML_Parser], lltype.Void, releasegil=False)
 XML_SetUserData = expat_external(
     'XML_SetUserData', [XML_Parser, rffi.VOIDP], lltype.Void)
 def XML_GetUserData(parser):
diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py
--- a/pypy/module/pypyjit/policy.py
+++ b/pypy/module/pypyjit/policy.py
@@ -109,7 +109,8 @@
                        'posix', '_socket', '_sre', '_lsprof', '_weakref',
                        '__pypy__', 'cStringIO', '_collections', 'struct',
                        'mmap', 'marshal', '_codecs', 'rctime', 'cppyy',
-                       '_cffi_backend', 'pyexpat', '_continuation', '_io']:
+                       '_cffi_backend', 'pyexpat', '_continuation', '_io',
+                       'thread']:
             if modname == 'pypyjit' and 'interp_resop' in rest:
                 return False
             return True
diff --git a/pypy/module/pypyjit/test/test_policy.py b/pypy/module/pypyjit/test/test_policy.py
--- a/pypy/module/pypyjit/test/test_policy.py
+++ b/pypy/module/pypyjit/test/test_policy.py
@@ -45,6 +45,10 @@
     from pypy.module._io.interp_bytesio import W_BytesIO
     assert pypypolicy.look_inside_function(W_BytesIO.seek_w.im_func)
 
+def test_thread():
+    from pypy.module.thread.os_lock import Lock
+    assert pypypolicy.look_inside_function(Lock.descr_lock_acquire.im_func)
+
 def test_pypy_module():
     from pypy.module._collections.interp_deque import W_Deque
     from pypy.module._random.interp_random import W_Random
diff --git a/pypy/module/pypyjit/test_pypy_c/test_thread.py b/pypy/module/pypyjit/test_pypy_c/test_thread.py
--- a/pypy/module/pypyjit/test_pypy_c/test_thread.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_thread.py
@@ -1,3 +1,4 @@
+import py
 from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC
 
 
@@ -48,3 +49,48 @@
             i58 = arraylen_gc(p43, descr=...)
             jump(..., descr=...)
         """)
+
+    def test_lock_acquire_release(self):
+        py.test.skip("test too precise, please fix me")
+        def main(n):
+            import threading
+            lock = threading.Lock()
+            while n > 0:
+                with lock:
+                    n -= 1
+        log = self.run(main, [500])
+        assert log.result == main(500)
+        loop, = log.loops_by_filename(self.filepath)
+        assert loop.match("""
+        i58 = int_gt(i43, 0)
+        guard_true(i58, descr=<Guard0x10483adb8>)
+        p59 = getfield_gc(p15, descr=<FieldP pypy.module.thread.os_lock.Lock.inst_lock 8>)
+        i60 = getfield_gc(p59, descr=<FieldU rpython.rlib.rthread.Lock.inst__lock 8>)
+        p61 = force_token()
+        setfield_gc(p0, p61, descr=<FieldP pypy.interpreter.pyframe.PyFrame.vable_token 24>)
+        i62 = call_release_gil(4312440032, i60, 1, descr=<Calli 4 ii EF=6>)
+        guard_not_forced(descr=<Guard0x103f3cca0>)
+        guard_no_exception(descr=<Guard0x10483ad40>)
+        i63 = int_is_true(i62)
+        guard_true(i63, descr=<Guard0x10483acc8>)
+        i64 = int_sub(i43, 1)
+        guard_not_invalidated(descr=<Guard0x10483ac50>)
+        p66 = getfield_gc(p15, descr=<FieldP pypy.module.thread.os_lock.Lock.inst_lock 8>)
+        i67 = getfield_gc(p66, descr=<FieldU rpython.rlib.rthread.Lock.inst__lock 8>)
+        p68 = force_token()
+        setfield_gc(p0, p68, descr=<FieldP pypy.interpreter.pyframe.PyFrame.vable_token 24>)
+        i69 = call_release_gil(4312440032, i67, 0, descr=<Calli 4 ii EF=6>)
+        guard_not_forced(descr=<Guard0x103f3cc20>)
+        guard_no_exception(descr=<Guard0x10483aae8>)
+        i70 = int_is_true(i69)
+        guard_false(i70, descr=<Guard0x10483aa70>)
+        i71 = getfield_gc(p66, descr=<FieldU rpython.rlib.rthread.Lock.inst__lock 8>)
+        p72 = force_token()
+        setfield_gc(p0, p72, descr=<FieldP pypy.interpreter.pyframe.PyFrame.vable_token 24>)
+        call_release_gil(4312441056, i71, descr=<Callv 0 i EF=6>)
+        guard_not_forced(descr=<Guard0x103f3cba0>)
+        guard_no_exception(descr=<Guard0x10483a9f8>)
+        guard_not_invalidated(descr=<Guard0x10483a980>)
+        --TICK--
+        jump(..., descr=TargetToken(4361239720))
+        """)
diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -151,7 +151,7 @@
     return rffi.llexternal(name, args, result,
                            compilation_info=eci,
                            calling_conv=calling_conv,
-                           threadsafe=False)
+                           releasegil=False)
 
 if _POSIX:
     cConfig.timeval.__name__ = "_timeval"
diff --git a/pypy/module/test_lib_pypy/cffi_tests/backend_tests.py b/pypy/module/test_lib_pypy/cffi_tests/backend_tests.py
--- a/pypy/module/test_lib_pypy/cffi_tests/backend_tests.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/backend_tests.py
@@ -199,6 +199,9 @@
         typerepr = self.TypeRepr
         ffi = FFI(backend=self.Backend())
         ffi.cdef("struct foo { short a, b, c; };")
+        p = ffi.cast("short unsigned int", 0)
+        assert repr(p) == "<cdata 'unsigned short' 0>"
+        assert repr(ffi.typeof(p)) == typerepr % "unsigned short"
         p = ffi.cast("unsigned short int", 0)
         assert repr(p) == "<cdata 'unsigned short' 0>"
         assert repr(ffi.typeof(p)) == typerepr % "unsigned short"
@@ -535,13 +538,13 @@
         for c_type, expected_size in [
             ('char', 1),
             ('unsigned int', 4),
-            ('char *', SIZE_OF_LONG),
+            ('char *', SIZE_OF_PTR),
             ('int[5]', 20),
             ('struct foo', 12),
             ('union foo', 4),
             ]:
             size = ffi.sizeof(c_type)
-            assert size == expected_size
+            assert size == expected_size, (size, expected_size, ctype)
 
     def test_sizeof_cdata(self):
         ffi = FFI(backend=self.Backend())
diff --git a/pypy/module/test_lib_pypy/cffi_tests/callback_in_thread.py b/pypy/module/test_lib_pypy/cffi_tests/callback_in_thread.py
--- a/pypy/module/test_lib_pypy/cffi_tests/callback_in_thread.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/callback_in_thread.py
@@ -27,6 +27,7 @@
     seen = []
     @ffi.callback('int(*)(int,int)')
     def mycallback(x, y):
+        time.sleep(0.022)
         seen.append((x, y))
         return 0
     lib.threaded_ballback_test(mycallback)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_function.py b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
@@ -382,3 +382,26 @@
         sin100 = my_decorator(m.sin)
         x = sin100(1.23)
         assert x == math.sin(1.23) + 100
+
+    def test_free_callback_cycle(self):
+        if self.Backend is CTypesBackend:
+            py.test.skip("seems to fail with the ctypes backend on windows")
+        import weakref
+        def make_callback(data):
+            container = [data]
+            callback = ffi.callback('int()', lambda: len(container))
+            container.append(callback)
+            # Ref cycle: callback -> lambda (closure) -> container -> callback
+            return callback
+
+        class Data(object):
+            pass
+        ffi = FFI(backend=self.Backend())
+        data = Data()
+        callback = make_callback(data)
+        wr = weakref.ref(data)
+        del callback, data
+        for i in range(3):
+            if wr() is not None:
+                import gc; gc.collect()
+        assert wr() is None    # 'data' does not leak
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_version.py b/pypy/module/test_lib_pypy/cffi_tests/test_version.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_version.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_version.py
@@ -8,6 +8,8 @@
 
 BACKEND_VERSIONS = {
     '0.4.2': '0.4',     # did not change
+    '0.7.1': '0.7',     # did not change
+    '0.7.2': '0.7',     # did not change
     }
 
 def test_version():
@@ -22,7 +24,7 @@
     content = open(p).read()
     #
     v = cffi.__version__
-    assert ("version = '%s'\n" % v) in content
+    assert ("version = '%s'\n" % BACKEND_VERSIONS.get(v, v)) in content
     assert ("release = '%s'\n" % v) in content
 
 def test_doc_version_file():
@@ -45,4 +47,5 @@
     v = cffi.__version__
     p = os.path.join(parent, 'c', 'test_c.py')
     content = open(p).read()
-    assert ('assert __version__ == "%s"' % v) in content
+    assert (('assert __version__ == "%s"' % BACKEND_VERSIONS.get(v, v))
+            in content)
diff --git a/pypy/module/test_lib_pypy/test_curses.py b/pypy/module/test_lib_pypy/test_curses.py
--- a/pypy/module/test_lib_pypy/test_curses.py
+++ b/pypy/module/test_lib_pypy/test_curses.py
@@ -1,4 +1,8 @@
 import pytest
+import sys
+if sys.platform == 'win32':
+    #This module does not exist in windows
+    pytest.skip('no curses on windows')
 
 # Check that lib_pypy.cffi finds the correct version of _cffi_backend.
 # Otherwise, the test is skipped.  It should never be skipped when run
diff --git a/pypy/module/test_lib_pypy/test_resource.py b/pypy/module/test_lib_pypy/test_resource.py
--- a/pypy/module/test_lib_pypy/test_resource.py
+++ b/pypy/module/test_lib_pypy/test_resource.py
@@ -3,6 +3,9 @@
 from lib_pypy.ctypes_config_cache import rebuild
 from pypy.module.test_lib_pypy.support import import_lib_pypy
 
+import os
+if os.name != 'posix':
+    skip('resource.h only available on unix')
 
 class AppTestResource:
 
diff --git a/pypy/module/thread/os_thread.py b/pypy/module/thread/os_thread.py
--- a/pypy/module/thread/os_thread.py
+++ b/pypy/module/thread/os_thread.py
@@ -182,7 +182,6 @@
     bootstrapper.acquire(space, w_callable, args)
     try:
         try:
-            rthread.gc_thread_prepare()     # (this has no effect any more)
             ident = rthread.start_new_thread(bootstrapper.bootstrap, ())
         except Exception:
             bootstrapper.release()     # normally called by the new thread
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
@@ -72,7 +72,6 @@
             state.datalen4 = 0
             state.threadlocals = gil.GILThreadLocals()
             state.threadlocals.setup_threads(space)
-            thread.gc_thread_prepare()
             subident = thread.start_new_thread(bootstrap, ())
             mainident = thread.get_ident()
             runme(True)
diff --git a/pypy/module/thread/test/test_thread.py b/pypy/module/thread/test/test_thread.py
--- a/pypy/module/thread/test/test_thread.py
+++ b/pypy/module/thread/test/test_thread.py
@@ -187,9 +187,12 @@
             skip("this OS supports too many threads to check (> 1000)")
         lock = thread.allocate_lock()
         lock.acquire()
+        count = [0]
         def f():
+            count[0] += 1
             lock.acquire()
             lock.release()
+            count[0] -= 1
         try:
             try:
                 for i in range(1000):
@@ -197,11 +200,15 @@
             finally:
                 lock.release()
                 # wait a bit to allow most threads to finish now
-                self.busywait(2.0)
+                while count[0] > 10:
+                    print count[0]     # <- releases the GIL
+                print "ok."
         except (thread.error, MemoryError):
             pass
         else:
             raise Exception("could unexpectedly start 1000 threads")
+        # safety: check that we can start a new thread here
+        thread.start_new_thread(lambda: None, ())
 
     def test_stack_size(self):
         import thread
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -597,8 +597,8 @@
         if num1 != num2:
             lt = num1      # if obj1 is a number, it is Lower Than obj2
         else:
-            name1 = w_typ1.getname(space, "")
-            name2 = w_typ2.getname(space, "")
+            name1 = w_typ1.getname(space)
+            name2 = w_typ2.getname(space)
             if name1 != name2:
                 lt = name1 < name2
             else:
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -494,6 +494,12 @@
         else:
             return w_self.name
 
+    def getname(w_self, space):
+        name = w_self.name
+        if name is None:
+            name = '?'
+        return name
+
     def add_subclass(w_self, w_subclass):
         space = w_self.space
         if not space.config.translation.rweakref:
diff --git a/rpython/jit/backend/arm/assembler.py b/rpython/jit/backend/arm/assembler.py
--- a/rpython/jit/backend/arm/assembler.py
+++ b/rpython/jit/backend/arm/assembler.py
@@ -29,6 +29,7 @@
 from rpython.rtyper.annlowlevel import llhelper, cast_instance_to_gcref
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.jit.backend.arm import callbuilder
+from rpython.rtyper.lltypesystem.lloperation import llop
 
 class AssemblerARM(ResOpAssembler):
 
@@ -1488,7 +1489,9 @@
 
 
 def not_implemented(msg):
-    os.write(2, '[ARM/asm] %s\n' % msg)
+    msg = '[ARM/asm] %s\n' % msg
+    if we_are_translated():
+        llop.debug_print(lltype.Void, msg)
     raise NotImplementedError(msg)
 
 
diff --git a/rpython/jit/backend/arm/runner.py b/rpython/jit/backend/arm/runner.py
--- a/rpython/jit/backend/arm/runner.py
+++ b/rpython/jit/backend/arm/runner.py
@@ -56,13 +56,13 @@
     def finish_once(self):
         self.assembler.finish_once()
 
-    def compile_loop(self, logger, inputargs, operations, looptoken,
-                                                    log=True, name=''):
+    def compile_loop(self, inputargs, operations, looptoken,
+                     log=True, name='', logger=None):
         return self.assembler.assemble_loop(logger, name, inputargs, operations,
                                             looptoken, log=log)
 
-    def compile_bridge(self, logger, faildescr, inputargs, operations,
-                                       original_loop_token, log=True):
+    def compile_bridge(self, faildescr, inputargs, operations,
+                       original_loop_token, log=True, logger=None):
         clt = original_loop_token.compiled_loop_token
         clt.compiling_a_bridge()
         return self.assembler.assemble_bridge(logger, faildescr, inputargs,
diff --git a/rpython/jit/backend/arm/test/test_generated.py b/rpython/jit/backend/arm/test/test_generated.py
--- a/rpython/jit/backend/arm/test/test_generated.py
+++ b/rpython/jit/backend/arm/test/test_generated.py
@@ -40,7 +40,7 @@
         looptoken = JitCellToken()
         operations[2].setfailargs([v12, v8, v3, v2, v1, v11])
         operations[3].setfailargs([v9, v6, v10, v2, v8, v5, v1, v4])
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [-12 , -26 , -19 , 7 , -5 , -24 , -37 , 62 , 9 , 12]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_int_value(deadframe, 0) == 0
@@ -92,7 +92,7 @@
         operations[9].setfailargs([v15, v7, v10, v18, v4, v17, v1])
         operations[-1].setfailargs([v7, v1, v2])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [16 , 5 , 5 , 16 , 46 , 6 , 63 , 39 , 78 , 0]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_int_value(deadframe, 0) == 105
@@ -136,7 +136,7 @@
         operations[-1].setfailargs([v5, v2, v1, v10, v3, v8, v4, v6])
 
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [-5 , 24 , 46 , -15 , 13 , -8 , 0 , -6 , 6 , 6]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 2
@@ -179,7 +179,7 @@
         operations[5].setfailargs([])
         operations[-1].setfailargs([v8, v2, v6, v5, v7, v1, v10])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [19 , -3 , -58 , -7 , 12 , 22 , -54 , -29 , -19 , -64]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_int_value(deadframe, 0) == -29
@@ -223,7 +223,7 @@
         looptoken = JitCellToken()
         operations[5].setfailargs([])
         operations[-1].setfailargs([v1, v4, v10, v8, v7, v3])
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [1073741824 , 95 , -16 , 5 , 92 , 12 , 32 , 17 , 37 , -63]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_int_value(deadframe, 0) == 1073741824
@@ -280,7 +280,7 @@
         operations[9].setfailargs([v10, v13])
         operations[-1].setfailargs([v8, v10, v6, v3, v2, v9])
         args = [32 , 41 , -9 , 12 , -18 , 46 , 15 , 17 , 10 , 12]
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 3
         assert cpu.get_int_value(deadframe, 0) == 12
@@ -328,7 +328,7 @@
         operations[8].setfailargs([v5, v9])
         operations[-1].setfailargs([v4, v10, v6, v5, v9, v7])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [-8 , 0 , 62 , 35 , 16 , 9 , 30 , 581610154 , -1 , 738197503]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 2
@@ -378,7 +378,7 @@
         operations[-2].setfailargs([v9, v4, v10, v11, v14])
         operations[-1].setfailargs([v10, v8, v1, v6, v4])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [-39 , -18 , 1588243114 , -9 , -4 , 1252698794 , 0 , 715827882 , -15 , 536870912]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 1
@@ -433,7 +433,7 @@
         operations[9].setfailargs([v5, v7, v12, v14, v2, v13, v8])
         operations[-1].setfailargs([v1, v2, v9])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [0 , -2 , 24 , 1 , -4 , 13 , -95 , 33 , 2 , -44]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 3
@@ -475,7 +475,7 @@
         operations[2].setfailargs([v10, v3, v6, v11, v9, v2])
         operations[-1].setfailargs([v8, v2, v10, v6, v7, v9, v5, v4])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [3 , -5 , 1431655765 , 47 , 12 , 1789569706 , 15 , 939524096 , 16 , -43]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 1
@@ -524,7 +524,7 @@
         operations[-1].setfailargs([v2, v3, v5, v7, v10, v8, v9])
         operations[4].setfailargs([v14])
         looptoken = JitCellToken()
-        cpu.compile_loop(None, inputargs, operations, looptoken)
+        cpu.compile_loop(inputargs, operations, looptoken)
         args = [14 , -20 , 18 , -2058005163 , 6 , 1 , -16 , 11 , 0 , 19]
         deadframe = cpu.execute_token(looptoken, *args)
         assert cpu.get_latest_descr(deadframe).identifier == 1
diff --git a/rpython/jit/backend/arm/test/test_regalloc2.py b/rpython/jit/backend/arm/test/test_regalloc2.py
--- a/rpython/jit/backend/arm/test/test_regalloc2.py
+++ b/rpython/jit/backend/arm/test/test_regalloc2.py
@@ -24,7 +24,7 @@
     cpu = CPU(None, None)
     cpu.setup_once()
     looptoken = JitCellToken()
-    cpu.compile_loop(None, inputargs, operations, looptoken)
+    cpu.compile_loop(inputargs, operations, looptoken)
     deadframe = cpu.execute_token(looptoken, 9)
     assert cpu.get_int_value(deadframe, 0) == (9 >> 3)
     assert cpu.get_int_value(deadframe, 1) == (~18)
@@ -48,7 +48,7 @@
     cpu = CPU(None, None)
     cpu.setup_once()
     looptoken = JitCellToken()
-    cpu.compile_loop(None, inputargs, operations, looptoken)
+    cpu.compile_loop(inputargs, operations, looptoken)
     deadframe = cpu.execute_token(looptoken, -10)
     assert cpu.get_int_value(deadframe, 0) == 0
     assert cpu.get_int_value(deadframe, 1) == -1000
@@ -145,7 +145,7 @@
     cpu = CPU(None, None)
     cpu.setup_once()
     looptoken = JitCellToken()
-    cpu.compile_loop(None, inputargs, operations, looptoken)
+    cpu.compile_loop(inputargs, operations, looptoken)
     args = [-13 , 10 , 10 , 8 , -8 , -16 , -18 , 46 , -12 , 26]
     deadframe = cpu.execute_token(looptoken, *args)
     assert cpu.get_int_value(deadframe, 0) == 0
@@ -252,7 +252,7 @@
     cpu = CPU(None, None)
     cpu.setup_once()
     looptoken = JitCellToken()
-    cpu.compile_loop(None, inputargs, operations, looptoken)
+    cpu.compile_loop(inputargs, operations, looptoken)
     args = [17 , -20 , -6 , 6 , 1 , 13 , 13 , 9 , 49 , 8]
     deadframe = cpu.execute_token(looptoken, *args)
     assert cpu.get_int_value(deadframe, 0) == 0
diff --git a/rpython/jit/backend/arm/test/test_runner.py b/rpython/jit/backend/arm/test/test_runner.py
--- a/rpython/jit/backend/arm/test/test_runner.py
+++ b/rpython/jit/backend/arm/test/test_runner.py
@@ -75,7 +75,7 @@
             ResOperation(rop.FINISH, [inp[1]], None, descr=BasicFinalDescr(1)),
             ]
         operations[-2].setfailargs(out)
-        cpu.compile_loop(None, inp, operations, looptoken)
+        cpu.compile_loop(inp, operations, looptoken)
         args = [i for i in range(1, 15)]
         deadframe = self.cpu.execute_token(looptoken, *args)
         output = [self.cpu.get_int_value(deadframe, i - 1) for i in range(1, 15)]
@@ -117,9 +117,9 @@
         i1 = int_sub(i0, 1)
         finish(i1)
         ''')
-        self.cpu.compile_loop(None, loop2.inputargs, loop2.operations, lt2)
-        self.cpu.compile_loop(None, loop3.inputargs, loop3.operations, lt3)
-        self.cpu.compile_loop(None, loop1.inputargs, loop1.operations, lt1)
+        self.cpu.compile_loop(loop2.inputargs, loop2.operations, lt2)
+        self.cpu.compile_loop(loop3.inputargs, loop3.operations, lt3)
+        self.cpu.compile_loop(loop1.inputargs, loop1.operations, lt1)
         df = self.cpu.execute_token(lt1, 10)
         assert self.cpu.get_int_value(df, 0) == 7
 
@@ -214,7 +214,7 @@
             ops = "".join(ops)
             loop = parse(ops)
             looptoken = JitCellToken()
-            self.cpu.compile_loop(None, loop.inputargs, loop.operations, looptoken)
+            self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
             ARGS = [lltype.Signed] * numargs
             RES = lltype.Signed
             args = [i+1 for i in range(numargs)]
@@ -246,7 +246,7 @@
         try:
             self.cpu.assembler.set_debug(True)
             looptoken = JitCellToken()
-            self.cpu.compile_loop(None, ops.inputargs, ops.operations, looptoken)
+            self.cpu.compile_loop(ops.inputargs, ops.operations, looptoken)
             self.cpu.execute_token(looptoken, 0)
             # check debugging info
             struct = self.cpu.assembler.loop_run_counters[0]
@@ -280,7 +280,7 @@
         faildescr = BasicFailDescr(2)
         loop = parse(ops, self.cpu, namespace=locals())
         looptoken = JitCellToken()


More information about the pypy-commit mailing list