FLI bug or pilot error?
Hello, I've been working on a FFI for the MacOSX CoreMIDI framework and I've run into some strange behavior while trying to define types for the MIDIPacket and MIDIPacketList structures. The FLI doesn't seems to be calculating the offsets to members in a structure correctly. The relevant C typedefs are: ================================== struct MIDIPacket { MIDITimeStamp timeStamp; UInt16 length; Byte data[256]; }; typedef struct MIDIPacket MIDIPacket; struct MIDIPacketList { UInt32 numPackets; MIDIPacket packet[1]; }; The FLI definitions I am using are: ============================================ (in-package :cl-user) (fli:define-c-typedef (uint16 (:foreign-name "UInt16")) (:unsigned :short)) (fli:define-c-typedef (uint32 (:foreign-name "UInt32")) (:unsigned :long)) (fli:define-c-typedef (uint64 (:foreign-name "UInt64")) (:unsigned :long-long)) (fli:define-c-typedef (midi-time-stamp (:foreign-name "MIDITimeStamp")) uint64) (fli:define-foreign-type (:struct midi-packet :foreign-name "MIDIPacket") (&key (size 256)) `(:struct (time-stamp midi-time-stamp) (length uint16) (data (:c-array (:unsigned :byte) ,size)))) (fli:define-foreign-type (:struct midi-packet-list :foreign-name "MIDIPacketList") (&key (length 1) (size 256)) `(:struct (num-packets uint32) (packet (:c-array (midi-packet :size ,size) ,length)))) When I allocate a foreign object the FLI is calculating the address of the 'packet slot of the 'midi-packet-list as base address + 8 bytes instead of the expected base address + 4 bytes (which is the size of a the UInt32 data type). CL-USER> (setf x (fli:malloc :type 'midi-packet-list)) #<Pointer to type (:STRUCT MIDI-PACKET-LIST) = #x03F44C00> CL-USER> (fli:foreign-slot-pointer x 'num-packets) #<Pointer to type UINT32 = #x03F44C00> CL-USER> (fli:foreign-slot-pointer x 'packet) #<Pointer to type (:C-ARRAY (MIDI-PACKET :SIZE 256)) = #x03F44C08> CL-USER> (- (fli:pointer-address *) (fli:pointer-address **)) 8 If change the element type of the 'midi-packet-list 'packet slot to one of the immediate types the address of the 'packet slot is calculated as base address + 4 (which I expect). Try the following: (fli:define-foreign-type (:struct midi-packet-list :foreign-name "MIDIPacketList") (&key (length 1) (size 256)) `(:struct (num-packets uint32) (packet (:c-array :byte ,length)))) Is this a bug or am I missing something? I'm using LWM 4.4.6. Thanks much, -greg _______________________________________________________ Greg Wuller greg@wuller.com _______________________________________________________