[pypy-commit] pypy py3k: merge default

pjenvey noreply at buildbot.pypy.org
Sat Oct 25 21:32:11 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r74239:8d5158ea78d5
Date: 2014-10-25 12:31 -0700
http://bitbucket.org/pypy/pypy/changeset/8d5158ea78d5/

Log:	merge default

diff --git a/pypy/config/test/test_pypyoption.py b/pypy/config/test/test_pypyoption.py
--- a/pypy/config/test/test_pypyoption.py
+++ b/pypy/config/test/test_pypyoption.py
@@ -64,7 +64,7 @@
     def check_file_exists(fn):
         assert configdocdir.join(fn).check()
 
-    from pypy.doc.config.confrest import all_optiondescrs
+    from pypy.doc.config.generate import all_optiondescrs
     configdocdir = thisdir.dirpath().dirpath().join("doc", "config")
     for descr in all_optiondescrs:
         prefix = descr._name
diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -119,6 +119,9 @@
 
     pypy rpython/bin/rpython --opt=2 pypy/goal/targetpypystandalone.py
 
+(You can use ``python`` instead of ``pypy`` here, which will take longer
+but works too.)
+
 If everything works correctly this will create an executable ``pypy-c`` in the
 current directory. The executable behaves mostly like a normal Python
 interpreter (see :doc:`cpython_differences`).
diff --git a/pypy/module/bz2/test/support.py b/pypy/module/bz2/test/support.py
--- a/pypy/module/bz2/test/support.py
+++ b/pypy/module/bz2/test/support.py
@@ -3,6 +3,11 @@
         from rpython.rtyper.lltypesystem import ll2ctypes
         import gc
         tries = 20
+        # remove the GC strings from ll2ctypes
+        for key, value in ll2ctypes.ALLOCATED.items():
+            if value._TYPE._gckind == 'gc':
+                del ll2ctypes.ALLOCATED[key]
+        #
         while tries and ll2ctypes.ALLOCATED:
             gc.collect() # to make sure we disallocate buffers
             tries -= 1
diff --git a/pypy/module/operator/tscmp.c b/pypy/module/operator/tscmp.c
--- a/pypy/module/operator/tscmp.c
+++ b/pypy/module/operator/tscmp.c
@@ -1,9 +1,9 @@
 /* Derived from CPython 3.3.5's operator.c::_tscmp
  */
 
+#include <stdlib.h>
+#include <wchar.h>
 #include "src/precommondefs.h"
-#include <stdlib.h>
-#include "tscmp.h"
 
 RPY_EXPORTED_FOR_TESTS int
 pypy_tscmp(const char *a, const char *b, long len_a, long len_b)
diff --git a/pypy/module/operator/tscmp.h b/pypy/module/operator/tscmp.h
deleted file mode 100644
--- a/pypy/module/operator/tscmp.h
+++ /dev/null
@@ -1,1 +0,0 @@
-int pypy_tscmp(const char *, const char *, long, long);
diff --git a/pypy/module/operator/tscmp.py b/pypy/module/operator/tscmp.py
--- a/pypy/module/operator/tscmp.py
+++ b/pypy/module/operator/tscmp.py
@@ -13,8 +13,7 @@
 
 cwd = py.path.local(__file__).dirpath()
 eci = ExternalCompilationInfo(
-    includes=[cwd.join('tscmp.h')],
-    include_dirs=[str(cwd), cdir],
+    include_dirs=[cdir],
     separate_module_files=[cwd.join('tscmp.c')])
 
 
diff --git a/pypy/module/pypyjit/test/test_jit_hook.py b/pypy/module/pypyjit/test/test_jit_hook.py
--- a/pypy/module/pypyjit/test/test_jit_hook.py
+++ b/pypy/module/pypyjit/test/test_jit_hook.py
@@ -11,7 +11,7 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rtyper.rclass import OBJECT
 from pypy.module.pypyjit.interp_jit import pypyjitdriver
