[Python] Is it possible to pass a python string by reference through ctypes?

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I'm sorry, but I generally have a hard time reading the current ctypes docs...

    If I have a C function that takes a const char * pointer, and I know it will neither modify the passed in string, nor keep a reference to it beyond the function call, it really makes sense to pass in a pointer directly to the bytes of a python string.

    Can ctypes can do this or is it just plain unsupported? Do I really have to create_string_buffer and copy my string into it?

    Continue reading...

Compartilhe esta Página