Ok, the problem is resolved thanks to Esteban.
There was a mistake in the code given in preceding mails so, I am
rewriting the 3 steps here:
===
1) Declare your class that subclasses FFIOpaqueObject:
FFIOpaqueObject subclass: USBDevice
etc...
2) Get a pointer to the array:
arrayPtr := ExternalAddress new.
size := self getDevice: context list: arrayPtr.
with:
getDevice: ctx list: list
^ self ffiCall: #(size_t libusb_get_device_list (libusb_context
*ctx, void **list))
3) Now that we have the size of the array, we can declare it:
array := FFIExternalArray fromHandle: arrayPtr type: USBDevice size: size.
===
The problem was that I was using #fromPointer:type:size instead of
#fromHandle:type:size:.
Thanks again Esteban!
Julien
On 04/07/16 13:15, Julien Delplanque wrote:
On 04/07/16 12:18, Ben Coman wrote:
On Mon, Jul 4, 2016 at 4:24 PM, Julien Delplanque <jul...@tamere.eu>
wrote:
Hello again Esteban, all others,
I am still experiencing strange behaviors with the objects in the
external
array.
I get a lot of NULL pointers and some strange addresses (I guess, I
am not a
C expert) that are close to NULL
(see the screenshot attached). These objects make the VM crash
(segmentation
fault) when I call a function
from the libusb binding (for NULL objects it may be ok but what about
others?). Some other objects (those with
a normal address in the screenshot) work finely with the functions
calls
using UFFI...
This kind of bug is not reported in libusb discussions I found on the
internet and I tried an example in C,
there is no NULL pointer received from the function (they are not even
considered in official examples).
So I guess the problem may come from Pharo?
Do you have any idea of what it could be?
I will be available on Slack all the day if you want. :)
Thanks in advance,
Julien
On Mon, Jul 4, 2016 at 6:15 PM, Ben Coman <b...@openinworld.com> wrote:
How does it compare with the result you get in pure C?
e.g. using this code...
http://libusb.org/browser/libusb/examples/lsusb.c?rev=efc29733ad31f81883a7ac51a6cc6cda9ad4feb9&order=name
Also, what is the return value of calling libusb_init() from Pharo?
cheers -ben
In pure C, it works. All my device are listed with the code at the
link you gave me (so there is no NULL pointer).
In Pharo, libusb_init() returns 0 as expected.
Julien