Commits

Philip Jenvey committed 331eda1 Merge

merge default

Comments (0)

Files changed (24)

py/_code/source.py

                 trysource = self[start:end]
                 if trysource.isparseable():
                     return start, end
+                if end == start + 100:   # XXX otherwise, it takes forever
+                    break                # XXX
         if end is None:
             raise IndexError("no valid source range around line %d " % (lineno,))
         return start, end

pypy/doc/whatsnew-head.rst

 
 .. branch: fix-lookinside-iff-oopspec
 Fixed the interaction between two internal tools for controlling the JIT.
+
+.. branch: inline-virtualref-2
+Better optimized certain types of frame accesses in the JIT, particularly
+around exceptions that escape the function they were raised in.

pypy/module/sys/version.py

 import pypy
 pypydir = os.path.dirname(os.path.abspath(pypy.__file__))
 del pypy
-from pypy.tool.version import get_repo_version_info
+from rpython.tool.version import get_repo_version_info
 
 import time as t
 gmtime = t.gmtime()

pypy/module/sys/vm.py

 def exc_info_with_tb(space):
     operror = space.getexecutioncontext().sys_exc_info()
     if operror is None:
-        return space.newtuple([space.w_None,space.w_None,space.w_None])
+        return space.newtuple([space.w_None, space.w_None, space.w_None])
     else:
         return space.newtuple([operror.w_type, operror.get_w_value(space),
                                space.wrap(operror.get_traceback())])

pypy/tool/jitlogparser/parser.py

     _lineset = None
     is_bytecode = False
     inline_level = None
+    bytecode_name = None
 
     # factory method
     TraceForOpcode = TraceForOpcode
             return ",".join([str(len(v)) for v in stack])
 
         def append_to_res(bc):
-            if not stack:
-                stack.append([])
-            else:
-                if bc.inline_level is not None and bc.inline_level + 1 != len(stack):
-                    if bc.inline_level < len(stack):
+            if bc.inline_level is not None:
+                if bc.inline_level == len(stack) - 1:
+                    pass
+                elif bc.inline_level > len(stack) - 1:
+                    stack.append([])
+                else:
+                    while bc.inline_level + 1 < len(stack):
                         last = stack.pop()
                         stack[-1].append(cls(last, getpath(stack), storage))
-                    else:
-                        stack.append([])
             stack[-1].append(bc)
 
         so_far = []
         stack = []
+        nothing_yet = True
         for op in operations:
             if op.name == 'debug_merge_point':
                 if so_far:
-                    append_to_res(cls.TraceForOpcode(so_far, storage, loopname))
+                    opc = cls.TraceForOpcode(so_far, storage, loopname)
+                    if nothing_yet:
+                        nothing_yet = False
+                        for i in xrange(opc.inline_level + 1):
+                            stack.append([])
+                    append_to_res(opc)
                     if limit:
                         break
                     so_far = []

pypy/tool/jitlogparser/test/test_parser.py

     f = Function.from_operations(loop.operations, LoopStorage())
     assert f.chunks[-1].filename == 'x.py'
     assert f.filename is None
+
+def test_parse_2_levels_up():
+    loop = parse("""
+    []
+    debug_merge_point(0, 0, 'one')
+    debug_merge_point(1, 0, 'two')
+    debug_merge_point(2, 0, 'three')
+    debug_merge_point(0, 0, 'one')    
+    """)
+    f = Function.from_operations(loop.operations, LoopStorage())
+    assert len(f.chunks) == 3
+
+def test_parse_from_inside():
+    loop = parse("""
+    []
+    debug_merge_point(1, 0, 'two')
+    debug_merge_point(2, 0, 'three')
+    debug_merge_point(0, 0, 'one')    
+    """)
+    f = Function.from_operations(loop.operations, LoopStorage())
+    assert len(f.chunks) == 2
+    

pypy/tool/release/package.py

 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__)))))
+sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
 import py
 import fnmatch
 from rpython.tool.udir import udir

pypy/tool/test/test_version.py

-import os, sys
-import py
-from pypy.tool.version import get_repo_version_info, _get_hg_archive_version
-
-def test_hg_archival_version(tmpdir):
-    def version_for(name, **kw):
-        path = tmpdir.join(name)
-        path.write('\n'.join('%s: %s' % x for x in kw.items()))
-        return _get_hg_archive_version(str(path))
-
-    assert version_for('release',
-                       tag='release-123',
-                       node='000',
-                      ) == ('PyPy', 'release-123', '000')
-    assert version_for('somebranch',
-                       node='000',
-                       branch='something',
-                      ) == ('PyPy', 'something', '000')
-
-
-def test_get_repo_version_info():
-    assert get_repo_version_info(None)
-    assert get_repo_version_info(os.devnull) == ('PyPy', '?', '?')
-    assert get_repo_version_info(sys.executable) == ('PyPy', '?', '?')

