Wrapping C functions that use memcpy/mmap

Scott Barron sbarron at twilight.
Sun Dec 12 15:33:17 EST 1999


Hi folks,

I am attempting to wrap a C library and port a bunch of code to Python.
Some of the C code has a function like this (somewhat abbreviated :) :

char contents[] = "spam";

int function (..., vm_address_t *data, ..., size_t datalen, size_t amount)
{
    /* ... */
    if (*data_len < amount)
	*data = (vm_address_t)mmap (0, amount, PROT_READ|PROT_WRITE,
		 MAP_ANON, 0, 0);
		 
    memcpy ((char*)*data, contents, amount);

    /* ... */
    return 0;
}

Where vm_addresss_t is a pointer to some memory (shared by the client and
this program).  My question is, how might I do such a thing in Python?
Will it be safe to call the mmap and memcpy functions from C controlled
by Python?

Thanks,
Scott




More information about the Python-list mailing list