Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3k
Changeset: r63755:832759b67482
Date: 2013-04-29 11:07 -0700
http://bitbucket.org/pypy/pypy/changeset/832759b67482/

Log:    merge default

diff --git a/lib-python/2.7/pydoc.py b/lib-python/2.7/pydoc.py
--- a/lib-python/2.7/pydoc.py
+++ b/lib-python/2.7/pydoc.py
@@ -1953,7 +1953,11 @@
                 if key is None:
                     callback(None, modname, '')
                 else:
-                    desc = split(__import__(modname).__doc__ or '', '\n')[0]
+                    try:
+                        module_doc = __import__(modname).__doc__
+                    except ImportError:
+                        module_doc = None
+                    desc = split(module_doc or '', '\n')[0]
                     if find(lower(modname + ' - ' + desc), key) >= 0:
                         callback(None, modname, desc)
 
diff --git a/py/_path/local.py b/py/_path/local.py
--- a/py/_path/local.py
+++ b/py/_path/local.py
@@ -655,7 +655,8 @@
     mkdtemp = classmethod(mkdtemp)
 
     def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,
-                          lock_timeout = 172800):   # two days
+                          lock_timeout = 172800,   # two days
+                          min_timeout = 300):      # five minutes
         """ return unique directory with a number greater than the current
             maximum one.  The number is assumed to start directly after prefix.
             if keep is true directories with a number less than (maxnum-keep)
@@ -723,6 +724,20 @@
             for path in rootdir.listdir():
                 num = parse_num(path)
                 if num is not None and num <= (maxnum - keep):
+                    if min_timeout:
+                        # NB: doing this is needed to prevent (or reduce
+                        # a lot the chance of) the following situation:
+                        # 'keep+1' processes call make_numbered_dir() at
+                        # the same time, they create dirs, but then the
+                        # last process notices the first dir doesn't have
+                        # (yet) a .lock in it and kills it.
+                        try:
+                            t1 = path.lstat().mtime
+                            t2 = lockfile.lstat().mtime
+                            if abs(t2-t1) < min_timeout:
+                                continue   # skip directories too recent
+                        except py.error.Error:
+                            continue   # failure to get a time, better skip
                     lf = path.join('.lock')
                     try:
                         t1 = lf.lstat().mtime
diff --git a/pypy/doc/getting-started-python.rst 
b/pypy/doc/getting-started-python.rst
--- a/pypy/doc/getting-started-python.rst
+++ b/pypy/doc/getting-started-python.rst
@@ -46,7 +46,7 @@
 2. Install build-time dependencies.  On a Debian box these are::
 
      [user@debian-box ~]$ sudo apt-get install \
-     gcc make python-dev libffi-dev lib-sqlite3-dev pkg-config \
+     gcc make python-dev libffi-dev libsqlite3-dev pkg-config \
      libz-dev libbz2-dev libncurses-dev libexpat1-dev \
      libssl-dev libgc-dev python-sphinx python-greenlet
 
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -89,9 +89,15 @@
 
 builtin_xrange = builtin_range # xxx for now allow it
 
+
 def builtin_enumerate(s_obj):
     return SomeIterator(s_obj, "enumerate")
 
+
+def builtin_reversed(s_obj):
+    return SomeIterator(s_obj, "reversed")
+
+
 def builtin_bool(s_obj):
     return s_obj.is_true()
 
diff --git a/rpython/annotator/test/test_annrpython.py 
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -3837,6 +3837,16 @@
         s = a.build_types(fn, [int])
         assert isinstance(s, annmodel.SomeInteger)
 
+    def test_reversed(self):
+        def fn(n):
+            for elem in reversed([1, 2, 3, 4, 5]):
+                return elem
+            return n
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(fn, [int])
+        assert isinstance(s, annmodel.SomeInteger)
+
     def test_no_attr_on_common_exception_classes(self):
         for cls in [ValueError, Exception]:
             def fn():
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -616,7 +616,10 @@
         if itr.variant == ("enumerate",):
             s_item = itr.s_container.getanyitem()
             return SomeTuple((SomeInteger(nonneg=True), s_item))
-        return itr.s_container.getanyitem(*itr.variant)
+        variant = itr.variant
+        if variant == ("reversed",):
+            variant = ()
+        return itr.s_container.getanyitem(*variant)
     next.can_only_throw = _can_only_throw
     method_next = next
 
diff --git a/rpython/rtyper/lltypesystem/rlist.py 
b/rpython/rtyper/lltypesystem/rlist.py
--- a/rpython/rtyper/lltypesystem/rlist.py
+++ b/rpython/rtyper/lltypesystem/rlist.py
@@ -52,8 +52,13 @@
     def get_eqfunc(self):
         return inputconst(Void, self.item_repr.get_ll_eq_function())
 
-    def make_iterator_repr(self):
-        return ListIteratorRepr(self)
+    def make_iterator_repr(self, *variant):
+        if not variant:
+            return ListIteratorRepr(self)
+        elif variant == ("reversed",):
+            return ReversedListIteratorRepr(self)
+        else:
+            raise NotImplementedError(variant)
 
     def get_itemarray_lowleveltype(self):
         ITEM = self.item_repr.lowleveltype
@@ -432,6 +437,7 @@
             self.ll_listnext = ll_listnext
         self.ll_getnextindex = ll_getnextindex
 
+
 def ll_listiter(ITERPTR, lst):
     iter = malloc(ITERPTR.TO)
     iter.list = lst
@@ -457,3 +463,30 @@
 
 def ll_getnextindex(iter):
     return iter.index
+
+
+class ReversedListIteratorRepr(AbstractListIteratorRepr):
+    def __init__(self, r_list):
+        self.r_list = r_list
+        self.lowleveltype = Ptr(GcStruct('revlistiter',
+            ('list', r_list.lowleveltype),
+            ('index', Signed),
+        ))
+        self.ll_listnext = ll_revlistnext
+        self.ll_listiter = ll_revlistiter
+
+
+def ll_revlistiter(ITERPTR, lst):
+    iter = malloc(ITERPTR.TO)
+    iter.list = lst
+    iter.index = lst.ll_length() - 1
+    return iter
+
+
+def ll_revlistnext(iter):
+    l = iter.list
+    index = iter.index
+    if index < 0:
+        raise StopIteration
+    iter.index -= 1
+    return l.ll_getitem_fast(index)
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -261,6 +261,12 @@
     hop.exception_cannot_occur()
     return hop.gendirectcall(ll_max, v1, v2)
 
+
+def rtype_builtin_reversed(hop):
+    hop.exception_cannot_occur()
+    return hop.r_result.newiter(hop)
+
+
 def ll_max(i1, i2):
     if i1 > i2:
         return i1
diff --git a/rpython/rtyper/test/test_rlist.py 
b/rpython/rtyper/test/test_rlist.py
--- a/rpython/rtyper/test/test_rlist.py
+++ b/rpython/rtyper/test/test_rlist.py
@@ -510,6 +510,17 @@
         res = self.interpret(dummyfn, ())
         assert res == 235
 
+    def test_reversed(self):
+        klist = [1, 2, 3]
+
+        def fn():
+            res = []
+            for elem in reversed(klist):
+                res.append(elem)
+            return res[0] * 100 + res[1] * 10 + res[2]
+        res = self.interpret(fn, [])
+        assert res == fn()
+
     def test_prebuilt_list(self):
         klist = [6, 7, 8, 9]
         def dummyfn(n):
@@ -1604,3 +1615,6 @@
 class TestOOtype(BaseTestRlist, OORtypeMixin):
     rlist = oo_rlist
     type_system = 'ootype'
+
+    def test_reversed(self):
+        py.test.skip("unsupported")
diff --git a/rpython/rtyper/test/test_runicode.py 
b/rpython/rtyper/test/test_runicode.py
--- a/rpython/rtyper/test/test_runicode.py
+++ b/rpython/rtyper/test/test_runicode.py
@@ -274,6 +274,7 @@
     test_char_isxxx = unsupported
     test_isdigit = unsupported
     test_str_isalpha = unsupported
+    test_str_isalnum = unsupported
     test_upper = unsupported
     test_lower = unsupported
     test_splitlines = unsupported
diff --git a/rpython/rtyper/tool/rffi_platform.py 
b/rpython/rtyper/tool/rffi_platform.py
--- a/rpython/rtyper/tool/rffi_platform.py
+++ b/rpython/rtyper/tool/rffi_platform.py
@@ -721,6 +721,8 @@
     eci = eci.convert_sources_to_files()
     files = [filepath]
     output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
+    if not output.startswith('-+- '):
+        raise Exception("run_example_code failed!\nlocals = %r" % (locals(),))
     section = None
     for line in output.splitlines():
         line = line.strip()
diff --git a/rpython/tool/gcc_cache.py b/rpython/tool/gcc_cache.py
--- a/rpython/tool/gcc_cache.py
+++ b/rpython/tool/gcc_cache.py
@@ -1,7 +1,7 @@
 from rpython.translator.platform import CompilationError
 from rpython.conftest import cache_dir
 from hashlib import md5
-import py
+import py, os
 
 cache_dir_root = py.path.local(cache_dir).ensure(dir=1)
 
@@ -35,37 +35,45 @@
             # compare equal to another instance without it
             if platform.log_errors != _previous:
                 platform.log_errors = _previous
-        path.write(result.out)
+        try_atomic_write(path, result.out)
         return result.out
 
+def try_atomic_write(path, data):
+    path = str(path)
+    tmppath = '%s~%d' % (path, os.getpid())
+    f = open(tmppath, 'wb')
+    f.write(data)
+    f.close()
+    try:
+        os.rename(tmppath, path)
+    except OSError:
+        try:
+            os.unlink(tmppath)
+        except OSError:
+            pass
+
 def try_compile_cache(c_files, eci):
-    "Try to compile a program; caches the result (starts with 'True' or 
'FAIL')"
+    "Try to compile a program.  If it works, caches this fact."
     # Import 'platform' every time, the compiler may have been changed
     from rpython.translator.platform import platform
     path = cache_file_path(c_files, eci, 'try_compile_cache')
     try:
         data = path.read()
+        if data == 'True':
+            return True
     except py.error.Error:
-        data = ''
-    if not (data.startswith('True') or data.startswith('FAIL\n')):
-        try:
-            _previous = platform.log_errors
-            try:
-                platform.log_errors = False
-                platform.compile(c_files, eci)
-            finally:
-                del platform.log_errors
-                # ^^^remove from the instance --- needed so that it can
-                # compare equal to another instance without it
-                if platform.log_errors != _previous:
-                    platform.log_errors = _previous
-            data = 'True'
-            path.write(data)
-        except CompilationError, e:
-            data = 'FAIL\n%s\n' % (e,)
-    if data.startswith('True'):
-        return True
-    else:
-        assert data.startswith('FAIL\n')
-        msg = data[len('FAIL\n'):]
-        raise CompilationError(msg.strip(), '')
+        pass
+    #
+    _previous = platform.log_errors
+    try:
+        platform.log_errors = False
+        platform.compile(c_files, eci)
+        # ^^^ may raise CompilationError.  We don't cache such results.
+    finally:
+        del platform.log_errors
+        # ^^^remove from the instance --- needed so that it can
+        # compare equal to another instance without it
+        if platform.log_errors != _previous:
+            platform.log_errors = _previous
+    path.write('True')
+    return True
diff --git a/rpython/translator/platform/openbsd.py 
b/rpython/translator/platform/openbsd.py
--- a/rpython/translator/platform/openbsd.py
+++ b/rpython/translator/platform/openbsd.py
@@ -2,9 +2,10 @@
 
 import os
 
-from pypy.translator.platform.bsd import BSD
+from rpython.translator.platform.bsd import BSD
 
 class OpenBSD(BSD):
+    DEFAULT_CC = "cc"
     name = "openbsd"
 
     link_flags = os.environ.get("LDFLAGS", '-pthread').split()
diff --git a/tddium.yml b/tddium.yml
--- a/tddium.yml
+++ b/tddium.yml
@@ -13,7 +13,6 @@
      - exclude: rpython/jit/backend/cli/**  # bitrotted AFAICT
      - exclude: rpython/jit/backend/llvm/** # bitrotted AFAICT
      # and things requiring a fix in Tddium, omitted to avoid confusion:
-     - exclude: pypy/tool/pytest/**  # we're running upstream pytest
      - exclude: rpython/rlib/unicodedata/test/test_ucd.py # need wide build
      - exclude: rpython/rlib/test/test_runicode.py # need wide build
      - exclude: rpython/rlib/test/test_rsocket.py # not clear why fails
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to