[pypy-svn] r79301 - in pypy/branch/jit-free/pypy/translator/c: src test

arigo at codespeak.net arigo at codespeak.net
Sat Nov 20 15:18:37 CET 2010


Author: arigo
Date: Sat Nov 20 15:18:36 2010
New Revision: 79301

Modified:
   pypy/branch/jit-free/pypy/translator/c/src/debug_print.h
   pypy/branch/jit-free/pypy/translator/c/test/test_standalone.py
Log:
Merge r79297 from trunk.


Modified: pypy/branch/jit-free/pypy/translator/c/src/debug_print.h
==============================================================================
--- pypy/branch/jit-free/pypy/translator/c/src/debug_print.h	(original)
+++ pypy/branch/jit-free/pypy/translator/c/src/debug_print.h	Sat Nov 20 15:18:36 2010
@@ -10,6 +10,7 @@
                      but not any nested debug_print
    :fname         full logging
    prefix:fname   conditional logging
+   prefix1,prefix2:fname   conditional logging with multiple selections
 
    Conditional logging means that it only includes the debug_start/debug_stop
    sections whose name match 'prefix'.  Other sections are ignored, including
@@ -70,6 +71,8 @@
 static void pypy_debug_open(void)
 {
   char *filename = getenv("PYPYLOG");
+  if (filename)
+    unsetenv("PYPYLOG");   /* don't pass it to subprocesses */
   if (filename && filename[0])
     {
       char *colon = strchr(filename, ':');
@@ -139,12 +142,22 @@
 #endif
 
 
-static bool_t startswith(const char *str, const char *substr)
+static bool_t startswithoneof(const char *str, const char *substr)
 {
-  while (*substr)
-    if (*str++ != *substr++)
-      return 0;
-  return 1;
+  const char *p = str;
+  for (; *substr; substr++)
+    {
+      if (*substr != ',')
+        {
+          if (p && *p++ != *substr)
+            p = NULL;   /* mismatch */
+        }
+      else if (p != NULL)
+        return 1;   /* match */
+      else
+        p = str;    /* mismatched, retry with the next */
+    }
+  return p != NULL;
 }
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
@@ -175,7 +188,7 @@
   if (!debug_profile)
     {
       /* non-profiling version */
-      if (!debug_prefix || !startswith(category, debug_prefix))
+      if (!debug_prefix || !startswithoneof(category, debug_prefix))
         {
           /* wrong section name, or no PYPYLOG at all, skip it */
           return;

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	Sat Nov 20 15:18:36 2010
@@ -368,12 +368,27 @@
         assert not err
         assert path.check(file=1)
         data = path.read()
-        assert 'toplevel' in path.read()
-        assert 'mycat' not in path.read()
-        assert 'foo 2 bar 3' not in path.read()
+        assert 'toplevel' in data
+        assert 'mycat' not in data
+        assert 'foo 2 bar 3' not in data
         assert 'cat2' in data
         assert 'baz' in data
         assert 'bok' not in data
+        # check with PYPYLOG=myc,cat2:somefilename   (includes mycat and cat2)
+        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.'
+        assert not err
+        assert path.check(file=1)
+        data = path.read()
+        assert 'toplevel' in data
+        assert '{mycat' in data
+        assert 'mycat}' in data
+        assert 'foo 2 bar 3' in data
+        assert 'cat2' in data
+        assert 'baz' in data
+        assert 'bok' in data
         #
         # finally, check compiling with logging disabled
         from pypy.config.pypyoption import get_pypy_config



More information about the Pypy-commit mailing list