jhass / crystal-gobject

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

LibGranite: Unhandled array constant #37

Closed aljelly closed 4 years ago

aljelly commented 4 years ago

There's an array constant in this class (Granite-1.0.gir):

<class name="Application" c:type="GraniteApplication" glib:type-name="GraniteApplication" glib:get-type="granite_application_get_type" glib:t
ype-struct="ApplicationClass" parent="Gtk.Application" abstract="1" deprecated="1" deprecated-version="0.5.0">
  <field name="parent_instance">
    <type name="Gtk.Application" c:type="GtkApplication"/>
  </field>
  <field name="priv">
    <type name="ApplicationPrivate" c:type="GraniteApplicationPrivate*"/>
  </field>
  <field name="build_data_dir">
    <type name="utf8" c:type="gchar*"/>
  </field>
...
  <constant name="options" c:identifier="GRANITE_APPLICATION_options" value="(null)">
    <array>
      <type name="GLib.OptionEntry" c:type="GOptionEntry"/>
    </array>
  </constant>

Which results in:

Unhandled exception: Bug: Unhandled constant type ARRAY (Exception)

I tried making it at least compile:

--- constant_info_orig.cr   2020-01-20 07:24:10.511492609 +0000
+++ constant_info.cr    2020-01-20 07:23:23.614319006 +0000
@@ -49,6 +49,8 @@
         when .utf8?
           string = String.new(value.v_string)
           string.inspect
+        when .array?
+          "# ARRAY CONSTANT #{name} #{size}" # ???
         when .interface?
           "# INTERFACE CONSTANT #{name} #{size}" # debug, should never end up being generated
         else
@@ -60,6 +62,8 @@
     def lib_definition
       if type.tag.interface?
         "  # #{name} = ungeneratable value"
+      elsif type.tag.array?
+        "  # #{name} = ???"
       else
         "  #{name} = #{literal} # : #{type.lib_definition}"
       end

And it works (now the bindings at least generate), but this probably isn't how it should be handled. I don't know enough about GIRs or C. StaticArray?

(Granite source is here, relevant line seems to be this)

jhass commented 4 years ago

Yeah, StaticArray seems like a sane option, but I'm not sure. First case I see for this and it's a null pointer, so not super insightful into how this would work for actual values. Pretty useless constant really. There's also an array type enum to this, so we probably have to flesh this out a lot more. But for now it should compile and hopefully not crash when you reference the constant.

This typelib also has a lot of unresolved references (references to types not included into it or any dependencies), which I had to add handling for in a place or two, so no promises yet :P