-from pypy.module.pypyjit.policy import pypy_hooks
+from pypy.module.pypyjit.hooks import pypy_hooks
 from rpython.jit.tool.oparser import parse
 from rpython.jit.metainterp.typesystem import llhelper
 from rpython.rlib.jit import JitDebugInfo, AsmInfo, Counters
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
--- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
@@ -1,13 +1,11 @@
+#include "src/precommondefs.h"
+
 #if defined(_MSC_VER) || defined(__CYGWIN__)
 #include <windows.h>
 #define MS_WIN32
 #endif
 
-#if defined(MS_WIN32)
-#define EXPORT(x) __declspec(dllexport) x
-#else
-#define EXPORT(x) x
-#endif
+#define EXPORT(x)  RPY_EXPORTED x
 
 #include <stdlib.h>
 #include <math.h>
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/conftest.py b/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/conftest.py
@@ -8,6 +8,7 @@
 def compile_so_file():
     from rpython.translator.platform import platform
     from rpython.translator.tool.cbuild import ExternalCompilationInfo
+    from rpython.translator import cdir
     udir = pytest.ensuretemp('_ctypes_test')
     cfile = py.path.local(__file__).dirpath().join("_ctypes_test.c")
 
@@ -15,7 +16,8 @@
         libraries = ['oleaut32']
     else:
         libraries = []
-    eci = ExternalCompilationInfo(libraries=libraries)
+    eci = ExternalCompilationInfo(libraries=libraries,
+                                  include_dirs=[cdir])
 
     return platform.compile([cfile], eci, str(udir.join('_ctypes_test')),
                             standalone=False)
diff --git a/pypy/tool/release/package.py b/pypy/tool/release/package.py
--- a/pypy/tool/release/package.py
+++ b/pypy/tool/release/package.py
@@ -163,9 +163,9 @@
     if sys.platform == 'win32' and not rename_pypy_c.lower().endswith('.exe'):
         rename_pypy_c += '.exe'
     binaries = [(pypy_c, rename_pypy_c)]
-    libpypy_c = basedir.join('pypy', 'goal', 'libpypy-c.so')
+    libpypy_c = pypy_c.new(basename='libpypy-c.so')
     if libpypy_c.check():
-        binaries.append('libpypy-c.so')
+        binaries.append((libpypy_c, 'libpypy-c.so'))
     #
     builddir = options.builddir
     pypydir = builddir.ensure(name, dir=True)
diff --git a/rpython/jit/backend/llsupport/descr.py b/rpython/jit/backend/llsupport/descr.py
--- a/rpython/jit/backend/llsupport/descr.py
+++ b/rpython/jit/backend/llsupport/descr.py
@@ -313,17 +313,18 @@
 # ____________________________________________________________
 # CallDescrs
 
+def _missing_call_stub_i(func, args_i, args_r, args_f):
+    return 0
+def _missing_call_stub_r(func, args_i, args_r, args_f):
+    return lltype.nullptr(llmemory.GCREF.TO)
+def _missing_call_stub_f(func, args_i, args_r, args_f):
+    return longlong.ZEROF
+
 class CallDescr(AbstractDescr):
     arg_classes = ''     # <-- annotation hack
     result_type = '\x00'
     result_flag = '\x00'
     ffi_flags = 1
-    call_stub_i = staticmethod(lambda func, args_i, args_r, args_f:
-                               0)
-    call_stub_r = staticmethod(lambda func, args_i, args_r, args_f:
-                               lltype.nullptr(llmemory.GCREF.TO))
-    call_stub_f = staticmethod(lambda func,args_i,args_r,args_f:
-                               longlong.ZEROF)
 
     def __init__(self, arg_classes, result_type, result_signed, result_size,
                  extrainfo=None, ffi_flags=1):
@@ -340,6 +341,9 @@
         self.result_size = result_size
         self.extrainfo = extrainfo
         self.ffi_flags = ffi_flags
