unreferencing pointers

Ty Young youngty1997 at gmail.com
Tue Dec 17 11:23:29 UTC 2019


On 12/17/19 5:07 AM, Maurizio Cimadamore wrote:
>
> On 17/12/2019 11:03, Ty Young wrote:
>>
>> On 12/17/19 4:31 AM, Maurizio Cimadamore wrote:
>>>
>>> On 17/12/2019 08:32, Ty Young wrote:
>>>> Hi,
>>>>
>>>>
>>>> Thanks to the LLVM 9 commit I've been able to create bindings for 
>>>> jextract. Problem is that the libusb API utilizes "unreference" 
>>>> variables to store the list of USB devices at it's entry pointer.
>>>>
>>>>
>>>> From the "In a nutshell..." section:
>>>>
>>>>
>>>> libusb_device **list;
>>>>
>>>> libusb_device *found = NULL;
>>>>
>>>> ssize_t cnt = libusb_get_device_list(NULL, &list);
>>>>
>>>>
>>>> ...which -unless I'm missing something- doesn't work in Java since 
>>>> variables have to be declared as *something* and declaring it as 
>>>> null hits an internal NullPointerException check.
>>>>
>>>>
>>>> Is this an unsupported edge case or am I missing something?
>>>
>>> What is the Java code that corresponds to this?
>>
>>
>> In Java the function signature looks like:
>>
>>
>> long libusb_lib.libusb_get_device_list(Pointer<libusb_context> 
>> context, Pointer<Pointer<Pointer<libusb_h.libusb_device>>> devices);
>>
>>
>> Where long is the size of the devices list. First argument can be 
>> null, as documented.
>
> Have you tried Pointer.ofNull() ?


Pointer.ofNull() just causes a hard segfault.


Usually doing Pointer.ofNull() would be required for this, but unlike 
other functions I've seen, this is returning the entire "list" itself 
and not individual elements(Pointer<libusb_h.libusb_devic> in this 
case). The Pointer<Pointer<Pointer<>>> madness makes no sense.


>
> Maurizio
>
>>
>>
>>> The one you are playing with. Is 'list' the variable you'd like to 
>>> start off with null? Note that that is not really what C does - when 
>>> C sees a blank declaration like that it would still allocate the 
>>> space to hold a pointer - so you must allocate, even if you don't 
>>> see the allocation in the corresponding C code.
>>>
>>> Maurizio
>>>
>>>>
>>>>
>>>> Thanks.
>>>>


More information about the panama-dev mailing list