How do I have SWIG a treat a return value of const char* as binary data (for Python)?

13 Views Asked by At

I have a function that takes a parameter (a size) that will dictate how large the byte array that is returned will be. The byte array is returned as a const char*. I want to use this from Python and get a byte string as the return value.

const char* getName( int arg1, int arg2, size_t byteCount );

I could, perhaps, define an out typemap, like:

%typemap(out) const char* const {
    $result = PyBytes_FromStringAndSize($1,<how_can_I_get_the_input_param?>);
}

but this would change all functions that return const char*, including ones that are returning normal NULL-terminated C strings.

Also, how can I access one of the (input) function parameters within an out typemap?

0

There are 0 best solutions below