Author: Ronan Lamy <[email protected]>
Branch: testing-cleanup-py3k
Changeset: r85261:9e634693f1eb
Date: 2016-06-20 19:10 +0100
http://bitbucket.org/pypy/pypy/changeset/9e634693f1eb/
Log: hg merge testing-default
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
@@ -19,3 +19,6 @@
.. branch: s390x-5.3-catchup
Implement the backend related changes for s390x.
+
+.. branch: incminimark-ll_assert
+.. branch: vmprof-openbsd
diff --git a/pypy/module/__pypy__/interp_intop.py
b/pypy/module/__pypy__/interp_intop.py
--- a/pypy/module/__pypy__/interp_intop.py
+++ b/pypy/module/__pypy__/interp_intop.py
@@ -2,21 +2,10 @@
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rlib.rarithmetic import r_uint, intmask
+from rpython.rlib.rarithmetic import int_c_div, int_c_mod
from rpython.rlib import jit
-# XXX maybe temporary: hide llop.int_{floordiv,mod} from the JIT,
-# because now it expects only Python-style divisions, not the
-# C-style divisions of these two ll operations
[email protected]_look_inside
-def _int_floordiv(n, m):
- return llop.int_floordiv(lltype.Signed, n, m)
-
[email protected]_look_inside
-def _int_mod(n, m):
- return llop.int_mod(lltype.Signed, n, m)
-
-
@unwrap_spec(n=int, m=int)
def int_add(space, n, m):
return space.wrap(llop.int_add(lltype.Signed, n, m))
@@ -31,11 +20,11 @@
@unwrap_spec(n=int, m=int)
def int_floordiv(space, n, m):
- return space.wrap(_int_floordiv(n, m))
+ return space.wrap(int_c_div(n, m))
@unwrap_spec(n=int, m=int)
def int_mod(space, n, m):
- return space.wrap(_int_mod(n, m))
+ return space.wrap(int_c_mod(n, m))
@unwrap_spec(n=int, m=int)
def int_lshift(space, n, m):
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
@@ -220,6 +220,11 @@
if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK:
raise oefmt(space.w_SystemError,
"libffi failed to build this callback")
+ if closure_ptr.c_user_data != unique_id:
+ raise oefmt(space.w_SystemError,
+ "ffi_prep_closure(): bad user_data (it seems that the "
+ "version of the libffi library seen at runtime is "
+ "different from the 'ffi.h' file seen at compile-time)")
def py_invoke(self, ll_res, ll_args):
jitdriver1.jit_merge_point(callback=self,
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
@@ -802,6 +802,21 @@
pypy_debug_catch_fatal_exception()
assert False
+def _restore_gil_state(pygilstate_release, gilstate, gil_release, _gil_auto,
tid):
+ from rpython.rlib import rgil
+ # see "Handling of the GIL" above
+ assert cpyext_glob_tid_ptr[0] == 0
+ if pygilstate_release:
+ from pypy.module.cpyext import pystate
+ unlock = (gilstate == pystate.PyGILState_UNLOCKED)
+ else:
+ unlock = gil_release or _gil_auto
+ if unlock:
+ rgil.release()
+ else:
+ cpyext_glob_tid_ptr[0] = tid
+
+
def make_wrapper_second_level(space, argtypesw, restype,
result_kind, error_value, gil):
from rpython.rlib import rgil
@@ -829,6 +844,7 @@
def wrapper_second_level(callable, pname, *args):
from pypy.module.cpyext.pyobject import make_ref, from_ref, is_pyobj
from pypy.module.cpyext.pyobject import as_pyobj
+ from pypy.module.cpyext import pystate
# we hope that malloc removal removes the newtuple() that is
# inserted exactly here by the varargs specializer
@@ -841,7 +857,6 @@
rgil.acquire()
assert cpyext_glob_tid_ptr[0] == 0
elif pygilstate_ensure:
- from pypy.module.cpyext import pystate
if cpyext_glob_tid_ptr[0] == tid:
cpyext_glob_tid_ptr[0] = 0
args += (pystate.PyGILState_LOCKED,)
@@ -852,6 +867,10 @@
if cpyext_glob_tid_ptr[0] != tid:
no_gil_error(pname)
cpyext_glob_tid_ptr[0] = 0
+ if pygilstate_release:
+ gilstate = rffi.cast(lltype.Signed, args[-1])
+ else:
+ gilstate = pystate.PyGILState_IGNORE
rffi.stackcounter.stacks_counter += 1
llop.gc_stack_bottom(lltype.Void) # marker for trackgcroot.py
@@ -921,24 +940,13 @@
except Exception as e:
unexpected_exception(pname, e, tb)
+ _restore_gil_state(pygilstate_release, gilstate, gil_release,
_gil_auto, tid)
return fatal_value
assert lltype.typeOf(retval) == restype
rffi.stackcounter.stacks_counter -= 1
- # see "Handling of the GIL" above
- assert cpyext_glob_tid_ptr[0] == 0
- if pygilstate_release:
- from pypy.module.cpyext import pystate
- arg = rffi.cast(lltype.Signed, args[-1])
- unlock = (arg == pystate.PyGILState_UNLOCKED)
- else:
- unlock = gil_release or _gil_auto
- if unlock:
- rgil.release()
- else:
- cpyext_glob_tid_ptr[0] = tid
-
+ _restore_gil_state(pygilstate_release, gilstate, gil_release,
_gil_auto, tid)
return retval
wrapper_second_level._dont_inline_ = True
diff --git a/pypy/module/cpyext/include/pymem.h
b/pypy/module/cpyext/include/pymem.h
--- a/pypy/module/cpyext/include/pymem.h
+++ b/pypy/module/cpyext/include/pymem.h
@@ -1,5 +1,11 @@
#include <stdlib.h>
+#ifndef Py_PYMEM_H
+#define Py_PYMEM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
#define PyMem_MALLOC(n) malloc((n) ? (n) : 1)
#define PyMem_REALLOC(p, n) realloc((p), (n) ? (n) : 1)
@@ -44,3 +50,9 @@
*/
#define PyMem_Del PyMem_Free
#define PyMem_DEL PyMem_FREE
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !Py_PYMEM_H */
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
@@ -211,6 +211,7 @@
PyGILState_STATE = rffi.INT
PyGILState_LOCKED = 0
PyGILState_UNLOCKED = 1
+PyGILState_IGNORE = 2
ExecutionContext.cpyext_gilstate_counter_noleave = 0
diff --git a/pypy/module/cpyext/test/conftest.py
b/pypy/module/cpyext/test/conftest.py
--- a/pypy/module/cpyext/test/conftest.py
+++ b/pypy/module/cpyext/test/conftest.py
@@ -1,4 +1,4 @@
-import py
+import os
import pytest
def pytest_configure(config):
@@ -23,3 +23,14 @@
def pytest_funcarg__api(request):
return request.cls.api
+if os.name == 'nt':
+ @pytest.yield_fixture(autouse=True, scope='session')
+ def prevent_dialog_box():
+ """Do not open dreaded dialog box on segfault on Windows"""
+ import ctypes
+ SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN
+ old_err_mode = ctypes.windll.kernel32.GetErrorMode()
+ new_err_mode = old_err_mode | SEM_NOGPFAULTERRORBOX
+ ctypes.windll.kernel32.SetErrorMode(new_err_mode)
+ yield
+ ctypes.windll.kernel32.SetErrorMode(old_err_mode)
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -48,15 +48,6 @@
/* foo methods */
-static void
-foo_dealloc(fooobject *foop)
-{
- PyObject_Del(foop);
-}
-
-
-/* foo methods-as-attributes */
-
static PyObject *
foo_copy(fooobject *self)
{
@@ -200,7 +191,7 @@
sizeof(fooobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- (destructor)foo_dealloc, /*tp_dealloc*/
+ 0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
@@ -468,9 +459,9 @@
PyTypeObject InitErrType = {
PyObject_HEAD_INIT(NULL)
0,
- "foo.InitErr",
- sizeof(PyObject),
- 0,
+ "foo.InitErrType",
+ sizeof(PyObject),/*tp_basicsize*/
+ 0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
@@ -513,12 +504,12 @@
0, /*tp_dictoffset*/
initerrtype_init, /*tp_init*/
- 0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
+ 0, /*tp_alloc*/
0, /*tp_new*/
- 0, /*tp_free Low-level free-memory routine */
- 0, /*tp_is_gc For PyObject_IS_GC */
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
0, /*tp_bases*/
- 0, /*tp_mro method resolution order */
+ 0, /*tp_mro*/
0, /*tp_cache*/
0, /*tp_subclasses*/
0 /*tp_weaklist*/
diff --git a/pypy/module/cpyext/test/support.py
b/pypy/module/cpyext/test/support.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/support.py
@@ -0,0 +1,68 @@
+import os
+import py
+from sys import platform
+
+if os.name != 'nt':
+ so_ext = 'so'
+else:
+ so_ext = 'dll'
+
+def c_compile(cfilenames, outputfilename,
+ compile_extra=None, link_extra=None,
+ include_dirs=None, libraries=None, library_dirs=None):
+ compile_extra = compile_extra or []
+ link_extra = link_extra or []
+ include_dirs = include_dirs or []
+ libraries = libraries or []
+ library_dirs = library_dirs or []
+ if platform == 'win32':
+ link_extra = link_extra + ['/DEBUG'] # generate .pdb file
+ if platform == 'darwin':
+ # support Fink & Darwinports
+ for s in ('/sw/', '/opt/local/'):
+ if (s + 'include' not in include_dirs
+ and os.path.exists(s + 'include')):
+ include_dirs.append(s + 'include')
+ if s + 'lib' not in library_dirs and os.path.exists(s + 'lib'):
+ library_dirs.append(s + 'lib')
+
+ outputfilename = py.path.local(outputfilename).new(ext=so_ext)
+ saved_environ = os.environ.copy()
+ try:
+ _build(
+ cfilenames, outputfilename,
+ compile_extra, link_extra,
+ include_dirs, libraries, library_dirs)
+ finally:
+ # workaround for a distutils bugs where some env vars can
+ # become longer and longer every time it is used
+ for key, value in saved_environ.items():
+ if os.environ.get(key) != value:
+ os.environ[key] = value
+ return outputfilename
+
+def _build(cfilenames, outputfilename, compile_extra, link_extra,
+ include_dirs, libraries, library_dirs):
+ from distutils.ccompiler import new_compiler
+ from distutils import sysconfig
+ compiler = new_compiler(force=1)
+ sysconfig.customize_compiler(compiler) # XXX
+ objects = []
+ for cfile in cfilenames:
+ cfile = py.path.local(cfile)
+ old = cfile.dirpath().chdir()
+ try:
+ res = compiler.compile([cfile.basename],
+ include_dirs=include_dirs, extra_preargs=compile_extra)
+ assert len(res) == 1
+ cobjfile = py.path.local(res[0])
+ assert cobjfile.check()
+ objects.append(str(cobjfile))
+ finally:
+ old.chdir()
+
+ compiler.link_shared_object(
+ objects, str(outputfilename),
+ libraries=libraries,
+ extra_preargs=link_extra,
+ library_dirs=library_dirs)
diff --git a/pypy/module/cpyext/test/test_bytearrayobject.py
b/pypy/module/cpyext/test/test_bytearrayobject.py
--- a/pypy/module/cpyext/test/test_bytearrayobject.py
+++ b/pypy/module/cpyext/test/test_bytearrayobject.py
@@ -31,7 +31,7 @@
if(s->ob_type->tp_basicsize != expected_size)
{
printf("tp_basicsize==%ld\\n",
- (long)s->ob_type->tp_basicsize);
+ (long)s->ob_type->tp_basicsize);
result = 0;
}
Py_DECREF(s);
@@ -53,7 +53,6 @@
"""
PyObject *s, *t;
char* c;
- Py_ssize_t len;
s = PyByteArray_FromStringAndSize(NULL, 4);
if (s == NULL)
@@ -84,7 +83,6 @@
("mutable", "METH_NOARGS",
"""
PyObject *base;
- char * p_str;
base = PyByteArray_FromStringAndSize("test", 10);
if (PyByteArray_GET_SIZE(base) != 10)
return PyLong_FromLong(-PyByteArray_GET_SIZE(base));
diff --git a/pypy/module/cpyext/test/test_bytesobject.py
b/pypy/module/cpyext/test/test_bytesobject.py
--- a/pypy/module/cpyext/test/test_bytesobject.py
+++ b/pypy/module/cpyext/test/test_bytesobject.py
@@ -72,7 +72,6 @@
"""
PyObject *s, *t;
char* c;
- Py_ssize_t len;
s = PyBytes_FromStringAndSize(NULL, 4);
if (s == NULL)
@@ -100,7 +99,6 @@
PyObject *base;
PyTypeObject * type;
PyObject *obj;
- char * p_str;
base = PyBytes_FromString("test");
if (PyBytes_GET_SIZE(base) != 4)
return PyLong_FromLong(-PyBytes_GET_SIZE(base));
@@ -258,7 +256,6 @@
assert ref.c_ob_refcnt == prev_refcnt
assert lenp[0] == 4
assert rffi.charp2str(bufp[0]) == 'text'
-
lltype.free(bufp, flavor='raw')
lltype.free(lenp, flavor='raw')
api.Py_DecRef(ref)
diff --git a/pypy/module/cpyext/test/test_cpyext.py
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -7,8 +7,6 @@
from pypy import pypydir
from pypy.interpreter import gateway
from rpython.rtyper.lltypesystem import lltype, ll2ctypes
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.translator import platform
from rpython.translator.gensupp import uniquemodulename
from rpython.tool.udir import udir
from pypy.module.cpyext import api
@@ -18,20 +16,7 @@
from rpython.tool import leakfinder
from rpython.rlib import rawrefcount
-def setup_module(module):
- if os.name == 'nt':
- # Do not open dreaded dialog box on segfault
- import ctypes
- SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN
- old_err_mode = ctypes.windll.kernel32.GetErrorMode()
- new_err_mode = old_err_mode | SEM_NOGPFAULTERRORBOX
- ctypes.windll.kernel32.SetErrorMode(new_err_mode)
- module.old_err_mode = old_err_mode
-
-def teardown_module(module):
- if os.name == 'nt':
- import ctypes
- ctypes.windll.kernel32.SetErrorMode(module.old_err_mode)
+from .support import c_compile
@api.cpython_api([], api.PyObject)
def PyPy_Crash1(space):
@@ -46,7 +31,30 @@
assert 'PyModule_Check' in api.FUNCTIONS
assert api.FUNCTIONS['PyModule_Check'].argtypes == [api.PyObject]
-def compile_extension_module(space, modname, include_dirs=[], **kwds):
+def convert_sources_to_files(sources, dirname):
+ files = []
+ for i, source in enumerate(sources):
+ filename = dirname / ('source_%d.c' % i)
+ with filename.open('w') as f:
+ f.write(str(source))
+ files.append(filename)
+ return files
+
+def create_so(modname, include_dirs, source_strings=None, source_files=None,
+ compile_extra=None, link_extra=None, libraries=None):
+ dirname = (udir/uniquemodulename('module')).ensure(dir=1)
+ if source_strings:
+ assert not source_files
+ files = convert_sources_to_files(source_strings, dirname)
+ source_files = files
+ soname = c_compile(source_files, outputfilename=str(dirname/modname),
+ compile_extra=compile_extra, link_extra=link_extra,
+ include_dirs=include_dirs,
+ libraries=libraries)
+ return soname
+
+def compile_extension_module(space, modname, include_dirs=[],
+ source_files=None, source_strings=None):
"""
Build an extension module and return the filename of the resulting native
code file.
@@ -60,38 +68,36 @@
state = space.fromcache(State)
api_library = state.api_lib
if sys.platform == 'win32':
- kwds["libraries"] = [api_library]
+ libraries = [api_library]
# '%s' undefined; assuming extern returning int
- kwds["compile_extra"] = ["/we4013"]
+ compile_extra = ["/we4013"]
# prevent linking with PythonXX.lib
w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
- kwds["link_extra"] = ["/NODEFAULTLIB:Python%d%d.lib" %
+ link_extra = ["/NODEFAULTLIB:Python%d%d.lib" %
(space.int_w(w_maj), space.int_w(w_min))]
- elif sys.platform == 'darwin':
- kwds["link_files"] = [str(api_library + '.dylib')]
else:
- kwds["link_files"] = [str(api_library + '.so')]
+ libraries = []
if sys.platform.startswith('linux'):
- kwds["compile_extra"]=["-Werror", "-g", "-O0"]
- kwds["link_extra"]=["-g"]
+ compile_extra = ["-Werror", "-g", "-O0", "-fPIC"]
+ link_extra = ["-g"]
+ else:
+ compile_extra = link_extra = None
modname = modname.split('.')[-1]
- eci = ExternalCompilationInfo(
- include_dirs=api.include_dirs + include_dirs,
- **kwds
- )
- eci = eci.convert_sources_to_files()
- dirname = (udir/uniquemodulename('module')).ensure(dir=1)
- soname = platform.platform.compile(
- [], eci,
- outputfilename=str(dirname/modname),
- standalone=False)
+ soname = create_so(modname,
+ include_dirs=api.include_dirs + include_dirs,
+ source_files=source_files,
+ source_strings=source_strings,
+ compile_extra=compile_extra,
+ link_extra=link_extra,
+ libraries=libraries)
from pypy.module.imp.importing import get_so_extension
pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
soname.rename(pydname)
return str(pydname)
-def compile_extension_module_applevel(space, modname, include_dirs=[], **kwds):
+def compile_extension_module_applevel(space, modname, include_dirs=[],
+ source_files=None, source_strings=None):
"""
Build an extension module and return the filename of the resulting native
code file.
@@ -103,24 +109,23 @@
build the module (so specify your source with one of those).
"""
if sys.platform == 'win32':
- kwds["compile_extra"] = ["/we4013"]
- kwds["link_extra"] = ["/LIBPATH:" + os.path.join(sys.exec_prefix,
'libs')]
+ compile_extra = ["/we4013"]
+ link_extra = ["/LIBPATH:" + os.path.join(sys.exec_prefix, 'libs')]
elif sys.platform == 'darwin':
+ compile_extra = link_extra = None
pass
elif sys.platform.startswith('linux'):
- kwds["compile_extra"]=["-O0",
"-g","-Werror=implicit-function-declaration"]
+ compile_extra = [
+ "-O0", "-g", "-Werror=implicit-function-declaration", "-fPIC"]
+ link_extra = None
modname = modname.split('.')[-1]
- eci = ExternalCompilationInfo(
- include_dirs = [space.include_dir] + include_dirs,
- **kwds
- )
- eci = eci.convert_sources_to_files()
- dirname = (udir/uniquemodulename('module')).ensure(dir=1)
- soname = platform.platform.compile(
- [], eci,
- outputfilename=str(dirname/modname),
- standalone=False)
+ soname = create_so(modname,
+ include_dirs=[space.include_dir] + include_dirs,
+ source_files=source_files,
+ source_strings=source_strings,
+ compile_extra=compile_extra,
+ link_extra=link_extra)
return str(soname)
def freeze_refcnts(self):
@@ -286,8 +291,8 @@
separate_module_sources = []
pydname = self.compile_extension_module(
space, name,
- separate_module_files=separate_module_files,
- separate_module_sources=separate_module_sources)
+ source_files=separate_module_files,
+ source_strings=separate_module_sources)
return space.wrap(pydname)
@gateway.unwrap_spec(name=str, init='str_or_None', body=str,
@@ -330,16 +335,16 @@
""" % dict(name=name, init=init, body=body,
PY_SSIZE_T_CLEAN='#define PY_SSIZE_T_CLEAN'
if PY_SSIZE_T_CLEAN else '')
- kwds = dict(separate_module_sources=[code])
+ kwds = dict(source_strings=[code])
else:
assert not PY_SSIZE_T_CLEAN
if filename is None:
filename = name
filename = py.path.local(pypydir) / 'module' \
/ 'cpyext'/ 'test' / (filename + ".c")
- kwds = dict(separate_module_files=[filename])
- kwds['include_dirs'] = include_dirs
- mod = self.compile_extension_module(space, name, **kwds)
+ kwds = dict(source_files=[filename])
+ mod = self.compile_extension_module(space, name,
+ include_dirs=include_dirs, **kwds)
if load_it:
if self.runappdirect:
@@ -995,7 +1000,7 @@
('bar', 'METH_NOARGS',
'''
/* reuse a name that is #defined in structmember.h */
- int RO;
+ int RO = 0; (void)RO;
Py_RETURN_NONE;
'''
),
diff --git a/pypy/module/cpyext/test/test_frameobject.py
b/pypy/module/cpyext/test/test_frameobject.py
--- a/pypy/module/cpyext/test/test_frameobject.py
+++ b/pypy/module/cpyext/test/test_frameobject.py
@@ -13,7 +13,7 @@
PyObject *empty_bytes = PyBytes_FromString("");
PyObject *empty_tuple = PyTuple_New(0);
PyCodeObject *py_code;
- PyFrameObject *py_frame;
+ PyFrameObject *py_frame = NULL;
py_code = PyCode_New(
0, /*int argcount,*/
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py
b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -239,7 +239,7 @@
except:
skip('numpy not importable')
else:
- numpy_incl = os.path.abspath(os.path.dirname(__file__) +
+ numpy_incl = os.path.abspath(os.path.dirname(__file__) +
'/../include/_numpypy')
assert os.path.exists(numpy_incl)
cls.w_numpy_include = cls.space.wrap([numpy_incl])
@@ -302,7 +302,7 @@
),
("test_DescrFromType", "METH_O",
"""
- Signed typenum = PyLong_AsLong(args);
+ long typenum = PyInt_AsLong(args);
return PyArray_DescrFromType(typenum);
"""
),
diff --git a/pypy/module/cpyext/test/test_object.py
b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -401,7 +401,6 @@
"""
Py_buffer buf;
PyObject *str = PyBytes_FromString("hello, world.");
- PyObject *result;
if (PyBuffer_FillInfo(&buf, str, PyBytes_AsString(str), 13,
1, PyBUF_WRITABLE)) {
diff --git a/pypy/module/cpyext/test/test_tupleobject.py
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -130,7 +130,7 @@
module = self.import_extension('foo', [
("run", "METH_NOARGS",
"""
- long prev, next;
+ long prev;
PyObject *t = PyTuple_New(1);
prev = Py_True->ob_refcnt;
Py_INCREF(Py_True);
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -716,7 +716,6 @@
"""
IntLikeObject *intObj;
long intval;
- PyObject *name;
if (!PyArg_ParseTuple(args, "i", &intval))
return NULL;
@@ -1037,7 +1036,6 @@
module = self.import_extension('foo', [
("getMetaClass", "METH_NOARGS",
'''
- PyObject *obj;
FooType_Type.tp_flags = Py_TPFLAGS_DEFAULT;
FooType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&FooType_Type) < 0) return NULL;
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -35,7 +35,7 @@
("test_GetSize_exception", "METH_NOARGS",
"""
PyObject* f = PyFloat_FromDouble(1.0);
- Py_ssize_t size = PyUnicode_GetSize(f);
+ PyUnicode_GetSize(f);
Py_DECREF(f);
return NULL;
@@ -57,7 +57,6 @@
"""
PyObject *s, *t;
Py_UNICODE* c;
- Py_ssize_t len;
s = PyUnicode_FromUnicode(NULL, 4);
if (s == NULL)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py
b/pypy/module/pypyjit/test_pypy_c/test_string.py
--- a/pypy/module/pypyjit/test_pypy_c/test_string.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_string.py
@@ -23,7 +23,7 @@
guard_true(i14, descr=...)
guard_not_invalidated(descr=...)
i16 = int_eq(i6, %d)
- i19 = call_i(ConstClass(ll_int_mod__Signed_Signed), i6, i10,
descr=<Calli . ii EF=0 OS=14>)
+ i19 = call_i(ConstClass(ll_int_py_mod__Signed_Signed), i6, i10,
descr=<Calli . ii EF=0 OS=14>)
i21 = int_lt(i19, 0)
guard_false(i21, descr=...)
i22 = int_ge(i19, i10)
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
@@ -3,10 +3,12 @@
It uses 'pypy/goal/pypy-c' and parts of the rest of the working
copy. Usage:
- package.py [--options] pypy-VER-PLATFORM
+ package.py [--options] --archive-name=pypy-VER-PLATFORM
The output is found in the directory from --builddir,
by default /tmp/usession-YOURNAME/build/.
+
+For a list of all options, see 'package.py --help'.
"""
import shutil
@@ -64,6 +66,7 @@
name = options.name
if not name:
name = 'pypy-nightly'
+ assert '/' not in name
rename_pypy_c = options.pypy_c
override_pypy_c = options.override_pypy_c
@@ -299,26 +302,12 @@
help='destination dir for archive')
parser.add_argument('--override_pypy_c', type=str, default='',
help='use as pypy exe instead of pypy/goal/pypy-c')
- # Positional arguments, for backward compatability with buldbots
- parser.add_argument('extra_args', help='optional interface to positional
arguments', nargs=argparse.REMAINDER,
- metavar='[archive-name] [rename_pypy_c] [targetdir] [override_pypy_c]',
- )
options = parser.parse_args(args)
- # Handle positional arguments, choke if both methods are used
- for i,target, default in ([1, 'name', ''], [2, 'pypy_c', pypy_exe],
- [3, 'targetdir', ''], [4,'override_pypy_c', '']):
- if len(options.extra_args)>i:
- if getattr(options, target) != default:
- print 'positional argument',i,target,'already has
value',getattr(options, target)
- parser.print_help()
- return
- setattr(options, target, options.extra_args[i])
if os.environ.has_key("PYPY_PACKAGE_NOSTRIP"):
options.nostrip = True
-
if os.environ.has_key("PYPY_PACKAGE_WITHOUTTK"):
- options.tk = True
+ options.no_tk = True
if not options.builddir:
# The import actually creates the udir directory
from rpython.tool.udir import udir
diff --git a/pypy/tool/release/test/test_package.py
b/pypy/tool/release/test/test_package.py
--- a/pypy/tool/release/test/test_package.py
+++ b/pypy/tool/release/test/test_package.py
@@ -21,8 +21,10 @@
def test_dir_structure(self, test='test'):
retval, builddir = package.package(
- '--without-cffi', str(py.path.local(pypydir).dirpath()),
- test, self.rename_pypy_c, _fake=True)
+ '--without-cffi',
+ '--archive-name', test,
+ '--rename_pypy_c', self.rename_pypy_c,
+ _fake=True)
assert retval == 0
prefix = builddir.join(test)
cpyver = '%d' % CPYTHON_VERSION[0]
@@ -71,8 +73,9 @@
builddir = udir.ensure("build", dir=True)
retval, builddir = package.package(
'--without-cffi', '--builddir', str(builddir),
- str(py.path.local(pypydir).dirpath()),
- test, self.rename_pypy_c, _fake=True)
+ '--archive-name', test,
+ '--rename_pypy_c', self.rename_pypy_c,
+ _fake=True)
def test_with_zipfile_module(self):
prev = package.USE_ZIPFILE_MODULE
diff --git a/rpython/jit/backend/llsupport/test/test_gc_integration.py
b/rpython/jit/backend/llsupport/test/test_gc_integration.py
--- a/rpython/jit/backend/llsupport/test/test_gc_integration.py
+++ b/rpython/jit/backend/llsupport/test/test_gc_integration.py
@@ -324,17 +324,19 @@
def check(frame):
expected_size = 1
idx = 0
+ fixed_size = self.cpu.JITFRAME_FIXED_SIZE
if self.cpu.backend_name.startswith('arm'):
# jitframe fixed part is larger here
expected_size = 2
idx = 1
+ fixed_size -= 32
assert len(frame.jf_gcmap) == expected_size
- if self.cpu.IS_64_BIT:
- exp_idx = self.cpu.JITFRAME_FIXED_SIZE + 1 # +1 from i0
- else:
- assert frame.jf_gcmap[idx]
- exp_idx = self.cpu.JITFRAME_FIXED_SIZE - 32 * idx + 1 # +1
from i0
- assert frame.jf_gcmap[idx] == (1 << (exp_idx + 1)) | (1 << exp_idx)
+ # check that we have two bits set, and that they are in two
+ # registers (p0 and p1 are moved away when doing p2, but not
+ # spilled, just moved to different registers)
+ bits = [n for n in range(fixed_size)
+ if frame.jf_gcmap[idx] & (1<<n)]
+ assert len(bits) == 2
self.cpu = self.getcpu(check)
ops = '''
diff --git a/rpython/jit/backend/ppc/regalloc.py
b/rpython/jit/backend/ppc/regalloc.py
--- a/rpython/jit/backend/ppc/regalloc.py
+++ b/rpython/jit/backend/ppc/regalloc.py
@@ -439,7 +439,7 @@
prepare_int_lshift = helper.prepare_binary_op
prepare_int_rshift = helper.prepare_binary_op
prepare_uint_rshift = helper.prepare_binary_op
- prepare_uint_mul_high = helper.prepare_int_mul_ovf
+ prepare_uint_mul_high = helper.prepare_binary_op
prepare_int_add_ovf = helper.prepare_binary_op
prepare_int_sub_ovf = helper.prepare_binary_op
diff --git a/rpython/jit/codewriter/jtransform.py
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -522,6 +522,7 @@
# but be really compiled
rewrite_op_int_abs = _do_builtin_call
rewrite_op_int_floordiv = _do_builtin_call
+ rewrite_op_int_mod = _do_builtin_call
rewrite_op_llong_abs = _do_builtin_call
rewrite_op_llong_floordiv = _do_builtin_call
rewrite_op_llong_mod = _do_builtin_call
@@ -531,7 +532,6 @@
rewrite_op_gc_id = _do_builtin_call
rewrite_op_gc_pin = _do_builtin_call
rewrite_op_gc_unpin = _do_builtin_call
- rewrite_op_uint_mod = _do_builtin_call
rewrite_op_cast_float_to_uint = _do_builtin_call
rewrite_op_cast_uint_to_float = _do_builtin_call
rewrite_op_weakref_create = _do_builtin_call
diff --git a/rpython/jit/codewriter/support.py
b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -252,7 +252,7 @@
def _ll_2_int_floordiv(x, y):
# this is used only if the RPython program uses llop.int_floordiv()
# explicitly. For 'a // b', see _handle_int_special() in jtransform.py.
- # This is the reverse of rpython.rtyper.rint.ll_int_floordiv(), i.e.
+ # This is the reverse of rpython.rtyper.rint.ll_int_py_div(), i.e.
# the same logic as rpython.rtyper.lltypesystem.opimpl.op_int_floordiv
# but written in a no-branch style.
r = x // y
@@ -260,6 +260,13 @@
# the JIT knows that if x and y are both positive, this is just 'r'
return r + (((x ^ y) >> (LONG_BIT - 1)) & (p != x))
+def _ll_2_int_mod(x, y):
+ # same comments as _ll_2_int_floordiv()
+ r = x % y
+ # the JIT knows that if x and y are both positive, this doesn't change 'r'
+ r -= y & (((x ^ y) & (r | -r)) >> (LONG_BIT - 1))
+ return r
+
def _ll_1_cast_uint_to_float(x):
# XXX on 32-bit platforms, this should be done using cast_longlong_to_float
@@ -431,6 +438,7 @@
inline_calls_to = [
('int_abs', [lltype.Signed], lltype.Signed),
('int_floordiv', [lltype.Signed, lltype.Signed], lltype.Signed),
+ ('int_mod', [lltype.Signed, lltype.Signed], lltype.Signed),
('ll_math.ll_math_sqrt', [lltype.Float], lltype.Float),
]
diff --git a/rpython/jit/codewriter/test/test_flatten.py
b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -478,7 +478,7 @@
except ZeroDivisionError:
return -42
self.encoding_test(f, [7, 2], """
- residual_call_ir_i $<* fn ll_int_floordiv_ovf_zer__Signed_Signed>,
I[%i0, %i1], R[], <Descr> -> %i2
+ residual_call_ir_i $<* fn ll_int_py_div_ovf_zer__Signed_Signed>,
I[%i0, %i1], R[], <Descr> -> %i2
-live-
catch_exception L1
int_return %i2
@@ -505,7 +505,7 @@
return 42
# XXX so far, this really produces a int_mod_ovf_zer...
self.encoding_test(f, [7, 2], """
- residual_call_ir_i $<* fn ll_int_mod_ovf_zer__Signed_Signed>,
I[%i0, %i1], R[], <Descr> -> %i2
+ residual_call_ir_i $<* fn ll_int_py_mod_ovf_zer__Signed_Signed>,
I[%i0, %i1], R[], <Descr> -> %i2
-live-
catch_exception L1
int_return %i2
diff --git a/rpython/jit/codewriter/test/test_support.py
b/rpython/jit/codewriter/test/test_support.py
--- a/rpython/jit/codewriter/test/test_support.py
+++ b/rpython/jit/codewriter/test/test_support.py
@@ -144,11 +144,13 @@
assert _ll_1_int_abs(-10) == 10
assert _ll_1_int_abs(-sys.maxint) == sys.maxint
-def test_int_floordiv():
+def test_int_floordiv_mod():
from rpython.rtyper.lltypesystem.lloperation import llop
- from rpython.jit.codewriter.support import _ll_2_int_floordiv
+ from rpython.jit.codewriter.support import _ll_2_int_floordiv,
_ll_2_int_mod
for x in range(-6, 7):
for y in range(-3, 4):
if y != 0:
assert (_ll_2_int_floordiv(x, y) ==
llop.int_floordiv(lltype.Signed, x, y))
+ assert (_ll_2_int_mod(x, y) ==
+ llop.int_mod(lltype.Signed, x, y))
diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py
b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -97,17 +97,14 @@
self.emit_operation(op)
r = self.getintbound(op)
- if b2.is_constant():
- val = b2.lower
- if val >= 0:
- r.intersect(IntBound(0, val))
- elif b1.is_constant():
- val = b1.lower
- if val >= 0:
- r.intersect(IntBound(0, val))
- elif b1.known_ge(IntBound(0, 0)) and b2.known_ge(IntBound(0, 0)):
- lesser = min(b1.upper, b2.upper)
- r.intersect(IntBound(0, next_pow2_m1(lesser)))
+ pos1 = b1.known_ge(IntBound(0, 0))
+ pos2 = b2.known_ge(IntBound(0, 0))
+ if pos1 or pos2:
+ r.make_ge(IntBound(0, 0))
+ if pos1:
+ r.make_le(b1)
+ if pos2:
+ r.make_le(b2)
def optimize_INT_SUB(self, op):
self.emit_operation(op)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -5188,6 +5188,25 @@
"""
self.optimize_loop(ops, ops)
+ def test_int_and_positive(self):
+ ops = """
+ [i0, i1]
+ i2 = int_ge(i1, 0)
+ guard_true(i2) []
+ i3 = int_and(i0, i1)
+ i4 = int_ge(i3, 0)
+ guard_true(i4) []
+ jump(i3)
+ """
+ expected = """
+ [i0, i1]
+ i2 = int_ge(i1, 0)
+ guard_true(i2) []
+ i3 = int_and(i0, i1)
+ jump(i3)
+ """
+ self.optimize_loop(ops, expected)
+
def test_int_or_cmp_above_bounds(self):
ops = """
[p0,p1]
diff --git a/rpython/jit/metainterp/test/test_ajit.py
b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -972,6 +972,58 @@
assert res == expected
# should contain a call_i(..., OS=OS_INT_PY_DIV)
+ def test_int_c_mod(self):
+ from rpython.rlib.rarithmetic import int_c_mod
+ myjitdriver = JitDriver(greens = [], reds = ['i', 't'])
+ def f(i):
+ t = 0
+ while i < 10:
+ myjitdriver.can_enter_jit(i=i, t=t)
+ myjitdriver.jit_merge_point(i=i, t=t)
+ t += int_c_mod(-100, i)
+ i += 1
+ return t
+ expected = -sum([100 % n for n in range(1, 10)])
+ assert f(1) == expected
+ res = self.meta_interp(f, [1])
+ assert res == expected
+ # should contain a call_i(..., OS=OS_INT_PY_MOD)
+
+ def test_positive_c_div_mod(self):
+ from rpython.rlib.rarithmetic import int_c_div, int_c_mod
+ myjitdriver = JitDriver(greens = [], reds = ['i', 't'])
+ def f(i):
+ t = 0
+ while i < 10:
+ myjitdriver.can_enter_jit(i=i, t=t)
+ myjitdriver.jit_merge_point(i=i, t=t)
+ assert i > 0
+ t += int_c_div(100, i) - int_c_mod(100, i)
+ i += 1
+ return t
+ expected = sum([100 // n - 100 % n for n in range(1, 10)])
+ assert f(1) == expected
+ res = self.meta_interp(f, [1])
+ assert res == expected
+ # all the correction code should be dead now, xxx test that
+
+ def test_int_c_div_by_constant(self):
+ from rpython.rlib.rarithmetic import int_c_div
+ myjitdriver = JitDriver(greens = ['k'], reds = ['i', 't'])
+ def f(i, k):
+ t = 0
+ while i < 100:
+ myjitdriver.can_enter_jit(i=i, t=t, k=k)
+ myjitdriver.jit_merge_point(i=i, t=t, k=k)
+ t += int_c_div(i, k)
+ i += 1
+ return t
+ expected = sum([i // 10 for i in range(51, 100)])
+ assert f(-50, 10) == expected
+ res = self.meta_interp(f, [-50, 10])
+ assert res == expected
+ self.check_resops(call=0, uint_mul_high=2)
+
def test_float(self):
myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
def f(x, y):
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -281,11 +281,12 @@
large_object=8*WORD,
ArenaCollectionClass=None,
**kwds):
+ "NOT_RPYTHON"
MovingGCBase.__init__(self, config, **kwds)
assert small_request_threshold % WORD == 0
self.read_from_env = read_from_env
self.nursery_size = nursery_size
-
+
self.small_request_threshold = small_request_threshold
self.major_collection_threshold = major_collection_threshold
self.growth_rate_max = growth_rate_max
@@ -644,6 +645,7 @@
# Get the memory from the nursery. If there is not enough space
# there, do a collect first.
result = self.nursery_free
+ ll_assert(result != llmemory.NULL, "uninitialized nursery")
self.nursery_free = new_free = result + totalsize
if new_free > self.nursery_top:
result = self.collect_and_reserve(totalsize)
@@ -703,6 +705,7 @@
# Get the memory from the nursery. If there is not enough space
# there, do a collect first.
result = self.nursery_free
+ ll_assert(result != llmemory.NULL, "uninitialized nursery")
self.nursery_free = new_free = result + totalsize
if new_free > self.nursery_top:
result = self.collect_and_reserve(totalsize)
@@ -1139,7 +1142,8 @@
Implemented a bit obscurely by checking an unrelated flag
that can never be set on a young object -- except if tid == -42.
"""
- assert self.is_in_nursery(obj)
+ ll_assert(self.is_in_nursery(obj),
+ "Can't forward an object outside the nursery.")
tid = self.header(obj).tid
result = (tid & GCFLAG_FINALIZATION_ORDERING != 0)
if result:
@@ -1463,7 +1467,8 @@
objhdr.tid |= GCFLAG_CARDS_SET
remember_young_pointer_from_array2._dont_inline_ = True
- assert self.card_page_indices > 0
+ ll_assert(self.card_page_indices > 0,
+ "non-positive card_page_indices")
self.remember_young_pointer_from_array2 = (
remember_young_pointer_from_array2)
@@ -1513,7 +1518,8 @@
return True
# ^^^ a fast path of write-barrier
#
- if source_hdr.tid & GCFLAG_HAS_CARDS != 0:
+ if (self.card_page_indices > 0 and # check constant-folded
+ source_hdr.tid & GCFLAG_HAS_CARDS != 0):
#
if source_hdr.tid & GCFLAG_TRACK_YOUNG_PTRS == 0:
# The source object may have random young pointers.
@@ -1548,7 +1554,8 @@
def manually_copy_card_bits(self, source_addr, dest_addr, length):
# manually copy the individual card marks from source to dest
- assert self.card_page_indices > 0
+ ll_assert(self.card_page_indices > 0,
+ "non-positive card_page_indices")
bytes = self.card_marking_bytes_for_length(length)
#
anybyte = 0
@@ -1721,12 +1728,15 @@
nursery_barriers = self.AddressDeque()
prev = self.nursery
self.surviving_pinned_objects.sort()
- assert self.pinned_objects_in_nursery == \
- self.surviving_pinned_objects.length()
+ ll_assert(
+ self.pinned_objects_in_nursery == \
+ self.surviving_pinned_objects.length(),
+ "pinned_objects_in_nursery != surviving_pinned_objects.length()")
while self.surviving_pinned_objects.non_empty():
#
cur = self.surviving_pinned_objects.pop()
- assert cur >= prev
+ ll_assert(
+ cur >= prev, "pinned objects encountered in backwards order")
#
# clear the arena between the last pinned object (or arena start)
# and the pinned object
@@ -1784,7 +1794,8 @@
debug_stop("gc-minor")
def _reset_flag_old_objects_pointing_to_pinned(self, obj, ignore):
- assert self.header(obj).tid & GCFLAG_PINNED_OBJECT_PARENT_KNOWN
+ ll_assert(self.header(obj).tid & GCFLAG_PINNED_OBJECT_PARENT_KNOWN !=
0,
+ "!GCFLAG_PINNED_OBJECT_PARENT_KNOWN, but requested to
reset.")
self.header(obj).tid &= ~GCFLAG_PINNED_OBJECT_PARENT_KNOWN
def _visit_old_objects_pointing_to_pinned(self, obj, ignore):
diff --git a/rpython/memory/gc/test/test_direct.py
b/rpython/memory/gc/test/test_direct.py
--- a/rpython/memory/gc/test/test_direct.py
+++ b/rpython/memory/gc/test/test_direct.py
@@ -554,6 +554,7 @@
assert res # we optimized it
assert hdr_dst.tid & minimark.GCFLAG_TRACK_YOUNG_PTRS == 0 # and we
copied the flag
#
+ self.gc.card_page_indices = 128 # force > 0
hdr_src.tid |= minimark.GCFLAG_TRACK_YOUNG_PTRS
hdr_dst.tid |= minimark.GCFLAG_TRACK_YOUNG_PTRS
hdr_src.tid |= minimark.GCFLAG_HAS_CARDS
diff --git a/rpython/rlib/clibffi.py b/rpython/rlib/clibffi.py
--- a/rpython/rlib/clibffi.py
+++ b/rpython/rlib/clibffi.py
@@ -148,7 +148,8 @@
('elements', FFI_TYPE_PP)])
ffi_cif = rffi_platform.Struct('ffi_cif', [])
- ffi_closure = rffi_platform.Struct('ffi_closure', [])
+ ffi_closure = rffi_platform.Struct('ffi_closure',
+ [('user_data', rffi.VOIDP)])
def add_simple_type(type_name):
for name in ['size', 'alignment', 'type']:
diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -662,6 +662,14 @@
from rpython.rtyper.lltypesystem.lloperation import llop
return llop.int_floordiv(lltype.Signed, x, y)
+def int_c_mod(x, y):
+ """Return the result of the C-style 'x % y'. This differs from the
+ Python-style division if (x < 0 xor y < 0).
+ """
+ from rpython.rtyper.lltypesystem import lltype
+ from rpython.rtyper.lltypesystem.lloperation import llop
+ return llop.int_mod(lltype.Signed, x, y)
+
@objectmodel.specialize.ll()
def byteswap(arg):
""" Convert little->big endian and the opposite
diff --git a/rpython/rlib/rvmprof/src/vmprof_config.h
b/rpython/rlib/rvmprof/src/vmprof_config.h
--- a/rpython/rlib/rvmprof/src/vmprof_config.h
+++ b/rpython/rlib/rvmprof/src/vmprof_config.h
@@ -1,10 +1,17 @@
-#define HAVE_SYS_UCONTEXT_H
+#if !defined(__OpenBSD__)
+# define HAVE_SYS_UCONTEXT_H
+#else
+# define HAVE_SIGNAL_H
+#endif
+
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#ifdef __i386__
#define PC_FROM_UCONTEXT uc_mcontext.mc_eip
#else
#define PC_FROM_UCONTEXT uc_mcontext.mc_rip
#endif
+#elif defined(__OpenBSD__)
+#define PC_FROM_UCONTEXT sc_rip
#elif defined( __APPLE__)
#if ((ULONG_MAX) == (UINT_MAX))
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip
diff --git a/rpython/rlib/rvmprof/src/vmprof_getpc.h
b/rpython/rlib/rvmprof/src/vmprof_getpc.h
--- a/rpython/rlib/rvmprof/src/vmprof_getpc.h
+++ b/rpython/rlib/rvmprof/src/vmprof_getpc.h
@@ -65,6 +65,10 @@
#elif defined(HAVE_CYGWIN_SIGNAL_H)
#include <cygwin/signal.h>
typedef ucontext ucontext_t;
+#elif defined(HAVE_SIGNAL_H)
+#include <signal.h>
+#else
+# error "don't know how to get the pc on this platform"
#endif
diff --git a/rpython/rlib/test/test_rarithmetic.py
b/rpython/rlib/test/test_rarithmetic.py
--- a/rpython/rlib/test/test_rarithmetic.py
+++ b/rpython/rlib/test/test_rarithmetic.py
@@ -401,10 +401,13 @@
@given(strategies.integers(min_value=0, max_value=sys.maxint),
strategies.integers(min_value=1, max_value=sys.maxint))
-def test_int_c_div(x, y):
+def test_int_c_div_mod(x, y):
assert int_c_div(~x, y) == -(abs(~x) // y)
assert int_c_div( x,-y) == -(x // y)
assert int_c_div(~x,-y) == +(abs(~x) // y)
+ for x1 in [x, ~x]:
+ for y1 in [y, -y]:
+ assert int_c_div(x1, y1) * y1 + int_c_mod(x1, y1) == x1
# these can't be prebuilt on 32bit
U1 = r_ulonglong(0x0102030405060708L)
diff --git a/rpython/rtyper/rint.py b/rpython/rtyper/rint.py
--- a/rpython/rtyper/rint.py
+++ b/rpython/rtyper/rint.py
@@ -236,11 +236,11 @@
return _rtype_template(hop, 'mul_ovf')
def rtype_floordiv(_, hop):
- return _rtype_call_helper(hop, 'floordiv', [ZeroDivisionError])
+ return _rtype_call_helper(hop, 'py_div', [ZeroDivisionError])
rtype_inplace_floordiv = rtype_floordiv
def rtype_floordiv_ovf(_, hop):
- return _rtype_call_helper(hop, 'floordiv_ovf', [ZeroDivisionError])
+ return _rtype_call_helper(hop, 'py_div_ovf', [ZeroDivisionError])
# turn 'div' on integers into 'floordiv'
rtype_div = rtype_floordiv
@@ -250,11 +250,11 @@
# 'def rtype_truediv' is delegated to the superclass FloatRepr
def rtype_mod(_, hop):
- return _rtype_call_helper(hop, 'mod', [ZeroDivisionError])
+ return _rtype_call_helper(hop, 'py_mod', [ZeroDivisionError])
rtype_inplace_mod = rtype_mod
def rtype_mod_ovf(_, hop):
- return _rtype_call_helper(hop, 'mod_ovf', [ZeroDivisionError])
+ return _rtype_call_helper(hop, 'py_mod_ovf', [ZeroDivisionError])
def rtype_xor(_, hop):
return _rtype_template(hop, 'xor')
@@ -319,7 +319,7 @@
vlist = hop.inputargs(repr, repr2)
prefix = repr.opprefix
- if '_ovf' in func or func.startswith(('mod', 'floordiv')):
+ if '_ovf' in func or func.startswith(('py_mod', 'py_div')):
if prefix+func not in ('int_add_ovf', 'int_add_nonneg_ovf',
'int_sub_ovf', 'int_mul_ovf'):
raise TyperError("%r should not be used here any more" % (func,))
@@ -353,7 +353,7 @@
any_implicit_exception = True
if not any_implicit_exception:
- if not func.startswith(('mod', 'floordiv')):
+ if not func.startswith(('py_mod', 'py_div')):
return _rtype_template(hop, func)
repr = hop.r_result
@@ -388,7 +388,7 @@
# ---------- floordiv ----------
@jit.oopspec("int.py_div(x, y)")
-def ll_int_floordiv(x, y):
+def ll_int_py_div(x, y):
# Python, and RPython, assume that integer division truncates
# towards -infinity. However, in C, integer division truncates
# towards 0. So assuming that, we need to apply a correction
@@ -400,159 +400,159 @@
return r + (u >> INT_BITS_1)
@jit.oopspec("int.py_div(x, y)")
-def ll_int_floordiv_nonnegargs(x, y):
+def ll_int_py_div_nonnegargs(x, y):
from rpython.rlib.debug import ll_assert
r = llop.int_floordiv(Signed, x, y) # <= truncates like in C
- ll_assert(r >= 0, "int_floordiv_nonnegargs(): one arg is negative")
+ ll_assert(r >= 0, "int_py_div_nonnegargs(): one arg is negative")
return r
-def ll_int_floordiv_zer(x, y):
+def ll_int_py_div_zer(x, y):
if y == 0:
raise ZeroDivisionError("integer division")
- return ll_int_floordiv(x, y)
+ return ll_int_py_div(x, y)
-def ll_int_floordiv_ovf(x, y):
+def ll_int_py_div_ovf(x, y):
# JIT: intentionally not short-circuited to produce only one guard
# and to remove the check fully if one of the arguments is known
if (x == -sys.maxint - 1) & (y == -1):
raise OverflowError("integer division")
- return ll_int_floordiv(x, y)
+ return ll_int_py_div(x, y)
-def ll_int_floordiv_ovf_zer(x, y):
+def ll_int_py_div_ovf_zer(x, y):
if y == 0:
raise ZeroDivisionError("integer division")
- return ll_int_floordiv_ovf(x, y)
+ return ll_int_py_div_ovf(x, y)
@jit.oopspec("int.udiv(x, y)")
-def ll_uint_floordiv(x, y):
+def ll_uint_py_div(x, y):
return llop.uint_floordiv(Unsigned, x, y)
-def ll_uint_floordiv_zer(x, y):
+def ll_uint_py_div_zer(x, y):
if y == 0:
raise ZeroDivisionError("unsigned integer division")
- return ll_uint_floordiv(x, y)
+ return ll_uint_py_div(x, y)
if SignedLongLong == Signed:
- ll_llong_floordiv = ll_int_floordiv
- ll_llong_floordiv_zer = ll_int_floordiv_zer
- ll_ullong_floordiv = ll_uint_floordiv
- ll_ullong_floordiv_zer = ll_uint_floordiv_zer
+ ll_llong_py_div = ll_int_py_div
+ ll_llong_py_div_zer = ll_int_py_div_zer
+ ll_ullong_py_div = ll_uint_py_div
+ ll_ullong_py_div_zer = ll_uint_py_div_zer
else:
@jit.dont_look_inside
- def ll_llong_floordiv(x, y):
+ def ll_llong_py_div(x, y):
r = llop.llong_floordiv(SignedLongLong, x, y) # <= truncates like in C
p = r * y
if y < 0: u = p - x
else: u = x - p
return r + (u >> LLONG_BITS_1)
- def ll_llong_floordiv_zer(x, y):
+ def ll_llong_py_div_zer(x, y):
if y == 0:
raise ZeroDivisionError("longlong division")
- return ll_llong_floordiv(x, y)
+ return ll_llong_py_div(x, y)
@jit.dont_look_inside
- def ll_ullong_floordiv(x, y):
+ def ll_ullong_py_div(x, y):
return llop.ullong_floordiv(UnsignedLongLong, x, y)
- def ll_ullong_floordiv_zer(x, y):
+ def ll_ullong_py_div_zer(x, y):
if y == 0:
raise ZeroDivisionError("unsigned longlong division")
- return ll_ullong_floordiv(x, y)
+ return ll_ullong_py_div(x, y)
@jit.dont_look_inside
-def ll_lllong_floordiv(x, y):
+def ll_lllong_py_div(x, y):
r = llop.lllong_floordiv(SignedLongLongLong, x, y) # <= truncates like in C
p = r * y
if y < 0: u = p - x
else: u = x - p
return r + (u >> LLLONG_BITS_1)
-def ll_lllong_floordiv_zer(x, y):
+def ll_lllong_py_div_zer(x, y):
if y == 0:
raise ZeroDivisionError("longlonglong division")
- return ll_lllong_floordiv(x, y)
+ return ll_lllong_py_div(x, y)
# ---------- mod ----------
@jit.oopspec("int.py_mod(x, y)")
-def ll_int_mod(x, y):
+def ll_int_py_mod(x, y):
r = llop.int_mod(Signed, x, y) # <= truncates like in C
if y < 0: u = -r
else: u = r
return r + (y & (u >> INT_BITS_1))
@jit.oopspec("int.py_mod(x, y)")
-def ll_int_mod_nonnegargs(x, y):
+def ll_int_py_mod_nonnegargs(x, y):
from rpython.rlib.debug import ll_assert
r = llop.int_mod(Signed, x, y) # <= truncates like in C
- ll_assert(r >= 0, "int_mod_nonnegargs(): one arg is negative")
+ ll_assert(r >= 0, "int_py_mod_nonnegargs(): one arg is negative")
return r
-def ll_int_mod_zer(x, y):
+def ll_int_py_mod_zer(x, y):
if y == 0:
raise ZeroDivisionError
- return ll_int_mod(x, y)
+ return ll_int_py_mod(x, y)
-def ll_int_mod_ovf(x, y):
- # see comment in ll_int_floordiv_ovf
+def ll_int_py_mod_ovf(x, y):
+ # see comment in ll_int_py_div_ovf
if (x == -sys.maxint - 1) & (y == -1):
raise OverflowError
- return ll_int_mod(x, y)
+ return ll_int_py_mod(x, y)
-def ll_int_mod_ovf_zer(x, y):
+def ll_int_py_mod_ovf_zer(x, y):
if y == 0:
raise ZeroDivisionError
- return ll_int_mod_ovf(x, y)
+ return ll_int_py_mod_ovf(x, y)
@jit.oopspec("int.umod(x, y)")
-def ll_uint_mod(x, y):
+def ll_uint_py_mod(x, y):
return llop.uint_mod(Unsigned, x, y)
-def ll_uint_mod_zer(x, y):
+def ll_uint_py_mod_zer(x, y):
if y == 0:
raise ZeroDivisionError
- return ll_uint_mod(x, y)
+ return ll_uint_py_mod(x, y)
if SignedLongLong == Signed:
- ll_llong_mod = ll_int_mod
- ll_llong_mod_zer = ll_int_mod_zer
- ll_ullong_mod = ll_uint_mod
- ll_ullong_mod_zer = ll_uint_mod_zer
+ ll_llong_py_mod = ll_int_py_mod
+ ll_llong_py_mod_zer = ll_int_py_mod_zer
+ ll_ullong_py_mod = ll_uint_py_mod
+ ll_ullong_py_mod_zer = ll_uint_py_mod_zer
else:
@jit.dont_look_inside
- def ll_llong_mod(x, y):
+ def ll_llong_py_mod(x, y):
r = llop.llong_mod(SignedLongLong, x, y) # <= truncates like in C
if y < 0: u = -r
else: u = r
return r + (y & (u >> LLONG_BITS_1))
- def ll_llong_mod_zer(x, y):
+ def ll_llong_py_mod_zer(x, y):
if y == 0:
raise ZeroDivisionError
- return ll_llong_mod(x, y)
+ return ll_llong_py_mod(x, y)
@jit.dont_look_inside
- def ll_ullong_mod(x, y):
+ def ll_ullong_py_mod(x, y):
return llop.ullong_mod(UnsignedLongLong, x, y)
- def ll_ullong_mod_zer(x, y):
+ def ll_ullong_py_mod_zer(x, y):
if y == 0:
raise ZeroDivisionError
return llop.ullong_mod(UnsignedLongLong, x, y)
@jit.dont_look_inside
-def ll_lllong_mod(x, y):
+def ll_lllong_py_mod(x, y):
r = llop.lllong_mod(SignedLongLongLong, x, y) # <= truncates like in C
if y < 0: u = -r
else: u = r
return r + (y & (u >> LLLONG_BITS_1))
-def ll_lllong_mod_zer(x, y):
+def ll_lllong_py_mod_zer(x, y):
if y == 0:
raise ZeroDivisionError
- return ll_lllong_mod(x, y)
+ return ll_lllong_py_mod(x, y)
# ---------- lshift, neg, abs ----------
diff --git a/rpython/rtyper/test/test_rint.py b/rpython/rtyper/test/test_rint.py
--- a/rpython/rtyper/test/test_rint.py
+++ b/rpython/rtyper/test/test_rint.py
@@ -390,7 +390,7 @@
res = self.interpret(f, [sys.maxint])
assert res == 0
- def test_int_floordiv_nonnegargs(self):
+ def test_int_py_div_nonnegargs(self):
def f(x, y):
assert x >= 0
assert y >= 0
@@ -398,7 +398,7 @@
res = self.interpret(f, [1234567, 123])
assert res == 1234567 // 123
- def test_int_mod_nonnegargs(self):
+ def test_int_py_mod_nonnegargs(self):
def f(x, y):
assert x >= 0
assert y >= 0
diff --git a/rpython/translator/sandbox/sandlib.py
b/rpython/translator/sandbox/sandlib.py
--- a/rpython/translator/sandbox/sandlib.py
+++ b/rpython/translator/sandbox/sandlib.py
@@ -530,6 +530,9 @@
def do_ll_os__ll_os_unlink(self, vpathname):
raise OSError(errno.EPERM, "write access denied")
+ def do_ll_os__ll_os_mkdir(self, vpathname, mode=None):
+ raise OSError(errno.EPERM, "write access denied")
+
def do_ll_os__ll_os_getuid(self):
return UID
do_ll_os__ll_os_geteuid = do_ll_os__ll_os_getuid
diff --git a/rpython/translator/test/test_simplify.py
b/rpython/translator/test/test_simplify.py
--- a/rpython/translator/test/test_simplify.py
+++ b/rpython/translator/test/test_simplify.py
@@ -55,7 +55,7 @@
graph, _ = translate(f, [int, int], backend_optimize=False)
assert len(graph.startblock.operations) == 1
assert graph.startblock.operations[0].opname == 'direct_call'
- assert 'int_floordiv_ovf_zer' in repr(
+ assert 'int_py_div_ovf_zer' in repr(
graph.startblock.operations[0].args[0].value)
assert len(graph.startblock.exits) == 3
assert [link.target.operations for link in graph.startblock.exits[1:]] == \
@@ -73,7 +73,7 @@
graph, _ = translate(f, [int, int], backend_optimize=False)
assert len(graph.startblock.operations) == 1
assert graph.startblock.operations[0].opname == 'direct_call'
- assert 'int_floordiv_ovf_zer' in repr(
+ assert 'int_py_div_ovf_zer' in repr(
graph.startblock.operations[0].args[0].value)
assert len(graph.startblock.exits) == 3
assert [link.target.operations for link in graph.startblock.exits[1:]] == \
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit