Commits

Philip Jenvey  committed 9949155 Merge

merge default

  • Participants
  • Parent commits b1ab47f, e4fa0b2
  • Branches py3k

Comments (0)

Files changed (28)

File pypy/bin/translatorshell.py

-#!/usr/bin/env python 
-
-
-"""PyPy Translator Frontend
-
-Glue script putting together the various pieces of the translator.
-Can be used for interactive testing of the translator.
-
-Example:
-
-    t = Translation(func, [int])       # pass the list of args types
-    t.view()                           # control flow graph
-
-    t.annotate()
-    t.view()                           # graph + annotations under the mouse
-
-    t.rtype()                          # use low level operations 
-    f = t.compile_c()                  # C compilation
-    assert f(arg) == func(arg)         # sanity check (for C)
-    
-
-Some functions are provided for the benefit of interactive testing.
-Try dir(snippet) for list of current snippets.
-"""
-
-import os, sys
-
-from rpython.translator.interactive import Translation
-from rpython.rtyper.rtyper import *
-from rpython.rlib.rarithmetic import *
-
-import py
-
-def setup_readline():
-    import readline
-    try:
-        import rlcompleter2
-        rlcompleter2.setup()
-    except ImportError:
-        import rlcompleter
-        readline.parse_and_bind("tab: complete")
-    import os
-    histfile = os.path.join(os.environ["HOME"], ".pypytrhist")
-    try:
-        getattr(readline, "clear_history", lambda : None)()
-        readline.read_history_file(histfile)
-    except IOError:
-        pass
-    import atexit
-    atexit.register(readline.write_history_file, histfile)
-
-if __name__ == '__main__':
-    try:
-        setup_readline()
-    except ImportError, err:
-        print "Disabling readline support (%s)" % err
-    from rpython.translator.test import snippet
-    from rpython.rtyper.rtyper import RPythonTyper
-
-    if (os.getcwd() not in sys.path and
-        os.path.curdir not in sys.path):
-        sys.path.insert(0, os.getcwd())
-
-    print __doc__
-
-    import os
-    os.putenv("PYTHONINSPECT", "1")
-
-

File pypy/doc/arm.rst

   export SB2=/srv/chroot/precise_arm
   export SB2OPT='-t ARM'
 
-Once this is set, you can call the translator 
-
-::
-
-  pypy ~/path_to_pypy_checkout/pypy/translator/goal/translate.py -O1 --platform=arm target.py
-
-If everything worked correctly this should yield an ARM binary. Running this binary in the ARM chroot or on an ARM device should produce the output ``"Hello World"``.
-
-.. _`this`:
+Once this is set, you can call the translator. For example save this file 
 
 ::
 
 
   def target(*args):
       return main, None
+
+and call the translator
+
+::
+
+  pypy ~/path_to_pypy_checkout/pypy/translator/goal/translate.py -O1 --platform=arm target.py
+
+If everything worked correctly this should yield an ARM binary. Running this binary in the ARM chroot or on an ARM device should produce the output ``"Hello World"``.
+
+To translate the full python pypy interpreter with a jit, you can cd into pypy/goal and call      
+
+::
+
+  pypy <path to rpython>/rpython/translator/goal/translate.py -Ojit --platform=arm --gcrootfinder=shadowstack --jit-backend=arm targetpypystandalone.py
+
+The gcrootfinder option is needed to work around `issue 1377`_ and the jit-backend works around `issue 1376`_
+
+.. _`issue 1377`: https://bugs.pypy.org/issue1377
+.. _`issue 1376`: https://bugs.pypy.org/issue1376

File pypy/goal/__init__.py

+#empty

File pypy/interpreter/astcompiler/codegen.py

 
     def visit_Set(self, s):
         self.update_position(s.lineno)
+        elt_count = len(s.elts) if s.elts is not None else 0
         self.visit_sequence(s.elts)
-        self.emit_op_arg(ops.BUILD_SET, len(s.elts))
+        self.emit_op_arg(ops.BUILD_SET, elt_count)
 
     def visit_Name(self, name):
         self.update_position(name.lineno)

File pypy/interpreter/test2/test_app_main.py

File contents unchanged.

File pypy/interpreter/test2/test_targetpypy.py

 
 import py
-from goal.targetpypystandalone import get_entry_point
+from pypy.goal.targetpypystandalone import get_entry_point
 from pypy.config.pypyoption import get_pypy_config
 
 class TestTargetPyPy(object):

File pypy/module/_ast/test/test_ast.py

         ])
         exec(compile(body, '<string>', 'exec'))
 
+    def test_empty_set(self):
+        import ast
+        m = ast.Module(body=[ast.Expr(value=ast.Set(elts=[]))])
+        ast.fix_missing_locations(m)
+        compile(m, "<test>", "exec")
+
     def test_invalid_sum(self):
         import _ast as ast
         pos = dict(lineno=2, col_offset=3)

File pypy/module/cpyext/classobject.py

File contents unchanged.

File pypy/module/cpyext/include/ceval.h

+/* empty */

File pypy/module/cpyext/stubs.py

File contents unchanged.

File pypy/module/cpyext/test/conftest.py

 import py
 import pytest
 
+def pytest_configure(config):
+    from pypy.tool.pytest.objspace import gettestobjspace
+    # For some reason (probably a ll2ctypes cache issue on linux64)
+    # it's necessary to run "import time" at least once before any
+    # other cpyext test, otherwise the same statement will fail in
+    # test_datetime.py.
+    space = gettestobjspace(usemodules=['rctime'])
+    space.getbuiltinmodule("time")
+
 def pytest_ignore_collect(path, config):
     if config.option.runappdirect:
         return True # "cannot be run by py.test -A"

File pypy/module/cpyext/test/test_classobject.py

File contents unchanged.

File pypy/module/micronumpy/arrayimpl/scalar.py

     def get_shape(self):
         return []
 
+    def get_strides(self):
+        return []
+
     def create_iter(self, shape=None):
         return ScalarIterator(self.value)
 

File pypy/module/micronumpy/interp_numarray.py

         self.implementation = self.implementation.set_shape(space,
             get_shape_from_iterable(space, self.get_size(), w_new_shape))
 
+    def descr_get_strides(self, space):
+        strides = self.implementation.get_strides()
+        return space.newtuple([space.wrap(i) for i in strides])
+
     def get_dtype(self):
         return self.implementation.dtype
 
     dtype = GetSetProperty(W_NDimArray.descr_get_dtype),
     shape = GetSetProperty(W_NDimArray.descr_get_shape,
                            W_NDimArray.descr_set_shape),
+    strides = GetSetProperty(W_NDimArray.descr_get_strides),
     ndim = GetSetProperty(W_NDimArray.descr_get_ndim),
     size = GetSetProperty(W_NDimArray.descr_get_size),
     itemsize = GetSetProperty(W_NDimArray.descr_get_itemsize),

File pypy/module/micronumpy/test/test_numarray.py

         assert a.reshape([1]).shape == (1,)
         raises(ValueError, "a.reshape(3)")
 
+    def test_strides(self):
+        from _numpypy import array
+        a = array([[1.0, 2.0],
+                   [3.0, 4.0]])
+        assert a.strides == (16, 8)
+        assert a[1:].strides == (16, 8)
+
+    def test_strides_scalar(self):
+        from _numpypy import array
+        a = array(42)
+        assert a.strides == ()
+
     def test_add(self):
         from _numpypy import array
         a = array(range(5))

File pypy/module/rctime/interp_time.py

             space.warn("Century info guessed for a 2-digit year.",
                        space.w_DeprecationWarning)
 
-    if rffi.getintfield(glob_buf, 'c_tm_wday') < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("day of week out of range"))
-
     rffi.setintfield(glob_buf, 'c_tm_year', y - 1900)
     rffi.setintfield(glob_buf, 'c_tm_mon',
                      rffi.getintfield(glob_buf, 'c_tm_mon') - 1)
     rffi.setintfield(glob_buf, 'c_tm_yday',
                      rffi.getintfield(glob_buf, 'c_tm_yday') - 1)
 
+    # tm_wday does not need checking of its upper-bound since taking "%
+    #  7" in gettmarg() automatically restricts the range.
+    if rffi.getintfield(glob_buf, 'c_tm_wday') < 0:
+        raise OperationError(space.w_ValueError,
+                             space.wrap("day of week out of range"))
+
     return glob_buf
 
 def time(space):

File pypy/module/rctime/test/test_rctime.py

         if os.name != 'nt':
             assert rctime.mktime(rctime.localtime(-1)) == -1
 
+        res = rctime.mktime((2000, 1, 1, 0, 0, 0, -1, -1, -1))
+        assert rctime.ctime(res) == 'Sat Jan  1 00:00:00 2000'
+
     def test_asctime(self):
         import time as rctime
         rctime.asctime()

File pypy/module/unicodedata/test/test_unicodedata.py

+import py
+import sys
+
+class AppTestUnicodeData:
+    spaceconfig = dict(usemodules=('unicodedata',))
+
+    def test_hangul_syllables(self):
+        import unicodedata
+        # Test all leading, vowel and trailing jamo
+        # but not every combination of them.
+        for code, name in ((0xAC00, 'HANGUL SYLLABLE GA'),
+                           (0xAE69, 'HANGUL SYLLABLE GGAEG'),
+                           (0xB0D2, 'HANGUL SYLLABLE NYAGG'),
+                           (0xB33B, 'HANGUL SYLLABLE DYAEGS'),
+                           (0xB5A4, 'HANGUL SYLLABLE DDEON'),
+                           (0xB80D, 'HANGUL SYLLABLE RENJ'),
+                           (0xBA76, 'HANGUL SYLLABLE MYEONH'),
+                           (0xBCDF, 'HANGUL SYLLABLE BYED'),
+                           (0xBF48, 'HANGUL SYLLABLE BBOL'),
+                           (0xC1B1, 'HANGUL SYLLABLE SWALG'),
+                           (0xC41A, 'HANGUL SYLLABLE SSWAELM'),
+                           (0xC683, 'HANGUL SYLLABLE OELB'),
+                           (0xC8EC, 'HANGUL SYLLABLE JYOLS'),
+                           (0xCB55, 'HANGUL SYLLABLE JJULT'),
+                           (0xCDBE, 'HANGUL SYLLABLE CWEOLP'),
+                           (0xD027, 'HANGUL SYLLABLE KWELH'),
+                           (0xD290, 'HANGUL SYLLABLE TWIM'),
+                           (0xD4F9, 'HANGUL SYLLABLE PYUB'),
+                           (0xD762, 'HANGUL SYLLABLE HEUBS'),
+                           (0xAE27, 'HANGUL SYLLABLE GYIS'),
+                           (0xB090, 'HANGUL SYLLABLE GGISS'),
+                           (0xB0AD, 'HANGUL SYLLABLE NANG'),
+                           (0xB316, 'HANGUL SYLLABLE DAEJ'),
+                           (0xB57F, 'HANGUL SYLLABLE DDYAC'),
+                           (0xB7E8, 'HANGUL SYLLABLE RYAEK'),
+                           (0xBA51, 'HANGUL SYLLABLE MEOT'),
+                           (0xBCBA, 'HANGUL SYLLABLE BEP'),
+                           (0xBF23, 'HANGUL SYLLABLE BBYEOH'),
+                           (0xD7A3, 'HANGUL SYLLABLE HIH')):
+            assert unicodedata.name(chr(code)) == name
+            assert unicodedata.lookup(name) == chr(code)
+        # Test outside the range
+        raises(ValueError, unicodedata.name, chr(0xAC00 - 1))
+        raises(ValueError, unicodedata.name, chr(0xD7A3 + 1))
+
+    def test_cjk(self):
+        import sys
+        import unicodedata
+        cases = ((0x3400, 0x4DB5),
+                 (0x4E00, 0x9FA5))
+        if unicodedata.unidata_version >= "5":    # don't know the exact limit
+            cases = ((0x3400, 0x4DB5),
+                     (0x4E00, 0x9FCB),
+                     (0x20000, 0x2A6D6),
+                     (0x2A700, 0x2B734))
+        elif unicodedata.unidata_version >= "4.1":
+            cases = ((0x3400, 0x4DB5),
+                     (0x4E00, 0x9FBB),
+                     (0x20000, 0x2A6D6))
+        for first, last in cases:
+            # Test at and inside the boundary
+            for i in (first, first + 1, last - 1, last):
+                charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
+                char = chr(i)
+                assert unicodedata.name(char) == charname
+                assert unicodedata.lookup(charname) == char
+            # Test outside the boundary
+            for i in first - 1, last + 1:
+                charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
+                char = chr(i)
+                try:
+                    unicodedata.name(char)
+                except ValueError as e:
+                    assert e.message == 'no such name'
+                raises(KeyError, unicodedata.lookup, charname)
+
+    def test_bug_1704793(self): # from CPython
+        import unicodedata
+        assert unicodedata.lookup("GOTHIC LETTER FAIHU") == '\U00010346'
+
+    def test_normalize(self):
+        import unicodedata
+        raises(TypeError, unicodedata.normalize, 'x')
+
+    @py.test.mark.skipif("sys.maxunicode < 0x10ffff",
+                         reason="requires a 'wide' python build.")
+    def test_normalize_wide(self):
+        import unicodedata
+        assert unicodedata.normalize('NFC', '\U000110a5\U000110ba') == u'\U000110ab'
+
+    def test_linebreaks(self):
+        linebreaks = (0x0a, 0x0b, 0x0c, 0x0d, 0x85,
+                      0x1c, 0x1d, 0x1e, 0x2028, 0x2029)
+        for i in linebreaks:
+            for j in range(-2, 3):
+                lines = (chr(i + j) + 'A').splitlines()
+                if i + j in linebreaks:
+                    assert len(lines) == 2
+                else:
+                    assert len(lines) == 1
+
+    def test_mirrored(self):
+        import unicodedata
+        # For no reason, unicodedata.mirrored() returns an int, not a bool
+        assert repr(unicodedata.mirrored(' ')) == '0'

File pypy/module/unicodedata/test_unicodedata.py

-
-class AppTestUnicodeData:
-    spaceconfig = dict(usemodules=('unicodedata',))
-
-    def test_hangul_syllables(self):
-        import unicodedata
-        # Test all leading, vowel and trailing jamo
-        # but not every combination of them.
-        for code, name in ((0xAC00, 'HANGUL SYLLABLE GA'),
-                           (0xAE69, 'HANGUL SYLLABLE GGAEG'),
-                           (0xB0D2, 'HANGUL SYLLABLE NYAGG'),
-                           (0xB33B, 'HANGUL SYLLABLE DYAEGS'),
-                           (0xB5A4, 'HANGUL SYLLABLE DDEON'),
-                           (0xB80D, 'HANGUL SYLLABLE RENJ'),
-                           (0xBA76, 'HANGUL SYLLABLE MYEONH'),
-                           (0xBCDF, 'HANGUL SYLLABLE BYED'),
-                           (0xBF48, 'HANGUL SYLLABLE BBOL'),
-                           (0xC1B1, 'HANGUL SYLLABLE SWALG'),
-                           (0xC41A, 'HANGUL SYLLABLE SSWAELM'),
-                           (0xC683, 'HANGUL SYLLABLE OELB'),
-                           (0xC8EC, 'HANGUL SYLLABLE JYOLS'),
-                           (0xCB55, 'HANGUL SYLLABLE JJULT'),
-                           (0xCDBE, 'HANGUL SYLLABLE CWEOLP'),
-                           (0xD027, 'HANGUL SYLLABLE KWELH'),
-                           (0xD290, 'HANGUL SYLLABLE TWIM'),
-                           (0xD4F9, 'HANGUL SYLLABLE PYUB'),
-                           (0xD762, 'HANGUL SYLLABLE HEUBS'),
-                           (0xAE27, 'HANGUL SYLLABLE GYIS'),
-                           (0xB090, 'HANGUL SYLLABLE GGISS'),
-                           (0xB0AD, 'HANGUL SYLLABLE NANG'),
-                           (0xB316, 'HANGUL SYLLABLE DAEJ'),
-                           (0xB57F, 'HANGUL SYLLABLE DDYAC'),
-                           (0xB7E8, 'HANGUL SYLLABLE RYAEK'),
-                           (0xBA51, 'HANGUL SYLLABLE MEOT'),
-                           (0xBCBA, 'HANGUL SYLLABLE BEP'),
-                           (0xBF23, 'HANGUL SYLLABLE BBYEOH'),
-                           (0xD7A3, 'HANGUL SYLLABLE HIH')):
-            assert unicodedata.name(chr(code)) == name
-            assert unicodedata.lookup(name) == chr(code)
-        # Test outside the range
-        raises(ValueError, unicodedata.name, chr(0xAC00 - 1))
-        raises(ValueError, unicodedata.name, chr(0xD7A3 + 1))
-
-    def test_cjk(self):
-        import sys
-        import unicodedata
-        cases = ((0x3400, 0x4DB5),
-                 (0x4E00, 0x9FA5))
-        if unicodedata.unidata_version >= "5":    # don't know the exact limit
-            cases = ((0x3400, 0x4DB5),
-                     (0x4E00, 0x9FCB),
-                     (0x20000, 0x2A6D6),
-                     (0x2A700, 0x2B734))
-        elif unicodedata.unidata_version >= "4.1":
-            cases = ((0x3400, 0x4DB5),
-                     (0x4E00, 0x9FBB),
-                     (0x20000, 0x2A6D6))
-        for first, last in cases:
-            # Test at and inside the boundary
-            for i in (first, first + 1, last - 1, last):
-                charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
-                char = chr(i)
-                assert unicodedata.name(char) == charname
-                assert unicodedata.lookup(charname) == char
-            # Test outside the boundary
-            for i in first - 1, last + 1:
-                charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
-                char = chr(i)
-                try:
-                    unicodedata.name(char)
-                except ValueError as e:
-                    assert e.message == 'no such name'
-                raises(KeyError, unicodedata.lookup, charname)
-
-    def test_bug_1704793(self): # from CPython
-        import unicodedata
-        assert unicodedata.lookup("GOTHIC LETTER FAIHU") == '\U00010346'
-
-    def test_normalize(self):
-        import unicodedata
-        raises(TypeError, unicodedata.normalize, 'x')
-
-    def test_normalize_wide(self):
-        import sys, unicodedata
-        if sys.maxunicode < 0x10ffff:
-            skip("requires a 'wide' python build.")
-        assert unicodedata.normalize('NFC', '\U000110a5\U000110ba') == '\U000110ab'
-
-    def test_linebreaks(self):
-        linebreaks = (0x0a, 0x0b, 0x0c, 0x0d, 0x85,
-                      0x1c, 0x1d, 0x1e, 0x2028, 0x2029)
-        for i in linebreaks:
-            for j in range(-2, 3):
-                lines = (chr(i + j) + 'A').splitlines()
-                if i + j in linebreaks:
-                    assert len(lines) == 2
-                else:
-                    assert len(lines) == 1
-
-    def test_mirrored(self):
-        import unicodedata
-        # For no reason, unicodedata.mirrored() returns an int, not a bool
-        assert repr(unicodedata.mirrored(' ')) == '0'

