![]() There are a few (obscure) limitations to the supported argument and To get a cdata containing a regular function pointer, This means you cannot pass them directly to some other Cįunction expecting a function pointer argument. Objects, but an object of a different type (on CPython, ). function_returning_a_struct () # `myfoo`: įor performance, non-variadic API-level functions that you get by # struct foo_s # struct foo_s function_returning_a_struct(void) myfoo = lib. This means that you can always pass arguments that can be converted to For example, int * is fullyĮquivalent to int (or even int the 5 is ignored). The C language makes no difference between argument declarations that You can also pass unicode strings as wchar_t * or char16_t * or If you need a pointer to remain valid, you need to make one explicitly,įor example with ptr = ffi.new("char", x).) Write code that relies on it: there are cases were that would break. The whole string at every call-it usually won’t-but you cannot Important notably for PyPy which uses many optimizations tweaking the data Pointers, with each of them only valid during the corresponding call. The two calls to f() could sometimes receive different char * Lib.f(x) lib.f(x) where x is a variable containing a byte string, (Note that there is no guarantee that the char * passed to theįunction remains valid after the call is done. # size_t strlen(const char *) assert lib. Place to keep alive the original pointer object (returned by You really want to have a struct object but don’t have any convenient Objects that can keep the same memory alive. Struct or union object returns a cdata struct or union object Unlike the “original” one, these freshĬdata objects don’t have ownership: they are merely references toĪs an exception to the above rule, dereferencing a pointer that owns a more_stuff ( handle )Īny operation that would in C return a pointer or array or struct type ![]() init_stuff ( p_handle ) # pass the pointer to the 'handle' pointer handle = p_handle # now we can read 'handle' out of 'p_handle' lib. fetch_size ( arr, arr 1 ) x = px x = arr y = py y = arr p_handle = ffi. You cannot take the address of a CFFI pointer. YouĬannot take the “address” of a number in Python, for example similarly, There is ffi.addressof(), but only for some cases. Would not fit nicely in the model, and it does not seem to be needed There is no general equivalent to the
0 Comments
Leave a Reply. |