[pypy-svn] r32329 - pypy/dist/pypy/jit/codegen/i386

arigo at codespeak.net arigo at codespeak.net
Thu Sep 14 18:44:03 CEST 2006


Author: arigo
Date: Thu Sep 14 18:44:02 2006
New Revision: 32329

Modified:
   pypy/dist/pypy/jit/codegen/i386/codebuf.py
   pypy/dist/pypy/jit/codegen/i386/codebuf_nt.py
   pypy/dist/pypy/jit/codegen/i386/codebuf_posix.py
Log:
Make codebuf_posix independent from module/mmap/.
Systematically avoid using c_void_p for its broken return-value behavior.


Modified: pypy/dist/pypy/jit/codegen/i386/codebuf.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/codebuf.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/codebuf.py	Thu Sep 14 18:44:02 2006
@@ -1,11 +1,13 @@
 import os
-from ctypes import *
+from ctypes import POINTER, cast, c_char, c_void_p, CFUNCTYPE, c_int
 from ri386 import AbstractCodeBuilder
 
 
 modname = 'pypy.jit.codegen.i386.codebuf_' + os.name
 memhandler = __import__(modname, globals(), locals(), ['__doc__'])
 
+PTR = memhandler.PTR
+
 
 class CodeBlockOverflow(Exception):
     pass
@@ -32,7 +34,7 @@
         return baseaddr + self._pos
 
     def __del__(self):
-        memhandler.free(cast(self._data, c_void_p), self._size)
+        memhandler.free(cast(self._data, PTR), self._size)
 
     def execute(self, arg1, arg2):
         fnptr = cast(self._data, binaryfn)

Modified: pypy/dist/pypy/jit/codegen/i386/codebuf_nt.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/codebuf_nt.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/codebuf_nt.py	Thu Sep 14 18:44:02 2006
@@ -18,8 +18,8 @@
 
 globals().update(ctypes_platform.configure(CConfig))
 
-LPVOID = ctypes.c_void_p
-
+# cannot use c_void_p as return value of functions :-(
+LPVOID = ctypes.POINTER(ctypes.c_char)
 
 VirtualAlloc = ctypes.windll.kernel32.VirtualAlloc
 VirtualAlloc.argtypes = [LPVOID, SIZE_T, DWORD, DWORD]

Modified: pypy/dist/pypy/jit/codegen/i386/codebuf_posix.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/codebuf_posix.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/codebuf_posix.py	Thu Sep 14 18:44:02 2006
@@ -1,16 +1,45 @@
-import mmap
-from pypy.module.mmap import interp_mmap
-from ctypes import c_void_p
+import pypy.rpython.rctypes.implementation  # register rctypes types
+from pypy.rpython.rctypes.tool import ctypes_platform
+from pypy.rpython.rctypes.tool.libc import libc
+from ctypes import POINTER, c_char, c_int
 
-libcmmap   = interp_mmap.libc.mmap
-libcmunmap = interp_mmap.libc.munmap
+class CConfig:
+    _includes_ = ("sys/types.h", "sys/mman.h")
+    size_t = ctypes_platform.SimpleType("size_t", c_int)
+    off_t = ctypes_platform.SimpleType("off_t", c_int)
+
+    MAP_PRIVATE   = ctypes_platform.DefinedConstantInteger("MAP_PRIVATE")
+    MAP_ANON      = ctypes_platform.DefinedConstantInteger("MAP_ANON")
+    MAP_ANONYMOUS = ctypes_platform.DefinedConstantInteger("MAP_ANONYMOUS")
+    PROT_READ     = ctypes_platform.DefinedConstantInteger("PROT_READ")
+    PROT_WRITE    = ctypes_platform.DefinedConstantInteger("PROT_WRITE")
+    PROT_EXEC     = ctypes_platform.DefinedConstantInteger("PROT_EXEC")
+
+globals().update(ctypes_platform.configure(CConfig))
+if MAP_ANONYMOUS is None:
+    MAP_ANONYMOUS = MAP_ANON
+    assert MAP_ANONYMOUS is not None
+del MAP_ANON
+
+# ____________________________________________________________
+
+PTR = POINTER(c_char)    # cannot use c_void_p as return value of functions :-(
+
+mmap_ = libc.mmap
+mmap_.argtypes = [PTR, size_t, c_int, c_int, c_int, off_t]
+mmap_.restype = PTR
+mmap_.includes = ("sys/mman.h",)
+munmap_ = libc.munmap
+munmap_.argtypes = [PTR, size_t]
+munmap_.restype = c_int
+munmap_.includes = ("sys/mman.h",)
 
 def alloc(map_size):
-    flags = mmap.MAP_PRIVATE | mmap.MAP_ANONYMOUS
-    prot = mmap.PROT_EXEC | mmap.PROT_READ | mmap.PROT_WRITE
-    res = libcmmap(c_void_p(), map_size, prot, flags, -1, 0)
+    flags = MAP_PRIVATE | MAP_ANONYMOUS
+    prot = PROT_EXEC | PROT_READ | PROT_WRITE
+    res = mmap_(PTR(), map_size, prot, flags, -1, 0)
     if not res:
         raise MemoryError
     return res
 
-free = libcmunmap
+free = munmap_



More information about the Pypy-commit mailing list