Author: Maciej Fijalkowski <[email protected]>
Branch: 
Changeset: r44322:a0e08567e692
Date: 2011-05-20 12:54 +0200
http://bitbucket.org/pypy/pypy/changeset/a0e08567e692/

Log:    merge what's interesting from jit-applevel-info branch, the rest
        will be retried differently

diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py
--- a/pypy/rlib/debug.py
+++ b/pypy/rlib/debug.py
@@ -140,6 +140,40 @@
             return hop.inputconst(lltype.Bool, False)
 
 
+def debug_offset():
+    """ Return an offset in log file
+    """
+    return -1
+
+class Entry(ExtRegistryEntry):
+    _about_ = debug_offset
+
+    def compute_result_annotation(self):
+        from pypy.annotation import model as annmodel
+        return annmodel.SomeInteger()
+
+    def specialize_call(self, hop):
+        from pypy.rpython.lltypesystem import lltype
+        hop.exception_cannot_occur()
+        return hop.genop('debug_offset', [], resulttype=lltype.Signed)
+
+
+def debug_flush():
+    """ Flushes the debug file
+    """
+    pass
+
+class Entry(ExtRegistryEntry):
+    _about_ = debug_flush
+
+    def compute_result_annotation(self):
+        return None
+    
+    def specialize_call(self, hop):
+        hop.exception_cannot_occur()
+        return hop.genop('debug_flush', [])
+
+
 def llinterpcall(RESTYPE, pythonfunction, *args):
     """When running on the llinterp, this causes the llinterp to call to
     the provided Python function with the run-time value of the given args.
diff --git a/pypy/rlib/test/test_debug.py b/pypy/rlib/test/test_debug.py
--- a/pypy/rlib/test/test_debug.py
+++ b/pypy/rlib/test/test_debug.py
@@ -2,7 +2,7 @@
 import py
 from pypy.rlib.debug import check_annotation, make_sure_not_resized
 from pypy.rlib.debug import debug_print, debug_start, debug_stop
-from pypy.rlib.debug import have_debug_prints
+from pypy.rlib.debug import have_debug_prints, debug_offset
 from pypy.rlib.debug import check_nonneg, IntegerCanBeNegative
 from pypy.rlib import debug
 from pypy.rpython.test.test_llinterp import interpret
@@ -60,6 +60,8 @@
             debug_start("mycat")
             debug_print("foo", 2, "bar", x)
             debug_stop("mycat")
+            debug_flush() # does nothing
+            debug_offset() # should not explode at least
             return have_debug_prints()
 
         try:
diff --git a/pypy/rpython/lltypesystem/lloperation.py 
b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -553,6 +553,8 @@
     'debug_start':          LLOp(canrun=True),
     'debug_stop':           LLOp(canrun=True),
     'have_debug_prints':    LLOp(canrun=True),
+    'debug_offset':         LLOp(canrun=True),
+    'debug_flush':          LLOp(canrun=True),
     'debug_assert':         LLOp(tryfold=True),
     'debug_fatalerror':     LLOp(),
     'debug_llinterpcall':   LLOp(canraise=(Exception,)),
diff --git a/pypy/rpython/lltypesystem/opimpl.py 
b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -513,6 +513,12 @@
 def op_debug_stop(category):
     debug.debug_stop(_normalize(category))
 
+def op_debug_offset():
+    return debug.debug_offset()
+
+def op_debug_flush():
+    pass
+
 def op_have_debug_prints():
     return debug.have_debug_prints()
 
diff --git a/pypy/translator/c/src/debug_print.c 
b/pypy/translator/c/src/debug_print.c
--- a/pypy/translator/c/src/debug_print.c
+++ b/pypy/translator/c/src/debug_print.c
@@ -65,6 +65,15 @@
   debug_ready = 1;
 }
 
+long pypy_debug_offset(void)
+{
+  if (!debug_ready)
+    return -1;
+  // note that we deliberately ignore errno, since -1 is fine
+  // in case this is not a real file
+  return ftell(pypy_debug_file);
+}
+
 void pypy_debug_ensure_opened(void)
 {
   if (!debug_ready)
diff --git a/pypy/translator/c/src/debug_print.h 
b/pypy/translator/c/src/debug_print.h
--- a/pypy/translator/c/src/debug_print.h
+++ b/pypy/translator/c/src/debug_print.h
@@ -26,8 +26,9 @@
 #define PYPY_DEBUG_FILE           pypy_debug_file
 #define PYPY_DEBUG_START(cat)     pypy_debug_start(cat)
 #define PYPY_DEBUG_STOP(cat)      pypy_debug_stop(cat)
+#define OP_DEBUG_OFFSET(res)      res = pypy_debug_offset()
 #define OP_HAVE_DEBUG_PRINTS(r)   r = (pypy_have_debug_prints & 1)
-
+#define OP_DEBUG_FLUSH() fflush(pypy_debug_file)
 
 /************************************************************/
 
@@ -35,6 +36,7 @@
 void pypy_debug_ensure_opened(void);
 void pypy_debug_start(const char *category);
 void pypy_debug_stop(const char *category);
+long pypy_debug_offset(void);
 
 extern long pypy_have_debug_prints;
 extern FILE *pypy_debug_file;
diff --git a/pypy/translator/c/test/test_standalone.py 
b/pypy/translator/c/test/test_standalone.py
--- a/pypy/translator/c/test/test_standalone.py
+++ b/pypy/translator/c/test/test_standalone.py
@@ -3,8 +3,8 @@
 
 from pypy.rlib.objectmodel import keepalive_until_here
 from pypy.rlib.rarithmetic import r_longlong
-from pypy.rlib.debug import ll_assert, have_debug_prints
-from pypy.rlib.debug import debug_print, debug_start, debug_stop
+from pypy.rlib.debug import ll_assert, have_debug_prints, debug_flush
+from pypy.rlib.debug import debug_print, debug_start, debug_stop, debug_offset
 from pypy.translator.translator import TranslationContext
 from pypy.translator.backendopt import all
 from pypy.translator.c.genc import CStandaloneBuilder, ExternalCompilationInfo
@@ -284,12 +284,13 @@
             debug_stop   ("mycat")
             if have_debug_prints(): x += "a"
             debug_print("toplevel")
-            os.write(1, x + '.\n')
+            debug_flush()
+            os.write(1, x + "." + str(debug_offset()) + '.\n')
             return 0
         t, cbuilder = self.compile(entry_point)
         # check with PYPYLOG undefined
         out, err = cbuilder.cmdexec("", err=True, env={})
-        assert out.strip() == 'got:a.'
+        assert out.strip() == 'got:a.-1.'
         assert 'toplevel' in err
         assert 'mycat' not in err
         assert 'foo 2 bar 3' not in err
@@ -298,7 +299,7 @@
         assert 'bok' not in err
         # check with PYPYLOG defined to an empty string (same as undefined)
         out, err = cbuilder.cmdexec("", err=True, env={'PYPYLOG': ''})
-        assert out.strip() == 'got:a.'
+        assert out.strip() == 'got:a.-1.'
         assert 'toplevel' in err
         assert 'mycat' not in err
         assert 'foo 2 bar 3' not in err
@@ -307,7 +308,7 @@
         assert 'bok' not in err
         # check with PYPYLOG=:- (means print to stderr)
         out, err = cbuilder.cmdexec("", err=True, env={'PYPYLOG': ':-'})
-        assert out.strip() == 'got:bcda.'
+        assert out.strip() == 'got:bcda.-1.'
         assert 'toplevel' in err
         assert '{mycat' in err
         assert 'mycat}' in err
@@ -320,7 +321,8 @@
         path = udir.join('test_debug_xxx.log')
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': ':%s' % path})
-        assert out.strip() == 'got:bcda.'
+        size = os.stat(str(path)).st_size
+        assert out.strip() == 'got:bcda.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -335,7 +337,8 @@
         # check with PYPYLOG=somefilename
         path = udir.join('test_debug_xxx_prof.log')
         out, err = cbuilder.cmdexec("", err=True, env={'PYPYLOG': str(path)})
-        assert out.strip() == 'got:a.'
+        size = os.stat(str(path)).st_size
+        assert out.strip() == 'got:a.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -351,7 +354,8 @@
         path = udir.join('test_debug_xxx_myc.log')
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': 'myc:%s' % path})
-        assert out.strip() == 'got:bda.'
+        size = os.stat(str(path)).st_size
+        assert out.strip() == 'got:bda.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -366,7 +370,8 @@
         path = udir.join('test_debug_xxx_cat.log')
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': 'cat:%s' % path})
-        assert out.strip() == 'got:ca.'
+        size = os.stat(str(path)).st_size
+        assert out.strip() == 'got:ca.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -380,7 +385,8 @@
         path = udir.join('test_debug_xxx_myc_cat2.log')
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': 'myc,cat2:%s' % path})
-        assert out.strip() == 'got:bcda.'
+        size = os.stat(str(path)).st_size
+        assert out.strip() == 'got:bcda.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -401,7 +407,7 @@
         path = udir.join('test_debug_does_not_show_up.log')
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': ':%s' % path})
-        assert out.strip() == 'got:.'
+        assert out.strip() == 'got:.-1.'
         assert not err
         assert path.check(file=0)
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to