File pypy/pytest-A.cfg

 cherrypick = ['interpreter', 'objspace/test', 'objspace/std', 'module']
 
-interp = ['translator/goal/pypy-c']
+interp = ['goal/pypy-c']
 test_driver = ['test_all.py', '-A']
 

File pypy/test_all.py

     if len(sys.argv) == 1 and os.path.dirname(sys.argv[0]) in '.':
         print >> sys.stderr, __doc__
         sys.exit(2)
-
+    #Add toplevel repository dir to sys.path
+    sys.path.insert(0,os.path.dirname(os.path.dirname(__file__)))
     import pytest
     import pytest_cov
     sys.exit(pytest.main(plugins=[pytest_cov]))

File pypy/tool/release/package.py

 
 import shutil
 import sys
+import os
+#Add toplevel repository dir to sys.path
+sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
 import py
-import os
 import fnmatch
 from rpython.tool.udir import udir
 

File rpython/bin/translatorshell.py

+#!/usr/bin/env python 
+
+
+"""PyPy Translator Frontend
+
+Glue script putting together the various pieces of the translator.
+Can be used for interactive testing of the translator.
+
+Example:
+
+    t = Translation(func, [int])       # pass the list of args types
+    t.view()                           # control flow graph
+
+    t.annotate()
+    t.view()                           # graph + annotations under the mouse
+
+    t.rtype()                          # use low level operations 
+    f = t.compile_c()                  # C compilation
+    assert f(arg) == func(arg)         # sanity check (for C)
+    
+
+Some functions are provided for the benefit of interactive testing.
+Try dir(snippet) for list of current snippets.
+"""
+
+import os, sys
+
+from rpython.translator.interactive import Translation
+from rpython.rtyper.rtyper import *
+from rpython.rlib.rarithmetic import *
+
+import py
+
+def setup_readline():
+    import readline
+    try:
+        import rlcompleter2
+        rlcompleter2.setup()
+    except ImportError:
+        import rlcompleter
+        readline.parse_and_bind("tab: complete")
+    import os
+    histfile = os.path.join(os.environ["HOME"], ".pypytrhist")
+    try:
+        getattr(readline, "clear_history", lambda : None)()
+        readline.read_history_file(histfile)
+    except IOError:
+        pass
+    import atexit
+    atexit.register(readline.write_history_file, histfile)
+
+if __name__ == '__main__':
+    try:
+        setup_readline()
+    except ImportError, err:
+        print "Disabling readline support (%s)" % err
+    from rpython.translator.test import snippet
+    from rpython.rtyper.rtyper import RPythonTyper
+
+    if (os.getcwd() not in sys.path and
+        os.path.curdir not in sys.path):
+        sys.path.insert(0, os.getcwd())
+
+    print __doc__
+
+    import os
+    os.putenv("PYTHONINSPECT", "1")
+
+

