I don’t really know why the following example works well under Linux but crashes badly and with no mercy under MacOSX and FreeBSD:
[code lang="python"] from ctypes import * import ctypes.util
_libc = cdll.LoadLibrary(ctypes.util.find_library("c"))
f = open("foo", "w+") f.write("foo\0") f.flush()
_libc.mmap.restype = c_void_p m = _libc.mmap(0, 4, 3, 1, f.fileno(), 0) print m if m != c_void_p(-1).value: c = cast(m, POINTER(c_char)) print [c[i] for i in range(4)] f.close() [/code]
Anytime I try to cast the void * into a char * it crashes. Gdb still tells me a SIGBUS has occurred but I can’t fix it.
More info in the previous post: Bus error in FreeBSD/MacOSX
Any ideas?
















