wide function pointer type
Martin Uecker
ma.uecker@gmail.com
Wed Oct 20 09:21:06 GMT 2021
Am Mittwoch, den 20.10.2021, 11:10 +0200 schrieb Florian Weimer:
> * Martin Uecker:
>
> > One (of several) use cases is for language interoperability.
> >
> > A common problem is to pass a function of a high-level
> > language as a callback to an C API. This now often
> > requires special boiler plate code for each case and
> > there is no automatic way to do this. The fundamental
> > problem is that the C type can not express that a data
> > pointer belongs to a function pointer.
> >
> > void foo(
> > void (cb1)(void* data, int a), void* data1,
> > void* other_data);
> >
> > Here a human (and maybe also a machine) could guess
> > that data1 belongs to cb1 but not other_data. But
> > it is not clear and in more complicated cases
> > even less so.
> >
> > void foo(void (_Wide cb1)(int a), void* other_data);
> >
> >
> > With the new type that would be unambiguous (and
> > wrappers could then often be created automatically).
> > At least for the C API one would also expect ABI
> > stability.
>
> I don't expect a lot of uptake for this. One problem is the suggested
> aggregate representation of wide function pointers. It's not exactly
> common for non-C implementations to implement those aspects of the
> platform C ABI.
Can you explain what you mean by this? Usually non-C
implementations build on C ABI, so if the C ABI is
extended the extension is then available to them.
I would expect a lot of update (in the long run) because
there is now a 1:1 mapping for a function pointer
type in other languages to the function type in C.
> For many targets, even C and C++ compilers do not
> always agree completely on the finer points.
Unfortunately, e.g. atomics. But the goal and intention
is interoperability.
> Passing code and data pointer in separate arguments is
> much more robust, and safely within the
> interoperable ABI subset.
It is not my experience that the void pointer based
APIs are robust and safe.
> Perhaps a set of standard attributes to describe the explicit closure
> argument would be useful, though.
I also thought about this (and this could be added
too) but this does not solve all problems.
Martin
More information about the Libffi-discuss
mailing list