Author: Manuel Jacob <m...@manueljacob.de>
Branch: py3.5
Changeset: r90782:9ca6b5dc03b0
Date: 2017-03-21 23:56 +0100
http://bitbucket.org/pypy/pypy/changeset/9ca6b5dc03b0/

Log:    hg merge default

diff --git a/lib-python/2.7/weakref.py b/lib-python/2.7/weakref.py
--- a/lib-python/2.7/weakref.py
+++ b/lib-python/2.7/weakref.py
@@ -36,9 +36,9 @@
 except ImportError:
     def _delitem_if_value_is(d, key, value):
         try:
-            if self.data[key] is value:  # fall-back: there is a potential
+            if d[key] is value:  # fall-back: there is a potential
                 #             race condition in multithreaded programs HERE
-                del self.data[key]
+                del d[key]
         except KeyError:
             pass
 
diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -107,22 +107,22 @@
 
     apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
     libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev libgdbm-dev \
-    tk-dev libgc-dev \
+    tk-dev libgc-dev python-cffi \
     liblzma-dev  # For lzma on PyPy3.
 
 On Fedora::
 
     dnf install gcc make libffi-devel pkgconfig zlib-devel bzip2-devel \
     sqlite-devel ncurses-devel expat-devel openssl-devel tk-devel \
-    gdbm-devel \
+    gdbm-devel python-cffi\
     xz-devel  # For lzma on PyPy3.
 
 On SLES11::
 
     zypper install gcc make python-devel pkg-config \
     zlib-devel libopenssl-devel libbz2-devel sqlite3-devel \
-    libexpat-devel libffi-devel python-curses \
-    xz-devel  # For lzma on PyPy3.
+    libexpat-devel libffi-devel python-curses python-cffi \
+    xz-devel # For lzma on PyPy3.
     (XXX plus the SLES11 version of libgdbm-dev and tk-dev)
 
 On Mac OS X, most of these build-time dependencies are installed alongside
diff --git a/pypy/module/_cffi_backend/cffi1_module.py 
b/pypy/module/_cffi_backend/cffi1_module.py
--- a/pypy/module/_cffi_backend/cffi1_module.py
+++ b/pypy/module/_cffi_backend/cffi1_module.py
@@ -48,3 +48,4 @@
     w_modules_dict = space.sys.get('modules')
     space.setitem(w_modules_dict, w_name, module)
     space.setitem(w_modules_dict, space.newtext(name + '.lib'), lib)
+    return module
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1489,10 +1489,6 @@
     copy_header_files(cts, trunk_include, use_micronumpy)
 
 
-def _load_from_cffi(space, name, path, initptr):
-    from pypy.module._cffi_backend import cffi1_module
-    cffi1_module.load_cffi1_module(space, name, path, initptr)
-
 @unwrap_spec(path='fsencode', name='text')
 def load_extension_module(space, path, name):
     # note: this is used both to load CPython-API-style C extension
@@ -1526,11 +1522,11 @@
             pass
         else:
             try:
-                _load_from_cffi(space, name, path, initptr)
+                from pypy.module._cffi_backend import cffi1_module
+                return cffi1_module.load_cffi1_module(space, name, path, 
initptr)
             except:
                 rdynload.dlclose(dll)
                 raise
-            return
     #
     if space.config.objspace.usemodules.cpyext:
         also_look_for = 'PyInit_%s' % (basename,)
@@ -1539,8 +1535,7 @@
         except KeyError:
             pass
         else:
-            load_cpyext_module(space, name, path, dll, initptr)
-            return
+            return load_cpyext_module(space, name, path, dll, initptr)
         if look_for is not None:
             look_for += ' or ' + also_look_for
         else:
@@ -1559,9 +1554,10 @@
 
     space.getbuiltinmodule("cpyext")    # mandatory to init cpyext
     state = space.fromcache(State)
-    if state.find_extension(name, path) is not None:
+    w_mod = state.find_extension(name, path)
+    if w_mod is not None:
         rdynload.dlclose(dll)
-        return
+        return w_mod
     old_context = state.package_context
     state.package_context = name, path
     try:
@@ -1571,6 +1567,7 @@
     finally:
         state.package_context = old_context
     state.fixup_extension(w_mod, name, path)
+    return w_mod
 
 @specialize.ll()
 def generic_cpy_call(space, func, *args):
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -163,6 +163,7 @@
         w_dict = w_mod.getdict(space)
         w_copy = space.call_method(w_dict, 'copy')
         self.extensions[path] = w_copy
+        return w_mod
 
 
 def _rawrefcount_perform(space):
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
@@ -128,7 +128,7 @@
 
 def load_c_extension(space, filename, modulename):
     from pypy.module.cpyext.api import load_extension_module
-    load_extension_module(space, filename, modulename)
+    return load_extension_module(space, filename, modulename)
     # NB. cpyext.api.load_extension_module() can also delegate to _cffi_backend
 
 # __________________________________________________________________
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -52,8 +52,8 @@
     w_modulename = space.getattr(w_spec, space.newtext("name"))
     w_path = space.getattr(w_spec, space.newtext("origin"))
     filename = space.fsencode_w(w_path)
