Author: Amaury Forgeot d'Arc <[email protected]>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r57721:c16499d28e1f
Date: 2012-09-30 20:39 +0200
http://bitbucket.org/pypy/pypy/changeset/c16499d28e1f/

Log:    Split instrument.h and instrument.c

diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -840,7 +840,7 @@
         self.db.instrument_ncounter = max(self.db.instrument_ncounter,
                                           counter_label+1)
         counter_label = self.expr(op.args[1])
-        return 'INSTRUMENT_COUNT(%s);' % counter_label
+        return 'PYPY_INSTRUMENT_COUNT(%s);' % counter_label
             
     def OP_IS_EARLY_CONSTANT(self, op):
         return '%s = 0; /* IS_EARLY_CONSTANT */' % (self.expr(op.result),)
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -252,7 +252,7 @@
         else:
             defines['PYPY_STANDALONE'] = db.get(pf)
             if self.config.translation.instrument:
-                defines['INSTRUMENT'] = 1
+                defines['PYPY_INSTRUMENT'] = 1
             if CBuilder.have___thread:
                 if not self.config.translation.no__thread:
                     defines['USE___THREAD'] = 1
@@ -912,6 +912,7 @@
         srcdir / 'debug_print.c',
         srcdir / 'thread.c',
         srcdir / 'asm.c',
+        srcdir / 'instrument.c',
     ]
     if _CYGWIN:
         files.append(srcdir / 'cygwin_wait.c')
@@ -961,10 +962,10 @@
     gen_startupcode(f, database)
     f.close()
 
-    if 'INSTRUMENT' in defines:
+    if 'PYPY_INSTRUMENT' in defines:
         fi = incfilename.open('a')
         n = database.instrument_ncounter
-        print >>fi, "#define INSTRUMENT_NCOUNTER %d" % n
+        print >>fi, "#define PYPY_INSTRUMENT_NCOUNTER %d" % n
         fi.close()
 
     eci = add_extra_files(eci)
diff --git a/pypy/translator/c/src/instrument.c 
b/pypy/translator/c/src/instrument.c
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/instrument.c
@@ -0,0 +1,69 @@
+#include <src/instrument.h>
+#include "common_header.h"
+
+#ifdef  PYPY_INSTRUMENT
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#ifndef _WIN32
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#else
+#include <windows.h>
+#endif
+
+typedef unsigned long instrument_count_t;
+
+instrument_count_t *_instrument_counters = NULL;
+
+void instrument_setup() {
+    char *fname = getenv("PYPY_INSTRUMENT_COUNTERS");
+    if (fname) {
+        int fd;
+#ifdef _WIN32
+        HANDLE map_handle;
+        HANDLE file_handle;
+#endif
+        void *buf;
+        size_t sz = sizeof(instrument_count_t)*PYPY_INSTRUMENT_NCOUNTER;
+        fd = open(fname, O_CREAT|O_TRUNC|O_RDWR, 0744);
+        if (sz > 0) {
+            lseek(fd, sz-1, SEEK_SET);
+            write(fd, "", 1);
+#ifndef _WIN32
+            buf = mmap(NULL, sz, PROT_WRITE|PROT_READ, MAP_SHARED,
+                       fd, 0);
+            if (buf == MAP_FAILED) {
+                fprintf(stderr, "mapping instrument counters file failed\n");
+                abort();
+            }
+#else
+            file_handle = (HANDLE)_get_osfhandle(fd);
+            map_handle = CreateFileMapping(file_handle, NULL, PAGE_READWRITE,
+                                           0, sz, "");
+            buf = MapViewOfFile(map_handle, FILE_MAP_WRITE, 0, 0, 0);
+            if (buf == 0) {
+                fprintf(stderr, "mapping instrument counters file failed\n");
+                abort();
+            }
+#endif
+            _instrument_counters = (instrument_count_t *)buf;
+        }
+    }
+}
+
+void instrument_count(long label) {
+    if(_instrument_counters) {
+        _instrument_counters[label]++;
+    }
+}
+
+#else
+
+void instrument_setup() {
+}
+
+#endif
diff --git a/pypy/translator/c/src/instrument.h 
b/pypy/translator/c/src/instrument.h
--- a/pypy/translator/c/src/instrument.h
+++ b/pypy/translator/c/src/instrument.h
@@ -1,80 +1,13 @@
+#ifndef _PYPY_INSTRUMENT_H
+#define _PYPY_INSTRUMENT_H
 
 void instrument_setup();
 
