[pypy-svn] r54929 - in pypy/branch/win32port/pypy/translator/c: src test

afa at codespeak.net afa at codespeak.net
Mon May 19 15:06:14 CEST 2008


Author: afa
Date: Mon May 19 15:06:11 2008
New Revision: 54929

Modified:
   pypy/branch/win32port/pypy/translator/c/src/instrument.h
   pypy/branch/win32port/pypy/translator/c/test/test_standalone.py
Log:
Instrumentation counters support on win32.
test_prof_inline seems more difficult to adapt, though.


Modified: pypy/branch/win32port/pypy/translator/c/src/instrument.h
==============================================================================
--- pypy/branch/win32port/pypy/translator/c/src/instrument.h	(original)
+++ pypy/branch/win32port/pypy/translator/c/src/instrument.h	Mon May 19 15:06:11 2008
@@ -9,10 +9,14 @@
 #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;
 
@@ -22,18 +26,33 @@
 	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;
 		}
 	}

Modified: pypy/branch/win32port/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/win32port/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/branch/win32port/pypy/translator/c/test/test_standalone.py	Mon May 19 15:06:11 2008
@@ -55,8 +55,6 @@
     # gives the strings unquoted in the list
 
 def test_counters():
-    if sys.platform == 'win32':
-        py.test.skip("instrument counters support is unix only for now")
     from pypy.rpython.lltypesystem import lltype
     from pypy.rpython.lltypesystem.lloperation import llop
     def entry_point(argv):
@@ -139,8 +137,6 @@
     assert map(float, data.split()) == [0.0, 0.0]
 
 def test_profopt():
-    if sys.platform == 'win32':
-        py.test.skip("instrumentation support is unix only for now")
     def add(a,b):
         return a + b - b + b - b + b - b + b - b + b - b + b - b + b
     def entry_point(argv):



More information about the Pypy-commit mailing list