-    importing.load_c_extension(space, filename, space.text_w(w_modulename))
-    return importing.check_sys_modules(space, w_modulename)
+    return importing.load_c_extension(space, filename,
+                                      space.text_w(w_modulename))
 
 def create_builtin(space, w_spec):
     w_name = space.getattr(w_spec, space.newtext("name"))
diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -1007,6 +1007,8 @@
             else:
                 return d.pop(key, w_default)
         elif self._never_equal_to(space.type(w_key)):
+            if w_default is not None:
+                return w_default
             raise KeyError
         else:
             self.switch_to_object_strategy(w_dict)
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py 
b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -227,6 +227,10 @@
         assert len(dd) == 1
         raises(KeyError, dd.pop, 33)
 
+        assert d.pop("abc", None) is None
+        raises(KeyError, d.pop, "abc")
+        assert len(d) == 2
+
     def test_items(self):
         d = {1: 2, 3: 4}
         its = list(d.items())
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -429,7 +429,11 @@
                 gc._trace_callback(callback, arg, p + offset)
             llop.threadlocalref_release(lltype.Void)
         _lambda_trace_tlref = lambda: _trace_tlref
-        TRACETLREF = lltype.GcStruct('TRACETLREF')
+        # WAAAH obscurity: can't use a name that may be non-unique,
+        # otherwise the types compare equal, even though we call
+        # register_custom_trace_hook() to register different trace
+        # functions...
+        TRACETLREF = lltype.GcStruct('TRACETLREF%d' % unique_id)
         _tracetlref_obj = lltype.malloc(TRACETLREF, immortal=True)
 
     @staticmethod
diff --git a/rpython/rlib/rurandom.py b/rpython/rlib/rurandom.py
--- a/rpython/rlib/rurandom.py
+++ b/rpython/rlib/rurandom.py
@@ -99,8 +99,11 @@
         eci = eci.merge(ExternalCompilationInfo(includes=['linux/random.h']))
         class CConfig:
             _compilation_info_ = eci
-            GRND_NONBLOCK = rffi_platform.ConstantInteger('GRND_NONBLOCK')
+            GRND_NONBLOCK = rffi_platform.DefinedConstantInteger(
+                'GRND_NONBLOCK')
         globals().update(rffi_platform.configure(CConfig))
+        if GRND_NONBLOCK is None:
+            GRND_NONBLOCK = 0x0001      # from linux/random.h
 
         # On Linux, use the syscall() function because the GNU libc doesn't
         # expose the Linux getrandom() syscall yet.
diff --git a/rpython/rlib/test/test_rthread.py 
b/rpython/rlib/test/test_rthread.py
--- a/rpython/rlib/test/test_rthread.py
+++ b/rpython/rlib/test/test_rthread.py
@@ -262,15 +262,23 @@
             py.test.skip("no __thread support here")
 
         class FooBar(object):
-            pass
+            def __init__(self, a, b):
+                self.lst = [a, b]
         t = ThreadLocalReference(FooBar)
+        t2 = ThreadLocalReference(FooBar)
 
         def tset():
-            x1 = FooBar()
+            x1 = FooBar(40, 2)
             t.set(x1)
             return weakref.ref(x1)
         tset._dont_inline_ = True
 
+        def t2set():
+            x1 = FooBar(50, 3)
+            t2.set(x1)
+            return weakref.ref(x1)
+        t2set._dont_inline_ = True
+
         class WrFromThread:
             pass
         wr_from_thread = WrFromThread()
@@ -279,22 +287,30 @@
             config = objectmodel.fetch_translated_config()
             assert t.automatic_keepalive(config) is True
             wr = tset()
-            import gc; gc.collect()   # 'x1' should not be collected
-            x2 = t.get()
+            wr2 = t2set()
+            import gc; gc.collect()   # the two 'x1' should not be collected
+            x1 = t.get()
+            assert x1 is not None
+            assert wr() is not None
+            assert wr() is x1
+            assert x1.lst == [40, 2]
+            x2 = t2.get()
             assert x2 is not None
-            assert wr() is not None
-            assert wr() is x2
-            return wr
+            assert wr2() is not None
+            assert wr2() is x2
+            assert x2.lst == [50, 3]
+            return wr, wr2
 
         def thread_entry_point():
-            wr = f()
+            wr, wr2 = f()
             wr_from_thread.wr = wr
+            wr_from_thread.wr2 = wr2
             wr_from_thread.seen = True
 
         def main():
             wr_from_thread.seen = False
             start_new_thread(thread_entry_point, ())
-            wr1 = f()
+            wr1, wr2 = f()
             count = 0
             while True:
                 time.sleep(0.5)
@@ -302,10 +318,15 @@
                     break
                 count += 1
             assert wr_from_thread.seen is True
-            wr2 = wr_from_thread.wr
-            import gc; gc.collect()      # wr2() should be collected here
+            wr_other_1 = wr_from_thread.wr
+            wr_other_2 = wr_from_thread.wr2
+            import gc; gc.collect()      # wr_other_*() should be collected 
here
             assert wr1() is not None     # this thread, still running
-            assert wr2() is None         # other thread, not running any more
+            assert wr2() is not None     # this thread, still running
+            assert wr_other_1() is None  # other thread, not running any more
+            assert wr_other_2() is None  # other thread, not running any more
+            assert wr1().lst == [40, 2]
+            assert wr2().lst == [50, 3]
             return 42
 
         extra_options = {'no__thread': no__thread, 'shared': True}
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to