unreferencing pointers
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Dec 18 00:22:01 UTC 2019
On 17/12/2019 17:26, Ty Young wrote:
>
> On 12/17/19 5:37 AM, Maurizio Cimadamore wrote:
>>
>> On 17/12/2019 11:23, Ty Young wrote:
>>>
>>> On 12/17/19 5:07 AM, Maurizio Cimadamore wrote:
>>>
>>>
>>> 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.
>>
>> I don't know what you mean. To me, looking at the C signature you
>> shared (although you don't paste full signature - but I can infer
>> from usage), what jextract does seems ok - you have one parameter
>> that is a *listusb_device, and another parameter that seems to be a
>> pointer to a **listusb_device (hence the triple pointer in the
>> jextract signature).
>>
>> If you pass Pointer.ofNull as first parameter and the function
>> segfaults, it seems to me that, maybe, there is some misunderstanding
>> in how the function should be called? (e.g. maybe a NULL parameter is
>> not valid?). Or, perhaps the segfault is not related to the first
>> parameter, but rather to the second (likely), for which I'm still not
>> clear what exactly you're doing.
>
>
> I thought you meant Pointer.ofNull for the second argument. Yes, doing
> that doesn't work.
>
>
>>
>> To be clear, I'd expect the second parameter to be something like:
>>
>> Pointer<Pointer<Pointer<libusb_h.libusb_device>>> devices =
>> scope.allocate(LayoutType.ofStruct(libusb_h.libusb_device.class).pointer().pointer());
>> ...
>> libusb_get_device_list(Pointer.ofNull(), devices)
>
>
> I did too but that just causes a segfault as well:
>
>
> A fatal error has been detected by the Java Runtime Environment:
>
> SIGSEGV (0xb) at pc=0x00007f6b37492dc4, pid=68886, tid=68887
>
> JRE version: OpenJDK Runtime Environment (14.0) (build
> 14-internal+0-adhoc.ty.panama-foreign-linkToNative)
> Java VM: OpenJDK 64-Bit Server VM
> (14-internal+0-adhoc.ty.panama-foreign-linkToNative, mixed mode,
> sharing, tiered, compressed oops, g1 gc, linux-amd64)
> Problematic frame:
> C [libpthread.so.0+0xbdc4] __pthread_mutex_lock+0x4
It is very hard for me to tell what could be wrong. Have you tried
making that library call directly from C and see if that configuration
of parameters actually works? The crash suggests that the call is
happening, you are already on the native side, but perhaps the second
parameter is not initialized in the way that the library likes it.
Reading from the example here:
https://github.com/libusb/libusb/blob/master/examples/listdevs.c
Is it possible that you forgot to call 'libusb_init' before calling
get_device_list? It seems like that call has been omitted from the 'in a
nutshell' section you were referring to...
Maurizio
>
>
>
> >Maurizio
More information about the panama-dev
mailing list