[pypy-commit] pypy py3.6: Use @support.refcount_test to skip tests relying on sys.getrefcount()
Author: Ronan Lamy Branch: py3.6 Changeset: r97314:18630a74b4d0 Date: 2019-08-27 19:56 +0100 http://bitbucket.org/pypy/pypy/changeset/18630a74b4d0/ Log:Use @support.refcount_test to skip tests relying on sys.getrefcount() diff --git a/lib-python/3/ctypes/test/test_memfunctions.py b/lib-python/3/ctypes/test/test_memfunctions.py --- a/lib-python/3/ctypes/test/test_memfunctions.py +++ b/lib-python/3/ctypes/test/test_memfunctions.py @@ -52,7 +52,7 @@ self.assertEqual(cast(a, POINTER(c_byte))[:7:7], [97]) -@support.refcount_test +#@support.refcount_test def test_string_at(self): s = string_at(b"foo bar") # XXX The following may be wrong, depending on how Python diff --git a/lib-python/3/ctypes/test/test_refcounts.py b/lib-python/3/ctypes/test/test_refcounts.py --- a/lib-python/3/ctypes/test/test_refcounts.py +++ b/lib-python/3/ctypes/test/test_refcounts.py @@ -13,10 +13,7 @@ @support.refcount_test def test_1(self): -try: -from sys import getrefcount as grc -except ImportError: -return unittest.skip("no sys.getrefcount()") +from sys import getrefcount as grc f = dll._testfunc_callback_i_if f.restype = ctypes.c_int @@ -41,10 +38,7 @@ @support.refcount_test def test_refcount(self): -try: -from sys import getrefcount as grc -except ImportError: -return unittest.skip("no sys.getrefcount()") +from sys import getrefcount as grc def func(*args): pass # this is the standard refcount for func @@ -91,19 +85,15 @@ self.assertEqual(grc(func), 2) class AnotherLeak(unittest.TestCase): +@support.refcount_test def test_callback(self): import sys -try: -from sys import getrefcount -except ImportError: -return unittest.skip("no sys.getrefcount()") proto = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int) def func(a, b): return a * b * 2 f = proto(func) -gc.collect() a = sys.getrefcount(ctypes.c_int) f(1, 2) self.assertEqual(sys.getrefcount(ctypes.c_int), a) diff --git a/lib-python/3/test/test_coroutines.py b/lib-python/3/test/test_coroutines.py --- a/lib-python/3/test/test_coroutines.py +++ b/lib-python/3/test/test_coroutines.py @@ -2078,15 +2078,6 @@ support.gc_collect() self.assertIn("was never awaited", stderr.getvalue()) -def test_fatal_coro_warning(self): -# Issue 27811 -async def func(): pass -with warnings.catch_warnings(), support.captured_stderr() as stderr: -warnings.filterwarnings("error") -func() -support.gc_collect() -self.assertIn("was never awaited", stderr.getvalue()) - class CoroAsyncIOCompatTest(unittest.TestCase): diff --git a/lib-python/3/test/test_socket.py b/lib-python/3/test/test_socket.py --- a/lib-python/3/test/test_socket.py +++ b/lib-python/3/test/test_socket.py @@ -4218,12 +4218,12 @@ self.write_file.write(self.write_msg) self.write_file.flush() +@support.refcount_test def testMakefileCloseSocketDestroy(self): -if hasattr(sys, "getrefcount"): -refcount_before = sys.getrefcount(self.cli_conn) -self.read_file.close() -refcount_after = sys.getrefcount(self.cli_conn) -self.assertEqual(refcount_before - 1, refcount_after) +refcount_before = sys.getrefcount(self.cli_conn) +self.read_file.close() +refcount_after = sys.getrefcount(self.cli_conn) +self.assertEqual(refcount_before - 1, refcount_after) def _testMakefileCloseSocketDestroy(self): pass diff --git a/lib-python/3/unittest/test/test_case.py b/lib-python/3/unittest/test/test_case.py --- a/lib-python/3/unittest/test/test_case.py +++ b/lib-python/3/unittest/test/test_case.py @@ -1287,8 +1287,7 @@ with self.assertRaises(TypeError): self.assertRaises((ValueError, object)) -@unittest.skipUnless(hasattr(sys, 'getrefcount'), - 'test needs sys.getrefcount()') +@support.refcount_test def testAssertRaisesRefcount(self): # bpo-23890: assertRaises() must not keep objects alive longer # than expected ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Don't use @xfail for tests that can't possibly work on pypy
Author: Ronan Lamy Branch: py3.6 Changeset: r97313:dfa10ae95bae Date: 2019-08-27 19:41 +0100 http://bitbucket.org/pypy/pypy/changeset/dfa10ae95bae/ Log:Don't use @xfail for tests that can't possibly work on pypy diff --git a/lib-python/3/ctypes/test/test_callbacks.py b/lib-python/3/ctypes/test/test_callbacks.py --- a/lib-python/3/ctypes/test/test_callbacks.py +++ b/lib-python/3/ctypes/test/test_callbacks.py @@ -1,7 +1,7 @@ import functools import unittest +from test import support from ctypes import * -from ctypes.test import xfail from ctypes.test import need_symbol import _ctypes_test @@ -96,7 +96,7 @@ self.check_type(c_char_p, "abc") self.check_type(c_char_p, "def") -@xfail +@support.refcount_test def test_pyobject(self): o = () from sys import getrefcount as grc diff --git a/lib-python/3/ctypes/test/test_python_api.py b/lib-python/3/ctypes/test/test_python_api.py --- a/lib-python/3/ctypes/test/test_python_api.py +++ b/lib-python/3/ctypes/test/test_python_api.py @@ -1,5 +1,4 @@ from ctypes import * -from ctypes.test import xfail import unittest, sys from test import support @@ -19,9 +18,9 @@ else: c_py_ssize_t = c_int +@support.cpython_only class PythonAPITestCase(unittest.TestCase): -@xfail def test_PyBytes_FromStringAndSize(self): PyBytes_FromStringAndSize = pythonapi.PyBytes_FromStringAndSize @@ -71,7 +70,6 @@ del pyobj self.assertEqual(grc(s), ref) -@xfail def test_PyOS_snprintf(self): PyOS_snprintf = pythonapi.PyOS_snprintf PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p @@ -86,7 +84,6 @@ # not enough arguments self.assertRaises(TypeError, PyOS_snprintf, buf) -@xfail def test_pyobject_repr(self): self.assertEqual(repr(py_object()), "py_object()") self.assertEqual(repr(py_object(42)), "py_object(42)") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: fix old merge cruft
Author: Ronan Lamy Branch: py3.6 Changeset: r97312:b70c9c1a4b02 Date: 2019-08-27 18:34 +0100 http://bitbucket.org/pypy/pypy/changeset/b70c9c1a4b02/ Log:fix old merge cruft diff --git a/lib-python/3/test/support/__init__.py b/lib-python/3/test/support/__init__.py --- a/lib-python/3/test/support/__init__.py +++ b/lib-python/3/test/support/__init__.py @@ -2309,9 +2309,6 @@ requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'), 'types are immortal if COUNT_ALLOCS is defined') -requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'), -'types are immortal if COUNT_ALLOCS is defined') - def args_from_interpreter_flags(): """Return a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.""" diff --git a/lib-python/3/test/test_telnetlib.py b/lib-python/3/test/test_telnetlib.py --- a/lib-python/3/test/test_telnetlib.py +++ b/lib-python/3/test/test_telnetlib.py @@ -398,5 +398,4 @@ if __name__ == '__main__': -import unittest unittest.main() diff --git a/lib-python/3/test/test_typing.py b/lib-python/3/test/test_typing.py --- a/lib-python/3/test/test_typing.py +++ b/lib-python/3/test/test_typing.py @@ -628,15 +628,6 @@ with self.assertRaises(TypeError): class MyGeneric(List[T], Generic[S]): ... -def test_generic_errors(self): -T = TypeVar('T') -with self.assertRaises(TypeError): -Generic[T]() -with self.assertRaises(TypeError): -isinstance([], List[int]) -with self.assertRaises(TypeError): -issubclass(list, List[int]) - def test_init(self): T = TypeVar('T') S = TypeVar('S') diff --git a/lib-python/3/test/test_zipfile.py b/lib-python/3/test/test_zipfile.py --- a/lib-python/3/test/test_zipfile.py +++ b/lib-python/3/test/test_zipfile.py @@ -2251,71 +2251,5 @@ with open(path, 'rb') as f: self.assertEqual(f.read(), zf.read(zi)) - -class CommandLineTest(unittest.TestCase): - -def zipfilecmd(self, *args, **kwargs): -rc, out, err = script_helper.assert_python_ok('-m', 'zipfile', *args, - **kwargs) -return out.replace(os.linesep.encode(), b'\n') - -def zipfilecmd_failure(self, *args): -return script_helper.assert_python_failure('-m', 'zipfile', *args) - -def test_test_command(self): -zip_name = findfile('zipdir.zip') -out = self.zipfilecmd('-t', zip_name) -self.assertEqual(out.rstrip(), b'Done testing') -zip_name = findfile('testtar.tar') -rc, out, err = self.zipfilecmd_failure('-t', zip_name) -self.assertEqual(out, b'') - -def test_list_command(self): -zip_name = findfile('zipdir.zip') -t = io.StringIO() -with zipfile.ZipFile(zip_name, 'r') as tf: -tf.printdir(t) -expected = t.getvalue().encode('ascii', 'backslashreplace') -out = self.zipfilecmd('-l', zip_name, - PYTHONIOENCODING='ascii:backslashreplace') -self.assertEqual(out, expected) - -@requires_zlib -def test_create_command(self): -self.addCleanup(unlink, TESTFN) -with open(TESTFN, 'w') as f: -f.write('test 1') -os.mkdir(TESTFNDIR) -self.addCleanup(rmtree, TESTFNDIR) -with open(os.path.join(TESTFNDIR, 'file.txt'), 'w') as f: -f.write('test 2') -files = [TESTFN, TESTFNDIR] -namelist = [TESTFN, TESTFNDIR + '/', TESTFNDIR + '/file.txt'] -try: -out = self.zipfilecmd('-c', TESTFN2, *files) -self.assertEqual(out, b'') -with zipfile.ZipFile(TESTFN2) as zf: -self.assertEqual(zf.namelist(), namelist) -self.assertEqual(zf.read(namelist[0]), b'test 1') -self.assertEqual(zf.read(namelist[2]), b'test 2') -finally: -unlink(TESTFN2) - -def test_extract_command(self): -zip_name = findfile('zipdir.zip') -with temp_dir() as extdir: -out = self.zipfilecmd('-e', zip_name, extdir) -self.assertEqual(out, b'') -with zipfile.ZipFile(zip_name) as zf: -for zi in zf.infolist(): -path = os.path.join(extdir, -zi.filename.replace('/', os.sep)) -if zi.filename.endswith('/'): -self.assertTrue(os.path.isdir(path)) -else: -self.assertTrue(os.path.isfile(path)) -with open(path, 'rb') as f: -self.assertEqual(f.read(), zf.read(zi)) - if __name__ == "__main__": unittest.main() ___ pypy-commit mailing list pypy-commit@python.org
[pypy-commit] pypy py3.6: fix bad merge
Author: Ronan Lamy Branch: py3.6 Changeset: r97311:79ea93489fc4 Date: 2019-08-27 16:58 +0100 http://bitbucket.org/pypy/pypy/changeset/79ea93489fc4/ Log:fix bad merge diff --git a/lib-python/3/ssl.py b/lib-python/3/ssl.py --- a/lib-python/3/ssl.py +++ b/lib-python/3/ssl.py @@ -52,7 +52,8 @@ PROTOCOL_SSLv3 PROTOCOL_SSLv23 PROTOCOL_TLS -(??) +PROTOCOL_TLS_CLIENT +PROTOCOL_TLS_SERVER PROTOCOL_TLSv1 PROTOCOL_TLSv1_1 PROTOCOL_TLSv1_2 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Remove accidentally duplicated definition for isfuture()
Author: Ronan Lamy Branch: py3.6 Changeset: r97310:cfffac8c5062 Date: 2019-08-27 16:21 +0100 http://bitbucket.org/pypy/pypy/changeset/cfffac8c5062/ Log:Remove accidentally duplicated definition for isfuture() diff --git a/lib-python/3/asyncio/futures.py b/lib-python/3/asyncio/futures.py --- a/lib-python/3/asyncio/futures.py +++ b/lib-python/3/asyncio/futures.py @@ -107,17 +107,6 @@ self.loop.call_exception_handler({'message': msg}) -def isfuture(obj): -"""Check for a Future. - -This returns True when obj is a Future instance or is advertising -itself as duck-type compatible by setting _asyncio_future_blocking. -See comment in Future for more details. -""" -return (hasattr(obj.__class__, '_asyncio_future_blocking') and -obj._asyncio_future_blocking is not None) - - class Future: """This class is *almost* compatible with concurrent.futures.Future. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Remove file deleted in CPython
Author: Ronan Lamy Branch: py3.6 Changeset: r97308:92ad09ea1c06 Date: 2019-08-27 16:00 +0100 http://bitbucket.org/pypy/pypy/changeset/92ad09ea1c06/ Log:Remove file deleted in CPython diff --git a/lib-python/3/collections/__main__.py b/lib-python/3/collections/__main__.py deleted file mode 100644 --- a/lib-python/3/collections/__main__.py +++ /dev/null @@ -1,38 +0,0 @@ - -### Simple tests - - -# verify that instances can be pickled -from collections import namedtuple -from pickle import loads, dumps -Point = namedtuple('Point', 'x, y', True) -p = Point(x=10, y=20) -assert p == loads(dumps(p)) - -# test and demonstrate ability to override methods -class Point(namedtuple('Point', 'x y')): -__slots__ = () -@property -def hypot(self): -return (self.x ** 2 + self.y ** 2) ** 0.5 -def __str__(self): -return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot) - -for p in Point(3, 4), Point(14, 5/7.): -print (p) - -class Point(namedtuple('Point', 'x y')): -'Point class with optimized _make() and _replace() without error-checking' -__slots__ = () -_make = classmethod(tuple.__new__) -def _replace(self, _map=map, **kwds): -return self._make(_map(kwds.get, ('x', 'y'), self)) - -print(Point(11, 22)._replace(x=100)) - -Point3D = namedtuple('Point3D', Point._fields + ('z',)) -print(Point3D.__doc__) - -import doctest, collections -TestResults = namedtuple('TestResults', 'failed attempted') -print(TestResults(*doctest.testmod(collections))) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: test, fix cpython3 exception compatibility
Author: Matti Picus Branch: py3.6 Changeset: r97306:50fa3485909f Date: 2019-08-27 15:22 +0300 http://bitbucket.org/pypy/pypy/changeset/50fa3485909f/ Log:test, fix cpython3 exception compatibility diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py --- a/pypy/objspace/std/newformat.py +++ b/pypy/objspace/std/newformat.py @@ -545,7 +545,8 @@ pass # ok else: raise oefmt(space.w_ValueError, -"invalid type with ',' or '_'") +"Cannot specify '%s' with '%s'.", +self._thousands_sep, tp) return False def _calc_padding(self, string, length): diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py --- a/pypy/objspace/std/test/test_newformat.py +++ b/pypy/objspace/std/test/test_newformat.py @@ -260,7 +260,8 @@ a = self.i(ord("a")) assert format(a, "c") == "a" raises(ValueError, format, a, "-c") -raises(ValueError, format, a, ",c") +exc = raises(ValueError, format, a, ",c") +assert str(exc.value) == "Cannot specify ',' with 'c'.", str(exc.value) raises(ValueError, format, a, "_c") raises(ValueError, format, a, "#c") assert format(a, "3c") == " a" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: remove pdb from test
Author: Matti Picus Branch: Changeset: r97307:2fc0a2974836 Date: 2019-08-27 15:25 +0300 http://bitbucket.org/pypy/pypy/changeset/2fc0a2974836/ Log:remove pdb from test diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py --- a/rpython/rlib/test/test_rbigint.py +++ b/rpython/rlib/test/test_rbigint.py @@ -360,7 +360,6 @@ from rpython.rlib.rstring import NumberStringParser s = "-99" p = NumberStringParser(s, s, 10, 'int') -import pdb; pdb.set_trace() assert p.sign == -1 res = p.next_digit() assert res == 9 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: synch text of -O, -OO options to cpython, clean extraneous \n\
Author: Matti Picus Branch: py3.6 Changeset: r97305:c919b265937a Date: 2019-08-27 14:41 +0300 http://bitbucket.org/pypy/pypy/changeset/c919b265937a/ Log:synch text of -O, -OO options to cpython, clean extraneous \n\ diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -5,8 +5,8 @@ # Missing vs CPython: -x USAGE1 = __doc__ = """\ Options and arguments (and corresponding environment variables): --b : issue warnings about str(bytes_instance), str(bytearray_instance)\n\ - and comparing bytes/bytearray with str. (-bb: issue errors)\n\ +-b : issue warnings about str(bytes_instance), str(bytearray_instance) + and comparing bytes/bytearray with str. (-bb: issue errors) -B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x -c cmd : program passed in as string (terminates option list) -d : debug output from parser; also PYTHONDEBUG=x\n\ @@ -16,8 +16,10 @@ if stdin does not appear to be a terminal; also PYTHONINSPECT=x -I : isolate Python from the user's environment (implies -E and -s) -m mod : run library module as a script (terminates option list) --O : skip assert statements; also PYTHONOPTIMIZE=x --OO: remove docstrings when importing modules in addition to -O +-O : remove assert and __debug__-dependent statements; add .opt-1 before + .pyc extension; also PYTHONOPTIMIZE=x +-OO: do -O changes and also discard docstrings; add .opt-2 before + .pyc extension -q : don't print version and copyright messages on interactive startup -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE -S : don't imply 'import site' on initialization ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: remove pdb :-(
Author: Carl Friedrich Bolz-Tereick Branch: Changeset: r97304:7850e3eaeff8 Date: 2019-08-27 13:11 +0200 http://bitbucket.org/pypy/pypy/changeset/7850e3eaeff8/ Log:remove pdb :-( diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py --- a/rpython/rlib/rarithmetic.py +++ b/rpython/rlib/rarithmetic.py @@ -877,8 +877,6 @@ characters of 's'. Raises ParseStringError in case of error. Raises ParseStringOverflowError in case the result does not fit. """ -if "9" in s: -import pdb; pdb.set_trace() from rpython.rlib.rstring import ( NumberStringParser, ParseStringOverflowError) p = NumberStringParser(s, s, base, 'int', ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix untested rewind method
Author: Carl Friedrich Bolz-Tereick Branch: Changeset: r97303:0d2efab3484a Date: 2019-08-27 13:09 +0200 http://bitbucket.org/pypy/pypy/changeset/0d2efab3484a/ Log:fix untested rewind method diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py --- a/rpython/rlib/rarithmetic.py +++ b/rpython/rlib/rarithmetic.py @@ -877,6 +877,8 @@ characters of 's'. Raises ParseStringError in case of error. Raises ParseStringOverflowError in case the result does not fit. """ +if "9" in s: +import pdb; pdb.set_trace() from rpython.rlib.rstring import ( NumberStringParser, ParseStringOverflowError) p = NumberStringParser(s, s, base, 'int', diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py --- a/rpython/rlib/rstring.py +++ b/rpython/rlib/rstring.py @@ -568,7 +568,7 @@ self.end = q def rewind(self): -self.i = 0 +self.i = self.start def next_digit(self): # -1 => exhausted if self.i < self.end: diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py --- a/rpython/rlib/test/test_rbigint.py +++ b/rpython/rlib/test/test_rbigint.py @@ -356,6 +356,30 @@ assert rbigint.fromstr('123L', 21).tolong() == 441 + 42 + 3 assert rbigint.fromstr('1891234174197319').tolong() == 1891234174197319 +def test__from_numberstring_parser_rewind_bug(self): +from rpython.rlib.rstring import NumberStringParser +s = "-99" +p = NumberStringParser(s, s, 10, 'int') +import pdb; pdb.set_trace() +assert p.sign == -1 +res = p.next_digit() +assert res == 9 +res = p.next_digit() +assert res == 9 +res = p.next_digit() +assert res == -1 +p.rewind() +res = p.next_digit() +assert res == 9 +res = p.next_digit() +assert res == 9 +res = p.next_digit() +assert res == -1 + +@given(longs) +def test_fromstr_hypothesis(self, l): +assert rbigint.fromstr(str(l)).tolong() == l + def test_from_numberstring_parser(self): from rpython.rlib.rstring import NumberStringParser parser = NumberStringParser("1231231241", "1231231241", 10, "long") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: remove duplicate import
Author: Carl Friedrich Bolz-Tereick Branch: Changeset: r97302:8a5b5159abd4 Date: 2019-08-26 21:15 +0200 http://bitbucket.org/pypy/pypy/changeset/8a5b5159abd4/ Log:remove duplicate import diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -296,7 +296,6 @@ def fromstr(s, base=0, allow_underscores=False): """As string_to_int(), but ignores an optional 'l' or 'L' suffix and returns an rbigint.""" -from rpython.rlib.rstring import NumberStringParser from rpython.rlib.rstring import NumberStringParser, \ strip_spaces s = literal = strip_spaces(s) # XXX could get rid of this slice ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6-sandbox-2: hg merge sandbox-2
Author: Armin Rigo Branch: py3.6-sandbox-2 Changeset: r97297:dcecc1d7905b Date: 2019-08-27 10:38 +0200 http://bitbucket.org/pypy/pypy/changeset/dcecc1d7905b/ Log:hg merge sandbox-2 diff --git a/pypy/module/__pypy__/interp_time.py b/pypy/module/__pypy__/interp_time.py --- a/pypy/module/__pypy__/interp_time.py +++ b/pypy/module/__pypy__/interp_time.py @@ -6,10 +6,12 @@ from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib import rtime from rpython.rlib.rtime import HAS_CLOCK_GETTIME +from rpython.rlib.objectmodel import sandbox_review if HAS_CLOCK_GETTIME: +@sandbox_review(reviewed=True) @unwrap_spec(clk_id="c_int") def clock_gettime(space, clk_id): with lltype.scoped_alloc(rtime.TIMESPEC) as tp: @@ -20,6 +22,7 @@ float(rffi.getintfield(tp, 'c_tv_nsec')) * 0.1) return space.newfloat(t) +@sandbox_review(reviewed=True) @unwrap_spec(clk_id="c_int") def clock_getres(space, clk_id): with lltype.scoped_alloc(rtime.TIMESPEC) as tp: diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py --- a/pypy/module/_io/interp_fileio.py +++ b/pypy/module/_io/interp_fileio.py @@ -458,7 +458,7 @@ length = rwbuffer.getlength() target_address = lltype.nullptr(rffi.CCHARP.TO) -if length > 64: +if length > 64 and not space.config.translation.sandbox: try: target_address = rwbuffer.get_raw_address() except ValueError: @@ -480,6 +480,13 @@ else: # optimized case: reading more than 64 bytes into a rwbuffer # with a valid raw address + +# XXX note that this is not fully safe, because we don't "lock" +# the buffer so we can't in theory pass its raw address to c_read(). +# Another thread could cause it to be freed in parallel. +# Without proper buffer locking, it's not going to be fixed, though. +assert not space.config.translation.sandbox + while True: got = c_read(self.fd, target_address, length) keepalive_until_here(rwbuffer) diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -2227,7 +2227,13 @@ except OSError as e: # 'rurandom' should catch and retry internally if it gets EINTR # (at least in os.read(), which is probably enough in practice) -raise wrap_oserror(space, e, eintr_retry=False) +# +# CPython raises NotImplementedError if /dev/urandom cannot be found. +# To maximize compatibility, we should also raise NotImplementedError +# and not OSError (although CPython also raises OSError in case it +# could open /dev/urandom but there are further problems). +raise wrap_oserror(space, e, eintr_retry=False, +w_exception_class=space.w_NotImplementedError) def ctermid(space): """ctermid() -> string diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py --- a/rpython/rlib/jit.py +++ b/rpython/rlib/jit.py @@ -3,7 +3,9 @@ import py from rpython.rlib.nonconst import NonConstant -from rpython.rlib.objectmodel import CDefinedIntSymbolic, keepalive_until_here, specialize, not_rpython, we_are_translated +from rpython.rlib.objectmodel import CDefinedIntSymbolic, keepalive_until_here +from rpython.rlib.objectmodel import specialize, not_rpython, we_are_translated +from rpython.rlib.objectmodel import sandbox_review from rpython.rlib.unroll import unrolling_iterable from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.tool.sourcetools import rpython_wrapper @@ -1196,6 +1198,7 @@ def _jit_conditional_call(condition, function, *args): pass # special-cased below +@sandbox_review(reviewed=True) # for the llop.jit_conditional_call @specialize.call_location() def conditional_call(condition, function, *args): """Does the same as: @@ -1217,6 +1220,7 @@ def _jit_conditional_call_value(value, function, *args): return value# special-cased below +@sandbox_review(reviewed=True) # for the llop.jit_conditional_call_value @specialize.call_location() def conditional_call_elidable(value, function, *args): """Does the same as: diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py --- a/rpython/rlib/rarithmetic.py +++ b/rpython/rlib/rarithmetic.py @@ -878,9 +878,8 @@ Raises ParseStringOverflowError in case the result does not fit. """ from rpython.rlib.rstring import ( -NumberStringParser, ParseStringOverflowError, strip_spaces) -s = literal = strip_spaces(s) -p = NumberStringParser(s, literal, base, 'int', +NumberStringParser, ParseStringOverflowError) +p = NumberStringParser(s, s, base, 'int', allow_underscores=allow_underscores,
[pypy-commit] pypy py3.6-sandbox-2: Found out there are two versions of os.urandom() around, and
Author: Armin Rigo Branch: py3.6-sandbox-2 Changeset: r97301:3a1756763860 Date: 2019-08-27 11:56 +0200 http://bitbucket.org/pypy/pypy/changeset/3a1756763860/ Log:Found out there are two versions of os.urandom() around, and figured out when one is shadowed by the other diff --git a/pypy/module/_random/interp_random.py b/pypy/module/_random/interp_random.py --- a/pypy/module/_random/interp_random.py +++ b/pypy/module/_random/interp_random.py @@ -30,7 +30,8 @@ try: w_n = interp_posix.urandom(space, 8) except OperationError as e: -if not e.match(space, space.w_OSError): +if not (e.match(space, space.w_NotImplementedError) or +e.match(space, space.w_OSError)): raise w_n = space.newint(int(time.time() * 256)) if space.isinstance_w(w_n, space.w_int): diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py --- a/pypy/module/posix/app_posix.py +++ b/pypy/module/posix/app_posix.py @@ -156,6 +156,9 @@ Return a string of n random bytes suitable for cryptographic use. """ +# NOTE: we also have interp_posix.urandom(), which we use on Windows. +# XXX unsure we shouldn't be removing the code below, though, because +# the interp version seems more complete try: with open('/dev/urandom', 'rb', buffering=0) as fd: return fd.read(n) diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -2217,6 +2217,10 @@ Return a string of 'size' random bytes suitable for cryptographic use. """ +# NOTE: this is not used for 'os.urandom' on POSIX; instead, +# app_posix.urandom() is. However, module/_random/ actually +# calls this code directly. XXX Unsure the version in app_posix +# is needed (or complete enough) nowadays. context = get(space).random_context try: # urandom() takes a final argument that should be a regular function, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6-sandbox-2: More sandbox_reviews
Author: Armin Rigo Branch: py3.6-sandbox-2 Changeset: r97300:6dcefdad5651 Date: 2019-08-27 11:27 +0200 http://bitbucket.org/pypy/pypy/changeset/6dcefdad5651/ Log:More sandbox_reviews diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -10,7 +10,7 @@ from rpython.rlib import rposix, rposix_stat, rfile from rpython.rlib import objectmodel, rurandom -from rpython.rlib.objectmodel import specialize, not_rpython +from rpython.rlib.objectmodel import specialize, not_rpython, sandbox_review from rpython.rlib.rarithmetic import r_longlong, intmask, r_uint, r_int from rpython.rlib.unroll import unrolling_iterable from rpython.rtyper.lltypesystem import lltype @@ -2432,6 +2432,7 @@ if _WIN32: have_functions.append("HAVE_MS_WINDOWS") +@sandbox_review(reviewed=True) def _get_terminal_size(space, w_fd=None): if w_fd is None: fd = rfile.RFile(rfile.c_stdout(), close2=(None, None)).fileno() diff --git a/pypy/module/posix/interp_scandir.py b/pypy/module/posix/interp_scandir.py --- a/pypy/module/posix/interp_scandir.py +++ b/pypy/module/posix/interp_scandir.py @@ -2,6 +2,7 @@ from errno import ENOENT from rpython.rlib import rgc from rpython.rlib import rposix, rposix_scandir, rposix_stat +from rpython.rlib.objectmodel import sandbox_review from pypy.interpreter.gateway import unwrap_spec, WrappedDefault, interp2app from pypy.interpreter.error import OperationError, oefmt, wrap_oserror2 @@ -11,6 +12,7 @@ from pypy.module.posix.interp_posix import unwrap_fd, build_stat_result, _WIN32 +@sandbox_review(reviewed=True) def scandir(space, w_path=None): "scandir(path='.') -> iterator of DirEntry objects for given path" if space.is_none(w_path): @@ -78,6 +80,7 @@ e.write_unraisable(space, '', self) self._close() +@sandbox_review(reviewed=True) def _close(self): dirp = self.dirp if dirp: @@ -87,6 +90,7 @@ def iter_w(self): return self +@sandbox_review(reviewed=True) def fail(self, err=None): dirp = self.dirp if dirp: @@ -98,6 +102,7 @@ else: raise err +@sandbox_review(reviewed=True) def next_w(self): if not self.dirp: raise self.fail() diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py --- a/pypy/module/time/interp_time.py +++ b/pypy/module/time/interp_time.py @@ -286,6 +286,7 @@ else: c_gettimeofday = external('gettimeofday', [lltype.Ptr(TIMEVAL), rffi.VOIDP], rffi.INT) +@sandbox_review(reviewed=True) def gettimeofday(space, w_info=None): if HAVE_GETTIMEOFDAY: with lltype.scoped_alloc(TIMEVAL) as timeval: @@ -662,6 +663,7 @@ if not 0 <= rffi.getintfield(t_ref, 'c_tm_yday') <= 365: raise oefmt(space.w_ValueError, "day of year out of range") +@sandbox_review(reviewed=True) def time(space, w_info=None): """time() -> floating point number @@ -792,6 +794,7 @@ def _timespec_to_seconds(timespec): return widen(timespec.c_tv_sec) + widen(timespec.c_tv_nsec) * 1e-9 +@sandbox_review(reviewed=True) @unwrap_spec(clk_id='c_int') def clock_gettime(space, clk_id): with lltype.scoped_alloc(TIMESPEC) as timespec: @@ -813,6 +816,7 @@ if ret != 0: raise exception_from_saved_errno(space, space.w_OSError) +@sandbox_review(reviewed=True) @unwrap_spec(clk_id='c_int') def clock_getres(space, clk_id): with lltype.scoped_alloc(TIMESPEC) as timespec: @@ -955,6 +959,7 @@ else: assert _POSIX +@sandbox_review(reviewed=True) def monotonic(space, w_info=None): if rtime.CLOCK_HIGHRES is not None: clk_id = rtime.CLOCK_HIGHRES @@ -1045,6 +1050,7 @@ else: have_times = hasattr(rposix, 'c_times') +@sandbox_review(reviewed=True) def process_time(space, w_info=None): if HAS_CLOCK_GETTIME and ( rtime.CLOCK_PROF is not None or ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6-sandbox-2: hg merge sandbox-2
Author: Armin Rigo Branch: py3.6-sandbox-2 Changeset: r97299:1c3f982ecaec Date: 2019-08-27 11:26 +0200 http://bitbucket.org/pypy/pypy/changeset/1c3f982ecaec/ Log:hg merge sandbox-2 diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py --- a/rpython/rlib/rfile.py +++ b/rpython/rlib/rfile.py @@ -5,7 +5,7 @@ import os, stat, errno, sys from rpython.rlib import rposix, rgc -from rpython.rlib.objectmodel import enforceargs +from rpython.rlib.objectmodel import enforceargs, sandbox_review from rpython.rlib.rarithmetic import intmask from rpython.rlib.rstring import StringBuilder from rpython.rtyper.lltypesystem import rffi, lltype @@ -242,6 +242,7 @@ _newlinetypes = NEWLINE_UNKNOWN _skipnextlf = False +@sandbox_review(check_caller=True) def __init__(self, ll_file, mode=None, close2=_fclose2): self._ll_file = ll_file if mode is not None: @@ -548,6 +549,7 @@ c_ungetc(c, self._ll_file) return res +@sandbox_review(reviewed=True) def fileno(self): self._check_closed() return intmask(c_fileno(self._ll_file)) diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -570,6 +570,7 @@ save_err=rffi.RFFI_SAVE_ERRNO) @enforceargs(int, int, None) +@sandbox_review(reviewed=True) def pread(fd, count, offset): if count < 0: raise OSError(errno.EINVAL, None) @@ -578,6 +579,7 @@ return buf.str(handle_posix_error('pread', c_pread(fd, void_buf, count, offset))) @enforceargs(int, None, None) +@sandbox_review(reviewed=True) def pwrite(fd, data, offset): count = len(data) with rffi.scoped_nonmovingbuffer(data) as buf: @@ -2343,6 +2345,7 @@ [rffi.INT, rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T], rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO) +@sandbox_review(reviewed=True) def readlinkat(pathname, dir_fd=AT_FDCWD): pathname = _as_bytes0(pathname) bufsize = 1023 @@ -2683,6 +2686,7 @@ res = c_sendfile(out_fd, in_fd, p_offset, count) return handle_posix_error('sendfile', res) +@sandbox_review(reviewed=True) def sendfile_no_offset(out_fd, in_fd, count): """Passes offset==NULL; not support on all OSes""" res = c_sendfile(out_fd, in_fd, lltype.nullptr(_OFF_PTR_T.TO), count) diff --git a/rpython/rlib/rposix_scandir.py b/rpython/rlib/rposix_scandir.py --- a/rpython/rlib/rposix_scandir.py +++ b/rpython/rlib/rposix_scandir.py @@ -1,5 +1,5 @@ from rpython.rlib import rposix, rwin32 -from rpython.rlib.objectmodel import specialize +from rpython.rlib.objectmodel import specialize, sandbox_review from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.rarithmetic import intmask @@ -16,11 +16,13 @@ raise OSError(rposix.get_saved_errno(), "opendir failed") return dirp +@sandbox_review(check_caller=True) def closedir(dirp): rposix.c_closedir(dirp) NULL_DIRP = lltype.nullptr(rposix.DIRP.TO) +@sandbox_review(check_caller=True) def nextentry(dirp): """Read the next entry and returns an opaque object. Use the methods has_xxx() and get_xxx() to read from that diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py --- a/rpython/rlib/rposix_stat.py +++ b/rpython/rlib/rposix_stat.py @@ -633,6 +633,7 @@ compilation_info=compilation_info, save_err=rffi.RFFI_SAVE_ERRNO, macro=True) +@sandbox_review(reviewed=True) def fstatat(pathname, dir_fd=AT_FDCWD, follow_symlinks=True): if follow_symlinks: flags = 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy sandbox-2: More sandbox_review in rlib for py3.6
Author: Armin Rigo Branch: sandbox-2 Changeset: r97298:a066296c84d2 Date: 2019-08-27 11:25 +0200 http://bitbucket.org/pypy/pypy/changeset/a066296c84d2/ Log:More sandbox_review in rlib for py3.6 diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py --- a/rpython/rlib/rfile.py +++ b/rpython/rlib/rfile.py @@ -5,7 +5,7 @@ import os, stat, errno, sys from rpython.rlib import rposix, rgc -from rpython.rlib.objectmodel import enforceargs +from rpython.rlib.objectmodel import enforceargs, sandbox_review from rpython.rlib.rarithmetic import intmask from rpython.rlib.rstring import StringBuilder from rpython.rtyper.lltypesystem import rffi, lltype @@ -242,6 +242,7 @@ _newlinetypes = NEWLINE_UNKNOWN _skipnextlf = False +@sandbox_review(check_caller=True) def __init__(self, ll_file, mode=None, close2=_fclose2): self._ll_file = ll_file if mode is not None: @@ -548,6 +549,7 @@ c_ungetc(c, self._ll_file) return res +@sandbox_review(reviewed=True) def fileno(self): self._check_closed() return intmask(c_fileno(self._ll_file)) diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -570,6 +570,7 @@ save_err=rffi.RFFI_SAVE_ERRNO) @enforceargs(int, int, None) +@sandbox_review(reviewed=True) def pread(fd, count, offset): if count < 0: raise OSError(errno.EINVAL, None) @@ -578,6 +579,7 @@ return buf.str(handle_posix_error('pread', c_pread(fd, void_buf, count, offset))) @enforceargs(int, None, None) +@sandbox_review(reviewed=True) def pwrite(fd, data, offset): count = len(data) with rffi.scoped_nonmovingbuffer(data) as buf: @@ -2343,6 +2345,7 @@ [rffi.INT, rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T], rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO) +@sandbox_review(reviewed=True) def readlinkat(pathname, dir_fd=AT_FDCWD): pathname = _as_bytes0(pathname) bufsize = 1023 @@ -2683,6 +2686,7 @@ res = c_sendfile(out_fd, in_fd, p_offset, count) return handle_posix_error('sendfile', res) +@sandbox_review(reviewed=True) def sendfile_no_offset(out_fd, in_fd, count): """Passes offset==NULL; not support on all OSes""" res = c_sendfile(out_fd, in_fd, lltype.nullptr(_OFF_PTR_T.TO), count) diff --git a/rpython/rlib/rposix_scandir.py b/rpython/rlib/rposix_scandir.py --- a/rpython/rlib/rposix_scandir.py +++ b/rpython/rlib/rposix_scandir.py @@ -1,5 +1,5 @@ from rpython.rlib import rposix, rwin32 -from rpython.rlib.objectmodel import specialize +from rpython.rlib.objectmodel import specialize, sandbox_review from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.rarithmetic import intmask @@ -16,11 +16,13 @@ raise OSError(rposix.get_saved_errno(), "opendir failed") return dirp +@sandbox_review(check_caller=True) def closedir(dirp): rposix.c_closedir(dirp) NULL_DIRP = lltype.nullptr(rposix.DIRP.TO) +@sandbox_review(check_caller=True) def nextentry(dirp): """Read the next entry and returns an opaque object. Use the methods has_xxx() and get_xxx() to read from that diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py --- a/rpython/rlib/rposix_stat.py +++ b/rpython/rlib/rposix_stat.py @@ -633,6 +633,7 @@ compilation_info=compilation_info, save_err=rffi.RFFI_SAVE_ERRNO, macro=True) +@sandbox_review(reviewed=True) def fstatat(pathname, dir_fd=AT_FDCWD, follow_symlinks=True): if follow_symlinks: flags = 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: fixup conftest for removed files
Author: Matti Picus Branch: py3.6 Changeset: r97296:da64fb221689 Date: 2019-08-27 11:57 +0300 http://bitbucket.org/pypy/pypy/changeset/da64fb221689/ Log:fixup conftest for removed files diff --git a/lib-python/conftest.py b/lib-python/conftest.py --- a/lib-python/conftest.py +++ b/lib-python/conftest.py @@ -333,14 +333,6 @@ RegrTest('test_pathlib.py'), RegrTest('test_pdb.py'), RegrTest('test_peepholer.py'), -RegrTest('test_pep247.py'), -RegrTest('test_pep277.py'), -RegrTest('test_pep3120.py'), -RegrTest('test_pep3131.py'), -RegrTest('test_pep3151.py'), -RegrTest('test_pep352.py'), -RegrTest('test_pep380.py'), -RegrTest('test_pep479.py'), RegrTest('test_pickle.py', core=True), RegrTest('test_pickletools.py', core=False), RegrTest('test_pipes.py'), @@ -415,7 +407,6 @@ RegrTest('test_string.py', core=True), RegrTest('test_string_literals.py'), RegrTest('test_stringprep.py'), -RegrTest('test_strlit.py'), RegrTest('test_strptime.py'), RegrTest('test_strtod.py'), RegrTest('test_struct.py', usemodules='struct'), ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy sandbox-2: Write docs about the @sandbox_review() and llexternal(sandboxsafe=..).
Author: Armin Rigo Branch: sandbox-2 Changeset: r97295:f4ba641484fa Date: 2019-08-27 10:33 +0200 http://bitbucket.org/pypy/pypy/changeset/f4ba641484fa/ Log:Write docs about the @sandbox_review() and llexternal(sandboxsafe=..). diff --git a/rpython/translator/sandbox/graphchecker.py b/rpython/translator/sandbox/graphchecker.py --- a/rpython/translator/sandbox/graphchecker.py +++ b/rpython/translator/sandbox/graphchecker.py @@ -2,8 +2,92 @@ This runs at the start of the database-c step, so it excludes the graphs produced later, notably for the GC. These are "low-level" graphs that are assumed to be safe. + +Here are again the rules around this check. + +- any graph that contains only "safe" lloperations is itself "safe". + The "safe" lloperations are the ones marked "tryfold" in + rtyper.lltypesystem.lloperation, plus the ones listed explicitly below, + plus a few variants of specific operations coded in graph_in_unsafe(). + +- any graph decorated with @objectmodel.sandbox_review() is "safe". + The different flags we can pass to @sandbox_review() are explained next, + but the decorated graph is itself always "safe". + +- "unsafe" operations are all special rare operations, plus most importantly + all *writes* into raw memory. We assume that *reads* from anywhere are + OK to ignore: any information that reaches the sandboxed process can be + detected and used by anything that runs inside this process (i.e. there + is no really "secret" data inside the sandboxed subprocess itself). + At worst, random reads will lead to segfaults. But random writes are not + safe because that could corrupt memory---e.g. overwrite some GC object + header, or even (although I'm not sure how) actually cause the sandboxed + process to misbehave in more important ways like doing actual system calls + that are supposed to be forbidden. + +- the decorator @sandbox_review(check_caller=True) means that the graph is + safe, but any call to this graph from somewhere else is an unsafe operation. + This forces all callers to also be reviewed and marked with some form of + @sandbox_review(). + +- @sandbox_review(reviewed=True) means that the graph is safe and all + calls to this graph are also safe. This should only be used on functions + that do internally "unsafe" stuff like writing to raw memory but don't + take arguments that could lead them to do bogus things. A typical counter- + example is a function that takes a raw pointer and that writes something to + it; this should *not* be marked with reviewed=True. On the other hand, many + RPython wrappers to external C functions can be reviewed=True because + they translate GC-safe information (say an RPython string) to raw memory, + do the call, and translate the result back to GC-safe information. + +- @sandbox_review(abort=True) is reserved for cases where calling this + function at runtime should just immediately abort the subprocess. + +Note that all flags above should be considered independently of what the +actual C function calls are supposed to do. For example, the RPython +wrapper rposix.system() is something you definitely don't want to allow as-is, +but the wrapper and the call to the C function are fine. It's up to the +controlling process to refuse to reply to the system() external call +(either by having it return ENOSYS or a similar error, or by killing the +sandboxed process completely). + +Like system(), all calls to external C functions are *by default* removed and +turned into I/O on stdin/stdout, asking the parent controlling process what +to do. This is controlled in more details by rffi.llexternal(). It takes +its own argument "sandboxsafe", which can be one of the following values: + +- sandboxsafe=False (the default): the external C call is not done but turned + into I/O on stdin/stdout. Moreover, *if* the function takes or returns a + raw pointer, then it is flagged with @sandbox_review(check_caller=True) to + ensure that all callers do something sane with these raw pointers. If + the C function only takes and returns integer or float arguments, there is + no real need, so in this case we flag @sandbox_review(reviewed=True) instead. + +- sandboxsafe=True: means the external call should be done straight from the + sandboxed process. Reserved for specific functions like rposix.c_strerror(), + or some memory-manipulation functions used by the GC itself. + +- sandboxsafe="abort": like @sandbox_review(abort=True). + +- sandboxsafe="check_caller": forces @sandbox_review(check_caller=True). + Useful for llexternal() functions that appear to return an integer but + that's really some address that must be carefully managed. + +- sandboxsafe="nowrite": forces @sandbox_review(reviewed=True). This is OK + for C functions that have pointer arguments but none of them can point + to anything that will be written to (hence the name). The idea is that + for the common case of a function that takes a "const char
[pypy-commit] pypy py3.6: pypy3 -b and pypy3 -d now exist, add them to the --help text
Author: Matti Picus Branch: py3.6 Changeset: r97294:39096734e7bc Date: 2019-08-27 11:10 +0300 http://bitbucket.org/pypy/pypy/changeset/39096734e7bc/ Log:pypy3 -b and pypy3 -d now exist, add them to the --help text diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -2,11 +2,14 @@ # This is pure Python code that handles the main entry point into "pypy3". # See test/test_app_main. -# Missing vs CPython: -b, -d, -x +# Missing vs CPython: -x USAGE1 = __doc__ = """\ Options and arguments (and corresponding environment variables): +-b : issue warnings about str(bytes_instance), str(bytearray_instance)\n\ + and comparing bytes/bytearray with str. (-bb: issue errors)\n\ -B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x -c cmd : program passed in as string (terminates option list) +-d : debug output from parser; also PYTHONDEBUG=x\n\ -E : ignore PYTHON* environment variables (such as PYTHONPATH) -h : print this help message and exit (also --help) -i : inspect interactively after running script; forces a prompt even ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy sandbox-2: Revert the changes to backendopt done in 906b820ecdac; instead
Author: Armin Rigo Branch: sandbox-2 Changeset: r97293:322c4bfc9c42 Date: 2019-08-27 09:47 +0200 http://bitbucket.org/pypy/pypy/changeset/322c4bfc9c42/ Log:Revert the changes to backendopt done in 906b820ecdac; instead move the review-checking before running backendopt. More small fixes. diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py --- a/rpython/rlib/jit.py +++ b/rpython/rlib/jit.py @@ -3,7 +3,9 @@ import py from rpython.rlib.nonconst import NonConstant -from rpython.rlib.objectmodel import CDefinedIntSymbolic, keepalive_until_here, specialize, not_rpython, we_are_translated +from rpython.rlib.objectmodel import CDefinedIntSymbolic, keepalive_until_here +from rpython.rlib.objectmodel import specialize, not_rpython, we_are_translated +from rpython.rlib.objectmodel import sandbox_review from rpython.rlib.unroll import unrolling_iterable from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.tool.sourcetools import rpython_wrapper @@ -1196,6 +1198,7 @@ def _jit_conditional_call(condition, function, *args): pass # special-cased below +@sandbox_review(reviewed=True) # for the llop.jit_conditional_call @specialize.call_location() def conditional_call(condition, function, *args): """Does the same as: @@ -1217,6 +1220,7 @@ def _jit_conditional_call_value(value, function, *args): return value# special-cased below +@sandbox_review(reviewed=True) # for the llop.jit_conditional_call_value @specialize.call_location() def conditional_call_elidable(value, function, *args): """Does the same as: diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -1600,6 +1600,7 @@ lltype.Ptr(rwin32.FILETIME), lltype.Ptr(rwin32.FILETIME)], rwin32.BOOL, calling_conv='win') +@sandbox_review(reviewed=True) @replace_os_function('times') def times(): if not _WIN32: diff --git a/rpython/translator/backendopt/all.py b/rpython/translator/backendopt/all.py --- a/rpython/translator/backendopt/all.py +++ b/rpython/translator/backendopt/all.py @@ -113,7 +113,7 @@ if config.profile_based_inline and not secondary: threshold = config.profile_based_inline_threshold heuristic = get_function(config.profile_based_inline_heuristic) -inline.instrument_inline_candidates(translator, graphs, threshold) +inline.instrument_inline_candidates(graphs, threshold) counters = translator.driver_instrument_result( config.profile_based_inline) n = len(counters) diff --git a/rpython/translator/backendopt/inline.py b/rpython/translator/backendopt/inline.py --- a/rpython/translator/backendopt/inline.py +++ b/rpython/translator/backendopt/inline.py @@ -548,8 +548,7 @@ return (0. * measure_median_execution_cost(graph) + count), True # may be NaN -def inlinable_static_callers(translator, graphs, store_calls=False, - ok_to_call=None): +def inlinable_static_callers(graphs, store_calls=False, ok_to_call=None): if ok_to_call is None: ok_to_call = set(graphs) result = [] @@ -559,7 +558,6 @@ else: result.append((parentgraph, graph)) # -dont_inline = make_dont_inline_checker(translator) for parentgraph in graphs: for block in parentgraph.iterblocks(): for op in block.operations: @@ -567,12 +565,13 @@ funcobj = op.args[0].value._obj graph = getattr(funcobj, 'graph', None) if graph is not None and graph in ok_to_call: -if dont_inline(funcobj): +if getattr(getattr(funcobj, '_callable', None), + '_dont_inline_', False): continue add(parentgraph, block, op, graph) return result -def instrument_inline_candidates(translator, graphs, threshold): +def instrument_inline_candidates(graphs, threshold): cache = {None: False} def candidate(graph): try: @@ -582,7 +581,6 @@ cache[graph] = res return res n = 0 -dont_inline = make_dont_inline_checker(translator) for parentgraph in graphs: for block in parentgraph.iterblocks(): ops = block.operations @@ -594,7 +592,8 @@ funcobj = op.args[0].value._obj graph = getattr(funcobj, 'graph', None) if graph is not None: -if dont_inline(funcobj): +if getattr(getattr(funcobj, '_callable', None), + '_dont_inline_', False): continue if candidate(graph): tag = Constant('inline', Void) @@ -611,17 +610,6 @@ return (hasattr(graph, 'func') and
[pypy-commit] pypy py3.6: remove test files that no longer exist in cpython 3.6.9
Author: Matti Picus Branch: py3.6 Changeset: r97292:81a9ec3c2935 Date: 2019-08-27 10:38 +0300 http://bitbucket.org/pypy/pypy/changeset/81a9ec3c2935/ Log:remove test files that no longer exist in cpython 3.6.9 diff too long, truncating to 2000 out of 11624 lines diff --git a/lib-python/3/ensurepip/_bundled/pip-8.1.2-py2.py3-none-any.whl b/lib-python/3/ensurepip/_bundled/pip-8.1.2-py2.py3-none-any.whl deleted file mode 100644 index cc49227a0c7e13757f4863a9b7ace1eb56c3ce61..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch [cut] diff --git a/lib-python/3/ensurepip/_bundled/setuptools-21.2.1-py2.py3-none-any.whl b/lib-python/3/ensurepip/_bundled/setuptools-21.2.1-py2.py3-none-any.whl deleted file mode 100644 index fe36464f79ba87960c33f3bdff817deb9e4e5f7c..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch [cut] diff --git a/lib-python/3/plat-aix4/IN.py b/lib-python/3/plat-aix4/IN.py deleted file mode 100644 --- a/lib-python/3/plat-aix4/IN.py +++ /dev/null @@ -1,165 +0,0 @@ -# Generated by h2py from /usr/include/netinet/in.h - -# Included from net/nh.h - -# Included from sys/machine.h -LITTLE_ENDIAN = 1234 -BIG_ENDIAN = 4321 -PDP_ENDIAN = 3412 -BYTE_ORDER = BIG_ENDIAN -DEFAULT_GPR = 0xDEADBEEF -MSR_EE = 0x8000 -MSR_PR = 0x4000 -MSR_FP = 0x2000 -MSR_ME = 0x1000 -MSR_FE = 0x0800 -MSR_FE0 = 0x0800 -MSR_SE = 0x0400 -MSR_BE = 0x0200 -MSR_IE = 0x0100 -MSR_FE1 = 0x0100 -MSR_AL = 0x0080 -MSR_IP = 0x0040 -MSR_IR = 0x0020 -MSR_DR = 0x0010 -MSR_PM = 0x0004 -DEFAULT_MSR = (MSR_EE | MSR_ME | MSR_AL | MSR_IR | MSR_DR) -DEFAULT_USER_MSR = (DEFAULT_MSR | MSR_PR) -CR_LT = 0x8000 -CR_GT = 0x4000 -CR_EQ = 0x2000 -CR_SO = 0x1000 -CR_FX = 0x0800 -CR_FEX = 0x0400 -CR_VX = 0x0200 -CR_OX = 0x0100 -XER_SO = 0x8000 -XER_OV = 0x4000 -XER_CA = 0x2000 -def XER_COMP_BYTE(xer): return ((xer >> 8) & 0x00FF) - -def XER_LENGTH(xer): return (xer & 0x007F) - -DSISR_IO = 0x8000 -DSISR_PFT = 0x4000 -DSISR_LOCK = 0x2000 -DSISR_FPIO = 0x1000 -DSISR_PROT = 0x0800 -DSISR_LOOP = 0x0400 -DSISR_DRST = 0x0400 -DSISR_ST = 0x0200 -DSISR_SEGB = 0x0100 -DSISR_DABR = 0x0040 -DSISR_EAR = 0x0010 -SRR_IS_PFT = 0x4000 -SRR_IS_ISPEC = 0x2000 -SRR_IS_IIO = 0x1000 -SRR_IS_GUARD = 0x1000 -SRR_IS_PROT = 0x0800 -SRR_IS_LOOP = 0x0400 -SRR_PR_FPEN = 0x0010 -SRR_PR_INVAL = 0x0008 -SRR_PR_PRIV = 0x0004 -SRR_PR_TRAP = 0x0002 -SRR_PR_IMPRE = 0x0001 -def BUID_7F_SRVAL(raddr): return (0x87F0 | (((uint)(raddr)) >> 28)) - -BT_256M = 0x1FFC -BT_128M = 0x0FFC -BT_64M = 0x07FC -BT_32M = 0x03FC -BT_16M = 0x01FC -BT_8M = 0x00FC -BT_4M = 0x007C -BT_2M = 0x003C -BT_1M = 0x001C -BT_512K = 0x000C -BT_256K = 0x0004 -BT_128K = 0x -BT_NOACCESS = 0x0 -BT_RDONLY = 0x1 -BT_WRITE = 0x2 -BT_VS = 0x2 -BT_VP = 0x1 -def BAT_ESEG(dbatu): return (((uint)(dbatu) >> 28)) - -MIN_BAT_SIZE = 0x0002 -MAX_BAT_SIZE = 0x1000 -def ntohl(x): return (x) - -def ntohs(x): return (x) - -def htonl(x): return (x) - -def htons(x): return (x) - -IPPROTO_IP = 0 -IPPROTO_ICMP = 1 -IPPROTO_IGMP = 2 -IPPROTO_GGP = 3 -IPPROTO_TCP = 6 -IPPROTO_EGP = 8 -IPPROTO_PUP = 12 -IPPROTO_UDP = 17 -IPPROTO_IDP = 22 -IPPROTO_TP = 29 -IPPROTO_LOCAL = 63 -IPPROTO_EON = 80 -IPPROTO_BIP = 0x53 -IPPROTO_RAW = 255 -IPPROTO_MAX = 256 -IPPORT_RESERVED = 1024 -IPPORT_USERRESERVED = 5000 -IPPORT_TIMESERVER = 37 -def IN_CLASSA(i): return (((int)(i) & 0x8000) == 0) - -IN_CLASSA_NET = 0xff00 -IN_CLASSA_NSHIFT = 24 -IN_CLASSA_HOST = 0x00ff -IN_CLASSA_MAX = 128 -def IN_CLASSB(i): return (((int)(i) & 0xc000) == 0x8000) - -IN_CLASSB_NET = 0x -IN_CLASSB_NSHIFT = 16 -IN_CLASSB_HOST = 0x -IN_CLASSB_MAX = 65536 -def IN_CLASSC(i): return (((int)(i) & 0xe000) == 0xc000) - -IN_CLASSC_NET = 0xff00 -IN_CLASSC_NSHIFT = 8 -IN_CLASSC_HOST = 0x00ff -def IN_CLASSD(i): return (((int)(i) & 0xf000) == 0xe000) - -def IN_MULTICAST(i): return IN_CLASSD(i) - -IN_CLASSD_NET = 0xf000 -IN_CLASSD_NSHIFT = 28 -IN_CLASSD_HOST = 0x0fff -INADDR_UNSPEC_GROUP = 0xe000 -INADDR_ALLHOSTS_GROUP = 0xe001 -INADDR_MAX_LOCAL_GROUP = 0xe0ff -def IN_EXPERIMENTAL(i): return (((int)(i) & 0xe000) == 0xe000) - -def IN_BADCLASS(i): return (((int)(i) & 0xf000) == 0xf000) - -INADDR_ANY = 0x -INADDR_BROADCAST = 0x -INADDR_LOOPBACK = 0x7f01 -INADDR_NONE = 0x -IN_LOOPBACKNET = 127 -IP_OPTIONS = 1 -IP_HDRINCL = 2 -IP_TOS = 3 -IP_TTL = 4 -IP_RECVOPTS = 5 -IP_RECVRETOPTS = 6 -IP_RECVDSTADDR = 7 -IP_RETOPTS = 8 -IP_MULTICAST_IF = 9 -IP_MULTICAST_TTL = 10 -IP_MULTICAST_LOOP = 11 -IP_ADD_MEMBERSHIP = 12 -IP_DROP_MEMBERSHIP = 13 -IP_DEFAULT_MULTICAST_TTL = 1 -IP_DEFAULT_MULTICAST_LOOP = 1 -IP_MAX_MEMBERSHIPS = 20 diff --git a/lib-python/3/plat-aix4/regen b/lib-python/3/plat-aix4/regen deleted file mode 100755 --- a/lib-python/3/plat-aix4/regen +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/sh -case `uname -sv` in
[pypy-commit] pypy sandbox-2: More fixes
Author: Armin Rigo Branch: sandbox-2 Changeset: r97291:bf7d11fce803 Date: 2019-08-27 09:35 +0200 http://bitbucket.org/pypy/pypy/changeset/bf7d11fce803/ Log:More fixes diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py --- a/pypy/module/_io/interp_fileio.py +++ b/pypy/module/_io/interp_fileio.py @@ -374,7 +374,7 @@ length = rwbuffer.getlength() target_address = lltype.nullptr(rffi.CCHARP.TO) -if length > 64: +if length > 64 and not space.config.translation.sandbox: try: target_address = rwbuffer.get_raw_address() except ValueError: @@ -394,6 +394,13 @@ else: # optimized case: reading more than 64 bytes into a rwbuffer # with a valid raw address + +# XXX note that this is not fully safe, because we don't "lock" +# the buffer so we can't in theory pass its raw address to c_read(). +# Another thread could cause it to be freed in parallel. +# Without proper buffer locking, it's not going to be fixed, though. +assert not space.config.translation.sandbox + got = c_read(self.fd, target_address, length) keepalive_until_here(rwbuffer) got = rffi.cast(lltype.Signed, got) diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -1016,6 +1016,7 @@ debug.debug_forked(ofs) return childpid +@sandbox_review(reviewed=True) @replace_os_function('openpty') @jit.dont_look_inside def openpty(): @@ -1353,6 +1354,7 @@ c_pipe2 = external('pipe2', [INT_ARRAY_P, rffi.INT], rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO) +@sandbox_review(reviewed=True) @replace_os_function('pipe') def pipe(flags=0): # 'flags' might be ignored. Check the result. @@ -1389,6 +1391,7 @@ finally: lltype.free(filedes, flavor='raw') +@sandbox_review(reviewed=True) def pipe2(flags): # Only available if there is really a c_pipe2 function. # No fallback to pipe() if we get ENOSYS. @@ -1906,6 +1909,7 @@ c_setresgid = external('setresgid', [GID_T] * 3, rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO) +@sandbox_review(reviewed=True) @replace_os_function('getresuid') def getresuid(): out = lltype.malloc(UID_T_P.TO, 3, flavor='raw') @@ -1918,6 +1922,7 @@ finally: lltype.free(out, flavor='raw') +@sandbox_review(reviewed=True) @replace_os_function('getresgid') def getresgid(): out = lltype.malloc(GID_T_P.TO, 3, flavor='raw') diff --git a/rpython/rlib/rposix_environ.py b/rpython/rlib/rposix_environ.py --- a/rpython/rlib/rposix_environ.py +++ b/rpython/rlib/rposix_environ.py @@ -169,6 +169,7 @@ l_result = getenv(l_name) return traits.charp2str(l_result) if l_result else None +@sandbox_review(reviewed=True) def putenv_llimpl(name, value): l_string = traits.str2charp(name + eq + value) error = rffi.cast(lltype.Signed, putenv(l_string)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy sandbox-2: More review of the posix modules
Author: Armin Rigo Branch: sandbox-2 Changeset: r97290:76b447660dd6 Date: 2019-08-27 09:26 +0200 http://bitbucket.org/pypy/pypy/changeset/76b447660dd6/ Log:More review of the posix modules diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -395,12 +395,14 @@ save_err=rffi.RFFI_SAVE_ERRNO) c_open = external(UNDERSCORE_ON_WIN32 + 'open', [rffi.CCHARP, rffi.INT, rffi.MODE_T], rffi.INT, - save_err=rffi.RFFI_SAVE_ERRNO) + save_err=rffi.RFFI_SAVE_ERRNO, + sandboxsafe="nowrite") # Win32 Unicode functions c_wopen = external(UNDERSCORE_ON_WIN32 + 'wopen', [rffi.CWCHARP, rffi.INT, rffi.MODE_T], rffi.INT, - save_err=rffi.RFFI_SAVE_ERRNO) + save_err=rffi.RFFI_SAVE_ERRNO, + sandboxsafe="nowrite") #___ # Wrappers around posix functions, that accept either strings, or @@ -495,7 +497,6 @@ #___ -@sandbox_review(reviewed=True) @replace_os_function('open') @specialize.argtype(0) @enforceargs(NOT_CONSTANT, int, int, typecheck=False) @@ -652,13 +653,13 @@ #___ c_chdir = external('chdir', [rffi.CCHARP], rffi.INT, - save_err=rffi.RFFI_SAVE_ERRNO) + save_err=rffi.RFFI_SAVE_ERRNO, sandboxsafe="nowrite") c_fchdir = external('fchdir', [rffi.INT], rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO) c_access = external(UNDERSCORE_ON_WIN32 + 'access', -[rffi.CCHARP, rffi.INT], rffi.INT) +[rffi.CCHARP, rffi.INT], rffi.INT, sandboxsafe="nowrite") c_waccess = external(UNDERSCORE_ON_WIN32 + 'waccess', - [rffi.CWCHARP, rffi.INT], rffi.INT) + [rffi.CWCHARP, rffi.INT], rffi.INT, sandboxsafe="nowrite") @replace_os_function('chdir') @specialize.argtype(0) @@ -714,7 +715,6 @@ with FdValidator(fd): handle_posix_error('fchdir', c_fchdir(fd)) -@sandbox_review(reviewed=True) @replace_os_function('access') @specialize.argtype(0) def access(path, mode): @@ -817,9 +817,11 @@ DIRENT = dirent_config['DIRENT'] DIRENTP = lltype.Ptr(DIRENT) c_opendir = external('opendir', -[rffi.CCHARP], DIRP, save_err=rffi.RFFI_SAVE_ERRNO) +[rffi.CCHARP], DIRP, save_err=rffi.RFFI_SAVE_ERRNO, +sandboxsafe="nowrite") c_fdopendir = external('fdopendir', -[rffi.INT], DIRP, save_err=rffi.RFFI_SAVE_ERRNO) +[rffi.INT], DIRP, save_err=rffi.RFFI_SAVE_ERRNO, +sandboxsafe="nowrite") c_rewinddir = external('rewinddir', [DIRP], lltype.Void, releasegil=False) # XXX macro=True is hack to make sure we get the correct kind of @@ -834,6 +836,7 @@ else: dirent_config = {} +@sandbox_review(reviewed=True) def _listdir(dirp, rewind=False): result = [] while True: @@ -853,6 +856,7 @@ return result if not _WIN32: +@sandbox_review(reviewed=True) def fdlistdir(dirfd): """ Like listdir(), except that the directory is specified as an open @@ -927,17 +931,17 @@ #___ c_execv = external('execv', [rffi.CCHARP, rffi.CCHARPP], rffi.INT, - save_err=rffi.RFFI_SAVE_ERRNO) + save_err=rffi.RFFI_SAVE_ERRNO, sandboxsafe="nowrite") c_execve = external('execve', [rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP], rffi.INT, -save_err=rffi.RFFI_SAVE_ERRNO) +save_err=rffi.RFFI_SAVE_ERRNO, sandboxsafe="nowrite") c_spawnv = external(UNDERSCORE_ON_WIN32 + 'spawnv', [rffi.INT, rffi.CCHARP, rffi.CCHARPP], rffi.INT, -save_err=rffi.RFFI_SAVE_ERRNO) +save_err=rffi.RFFI_SAVE_ERRNO, sandboxsafe="nowrite") c_spawnve = external(UNDERSCORE_ON_WIN32 + 'spawnve', [rffi.INT, rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP], rffi.INT, - save_err=rffi.RFFI_SAVE_ERRNO) + save_err=rffi.RFFI_SAVE_ERRNO, sandboxsafe="nowrite") @replace_os_function('execv') def execv(path, args): @@ -1116,6 +1120,7 @@ c_getloadavg = external('getloadavg', [rffi.CArrayPtr(lltype.Float), rffi.INT], rffi.INT) +@sandbox_review(reviewed=True) @replace_os_function('getlogin') def getlogin(): result = c_getlogin() @@ -1123,6 +1128,7 @@ raise OSError(get_saved_errno(), "getlogin failed") return rffi.charp2str(result) +@sandbox_review(reviewed=True) @replace_os_function('getloadavg') def getloadavg(): load = lltype.malloc(rffi.CArrayPtr(lltype.Float).TO, 3, flavor='raw') @@ -1140,6
[pypy-commit] pypy sandbox-2: Fix some of the tests
Author: Armin Rigo Branch: sandbox-2 Changeset: r97288:7177f77afa08 Date: 2019-08-26 23:04 +0200 http://bitbucket.org/pypy/pypy/changeset/7177f77afa08/ Log:Fix some of the tests diff --git a/rpython/translator/sandbox/graphchecker.py b/rpython/translator/sandbox/graphchecker.py --- a/rpython/translator/sandbox/graphchecker.py +++ b/rpython/translator/sandbox/graphchecker.py @@ -105,7 +105,7 @@ elif opname in ('cast_ptr_to_adr', 'force_cast', 'cast_int_to_ptr'): if is_gc_ptr(op.result.concretetype): -return "result is a GC ptr: %r" % (opname,) +return "result is a GC ptr: %r" % (op,) else: return "unsupported llop: %r" % (opname,) diff --git a/rpython/translator/sandbox/sandlib.py b/rpython/translator/sandbox/sandlib.py deleted file mode 100644 --- a/rpython/translator/sandbox/sandlib.py +++ /dev/null @@ -1,517 +0,0 @@ -""" -A Python library to execute and communicate with a subprocess that -was translated from RPython code with --sandbox. This library is -for the outer process, which can run CPython or PyPy. -""" - -import sys, os, posixpath, errno, stat, time -import subprocess -from rpython.tool.killsubprocess import killsubprocess -from rpython.translator.sandbox.vfs import UID, GID -import py - -WIN32 = os.name == "nt" - - -def create_log(): -"""Make and return a log for the sandbox to use, if needed.""" -from rpython.tool.ansi_print import AnsiLogger -return AnsiLogger("sandlib") - -def write_exception(g, exception, tb=None): -for i, excclass in EXCEPTION_TABLE: -if isinstance(exception, excclass): -write_message(g, i) -if excclass is OSError: -error = exception.errno -if error is None: -error = errno.EPERM -write_message(g, error) -g.flush() -break -else: -# just re-raise the exception -raise exception.__class__, exception, tb - -def shortrepr(x): -r = repr(x) -if len(r) >= 80: -r = r[:20] + '...' + r[-8:] -return r - -def signal_name(n): -import signal -for key, value in signal.__dict__.items(): -if key.startswith('SIG') and not key.startswith('SIG_') and value == n: -return key -return 'signal %d' % (n,) - - -class SandboxedProc(object): -"""Base class to control a sandboxed subprocess. -Inherit from this class and implement all the do_xxx() methods -for the external functions xxx that you want to support. -""" -debug = False -log = None -os_level_sandboxing = False # Linux only: /proc/PID/seccomp - -def __init__(self, args, executable=None): -"""'args' should a sequence of argument for the subprocess, -starting with the full path of the executable. -""" -self.popen = subprocess.Popen(args, executable=executable, - bufsize=-1, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - close_fds=False if WIN32 else True, - env={}) -self.popenlock = None -self.currenttimeout = None -self.currentlyidlefrom = None - -if self.debug: -self.log = create_log() - -def withlock(self, function, *args, **kwds): -lock = self.popenlock -if lock is not None: -lock.acquire() -try: -return function(*args, **kwds) -finally: -if lock is not None: -lock.release() - -def settimeout(self, timeout, interrupt_main=False): -"""Start a timeout that will kill the subprocess after the given -amount of time. Only one timeout can be active at a time. -""" -import thread - -def _waiting_thread(): -while True: -while self.currentlyidlefrom is not None: -time.sleep(1) # can't timeout while idle -t = self.currenttimeout -if t is None: -return # cancelled -delay = t - time.time() -if delay <= 0.0: -break # expired! -time.sleep(min(delay*1.001, 1)) -if self.log: -self.log.timeout("timeout!") -self.kill() -#if interrupt_main: -#if hasattr(os, 'kill'): -#import signal -#os.kill(os.getpid(), signal.SIGINT) -#else: -#thread.interrupt_main() - -def _settimeout(): -need_new_thread = self.currenttimeout is None -self.currenttimeout = time.time() + timeout -if need_new_thread: -
[pypy-commit] pypy sandbox-2: in-progress
Author: Armin Rigo Branch: sandbox-2 Changeset: r97289:f4bf2fbd0c19 Date: 2019-08-27 08:42 +0200 http://bitbucket.org/pypy/pypy/changeset/f4bf2fbd0c19/ Log:in-progress diff --git a/pypy/module/__pypy__/interp_time.py b/pypy/module/__pypy__/interp_time.py --- a/pypy/module/__pypy__/interp_time.py +++ b/pypy/module/__pypy__/interp_time.py @@ -6,10 +6,12 @@ from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib import rtime from rpython.rlib.rtime import HAS_CLOCK_GETTIME +from rpython.rlib.objectmodel import sandbox_review if HAS_CLOCK_GETTIME: +@sandbox_review(reviewed=True) @unwrap_spec(clk_id="c_int") def clock_gettime(space, clk_id): with lltype.scoped_alloc(rtime.TIMESPEC) as tp: @@ -20,6 +22,7 @@ float(rffi.getintfield(tp, 'c_tv_nsec')) * 0.1) return space.newfloat(t) +@sandbox_review(reviewed=True) @unwrap_spec(clk_id="c_int") def clock_getres(space, clk_id): with lltype.scoped_alloc(rtime.TIMESPEC) as tp: diff --git a/pypy/module/_file/readinto.py b/pypy/module/_file/readinto.py --- a/pypy/module/_file/readinto.py +++ b/pypy/module/_file/readinto.py @@ -22,7 +22,7 @@ fd = -1 target_pos = 0 -if size > 64: +if size > 64 and not self.space.config.translation.sandbox: try: target_address = rwbuffer.get_raw_address() except ValueError: @@ -48,6 +48,13 @@ else: # optimized case: reading more than 64 bytes into a rwbuffer # with a valid raw address + +# XXX note that this is not fully safe, because we don't "lock" +# the buffer so we can't in theory pass its raw address to c_read(). +# Another thread could cause it to be freed in parallel. +# Without proper buffer locking, it's not going to be fixed, though. +assert not self.space.config.translation.sandbox + self.check_readable() # first "read" the part that is already sitting in buffers, if any diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -495,6 +495,7 @@ #___ +@sandbox_review(reviewed=True) @replace_os_function('open') @specialize.argtype(0) @enforceargs(NOT_CONSTANT, int, int, typecheck=False) @@ -514,6 +515,7 @@ c_close = external(UNDERSCORE_ON_WIN32 + 'close', [rffi.INT], rffi.INT, releasegil=False, save_err=rffi.RFFI_SAVE_ERRNO) +@sandbox_review(reviewed=True) @replace_os_function('read') @signature(types.int(), types.int(), returns=types.any()) def read(fd, count): @@ -525,6 +527,7 @@ got = handle_posix_error('read', c_read(fd, void_buf, count)) return buf.str(got) +@sandbox_review(reviewed=True) @replace_os_function('write') @signature(types.int(), types.any(), returns=types.any()) def write(fd, data): @@ -711,6 +714,7 @@ with FdValidator(fd): handle_posix_error('fchdir', c_fchdir(fd)) +@sandbox_review(reviewed=True) @replace_os_function('access') @specialize.argtype(0) def access(path, mode): @@ -753,6 +757,7 @@ [rffi.CWCHARP, rffi.SIZE_T], rffi.CWCHARP, save_err=rffi.RFFI_SAVE_ERRNO) +@sandbox_review(reviewed=True) @replace_os_function('getcwd') def getcwd(): bufsize = 256 @@ -773,6 +778,7 @@ lltype.free(buf, flavor='raw') return result +@sandbox_review(reviewed=True) @replace_os_function('getcwdu') def getcwdu(): bufsize = 256 diff --git a/rpython/rlib/rposix_environ.py b/rpython/rlib/rposix_environ.py --- a/rpython/rlib/rposix_environ.py +++ b/rpython/rlib/rposix_environ.py @@ -2,7 +2,7 @@ import sys from rpython.annotator import model as annmodel from rpython.rlib._os_support import _WIN32, StringTraits, UnicodeTraits -from rpython.rlib.objectmodel import enforceargs +from rpython.rlib.objectmodel import enforceargs, sandbox_review # importing rposix here creates a cycle on Windows from rpython.rtyper.controllerentry import Controller from rpython.rtyper.lltypesystem import rffi, lltype @@ -148,6 +148,7 @@ byname, eq = envkeepalive.bywname, u'=' from rpython.rlib.rwin32 import lastSavedWindowsError as last_error +@sandbox_review(reviewed=True) def envitems_llimpl(): environ = get_environ() result = [] @@ -162,6 +163,7 @@ i += 1 return result +@sandbox_review(reviewed=True) def getenv_llimpl(name): with traits.scoped_str2charp(name) as l_name: l_result = getenv(l_name) diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py --- a/rpython/rlib/rposix_stat.py +++ b/rpython/rlib/rposix_stat.py @@ -18,6 +18,7 @@ from rpython.rlib._os_support import _preferred_traits, string_traits from rpython.rlib.objectmodel import specialize, we_are_translated, not_rpython +from