File rpython/jit/backend/arm/test/support.py

     def check_jumps(self, maxcount):
         pass
 
+if not getattr(os, 'uname', None):
+    pytest.skip('cannot run arm tests on non-posix platform')
+
 if os.uname()[1] == 'llaima.local':
     AS = '~/Code/arm-jit/android/android-ndk-r4b//build/prebuilt/darwin-x86/arm-eabi-4.4.0/arm-eabi/bin/as'
 else:

File rpython/rlib/parsing/test/test_pcre_regtest.py

 from rpython.rlib.parsing.regexparse import make_runner, unescape
 import string
 import re
-import os
-this_dir = py.path.local(os.path.realpath(os.path.dirname(__file__)))
+this_dir = py.path.local(__file__).join('..')
 
 #py.test.skip("Still in progress")
 

File rpython/translator/c/genc.py

         self.secondary_entrypoints = secondary_entrypoints
 
     def get_eci(self):
-        pypy_include_dir = py.path.local(os.path.realpath(os.path.dirname(__file__)))
+        pypy_include_dir = py.path.local(__file__).join('..')
         include_dirs = [pypy_include_dir]
         return ExternalCompilationInfo(include_dirs=include_dirs)
 
     defines['PYPY_LONGLONG_BIT'] = LONGLONG_BIT
 
 def add_extra_files(eci):
-    srcdir = py.path.local(os.path.realpath(os.path.dirname(__file__))).join('src')
+    srcdir = py.path.local(__file__).join('..', 'src')
     files = [
         srcdir / 'entrypoint.c',       # ifdef PYPY_STANDALONE
         srcdir / 'allocator.c',        # ifdef PYPY_STANDALONE

File rpython/translator/platform/posix.py

 from rpython.translator.platform import Platform, log, _run_subprocess
 
 import rpython
-rpydir = os.path.dirname(rpython.__file__)
+rpydir = str(py.path.local(rpython.__file__).join('..'))
 
 class BasePosix(Platform):
     exe_ext = ''

File rpython/translator/platform/windows.py

 from rpython.translator.platform import Platform, posix
 
 import rpython
-rpydir = os.path.dirname(rpython.__file__)
+rpydir = str(py.path.local(rpython.__file__).join('..'))
 
 def _get_compiler_type(cc, x64_flag):
     import subprocess