c-for-go and slice output parameters.

122 views
Skip to first unread message

Jason Watson

unread,
Nov 13, 2021, 4:42:24 PM11/13/21
to golang-nuts
Does anyone know how to configure c-for-go to work with output function parameters - specifically slices?

I was trying to play around with adding some vulkan 1.1 and vulkan 1.2 bindings to the vulkan-go bindings (github.com/vulkan-go/vulkan), but in order to regenerate the bindings, I needed to use c-for-go (github.com/xlab/c-for-go). After struggling to get the local instance to work, I realized that c-for-go is generating different helper functions than when vulkan was previously checked-in.

After digging a bit further, it looks like c-for-go now copies slices that are "arr" hinted before passing them to C. As a result, a nil slice is copied into an empty slice when crossing the membrane and not NULL. Additionally, if the C function is expecting to populate the slice ( e.g. https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDevices.html ), the results are lost as they are populated into the copied slice, and not copied back into the original slice.

The only way I've been able to get it to work is by configuring it as a pointer and removing the slice header before hand, but I was curious if anyone else was using c-for-go and had other solutions or configuration tricks that I don't know as a c-for-go newbie.

Jmw

Jason Watson

unread,
Nov 21, 2021, 1:03:44 PM11/21/21
to golang-nuts
I got frustrated trying to figure out the c-for-go side of things, so I wrote my own lightweight wrapper over the vulkan API. Instead of trying to reverse engineer the c header files, I started with their published XML specification. https://github.com/ibd1279/vks

Jmw

Reply all
Reply to author
Forward
0 new messages