-#ifdef INSTRUMENT
-
+#ifdef PYPY_INSTRUMENT
 void instrument_count(long);
-
-#ifdef PYPY_MAIN_IMPLEMENTATION_FILE
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#ifndef _WIN32
-#include <sys/mman.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
+#define PYPY_INSTRUMENT_COUNT(label) instrument_count(label)
 #else
-#include <windows.h>
+#define PYPY_INSTRUMENT_COUNT
 #endif
 
-typedef unsigned long instrument_count_t;
-
-instrument_count_t *_instrument_counters = NULL;
-
-void instrument_setup() {
-       char *fname = getenv("_INSTRUMENT_COUNTERS");
-       if (fname) {
-               int fd;
-#ifdef _WIN32
-        HANDLE map_handle;
-        HANDLE file_handle;
-#endif
-               void *buf;
-               size_t sz = sizeof(instrument_count_t)*INSTRUMENT_NCOUNTER;
-               fd = open(fname, O_CREAT|O_TRUNC|O_RDWR, 0744);
-               if (sz > 0) {
-                       lseek(fd, sz-1, SEEK_SET);
-                       write(fd, "", 1);
-#ifndef _WIN32
-                       buf = mmap(NULL, sz, PROT_WRITE|PROT_READ, MAP_SHARED,
-                                  fd, 0);
-                       if (buf == MAP_FAILED) {
-                               fprintf(stderr, "mapping instrument counters 
file failed\n");
-                               abort();
-                       }
-#else
-            file_handle = (HANDLE)_get_osfhandle(fd);
-            map_handle = CreateFileMapping(file_handle, NULL, PAGE_READWRITE,
-                                           0, sz, "");
-            buf = MapViewOfFile(map_handle, FILE_MAP_WRITE, 0, 0, 0);
-                       if (buf == 0) {
-                               fprintf(stderr, "mapping instrument counters 
file failed\n");
-                               abort();
-                       }
-#endif
-                       _instrument_counters = (instrument_count_t *)buf;
-               }
-       }
-}
-
-void instrument_count(long label) {
-       if(_instrument_counters) {
-               _instrument_counters[label]++;
-       }
-}
-#endif
-
-
-#define INSTRUMENT_COUNT(label) instrument_count(label)
-
-#else
-
-#ifdef PYPY_MAIN_IMPLEMENTATION_FILE
-void instrument_setup() {
-}
-#endif
-
-#define INSTRUMENT_COUNT
-
-#endif
+#endif  /* _PYPY_INSTRUMENT_H */ 
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
@@ -101,11 +101,11 @@
         cbuilder.compile()
 
         counters_fname = udir.join("_counters_")
-        os.environ['_INSTRUMENT_COUNTERS'] = str(counters_fname)
+        os.environ['PYPY_INSTRUMENT_COUNTERS'] = str(counters_fname)
         try:
             data = cbuilder.cmdexec()
         finally:
-            del os.environ['_INSTRUMENT_COUNTERS']
+            del os.environ['PYPY_INSTRUMENT_COUNTERS']
 
         f = counters_fname.open('rb')
         counters_data = f.read()
diff --git a/pypy/translator/driver.py b/pypy/translator/driver.py
--- a/pypy/translator/driver.py
+++ b/pypy/translator/driver.py
@@ -57,7 +57,7 @@
 
     def probe(self, exe, args):
         env = os.environ.copy()
-        env['_INSTRUMENT_COUNTERS'] = str(self.datafile)
+        env['PYPY_INSTRUMENT_COUNTERS'] = str(self.datafile)
         self.compiler.platform.execute(exe, args, env=env)
         
     def after(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to