jhass / crystal-gobject

gobject-introspection for Crystal
BSD 3-Clause "New" or "Revised" License
127 stars 13 forks source link

Error: undefined method 'to_unsafe' for Pointer(Void) #95

Open christopherzimmerman opened 2 years ago

christopherzimmerman commented 2 years ago

I am trying to bind to Apache Arrow using this library. Most methods work, except for methods that (in C), take GLib::Lists as arguments. The C-bindings that are generated are expecting Pointer(Pointer(Void)), while the GObject constructors are expecting Pointer(Void), and so when the pointer gets passed, to_unsafe fails.

Minimal example:

require "gobject"
require_gobject "Arrow"

f0 = Arrow::Field.new("int_field", Arrow::Int8DataType.new)
f1 = Arrow::Field.new("bool_field", Arrow::BooleanDataType.new)
puts f0.to_string
puts f1.to_string

schema = Arrow::Schema.new(Box.box([f0, f1]))

# > 18767 | 
# > 18768 |     def self.new(fields : Void*) : self
# > 18769 |       __var0 = LibArrow.schema_new(fields)
#                                              ^--------
# Error: undefined method 'to_unsafe' for Pointer(Void)

Here is the C function being called

I've tested out these methods using other language's GObject libraries, and it seems like these constructors accept the respective language's stdlib arrays where GLib::Lists are accepted.

I messed around a bit trying to update the return type for the TypeTag::GLIST, but didn't have any luck.