<div dir="ltr"><div>Hello,</div><div><br></div><div>I'm trying to make racket bindings for libgphoto2. Its API uses CameraText struct for outputting strings, which just wraps char array.</div><div><br></div><div>My first attempt was:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>(define _Camera-ptr (_cpointer 'Camera))</div><div>(define _CameraText-ptr (_cpointer 'CameraText))</div></blockquote><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>(define-gphoto gp_camera_get_about</div><div>  (_fun _Camera-ptr (v : _CameraText-ptr) _GPContext-ptr</div><div>     -> _int))</div><div><br></div></blockquote><div>But this was giving me segfaults (not to mention the pointer here is opaque and there are no getter functions in API).</div><div><br></div><div>Later on I've stumbled across <a href="https://github.com/dyoo/ffi-tutorial/blob/master/ffi/tutorial/examples/struct-with-array/struct-with-array.rkt">https://github.com/dyoo/ffi-tutorial/blob/master/ffi/tutorial/examples/struct-with-array/struct-with-array.rkt</a> so I've tried this:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>(define _Camera-ptr (_cpointer 'Camera))</div><div><br></div><div>(define camera-text-size (* 32 1024))</div><div>(define-cstruct _CameraText ([text (_bytes/len (camera-text-size))]))</div><div><br></div><div>(define-gphoto gp_camera_get_about</div><div>  (_fun _Camera-ptr (v : _CameraText-pointer) _GPContext-ptr</div><div>     -> _int))</div><div><br></div></blockquote><div>(Where bytes/len is helper taken from that example)</div><div><br></div><div>How can I initialize this struct to mimic C CameraText txt;? Is there some better way to handle char arrays (and converting them to strings) than _byte array? Or should I go with something like (but this was segfaulting as well):</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>(define-cstruct _CameraText ([text _string]))</div></blockquote></div>