PXcursorImages* = ptr XcursorImages
XcursorImages* = object
nimage*: cint #* number of images */
images*: seq[ PXcursorImage] #* array of XcursorImage pointers */
name*: cstring #* name used to load images */
proc XcursorFilenameLoadAllImages*( filename:cstring): PxcursorImages
{.libxcursor.}
This is following some c code for learning purposes which dumps the Xcursor file to a series of png images
var
xcIs: PXcursorImages
name = "sailboat"
xcIs = name.cstring.XcursorFilenameLoadALLImages( )
And works as expected, so that xcIs.images is iterable
PXcursorImage* = ptr XcursorImage
XcursorImage* = object
version*: XcursorUInt #* version of the image data */
size*: XcursorDim #* nominal size for matching */
width*: XcursorDim #* actual width */
height*: XcursorDim #* actual height */
xhot*: XcursorDim #* hot spot x (must be inside image) */
yhot*: XcursorDim #* hot spot y (must be inside image) */
delay*: XcursorUInt #* animation delay to next frame (ms) */
pixels*: PXcursorPixel #* pointer to pixels */
var p: PXcursorImage
for i in 0..< xcIs.nimage:
p = xcIs.images[ i]
echo repr( p)
But the iteration only sort of works. The output gives three good repr( p) followed by two nils. This is because the nim loop starts at i == 2, missing the two smallest images. This has so far always been the case irrespective of image file (always though with 5 numimage) and irrespective of platform ubuntu arm64, void (muscl) amd_64.
Am I miss-messing with pointers? And if so why does it compile and part work?
I think your problem could lie in this definition:
XcursorImages* = object
nimage*: cint #* number of images */
images*: seq[ PXcursorImage] #* array of XcursorImage pointers */
name*: cstring #* name used to load images */
a seq is a structure maintained by the Nim runtime, so a seq can't be part of an imported C struct. Instead you probably have a pointer, pointing to the first element of an array. Nim has to distinguish between a pointer to a single object (ptr T), ptr UncheckedArray[T] for this.