Skip to content

Bus error is still here

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?

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Twitter
  • Google Bookmarks
  • FriendFeed
  • Google Buzz
  • HackerNews
  • Posterous
  • Reddit
  • Slashdot
  • Tumblr
  • bla

    alignment

  • Raffaele

    mmm, non è c = cast(m, POINTER(c_char_p)) ? così non mi fa nessun bus error

    (nel caso: visto ctypes per la prima volta oggi, quindi spero di aver capito come funziona cast correttamente)

    • python 2.3 di sistema
  • http://www.oluyede.org/blog/ Lawrence

    Continua a darmi bus error purtroppo :-(

    ps. non è meglio se commenti in inglese :-P ?