Closed hugopl closed 3 years ago
I see that some tests triggered a compiler crash :thinking:
https://github.com/jhass/crystal-gobject/pull/81/checks?check_run_id=1803068062
I'm a bit busy last days, but once I have some time I'll be back on this.... BTW, the CI show the compiler crashing compiling some example... weird.
I'm a bit busy last days, but once I have some time I'll be back on this.... BTW, the CI show the compiler crashing compiling some example... weird.
I said I would be back on this, but I'm really with not much free time to work on this last weeks, so I think is better to close this MR so if someone with more time want to fix it, the existence of this MR wont stop anybody to create a fix instead of wait for a patch from me.
So I'm also going to create a issue to keep track on this.
@hugopl i've made some headway and have most tests passing. however, there's an issue somewhere in the generated code and i can't find it, but it's breaking a few tests
the broken tests are:
gtk_application.cr:
Compiling gtk_application.cr... Showing last frame. Use --error-trace for full trace.
There was a problem expanding macro 'require_gobject'
Code in macro 'require_gobject'
6 | require_gobject("Gio", "2.0")
^
Called macro defined in lib/gobject/gobject.cr:25:1
25 | macro require_gobject(namespace, version = nil)
Which expanded to:
> 8180 | def run(argv : ::Enumerable?)
> 8181 | argc = argv ? argv.size : 0
> 8182 | __var0 = LibGio.application_run(@pointer.as(LibGio::Application*), Int32.new(argc), argv ? (__argv_ary = argv.map { |__item| __item.to_unsafe }.to_a).to_unsafe : nil)
^--------
Error: undefined method 'to_unsafe' for Pointer(Pointer(UInt8)) (compile-time type is (Pointer(Pointer(UInt8)) | Nil))
failed.
gtk_menu_and_actions.cr:
Compiling gtk_menu_and_actions.cr... Showing last frame. Use --error-trace for full trace.
There was a problem expanding macro 'require_gobject'
Code in lib/gobject/gtk/gtk.cr:4:1
4 | require_gobject "Gtk", "3.0"
^
Called macro defined in lib/gobject/gobject.cr:25:1
25 | macro require_gobject(namespace, version = nil)
Which expanded to:
> 65299 |
> 65300 | def attach_to_widget(attach_widget : Gtk::Widget, detacher : Gtk::MenuDetachFunc?)
> 65301 | LibGtk.menu_attach_to_widget(@pointer.as(LibGtk::Menu*), attach_widget.to_unsafe_widget, detacher ? detacher : Pointer(LibGtk::MenuDetachFunc).null)
^--------
Error: undefined method 'to_unsafe' for Pointer(Proc(Pointer(LibGtk::Widget), Pointer(LibGtk::Menu), Nil))
failed.
gtk_subclasses.cr:
Compiling gtk_subclasses.cr... Showing last frame. Use --error-trace for full trace.
There was a problem expanding macro 'require_gobject'
Code in macro 'require_gobject'
6 | require_gobject("Gio", "2.0")
^
Called macro defined in lib/gobject/gobject.cr:25:1
25 | macro require_gobject(namespace, version = nil)
Which expanded to:
> 8180 | def run(argv : ::Enumerable?)
> 8181 | argc = argv ? argv.size : 0
> 8182 | __var0 = LibGio.application_run(@pointer.as(LibGio::Application*), Int32.new(argc), argv ? (__argv_ary = argv.map { |__item| __item.to_unsafe }.to_a).to_unsafe : nil)
^--------
Error: undefined method 'to_unsafe' for Pointer(Pointer(UInt8)) (compile-time type is (Pointer(Pointer(UInt8)) | Nil))
failed.
and also potentially gdk_window.cr. it looked weird, and i'm not sure if that's how it's supposed to look (it's doing the faux see-through weirdness i've seen in a few other buggy programs, but it responds to everything just fine. pic attached)
here's a diff of the changes i've made so far:
diff --git a/src/gdk/gdk.cr b/src/gdk/gdk.cr
index 6cf8d62f..d6be2c78 100644
--- a/src/gdk/gdk.cr
+++ b/src/gdk/gdk.cr
@@ -4,7 +4,7 @@ require_gobject "Gdk", "3.0"
require "./event"
module Gdk
- def self.init
- LibGdk.init pointerof(ARGC_UNSAFE), pointerof(ARGV_UNSAFE)
+ def self.init(argc = Pointer(Int32).null, argv = Pointer(Pointer(Pointer(UInt8))).null)
+ LibGdk.init argc, argv
end
end
diff --git a/src/gtk/autorun.cr b/src/gtk/autorun.cr
index 48db939a..6d8a7c5a 100644
--- a/src/gtk/autorun.cr
+++ b/src/gtk/autorun.cr
@@ -2,7 +2,7 @@ require "./gtk"
fun main(argc: Int32, argv : UInt8**) : Int32
Crystal.main do
- LibGtk.init pointerof(ARGC_UNSAFE), pointerof(ARGV_UNSAFE)
+ LibGtk.init pointerof(argc), pointerof(argv)
Crystal.main_user_code(argc, argv)
i'd love if you re-opened this, just in case someone comes along that knows how to debug that codegen mess
from what i can tell, the issue is somewhere in src/g_i_repository/info/
, but i keep getting nonsensical errors about calling "to_unsafe" in bad places despite "to_unsafe" not being called at all
This is because the tests I wrote in the patch doesn't cover all use cases, so it passed on all tests here but failed to compile my GTK project. I have not much knowledge about the GIR API, this is why I stopped working on this, when I saw that I would need to spend a bit more time (that I not always have) on it and need to take a better look on GIR API to discover the missing bits in the patch.
In this patch I add a method to write the NULL
version of a type, but it is clearly missing a lot of cases.
I was trying to make the generator work with Crystal 0.36, I fixed some stuff (not sure if in the better/complete way) and added some tests, by what I remember there are basically two issues:
nil vs Pointer(T).null
when passing parameters to C functions.The fix doesn't really fix all issues, since my app still failing to compile, mainly with
nil
vsPointer.null
issues (i.e. the few tests I wrote doesn't cover all basic use cases), but I think these patches can help, if the lame implementation I did isn't ok, at least the tests can be used :-).