pypy/tool/version.py

-import py
-import os
-from subprocess import Popen, PIPE
-import pypy
-pypydir = os.path.dirname(os.path.abspath(pypy.__file__))
-pypyroot = os.path.dirname(pypydir)
-default_retval = 'PyPy', '?', '?'
-
-def maywarn(err, repo_type='Mercurial'):
-    if not err:
-        return
-
-    from rpython.tool.ansi_print import ansi_log
-    log = py.log.Producer("version")
-    py.log.setconsumer("version", ansi_log)
-    log.WARNING('Errors getting %s information: %s' % (repo_type, err))
-
-def get_repo_version_info(hgexe=None):
-    '''Obtain version information by invoking the 'hg' or 'git' commands.'''
-
-    # Try to see if we can get info from Git if hgexe is not specified.
-    if not hgexe:
-        if os.path.isdir(os.path.join(pypyroot, '.git')):
-            return _get_git_version()
-
-    # Fallback to trying Mercurial.
-    if hgexe is None:
-        hgexe = py.path.local.sysfind('hg')
-
-    if os.path.isfile(os.path.join(pypyroot, '.hg_archival.txt')):
-        return _get_hg_archive_version(os.path.join(pypyroot, '.hg_archival.txt'))
-    elif not os.path.isdir(os.path.join(pypyroot, '.hg')):
-        maywarn('Not running from a Mercurial repository!')
-        return default_retval
-    elif not hgexe:
-        maywarn('Cannot find Mercurial command!')
-        return default_retval
-    else:
-        return _get_hg_version(hgexe)
-
-
-def _get_hg_version(hgexe):
-    env = dict(os.environ)
-    # get Mercurial into scripting mode
-    env['HGPLAIN'] = '1'
-    # disable user configuration, extensions, etc.
-    env['HGRCPATH'] = os.devnull
-
-    try:
-        p = Popen([str(hgexe), 'version', '-q'],
-                  stdout=PIPE, stderr=PIPE, env=env)
-    except OSError, e:
-        maywarn(e)
-        return default_retval
-
-    if not p.stdout.read().startswith('Mercurial Distributed SCM'):
-        maywarn('command does not identify itself as Mercurial')
-        return default_retval
-
-    p = Popen([str(hgexe), 'id', '-i', pypyroot],
-              stdout=PIPE, stderr=PIPE, env=env)
-    hgid = p.stdout.read().strip()
-    maywarn(p.stderr.read())
-    if p.wait() != 0:
-        hgid = '?'
-
-    p = Popen([str(hgexe), 'id', '-t', pypyroot],
-              stdout=PIPE, stderr=PIPE, env=env)
-    hgtags = [t for t in p.stdout.read().strip().split() if t != 'tip']
-    maywarn(p.stderr.read())
-    if p.wait() != 0:
-        hgtags = ['?']
-
-    if hgtags:
-        return 'PyPy', hgtags[0], hgid
-    else:
-        # use the branch instead
-        p = Popen([str(hgexe), 'id', '-b', pypyroot],
-                  stdout=PIPE, stderr=PIPE, env=env)
-        hgbranch = p.stdout.read().strip()
-        maywarn(p.stderr.read())
-
-        return 'PyPy', hgbranch, hgid
-
-
-def _get_hg_archive_version(path):
-    fp = open(path)
-    try:
-        data = dict(x.split(': ', 1) for x in fp.read().splitlines())
-    finally:
-        fp.close()
-    if 'tag' in data:
-        return 'PyPy', data['tag'], data['node']
-    else:
-        return 'PyPy', data['branch'], data['node']
-
-
-def _get_git_version():
-    #XXX: this function is a untested hack,
-    #     so the git mirror tav made will work
-    gitexe = py.path.local.sysfind('git')
-    if not gitexe:
-        return default_retval
-
-    try:
-        p = Popen(
-            [str(gitexe), 'rev-parse', 'HEAD'],
-            stdout=PIPE, stderr=PIPE, cwd=pypyroot
-            )
-    except OSError, e:
-        maywarn(e, 'Git')
-        return default_retval
-    if p.wait() != 0:
-        maywarn(p.stderr.read(), 'Git')
-        return default_retval
-    revision_id = p.stdout.read().strip()[:12]
-    p = Popen(
-        [str(gitexe), 'describe', '--tags', '--exact-match'],
-        stdout=PIPE, stderr=PIPE, cwd=pypyroot
-        )
-    if p.wait() != 0:
-        p = Popen(
-            [str(gitexe), 'branch'], stdout=PIPE, stderr=PIPE,
-            cwd=pypyroot
-            )
-        if p.wait() != 0:
-            maywarn(p.stderr.read(), 'Git')
-            return 'PyPy', '?', revision_id
-        branch = '?'
-        for line in p.stdout.read().strip().split('\n'):
-            if line.startswith('* '):
-                branch = line[1:].strip()
-                if branch == '(no branch)':
-                    branch = '?'
-                break
-        return 'PyPy', branch, revision_id
-    return 'PyPy', p.stdout.read().strip(), revision_id
-
-
-if __name__ == '__main__':
-    print get_repo_version_info()

