Author: Manuel Jacob <m...@manueljacob.de> Branch: kill-multimethod Changeset: r74274:d1bb4e734c56 Date: 2014-10-29 14:57 +0100 http://bitbucket.org/pypy/pypy/changeset/d1bb4e734c56/
Log: hg merge default 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,12 +1,12 @@ /* Derived from CPython 3.3.5's operator.c::_tscmp */ -#include "src/precommondefs.h" #include <stdlib.h> #include <wchar.h> +#include "src/precommondefs.h" #include "tscmp.h" -RPY_EXPORTED_FOR_TESTS int +int pypy_tscmp(const char *a, const char *b, long len_a, long len_b) { /* The volatile type declarations make sure that the compiler has no @@ -43,7 +43,7 @@ return (result == 0); } -RPY_EXPORTED_FOR_TESTS int +int pypy_tscmp_wide(const wchar_t *a, const wchar_t *b, long len_a, long len_b) { /* The volatile type declarations make sure that the compiler has no diff --git a/pypy/module/operator/tscmp.h b/pypy/module/operator/tscmp.h --- a/pypy/module/operator/tscmp.h +++ b/pypy/module/operator/tscmp.h @@ -1,2 +1,2 @@ -int pypy_tscmp(const char *, const char *, long, long); -int pypy_tscmp_wide(const wchar_t *, const wchar_t *, long, long); +RPY_EXPORTED_FOR_TESTS int pypy_tscmp(const char *, const char *, long, long); +RPY_EXPORTED_FOR_TESTS int pypy_tscmp_wide(const wchar_t *, const wchar_t *, long, long); 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/select/test/test_select.py b/pypy/module/select/test/test_select.py --- a/pypy/module/select/test/test_select.py +++ b/pypy/module/select/test/test_select.py @@ -309,7 +309,6 @@ import select class Foo(object): def fileno(self): - print len(l) if len(l) < 100: l.append(Foo()) return 0 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 @@ -160,9 +160,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', '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/assembler.py b/rpython/jit/backend/llsupport/assembler.py --- a/rpython/jit/backend/llsupport/assembler.py +++ b/rpython/jit/backend/llsupport/assembler.py @@ -225,7 +225,8 @@ raise AssertionError(kind) gcref = cast_instance_to_gcref(value) - rgc._make_sure_does_not_move(gcref) + if gcref: + rgc._make_sure_does_not_move(gcref) value = rffi.cast(lltype.Signed, gcref) je_location = self._call_assembler_check_descr(value, tmploc) # 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/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,14 @@ """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] + return + except TypeError: + pass + class UnpinEntry(ExtRegistryEntry): _about_ = unpin @@ -79,7 +84,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/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 @@ -103,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 */ @@ -116,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); @@ -162,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 # ____________________________________________________________________ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit