python - How to dereference void* in ctypes? -


consider following code:

import ctypes  ipc_private, map_size, ipc_creat, ipc_excl = 0, 65536, 512, 1024  shmget = ctypes.cdll.loadlibrary("libc.so.6").shmget shmat = ctypes.cdll.loadlibrary("libc.so.6").shmat  shm_id = shmget(ipc_private, map_size, ipc_creat | ipc_excl | 0600) trace_bits = shmat(shm_id, 0, 0) s = ctypes.string_at(ctypes.c_void_p(trace_bits), 1) print(s[0]) 

when try run it, gives me "segmentation fault" after successful run of shmat. doing wrong?

by default, ctypes functions wrapped have restype == c_int. need set correctly before call it. same argtypes.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -