[plt-scheme] FFI and pointer tags

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Nov 4 10:59:22 EST 2006

On Nov  4, Jakub Piotr C$,1 b(Bapa wrote:
> I'm trying to wrap libusb using the FFI interface and I've encountered 
> some problems.
> 
> I was trying to use the super-struct for USB descriptor structs (they 
> all begin with the same two fields) but I can't access those fields. 
> There are no accessors created by the new struct and the ones for the 
> super struct don't accept the child instances.
> 
> Some code for tests:
> #v+
> (define-cstruct _usb-descriptor
>    ([length _uint8]
>     [type _uint8]))
> 
> (define-cstruct (_usb-device-descriptor _usb-decriptor)
                                               ^^^^^^^^^
You have a typo there -- maybe you had several attempts in a single
repl and mixed up different types?

>    ([usbMajor _uint8]
>     [usbMinor _uint8]))
> 
> (define-cstruct _usb-device
>    ([next         _usb-device-pointer/null]
>     [prev         _usb-device-pointer/null]
>     [filename     _path-type]
>     [bus          _usb-bus-pointer]
>     [descr        _usb-device-descriptor]
>     [config       (_cpointer _usb-config-descriptor)]
>     [dev          _pointer]
>     [devnum       _uint8]
>     [num_children _uint8]
>     [children     (_cpointer _usb-device-pointer)]))
> 
> > (usb-descriptor-type (usb-device-descr (usb-bus-devices (usb-get-busses))))
> usb-descriptor-type: expected argument of type <struct:usb-descriptor>; 
> given #<cpointer:usb-device-descriptor>
> 
> > (usb-device-descriptor-type (usb-device-descr (usb-bus-devices (usb-get-busses))))
> reference to undefined identifier: usb-device-descriptor-type
> 
> > (usb-device-descriptor-header (usb-device-descr (usb-bus-devices (usb-get-busses))))
> #<cpointer:usb-descriptor>
> #v-
> 
> On the other hand, an usb-device-descriptor created by make-... has the 
> proper tags. It there something wrong with my _usb-device struct 
> declaration?

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.