[pypy-svn] r76362 - in pypy/branch/x86-64-jit-backend: . lib-python lib_pypy lib_pypy/pypy_test pypy/jit/metainterp pypy/module/_rawffi/test pypy/rlib pypy/rpython/lltypesystem pypy/translator/goal pypy/translator/goal/test2

jcreigh at codespeak.net jcreigh at codespeak.net
Tue Jul 27 14:21:00 CEST 2010


Author: jcreigh
Date: Tue Jul 27 14:20:58 2010
New Revision: 76362

Modified:
   pypy/branch/x86-64-jit-backend/   (props changed)
   pypy/branch/x86-64-jit-backend/lib-python/conftest.py
   pypy/branch/x86-64-jit-backend/lib_pypy/datetime.py
   pypy/branch/x86-64-jit-backend/lib_pypy/pypy_test/test_datetime.py
   pypy/branch/x86-64-jit-backend/pypy/jit/metainterp/executor.py
   pypy/branch/x86-64-jit-backend/pypy/module/_rawffi/test/test__rawffi.py
   pypy/branch/x86-64-jit-backend/pypy/rlib/objectmodel.py
   pypy/branch/x86-64-jit-backend/pypy/rpython/lltypesystem/rstr.py
   pypy/branch/x86-64-jit-backend/pypy/translator/goal/app_main.py
   pypy/branch/x86-64-jit-backend/pypy/translator/goal/test2/test_app_main.py
Log:
merged changes from trunk through r76361

Modified: pypy/branch/x86-64-jit-backend/lib-python/conftest.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/lib-python/conftest.py	(original)
+++ pypy/branch/x86-64-jit-backend/lib-python/conftest.py	Tue Jul 27 14:20:58 2010
@@ -464,11 +464,7 @@
     RegrTest('test_coding.py'),
     RegrTest('test_complex_args.py'),
     RegrTest('test_contextlib.py', usemodules="thread"),
-    # we skip test ctypes, since we adapted it massively in order
-    # to test what we want to support. There are real failures,
-    # but it's about missing features that we don't want to support
-    # now
-    RegrTest('test_ctypes.py', skip="we have a replacement"),
+    RegrTest('test_ctypes.py', usemodules="_rawffi"),
     RegrTest('test_defaultdict.py'),
     RegrTest('test_email_renamed.py'),
     RegrTest('test_exception_variations.py'),

Modified: pypy/branch/x86-64-jit-backend/lib_pypy/datetime.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/lib_pypy/datetime.py	(original)
+++ pypy/branch/x86-64-jit-backend/lib_pypy/datetime.py	Tue Jul 27 14:20:58 2010
@@ -1412,7 +1412,7 @@
 
     def utcfromtimestamp(cls, t):
         "Construct a UTC datetime from a POSIX timestamp (like time.time())."
-        if 1 - (t % 1.0) < 0.000001:
+        if 1 - (t % 1.0) < 0.0000005:
             t = float(int(t)) + 1
         if t < 0:
             t -= 1

Modified: pypy/branch/x86-64-jit-backend/lib_pypy/pypy_test/test_datetime.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/lib_pypy/pypy_test/test_datetime.py	(original)
+++ pypy/branch/x86-64-jit-backend/lib_pypy/pypy_test/test_datetime.py	Tue Jul 27 14:20:58 2010
@@ -15,4 +15,18 @@
     expected = datetime.datetime(*(time.strptime(string, format)[0:6]))
     got = datetime.datetime.strptime(string, format)
     assert expected == got
+
+def test_datetime_rounding():
+    b = 0.0000001
+    a = 0.9999994
+
+    assert datetime.datetime.utcfromtimestamp(a).microsecond == 999999
+    assert datetime.datetime.utcfromtimestamp(a).second == 0
+    a += b
+    assert datetime.datetime.utcfromtimestamp(a).microsecond == 999999
+    assert datetime.datetime.utcfromtimestamp(a).second == 0
+    a += b
+    assert datetime.datetime.utcfromtimestamp(a).microsecond == 0
+    assert datetime.datetime.utcfromtimestamp(a).second == 1
+
     

