[plt-scheme] FFI and pointer tags

From: Jakub Piotr Cłapa (jpc at pld-linux.org)
Date: Sat Nov 4 06:43:18 EST 2006

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:
(define-cstruct _usb-descriptor
   ([length _uint8]
    [type _uint8]))

(define-cstruct (_usb-device-descriptor _usb-decriptor)
   ([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))))

On the other hand, an usb-device-descriptor created by make-... has the 
proper tags. It there something wrong with my _usb-device struct 

Jakub Piotr Cłapa

Posted on the users mailing list.