+        self.call_stub_i = _missing_call_stub_i
+        self.call_stub_r = _missing_call_stub_r
+        self.call_stub_f = _missing_call_stub_f
         # NB. the default ffi_flags is 1, meaning FUNCFLAG_CDECL, which
         # makes sense on Windows as it's the one for all the C functions
         # we are compiling together with the JIT.  On non-Windows platforms
diff --git a/rpython/jit/backend/llsupport/test/test_pinned_object_rewrite.py b/rpython/jit/backend/llsupport/test/test_pinned_object_rewrite.py
--- a/rpython/jit/backend/llsupport/test/test_pinned_object_rewrite.py
+++ b/rpython/jit/backend/llsupport/test/test_pinned_object_rewrite.py
@@ -10,7 +10,8 @@
 from rpython.jit.metainterp.optimizeopt.util import equaloplists
 from rpython.jit.codewriter.heaptracker import register_known_gctype
 from rpython.jit.metainterp.history import JitCellToken, FLOAT
-from rpython.rtyper.lltypesystem import lltype, rclass, rffi, lltype, llmemory
+from rpython.rtyper.lltypesystem import lltype, rffi, lltype, llmemory
+from rpython.rtyper import rclass
 from rpython.jit.backend.x86.arch import WORD
 from rpython.rlib import rgc
 
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -20,8 +20,7 @@
 
 # for test purposes we allow objects to be pinned and use
 # the following list to keep track of the pinned objects
-if not we_are_translated():
-    pinned_objects = []
+_pinned_objects = []
 
 def pin(obj):
     """If 'obj' can move, then attempt to temporarily fix it.  This
@@ -45,7 +44,7 @@
     Note further that pinning an object does not prevent it from being
     collected if it is not used anymore.
     """
-    pinned_objects.append(obj)
+    _pinned_objects.append(obj)
     return True
         
 
@@ -64,8 +63,13 @@
     """Unpin 'obj', allowing it to move again.
     Must only be called after a call to pin(obj) returned True.
     """
-    pinned_objects.remove(obj)
-        
+    for i in range(len(_pinned_objects)):
+        try:
+            if _pinned_objects[i] == obj:
+                del _pinned_objects[i]
+        except TypeError:
+            pass
+
 
 class UnpinEntry(ExtRegistryEntry):
     _about_ = unpin
@@ -79,7 +83,14 @@
 
 def _is_pinned(obj):
     """Method to check if 'obj' is pinned."""
-    return obj in pinned_objects
+    for i in range(len(_pinned_objects)):
+        try:
+            if _pinned_objects[i] == obj:
+                return True
+        except TypeError:
+            pass
+    return False
+
 
 class IsPinnedEntry(ExtRegistryEntry):
     _about_ = _is_pinned
diff --git a/rpython/rlib/rzlib.py b/rpython/rlib/rzlib.py
--- a/rpython/rlib/rzlib.py
+++ b/rpython/rlib/rzlib.py
@@ -185,16 +185,14 @@
 ADLER32_DEFAULT_START = 1
 
 def deflateSetDictionary(stream, string):
-    bytes = rffi.get_nonmovingbuffer(string)
-    err = _deflateSetDictionary(stream, rffi.cast(Bytefp, bytes), len(string))
-    rffi.free_nonmovingbuffer(string, bytes)
+    with rffi.scoped_nonmovingbuffer(string) as buf:
+        err = _deflateSetDictionary(stream, rffi.cast(Bytefp, buf), len(string))
     if err == Z_STREAM_ERROR:
         raise RZlibError("Parameter is invalid or the stream state is inconsistent")
 
 def inflateSetDictionary(stream, string):