Modified: pypy/branch/x86-64-jit-backend/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/jit/metainterp/executor.py	Tue Jul 27 14:20:58 2010
@@ -91,7 +91,7 @@
         return BoxInt(cpu.bh_getarrayitem_gc_i(arraydescr, array, index))
 
 def do_getarrayitem_raw(cpu, _, arraybox, indexbox, arraydescr):
-    array = arraybox.getref_base()
+    array = arraybox.getint()
     index = indexbox.getint()
     assert not arraydescr.is_array_of_pointers()
     if arraydescr.is_array_of_floats():

Modified: pypy/branch/x86-64-jit-backend/pypy/module/_rawffi/test/test__rawffi.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/module/_rawffi/test/test__rawffi.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/module/_rawffi/test/test__rawffi.py	Tue Jul 27 14:20:58 2010
@@ -677,7 +677,12 @@
         a = A(1)
         a[0] = -1234
         a.free()
-        
+
+    def test_long_with_fromaddress(self):
+        import _rawffi
+        addr = -1
+        raises(ValueError, _rawffi.Array('u').fromaddress, addr, 100)
+
     def test_passing_raw_pointers(self):
         import _rawffi
         lib = _rawffi.CDLL(self.lib_name)

Modified: pypy/branch/x86-64-jit-backend/pypy/rlib/objectmodel.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/rlib/objectmodel.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/rlib/objectmodel.py	Tue Jul 27 14:20:58 2010
@@ -19,29 +19,66 @@
 # def f(...
 #
 
-class _AttachSpecialization(object):
+class _Specialize(object):
+    def memo(self):
+        """ Specialize functions based on argument values. All arguments has
+        to be constant at the compile time. The whole function call is replaced
+        by a call result then.
+        """
+        def decorated_func(func):
+            func._annspecialcase_ = 'memo()'
+            return func
+        return decorated_func
 
-    def __init__(self, tag):
-        self.tag = tag
+    def arg(self, *args):
+        """ Specialize function based on values of given positions of arguments.
+        They must be compile-time constants in order to work.
+
+        There will be a copy of provided function for each combination
+        of given arguments on positions in args (that can lead to
+        exponential behavior!).
+        """
+        def decorated_func(func):
+            func._annspecialcase_ = 'args' + self._wrap(args)
+            return func
 
-    def __call__(self, *args):
-        if not args:
-            args = ""
-        else:
-            args = "("+','.join([repr(arg) for arg in args]) +")"
-        specialcase = "specialize:%s%s" % (self.tag, args)
-        
-        def specialize_decorator(func):
-            "NOT_RPYTHON"
-            func._annspecialcase_ = specialcase
+        return decorated_func
+
+    def argtype(self, *args):
+        """ Specialize function based on types of arguments on given positions.
+
+        There will be a copy of provided function for each combination
+        of given arguments on positions in args (that can lead to
+        exponential behavior!).
+        """
+        def decorated_func(func):
+            func._annspecialcase_ = 'argtypes' + self._wrap(args)
             return func
 
-        return specialize_decorator
-        
-class _Specialize(object):
+        return decorated_func
+
+    def ll(self):
+        """ This is version of argtypes that cares about low-level types
+        (so it'll get additional copies for two different types of pointers
+        for example). Same warnings about exponential behavior apply.
+        """
+        def decorated_func(func):
+            func._annspecialcase_ = 'll()'
+            return func
+
+        return decorated_func
+
+    def ll_and_arg(self, arg):
+        """ XXX what does that do?
+        """
+        def decorated_func(func):
+            func._annspecialcase_ = 'll_and_arg(%d)' % arg
+            return func
+
+        return decorated_func
 
