Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r43:c27946a8f461
Date: 2013-05-27 16:14 +0200
http://bitbucket.org/pypy/stmgc/changeset/c27946a8f461/

Log:    Add a hack to display the stderr messages in colors depending on
        which thread emits them.

diff --git a/c3/fprintcolor.h b/c3/fprintcolor.h
new file mode 100644
--- /dev/null
+++ b/c3/fprintcolor.h
@@ -0,0 +1,37 @@
+#include <stdarg.h>
+
+
+#define fprintf threadcolor_fprintf
+
+
+int threadcolor_fprintf(FILE *stream, const char *format, ...)
+     __attribute__((unused, format (printf, 2, 3), weak));
+
+int threadcolor_fprintf(FILE *stream, const char *format, ...)
+{
+    char buffer[2048];
+    va_list ap;
+    int result;
+    static __thread revision_t color = 0;
+    if (color == 0) {
+        static revision_t nextid = 0;
+        while (1) {
+            color = nextid;
+            if (bool_cas(&nextid, color, color + 1))
+                break;
+        }
+        color = 31 + color % 7;
+    }
+    int size = (int)sprintf(buffer, "\033[%dm", (int)color);
+    assert(size >= 0);
+
+    va_start(ap, format);
+    result = vsnprintf(buffer + size, 2000, format, ap);
+    assert(result >= 0);
+    va_end(ap);
+
+    strcpy(buffer + size + result, "\033[0m");
+    fputs(buffer, stream);
+
+    return result;
+}
diff --git a/c3/stmimpl.h b/c3/stmimpl.h
--- a/c3/stmimpl.h
+++ b/c3/stmimpl.h
@@ -27,6 +27,7 @@
 
 #include "stmgc.h"
 #include "atomic_ops.h"
+#include "fprintcolor.h"
 #include "lists.h"
 #include "dbgmem.h"
 #include "nursery.h"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to