rpython/annotator/test/test_annrpython.py

File contents unchanged.

rpython/annotator/unaryop.py

File contents unchanged.

rpython/jit/backend/x86/runner.py

     def setup_once(self):
         self.profile_agent.startup()
         self.assembler.setup_once()
+        self.gc_set_extra_threshold()
 
     def finish_once(self):
         self.assembler.finish_once()

rpython/rlib/jit.py

File contents unchanged.

rpython/rlib/rrandom.py

 
     def jumpahead(self, n):
         mt = self.state
-        for i in range(N - 1, 0, -1):
+        for i in range(N - 1, 1, -1):
             j = n % i
             mt[i], mt[j] = mt[j], mt[i]
-        for i in range(N):
+        nonzero = False
+        for i in range(1, N):
             mt[i] += r_uint(i + 1)
+            mt[i] &= r_uint(0xffffffff)
+            nonzero |= bool(mt[i])
+        # Ensure the state is nonzero: in the unlikely event that mt[1] through
+        # mt[N-1] are all zero, set the MSB of mt[0] (see issue #14591). In the
+        # normal case, we fall back to the pre-issue 14591 behaviour for mt[0].
+        if nonzero:
+            mt[0] += r_uint(1)
+            mt[0] &= r_uint(0xffffffff)
+        else:
+            mt[0] = r_uint(0x80000000)
         self.index = N

rpython/rlib/rsocket.py

     def dup(fd):
         return _c.dup(fd)
 
+    def fromfd(fd, family, type, proto=0, SocketClass=RSocket):
+        # Dup the fd so it and the socket can be closed independently
+        fd = _c.dup(fd)
+        if fd < 0:
+            raise last_error()
+        return make_socket(fd, family, type, proto, SocketClass)
+
 def getdefaulttimeout():
     return defaults.timeout
 

rpython/rlib/test/test_jit.py

     assert driver.reds == []
     assert driver.numreds is None
     py.test.raises(TypeError, "driver.can_enter_jit(foo='something')")
-    #
-    py.test.raises(AssertionError, "JitDriver(greens=['foo'], reds='auto', get_printable_location='something')")
     py.test.raises(AssertionError, "JitDriver(greens=['foo'], reds='auto', confirm_enter_jit='something')")
 
 def test_jitdriver_numreds():

rpython/rlib/test/test_rrandom.py

     assert tuple(rnd.state) + (rnd.index, ) == cpyrandom.getstate()
 
 
+def test_jumpahead_badstate():
+    rnd = Random()
+    s, j = 4043161618, 2674112291824205302
+    rnd.init_by_array([s])
+    rnd.jumpahead(j)
+    for i in range(500):
+        r = rnd.random()
+        assert r <= 1.0, (r, i)
+
 def test_translate():
     def f(x, y):
         x = r_uint(x)

rpython/rlib/test/test_rsocket.py

     assert s.fd != s2.fd
     assert s.getsockname().eq(s2.getsockname())
 
+def test_c_dup():
+    # rsocket.dup() duplicates fd, it also works on Windows
+    # (but only on socket handles!)
+    s = RSocket(AF_INET, SOCK_STREAM)
+    s.setsockopt_int(SOL_SOCKET, SO_REUSEADDR, 1)
+    s.bind(INETAddress('localhost', 50007))
+    fd2 = dup(s.fd)
+    assert s.fd != fd2
+
 def test_inet_aton():
     assert inet_aton('1.2.3.4') == '\x01\x02\x03\x04'
     assert inet_aton('127.0.0.1') == '\x7f\x00\x00\x01'