-    def __getattr__(self, name):
-        return _AttachSpecialization(name)
+    def _wrap(self, args):
+        return "("+','.join([repr(arg) for arg in args]) +")"
         
 specialize = _Specialize()
 

Modified: pypy/branch/x86-64-jit-backend/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/rpython/lltypesystem/rstr.py	Tue Jul 27 14:20:58 2010
@@ -674,6 +674,7 @@
             res_index += item_len
             i += 1
         return result
+    ll_join_strs._annenforceargs_ = [int, None]
 
     def ll_join_chars(length, chars):
         # no need to optimize this, will be replaced by string builder

Modified: pypy/branch/x86-64-jit-backend/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/translator/goal/app_main.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/translator/goal/app_main.py	Tue Jul 27 14:20:58 2010
@@ -223,7 +223,6 @@
     path = os.getenv('PYTHONPATH')
     if path:
         newpath = path.split(os.pathsep) + newpath
-    newpath.insert(0, '')
     # remove duplicates
     _seen = {}
     del sys.path[:]
@@ -327,6 +326,10 @@
         except:
             print >> sys.stderr, "'import site' failed"
 
+    # update sys.path *after* loading site.py, in case there is a
+    # "site.py" file in the script's directory.
+    sys.path.insert(0, '')
+
     if warnoptions:
         sys.warnoptions.append(warnoptions)
         from warnings import _processoptions

Modified: pypy/branch/x86-64-jit-backend/pypy/translator/goal/test2/test_app_main.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/translator/goal/test2/test_app_main.py	(original)
+++ pypy/branch/x86-64-jit-backend/pypy/translator/goal/test2/test_app_main.py	Tue Jul 27 14:20:58 2010
@@ -5,6 +5,7 @@
 import sys, os, re
 import autopath
 from pypy.tool.udir import udir
+from contextlib import contextmanager
 
 banner = sys.version.splitlines()[0]
 
@@ -326,8 +327,9 @@
 class TestNonInteractive:
 
     def run(self, cmdline, senddata='', expect_prompt=False,
-            expect_banner=False):
-        cmdline = '%s "%s" %s' % (sys.executable, app_main, cmdline)
+            expect_banner=False, python_flags=''):
+        cmdline = '%s %s "%s" %s' % (sys.executable, python_flags,
+                                     app_main, cmdline)
         print 'POPEN:', cmdline
         child_in, child_out_err = os.popen4(cmdline)
         child_in.write(senddata)
@@ -449,6 +451,43 @@
         assert data == '\x00(STDOUT)\n\x00'    # from stdout
         child_out_err.close()
 
+    def test_proper_sys_path(self, tmpdir):
+
+        @contextmanager
+        def chdir_and_unset_pythonpath(new_cwd):
+            old_cwd = new_cwd.chdir()
+            old_pythonpath = os.getenv('PYTHONPATH')
+            os.unsetenv('PYTHONPATH')
+            try:
+                yield
+            finally:
+                old_cwd.chdir()
+                os.putenv('PYTHONPATH', old_pythonpath)
+        
+        tmpdir.join('site.py').write('print "SHOULD NOT RUN"')
+        runme_py = tmpdir.join('runme.py')
+        runme_py.write('print "some text"')
+
+        cmdline = str(runme_py)
+
+        with chdir_and_unset_pythonpath(tmpdir):
+            data = self.run(cmdline, python_flags='-S')
+
+        assert data == "some text\n"
+
+        runme2_py = tmpdir.mkdir('otherpath').join('runme2.py')
+        runme2_py.write('print "some new text"\n'
+                        'import sys\n'
+                        'print sys.path\n')
+
+        cmdline2 = str(runme2_py)
+
+        with chdir_and_unset_pythonpath(tmpdir):
+            data = self.run(cmdline2, python_flags='-S')
+
+        assert data.startswith("some new text\n")
+        assert repr(str(tmpdir.join('otherpath'))) in data
+
 
 class AppTestAppMain:
 



More information about the Pypy-commit mailing list