[pypy-svn] r79278 - in pypy/branch/jit-free/pypy/translator/c: . test

antocuni at codespeak.net antocuni at codespeak.net
Fri Nov 19 16:13:31 CET 2010


Author: antocuni
Date: Fri Nov 19 16:13:29 2010
New Revision: 79278

Modified:
   pypy/branch/jit-free/pypy/translator/c/funcgen.py
   pypy/branch/jit-free/pypy/translator/c/test/test_standalone.py
Log:
(arigo, antocuni): make debug_{start,stop} working also with non-constant strings (needed by __pypy__.debug*)


Modified: pypy/branch/jit-free/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/jit-free/pypy/translator/c/funcgen.py	(original)
+++ pypy/branch/jit-free/pypy/translator/c/funcgen.py	Fri Nov 19 16:13:29 2010
@@ -769,17 +769,20 @@
             "if (PYPY_HAVE_DEBUG_PRINTS) { fprintf(PYPY_DEBUG_FILE, %s); %s}"
             % (', '.join(argv), free_line))
 
+    def _op_debug(self, opname, arg):
+        if isinstance(arg, Constant):
+            string_literal = c_string_constant(''.join(arg.value.chars))
+            return "%s(%s);" % (opname, string_literal)
+        else:
+            x = "%s(RPyString_AsCharP(%s));\n" % (opname, self.expr(arg))
+            x += "RPyString_FreeCache();"
+            return x
+
     def OP_DEBUG_START(self, op):
-        arg = op.args[0]
-        assert isinstance(arg, Constant)
-        return "PYPY_DEBUG_START(%s);" % (
-            c_string_constant(''.join(arg.value.chars)),)
+        return self._op_debug('PYPY_DEBUG_START', op.args[0])
 
     def OP_DEBUG_STOP(self, op):
-        arg = op.args[0]
-        assert isinstance(arg, Constant)
-        return "PYPY_DEBUG_STOP(%s);" % (
-            c_string_constant(''.join(arg.value.chars)),)
+        return self._op_debug('PYPY_DEBUG_STOP', op.args[0])
 
     def OP_DEBUG_ASSERT(self, op):
         return 'RPyAssert(%s, %s);' % (self.expr(op.args[0]),

Modified: pypy/branch/jit-free/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/jit-free/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/branch/jit-free/pypy/translator/c/test/test_standalone.py	Fri Nov 19 16:13:29 2010
@@ -388,6 +388,20 @@
         assert not err
         assert path.check(file=0)
 
+    def test_debug_print_start_stop_nonconst(self):
+        def entry_point(argv):
+            debug_start(argv[1])
+            debug_print(argv[2])
+            debug_stop(argv[1])
+            return 0
+        t, cbuilder = self.compile(entry_point)
+        out, err = cbuilder.cmdexec("foo bar", err=True, env={'PYPYLOG': ':-'})
+        lines = err.splitlines()
+        assert '{foo' in lines[0]
+        assert 'bar' == lines[1]
+        assert 'foo}' in lines[2]
+
+
     def test_fatal_error(self):
         def g(x):
             if x == 1:



More information about the Pypy-commit mailing list