Hi,
On Tue, 19 Dec 2023 at 11:00, Vasiliy Poverennov <
bazoo...@gmail.com> wrote:
> One interesting thing I noted when testing is that in ABI in-line mode this definition gives an error, and in out-of-line mode it crashes when I try to call it direct / pass into lib.call. Just curious - is this by design?
Ah. OK, my mistake, then it won't work in any ABI mode. You get an
error in in-line ABI mode, and in the slightly less tested out-of-line
ABI mode you get a crash, which (I think now) is because cffi takes
the address of the function, and then reads the first 8 bytes there
and assumes it's a function pointer---but it is not, it's the start of
the code for the function. Sorry. In my test I get `<cdata
'int(*)(int)' 0xe5894855fa1e0ff3>`; that number is definitely not a
valid pointer and looks more like 8 bytes of executable code.
For now you'll have to use the "const function pointer" as a
workaround for the API mode only. A possibility in the future would
be in some cases to allow the "builtin function" objects from API libs
to be passed at places that expect a cdata object, like you can pass,
say, an integer where in theory you need a cdata object containing an
integer, and there is automatic conversion.
A bientôt,
Armin Rigo