hugopl / gtk4.cr

GTK4 bindings for Crystal
https://hugopl.github.io/gtk4.cr/
MIT License
101 stars 8 forks source link

`Gdk::ContentProvider#value` must accept a GType somehow #61

Open hugopl opened 11 months ago

hugopl commented 11 months ago

Using Gtk::TextBuffer#selection_content returns a Gdk::ContentProvider object, this object can return its contents wrapped in a GValue, however the called must initialize the GValue to the right type before calling Gdk::ContentProvider#value, otherwise an error is thrown when e.g. a call for #as_s is done in the returned GValue:

Unhandled exception: Cannot obtain raw value for g_type 0 (ArgumentError)
  from lib/gi-crystal/src/bindings/g_object/value.cr:113:9 in 'raw'
  from lib/gi-crystal/src/bindings/g_object/value.cr:120:7 in 'raw'
  from lib/gi-crystal/src/bindings/g_object/value.cr:123:5 in 'as_s'

Current Gdk::ContentProvider#value generated binding implementation:

    def value : GObject::Value
      # gdk_content_provider_get_value: (Method | Throws)
      # @value: (out) (caller-allocates)
      # Returns: (transfer none)

      _error = Pointer(LibGLib::Error).null

      # Generator::CallerAllocatesPlan
      value = GObject::Value.new
      # C call
      _retval = LibGdk.gdk_content_provider_get_value(to_unsafe, value, pointerof(_error))

      # Error check
      Gdk.raise_gerror(_error) unless _error.null?

      # Return value handling
      value
    end

Note that the return value is also lost... i.e. I need to decide what to do with the tons of out values the GTK API has.