-    bytes = rffi.get_nonmovingbuffer(string)
-    err = _inflateSetDictionary(stream, rffi.cast(Bytefp, bytes), len(string))
-    rffi.free_nonmovingbuffer(string, bytes)
+    with rffi.scoped_nonmovingbuffer(string) as buf:
+        err = _inflateSetDictionary(stream, rffi.cast(Bytefp, buf), len(string))
     if err == Z_STREAM_ERROR:
         raise RZlibError("Parameter is invalid or the stream state is inconsistent")
     elif err == Z_DATA_ERROR:
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
@@ -1,5 +1,6 @@
 import gc, time
 from rpython.rlib.rthread import *
+from rpython.rlib.rarithmetic import r_longlong
 from rpython.translator.c.test.test_boehm import AbstractGCTestClass
 from rpython.rtyper.lltypesystem import lltype, rffi
 import py
@@ -188,6 +189,15 @@
         res = fn()
         assert res < -1.0
 
+    def test_acquire_timed_huge_timeout(self):
+        t = r_longlong(2 ** 61)
+        def f():
+            l = allocate_lock()
+            return l.acquire_timed(t)
+        fn = self.getcompiled(f, [])
+        res = fn()
+        assert res == 1       # RPY_LOCK_ACQUIRED
+
     def test_acquire_timed_alarm(self):
         import sys
         if not sys.platform.startswith('linux'):
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -565,8 +565,6 @@
         if addr in ALLOCATED:
             raise Exception("internal ll2ctypes error - "
                             "double conversion from lltype to ctypes?")
-        if self._TYPE._gckind == 'gc':
-            return
         # XXX don't store here immortal structures
         ALLOCATED[addr] = self
 
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -1147,6 +1147,9 @@
         return self.buf
     def __exit__(self, *args):
         free_nonmovingbuffer(self.data, self.buf, self.pinned, self.is_raw)
+    __init__._always_inline_ = 'try'
+    __enter__._always_inline_ = 'try'
+    __exit__._always_inline_ = 'try'
 
 class scoped_nonmoving_unicodebuffer:
     def __init__(self, data):
@@ -1156,6 +1159,9 @@
         return self.buf
     def __exit__(self, *args):
         free_nonmoving_unicodebuffer(self.data, self.buf, self.pinned, self.is_raw)
+    __init__._always_inline_ = 'try'
+    __enter__._always_inline_ = 'try'
+    __exit__._always_inline_ = 'try'
 
 class scoped_alloc_buffer:
     def __init__(self, size):
diff --git a/rpython/rtyper/lltypesystem/test/test_lltype.py b/rpython/rtyper/lltypesystem/test/test_lltype.py
--- a/rpython/rtyper/lltypesystem/test/test_lltype.py
+++ b/rpython/rtyper/lltypesystem/test/test_lltype.py
@@ -827,10 +827,10 @@
     def test_str_from_buffer(self):
         """gc-managed memory does not need to be freed"""
         size = 50
-        raw_buf, gc_buf = rffi.alloc_buffer(size)
+        raw_buf, gc_buf, case_num = rffi.alloc_buffer(size)
         for i in range(size): raw_buf[i] = 'a'
-        rstr = rffi.str_from_buffer(raw_buf, gc_buf, size, size)
-        rffi.keep_buffer_alive_until_here(raw_buf, gc_buf)
+        rstr = rffi.str_from_buffer(raw_buf, gc_buf, case_num, size, size)
+        rffi.keep_buffer_alive_until_here(raw_buf, gc_buf, case_num)
         assert not leakfinder.ALLOCATED
 
     def test_leak_traceback(self):
diff --git a/rpython/translator/c/src/support.h b/rpython/translator/c/src/support.h
--- a/rpython/translator/c/src/support.h
+++ b/rpython/translator/c/src/support.h
@@ -49,12 +49,12 @@
      ((RPyCHECK((index) >= 0 && (index) < (array)->length),                 \
       (array))->items[index])
 #  define RPyFxItem(ptr, index, fixedsize)                                  \