rpython/rtyper/rlist.py

     res._ll_resize(resultlen)
     j = length
     while j < resultlen:
-        i = 0
-        while i < length:
-            p = j + i
-            res.ll_setitem_fast(p, l.ll_getitem_fast(i))
-            i += 1
+        ll_arraycopy(l, res, 0, j, length)
         j += length
     return res
 ll_inplace_mul.oopspec = 'list.inplace_mul(l, factor)'
     res = RESLIST.ll_newlist(resultlen)
     j = 0
     while j < resultlen:
-        i = 0
-        while i < length:
-            p = j + i
-            res.ll_setitem_fast(p, l.ll_getitem_fast(i))
-            i += 1
+        ll_arraycopy(l, res, 0, j, length)
         j += length
     return res
 # not inlined by the JIT -- contains a loop

rpython/tool/test/test_version.py

+import os, sys
+import py
+from rpython.tool.version import get_repo_version_info, _get_hg_archive_version
+
+def test_hg_archival_version(tmpdir):
+    def version_for(name, **kw):
+        path = tmpdir.join(name)
+        path.write('\n'.join('%s: %s' % x for x in kw.items()))
+        return _get_hg_archive_version(str(path))
+
+    assert version_for('release',
+                       tag='release-123',
+                       node='000',
+                      ) == ('RPython', 'release-123', '000')
+    assert version_for('somebranch',
+                       node='000',
+                       branch='something',
+                      ) == ('RPython', 'something', '000')
+
+
+def test_get_repo_version_info():
+    assert get_repo_version_info(None)
+    assert get_repo_version_info(os.devnull) == ('RPython', '?', '?')
+    assert get_repo_version_info(sys.executable) == ('RPython', '?', '?')

rpython/tool/udir.py

 import os, sys
 import py
 
+from rpython.tool.version import get_repo_version_info
 from py.path import local 
 
 PYPY_KEEP = int(os.environ.get('PYPY_USESSION_KEEP', '3'))
     if dir is not None:
         dir = local(dir)
     if basename is None:
-        basename = ''
+        info = get_repo_version_info()
+        if info:
+            project, hgtag, hgid = info
+            basename = hgtag
+            if basename == '?':
+                basename = 'unknown' # directories with ? are not fun
+                # especially on windows
+            if isinstance(basename, unicode):
+                basename = basename.encode(sys.getdefaultencoding())
+        else:
+            basename = ''
     basename = basename.replace('/', '--')
     if not basename.startswith('-'):
         basename = '-' + basename

rpython/tool/version.py

