Commit c786ee6a authored by Manuel Jacob's avatar Manuel Jacob

hg merge default

parents 39818ad7 c68f9e02
/* 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 @@ pypy_tscmp(const char *a, const char *b, long len_a, long len_b)
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
......
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);
......@@ -11,7 +11,7 @@ from rpython.rtyper.annlowlevel import (cast_instance_to_base_ptr,
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
......
......@@ -309,7 +309,6 @@ class AppTestSelectWithPipes(_AppTestSelect):
import select
class Foo(object):
def fileno(self):
print len(l)
if len(l) < 100:
l.append(Foo())
return 0
......
#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>
......
......@@ -8,6 +8,7 @@ def pytest_ignore_collect(path):
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 @@ def compile_so_file():
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)
......
......@@ -160,9 +160,9 @@ def create_package(basedir, options):
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)
......
......@@ -225,7 +225,8 @@ class BaseAssembler(object):
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)
#
......
......@@ -313,17 +313,18 @@ def get_interiorfield_descr(gc_ll_descr, ARRAY, name, arrayfieldname=None):
# ____________________________________________________________
# 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 @@ class CallDescr(AbstractDescr):
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
......
......@@ -20,8 +20,7 @@ def set_max_heap_size(nbytes):
# 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 @@ def pin(obj):
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 @@ def unpin(obj):
"""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 @@ class UnpinEntry(ExtRegistryEntry):
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
......
......@@ -185,16 +185,14 @@ def crc32(string, start=CRC32_DEFAULT_START):
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:
......
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 @@ class AbstractThreadTests(AbstractGCTestClass):
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'):
......
......@@ -1147,6 +1147,9 @@ class scoped_nonmovingbuffer:
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 @@ class scoped_nonmoving_unicodebuffer:
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):
......
......@@ -827,10 +827,10 @@ class TestTrackAllocation:
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):
......
......@@ -49,12 +49,12 @@ void RPyAbort(void);
((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)
......
......@@ -103,12 +103,14 @@ long RPyThreadSetStackSize(long newsize)
/************************************************************/
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 @@ VOID DeleteNonRecursiveMutex(PNRMUTEX mutex)
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 @@ RPyThreadAcquireLockTimed(struct RPyOpaque_ThreadLock *lock,
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 {
......
......@@ -1514,7 +1514,7 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC):
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 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC):
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
# ____________________________________________________________________
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment