jhass / crystal-gobject

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

Wrong code generated for GFileMonitorEvent #67

Closed hugopl closed 4 years ago

hugopl commented 4 years ago

The following code fails to compile:

require "gobject/gio"

def file_changed(monitor : Gio::FileMonitor, file : Gio::File, other_file : Gio::File, event : Gio::FileMonitorEvent)
  puts "something happpened"
end

monitor = Gio::File.new_for_path(".").monitor_directory(:watch_moves, nil)
monitor.on_changed(&->file_changed(Gio::FileMonitor, Gio::File, Gio::File, Gio::FileMonitorEvent))

Error:

There was a problem expanding macro 'require_gobject'

Code in lib/gobject/gio/gio.cr:4:1

 4 | require_gobject "Gio"
     ^
Called macro defined in lib/gobject/gobject.cr:24:1

 24 | macro require_gobject(namespace, version = nil)

Which expanded to:

 > 17520 | def on_changed(&block : ChangedSignal)
 > 17521 |   __var0 = -> (arg1 : LibGio::File*, arg2 : LibGio::File*, arg3 : LibGio::FileMonitorEvent*, arg0 : LibGio::FileMonitor*) {
 > 17522 |     block.call(FileMonitor.new(arg0), Gio::File::Wrapper.new(arg1), Gio::File::Wrapper.new(arg2), Gio::FileMonitorEvent.new(arg3))
                                                                                                                                   ^--
Error: no overload matches 'Gio::FileMonitorEvent.new' with type Pointer(UInt32)

Overloads are:
 - Gio::FileMonitorEvent.new(value : ::UInt32)

GFileMonitorEvent is a enum in C.

hugopl commented 4 years ago

The compilation was fixed, but crashes.

Code to crash (Need to go on another terminal and touch/create some file)

require "gobject/gtk/autorun"

def file_changed(monitor : Gio::FileMonitor, file : Gio::File, other_file : Gio::File, event : Gio::FileMonitorEvent)
end

monitor = Gio::File.new_for_path(".").monitor_directory(:watch_moves, nil)
monitor.on_changed(&->file_changed(Gio::FileMonitor, Gio::File, Gio::File, Gio::FileMonitorEvent))

# just the check to see if gtk side is ok
#monitor.connect("changed") do
#  puts "hey"
#end

Crash

Invalid memory access (signal 11) at address 0x0
[0x55f00e6f4a06] *CallStack::print_backtrace:Int32 +118
[0x55f00e6e738e] __crystal_sigfault_handler +286
[0x7fd02349f960] ???
[0x55f00e74b6d4] *Gio::File::Wrapper +4
[0x55f00e74b6c6] *Gio::File::Wrapper +6
[0x55f00e74b693] *Gio::File::Wrapper#initialize<Pointer(LibGio::File)>:Nil +67
[0x55f00e74b638] *Gio::File::Wrapper::new<Pointer(LibGio::File)>:Gio::File::Wrapper +104
[0x55f00e6e7589] ~procProc(Pointer(LibGio::File), Pointer(LibGio::File), UInt32, Pointer(LibGio::FileMonitor), Nil) +73
[0x7fd0238c4295] ???
[0x7fd02383080a] g_signal_emit_valist +4730
[0x7fd023830980] g_signal_emit +144
[0x7fd023981565] ???
[0x7fd02372a43c] g_main_context_dispatch +604
[0x7fd023777fa9] ???
[0x7fd023728c03] g_main_loop_run +131
[0x7fd023c94c0f] gtk_main +127
[0x55f00e6e7416] main +86
[0x7fd023269002] __libc_start_main +242
[0x55f00e6d158e] _start +46
[0x0] ???