-     ((RPyCHECK((ptr) && (index) >= 0 && (index) < (fixedsize)),            \
+     ((RPyCHECK((ptr) != NULL && (index) >= 0 && (index) < (fixedsize)),    \
       (ptr))[index])
 #  define RPyNLenItem(array, index)                                         \
-     ((RPyCHECK((array) && (index) >= 0), (array))->items[index])
+     ((RPyCHECK((array) != NULL && (index) >= 0), (array))->items[index])
 #  define RPyBareItem(array, index)                                         \
-     ((RPyCHECK((array) && (index) >= 0), (array))[index])
+     ((RPyCHECK((array) != NULL && (index) >= 0), (array))[index])
 
 #else
 #  define RPyField(ptr, name)                ((ptr)->name)
diff --git a/rpython/translator/c/src/thread_nt.c b/rpython/translator/c/src/thread_nt.c
--- a/rpython/translator/c/src/thread_nt.c
+++ b/rpython/translator/c/src/thread_nt.c
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <limits.h>
 #include <process.h>
+#include <errno.h>
 
 
 /*
@@ -102,12 +103,14 @@
 /************************************************************/
 
 
+static
 BOOL InitializeNonRecursiveMutex(PNRMUTEX mutex)
 {
     mutex->sem = CreateSemaphore(NULL, 1, 1, NULL);
     return !!mutex->sem;
 }
 
+static
 VOID DeleteNonRecursiveMutex(PNRMUTEX mutex)
 {
     /* No in-use check */
@@ -115,11 +118,24 @@
     mutex->sem = NULL ; /* Just in case */
 }
 
-DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
+static
+DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, RPY_TIMEOUT_T milliseconds)
 {
-    return WaitForSingleObject(mutex->sem, milliseconds);
+    DWORD res;
+
+    if (milliseconds < 0)
+        return WaitForSingleObject(mutex->sem, INFINITE);
+
+    while (milliseconds >= (RPY_TIMEOUT_T)INFINITE) {
+        res = WaitForSingleObject(mutex->sem, INFINITE - 1);
+        if (res != WAIT_TIMEOUT)
+            return res;
+        milliseconds -= (RPY_TIMEOUT_T)(INFINITE - 1);
+    }
+    return WaitForSingleObject(mutex->sem, (DWORD)milliseconds);
 }
 
+static
 BOOL LeaveNonRecursiveMutex(PNRMUTEX mutex)
 {
     return ReleaseSemaphore(mutex->sem, 1, NULL);
@@ -161,17 +177,9 @@
         milliseconds = microseconds / 1000;
         if (microseconds % 1000 > 0)
             ++milliseconds;
-        if ((DWORD) milliseconds != milliseconds) {
-            fprintf(stderr, "Timeout too large for a DWORD, "
-                            "please check RPY_TIMEOUT_MAX");
-            abort();
-        }
     }
-    else
-        milliseconds = INFINITE;
 
-    if (lock && EnterNonRecursiveMutex(
-	    lock, (DWORD)milliseconds) == WAIT_OBJECT_0) {
+    if (lock && EnterNonRecursiveMutex(lock, milliseconds) == WAIT_OBJECT_0) {
         success = RPY_LOCK_ACQUIRED;
     }
     else {
diff --git a/rpython/translator/c/test/test_newgc.py b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -1514,7 +1514,7 @@
             i = 0
             j = 0
             k = 0
-            while i < 3000000:
+            while i < 400000:
                 k = (k * 1291 + i) % 4603
                 a = A()
                 if k < 1000:
@@ -1546,11 +1546,12 @@
                     n += ord(a.foo.bar[0])
                     m += ord(a.foo.bar[1])
             return m - n
+        assert f() == 28495
         return f
 
     def test_random_pin(self):
         res = self.run("random_pin")
-        assert res == 279882
+        assert res == 28495
 
 
 # ____________________________________________________________________


More information about the pypy-commit mailing list