unreferencing pointers
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Dec 17 11:07:27 UTC 2019
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() ?
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