Calling inline functions

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Apr 20 14:55:48 UTC 2020


Strictly speaking, it is an API client (which can be used w/ or w/o 
jextract).

E.g. what is needed is a visitor which reads the inline function/macro 
and then generates the required C plumbing.

Maurizio

On 20/04/2020 15:44, Ty Young wrote:
> That's disappointing. Instead of jextract, could it be added into the 
> core API somehow?
>
>
> On 4/20/20 8:25 AM, Maurizio Cimadamore wrote:
>> Inline functions do not exist in the .so/.dll/.dynlib file. They are 
>> essentially function-like macros, expanded by the compiler whenever 
>> they are used.
>>
>> If you want to call them using the current support you need to create 
>> your own C library wrapper which exposes the additional symbol (as a 
>> regular function) and then calls the corresponding inline function. 
>> Then you extract your header (which will also include the original 
>> header you wanted to work on) with jextract.
>>
>> In the future we might automate support for function-like macro a 
>> little, by providing jextract API plugins which generate the correct 
>> plumbings.
>>
>> Maurizio
>>
>> On 20/04/2020 13:34, Ty Young wrote:
>>> Is calling inline functions supported right now? I'm trying to call 
>>> this function:
>>>
>>>
>>> __attribute__((always_inline)) static inline int 
>>> internal_load_libgamemode(void)
>>>
>>>
>>> with:
>>>
>>>
>>> this.address = 
>>> gamemode_client_h.LIBRARY_LOOKUP.lookup("internal_load_libgamemode");
>>>
>>> this.descriptor = FunctionDescriptor.of(MemoryLayouts.C_INT);
>>>
>>> this.type = MethodType.methodType(int.class);
>>>
>>> this.handle = 
>>> Foreign.getInstance().getSystemABI().downcallHandle(this.address, 
>>> this.type, this.descriptor);
>>>
>>>
>>> ...but it fails saying the symbol doesn't exist. Is there a way to 
>>> call it?
>>>
>>>
>>> Full header: 
>>> https://github.com/FeralInteractive/gamemode/blob/master/lib/gamemode_client.h
>>>
>>>


More information about the panama-dev mailing list