[racket] FFI - pointer to an array of structs

From: Bartosz Przygoda (bprzygoda at gmail.com)
Date: Fri Nov 14 07:59:03 EST 2014


I'm struggling with binding libgphoto2. The function:
the resulting structures in an array and therefore its argument is:

I've mapped the structure in following way:

(define _CameraStorageInfoFields (_enum '(gp_storageinfo_base
gp_storageinfo_label))) ; not all mapped
(define _CameraStorageType (_enum '(gp_storageinfo_st_unknown
gp_storageinfo_st_fixed_rom))) ; not all mapped
(define _CameraStorageFilesystemType (_enum
'(gp_storageinfo_fst_undefined))) ; not all mapped
(define _CameraStorageAccessType (_enum '(gp_storageinfo_ac_readwrite))) ;
not all mapped

(define-cstruct _CameraStorageInformation
  ([fields _CameraStorageInfoFields]
   [basedir (_array/list _byte 256)]
   [label (_array/list _byte 256)]
   [description (_array/list _byte 256)]
   [type _CameraStorageType]
   [fstype _CameraStorageFilesystemType]
   [access _CameraStorageAccessType]
   [capacitykbytes _uint64]
   [freekbytes _uint64]
   [freeimages _uint64]))

And said function:

(define-gphoto gp_camera_get_storageinfo
  (_fun (cam ctx) :: (cam : _Camera-pointer) (v : (_ptr o
_CameraStorageInformation-pointer)) (n : (_ptr o _int)) (ctx :
     -> _int
     -> n)) ; let's only check size for now

Upon execution:

(gp_camera_get_storageinfo cam #f)

It gives SIGSEGV MAPPER si_code 1

How one should go about such binding? Should the parameter involve some
array helpers (here I've only tried to mimic pointer to a pointer, hoping
that later I could wrap it in some array)?

Or maybe the struct has wrong size (there are enums...)?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141114/8d9150b8/attachment.html>

Posted on the users mailing list.