+import py
+import os
+from subprocess import Popen, PIPE
+import rpython
+rpythondir = os.path.dirname(os.path.abspath(rpython.__file__))
+rpythonroot = os.path.dirname(rpythondir)
+default_retval = 'RPython', '?', '?'
+
+def maywarn(err, repo_type='Mercurial'):
+    if not err:
+        return
+
+    from rpython.tool.ansi_print import ansi_log
+    log = py.log.Producer("version")
+    py.log.setconsumer("version", ansi_log)
+    log.WARNING('Errors getting %s information: %s' % (repo_type, err))
+
+def get_repo_version_info(hgexe=None):
+    '''Obtain version information by invoking the 'hg' or 'git' commands.'''
+
+    # Try to see if we can get info from Git if hgexe is not specified.
+    if not hgexe:
+        if os.path.isdir(os.path.join(rpythonroot, '.git')):
+            return _get_git_version()
+
+    # Fallback to trying Mercurial.
+    if hgexe is None:
+        hgexe = py.path.local.sysfind('hg')
+
+    if os.path.isfile(os.path.join(rpythonroot, '.hg_archival.txt')):
+        return _get_hg_archive_version(os.path.join(rpythonroot, '.hg_archival.txt'))
+    elif not os.path.isdir(os.path.join(rpythonroot, '.hg')):
+        maywarn('Not running from a Mercurial repository!')
+        return default_retval
+    elif not hgexe:
+        maywarn('Cannot find Mercurial command!')
+        return default_retval
+    else:
+        return _get_hg_version(hgexe)
+
+
+def _get_hg_version(hgexe):
+    env = dict(os.environ)
+    # get Mercurial into scripting mode
+    env['HGPLAIN'] = '1'
+    # disable user configuration, extensions, etc.
+    env['HGRCPATH'] = os.devnull
+
+    try:
+        p = Popen([str(hgexe), 'version', '-q'],
+                  stdout=PIPE, stderr=PIPE, env=env)
+    except OSError, e:
+        maywarn(e)
+        return default_retval
+
+    if not p.stdout.read().startswith('Mercurial Distributed SCM'):
+        maywarn('command does not identify itself as Mercurial')
+        return default_retval
+
+    p = Popen([str(hgexe), 'id', '-i', rpythonroot],
+              stdout=PIPE, stderr=PIPE, env=env)
+    hgid = p.stdout.read().strip()
+    maywarn(p.stderr.read())
+    if p.wait() != 0:
+        hgid = '?'
+
+    p = Popen([str(hgexe), 'id', '-t', rpythonroot],
+              stdout=PIPE, stderr=PIPE, env=env)
+    hgtags = [t for t in p.stdout.read().strip().split() if t != 'tip']
+    maywarn(p.stderr.read())
+    if p.wait() != 0:
+        hgtags = ['?']
+
+    if hgtags:
+        return 'RPython', hgtags[0], hgid
+    else:
+        # use the branch instead
+        p = Popen([str(hgexe), 'id', '-b', rpythonroot],
+                  stdout=PIPE, stderr=PIPE, env=env)
+        hgbranch = p.stdout.read().strip()
+        maywarn(p.stderr.read())
+
+        return 'RPython', hgbranch, hgid
+
+
+def _get_hg_archive_version(path):
+    fp = open(path)
+    try:
+        data = dict(x.split(': ', 1) for x in fp.read().splitlines())
+    finally:
+        fp.close()
+    if 'tag' in data:
+        return 'RPython', data['tag'], data['node']
+    else:
+        return 'RPython', data['branch'], data['node']
+
+
+def _get_git_version():
+    #XXX: this function is a untested hack,
+    #     so the git mirror tav made will work
+    gitexe = py.path.local.sysfind('git')
+    if not gitexe:
+        return default_retval
+
+    try:
+        p = Popen(
+            [str(gitexe), 'rev-parse', 'HEAD'],
+            stdout=PIPE, stderr=PIPE, cwd=rpythonroot
+            )
+    except OSError, e:
+        maywarn(e, 'Git')
+        return default_retval
+    if p.wait() != 0:
+        maywarn(p.stderr.read(), 'Git')
+        return default_retval
+    revision_id = p.stdout.read().strip()[:12]
+    p = Popen(
+        [str(gitexe), 'describe', '--tags', '--exact-match'],
+        stdout=PIPE, stderr=PIPE, cwd=rpythonroot
+        )
+    if p.wait() != 0:
+        p = Popen(
+            [str(gitexe), 'branch'], stdout=PIPE, stderr=PIPE,
+            cwd=rpythonroot
+            )
+        if p.wait() != 0:
+            maywarn(p.stderr.read(), 'Git')
+            return 'RPython', '?', revision_id
+        branch = '?'
+        for line in p.stdout.read().strip().split('\n'):
+            if line.startswith('* '):
+                branch = line[1:].strip()
+                if branch == '(no branch)':
+                    branch = '?'
+                break
+        return 'RPython', branch, revision_id
+    return 'RPython', p.stdout.read().strip(), revision_id
+
+
+if __name__ == '__main__':
+    print get_repo_version_info()

rpython/translator/platform/posix.py

             cflags = self.cflags + self.standalone_only
 
         m = GnuMakefile(path)
-        m.exe_name = exe_name
+        m.exe_name = path.join(target_name)
         m.eci = eci
 
         def rpyrel(fpath):

rpython/translator/platform/windows.py

         else:
             exe_name = exe_name.new(ext=self.exe_ext)
 
+        if shared:
+            so_name = exe_name.new(purebasename='lib' + exe_name.purebasename,
+                                   ext=self.so_ext)
+            target_name = so_name.basename
+        else:
+            target_name = exe_name.basename
+
         m = NMakefile(path)
-        m.exe_name = exe_name
+        m.exe_name = path.join(target_name)
         m.eci = eci
 
         linkflags = list(self.link_flags)
         # This is required for the JIT.
         linkflags.append('/opt:noicf')
 
-        if shared:
-            so_name = exe_name.new(purebasename='lib' + exe_name.purebasename,
-                                   ext=self.so_ext)
-            target_name = so_name.basename
-        else:
-            target_name = exe_name.basename
-
         def rpyrel(fpath):
             rel = py.path.local(fpath).relto(rpypath)
             if rel: