passing a mmap pointer from C to python as a mmap object -
i trying interface c library (beaglebone pru driver prussdrv.c) python. particular function want access returns mmap pointer illustrated below:
int __prussdrv_memmap_init(void) { prussdrv.pru0_dataram_base = mmap(0, prussdrv.pruss_map_size, prot_read | prot_write, map_shared, prussdrv.mmap_fd, pruss_uio_map_offset_pruss); ... int prussdrv_map_prumem(unsigned int pru_ram_id, void **address) { switch (pru_ram_id) { case pruss0_pru0_dataram: *address = prussdrv.pru0_dataram_base; break; prussdrv_map_prumem (dataram[pru_num], &prudatamem); prudatamem_byte = (unsigned char*) prudatamem;
i encapsulate either prudatamem or prudatamem_byte , pass python mmap object. there straightforward way this? i've looked @ capsule , ctypes not appear looking for?
i don't think there's way create python mmap
object out of native mapping this. protocol isn't published, , neither internal format.
but of course of study the source available. so, long mapping meets same criteria 1 created new_mmap_object
, manually build mmap_object
wrapping information, , pass back. (you can't actually access mmap_object
type, because it's not in header file. if create equivalent type, or copy-and-paste code, you'll passing around pyobject *
, , long type field points right type, it'll work.)
however, i'm not sure need this. need mmap
, or buffer can treat string/list/iterator? because latter lot easier. that, can create old-style buffer or new-style buffer class—or, if need 2.7+, utilize concrete memoryview
type. conceptually, seems create sense you're returning view of mapped memory, rather mapping itself, can imagine utilize cases might inappropriate.
finally, can create new class exposes whatever interface want around mapping, , create much (or little) mmap
want.
python c pointers mmap wrapping
No comments:
Post a Comment