-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated code expects incorrect type for Gio::AsyncReadyCallback #83
Comments
Here is the explanation why your attempt to fix didn't work. |
I don't think boxing is the reason for this. The signature for Gio.AsyncReadyCallback is actually not a I ran into this while trying to use Gio.Task which generates mismatched bindings between lib LIbGio
# generates the alias, but doesn't use it.
alias AsyncReadyCallback = Pointer(LibGObject::Object), Pointer(LibGio::AsyncResult), Pointer(Void) -> Void
fun g_task_new(source_object : Pointer(Void), cancellable : Pointer(Void), callback : Void*, callback_data : Pointer(Void)) : Pointer(Void)
end
module Gio
def self.new(source_object : GObject::Object?, cancellable : Gio::Cancellable?, callback : Gio::AsyncReadyCallback?, callback_data : Pointer(Void)?) : self
# g_task_new: (Constructor)
# @source_object: (nullable)
# @cancellable: (nullable)
# @callback: (nullable)
# @callback_data: (nullable)
# Returns: (transfer full)
# Generator::NullableArrayPlan
source_object = if source_object.nil?
Pointer(Void).null
else
source_object.to_unsafe
end
# Generator::NullableArrayPlan
cancellable = if cancellable.nil?
Pointer(Void).null
else
cancellable.to_unsafe
end
# Generator::NullableArrayPlan
callback_data = if callback_data.nil?
Pointer(Void).null
else
callback_data.to_unsafe
end
# C call
_retval = LibGio.g_task_new(source_object, cancellable, callback, callback_data)
# Return value handling
Gio::Task.new(_retval, GICrystal::Transfer::Full)
end
end There's also a clear problem with trying to call Unfortunately, I'm not sure there are any workarounds that I can find. Monkey patching isn't possible as you can't monkey patch C lib bindings. Trying to override the Trying to use
Putting
So it seems that While the lib is cool, I can't seem to make an app do moderate computation without blocking the UI thread. Definitely open to suggestions. It'd be really great if |
The Callback need more <3 for sure. On top of my head it needs:
It's possible to mimic a async API in libtest to be able to fix and test these issues in gi-crystal. |
I'm trying to use The problem is that the method doesn't have a Anyway... I also need to think a better way to map these GObject assync API to Crystal... probably: proc = Gio::Subprocess.new(argv: ["ls", "-l"], flags: :none)
proc.wait_async(cancelable) do |result|
...
end This would cause GI-Crystal to call |
Here´s a monkey patch I did to be able to use module GtkSource
class FileSaver
def save_async(io_priority : GLib::Priority, cancellable : Gio::Cancellable? = nil, &callback : Gio::AsyncReadyCallback) : Nil
c_callback = Pointer(Void).null
if callback
c_callback = ->(gobj : Void*, result : Void*, box : Void*) {
unboxed_callback = Box(Gio::AsyncReadyCallback).unbox(box)
unboxed_callback.call(GObject::Object.new(gobj, :none), Gio::AbstractAsyncResult.new(result, :none))
GICrystal::ClosureDataManager.deregister(box)
nil
}.pointer
end
# C call
box = Box.box(callback)
GICrystal::ClosureDataManager.register(box)
LibGtkSource.gtk_source_file_saver_save_async(to_unsafe, io_priority, cancellable, Pointer(Void).null, Pointer(Void).null, Pointer(Void).null, c_callback, box)
end
end
end I have plans to let the generator generate something similar to this, but passing to the block a generated type base don what the In case of error, any of these methods would just thrown the corresponding exception. As usual... I'm not sure when I'll implement this, but at least it's all clear how to do it. |
If you try to compile this branch of my project, you will get the following error.
https://gitlab.gnome.org/wildeyedskies/wince/-/tree/fix-geoclue-init
This results from the generated code function requiring a Gio::AsyncReadyCallback, but the C call expects a pointer for the callback.
However, if you change the C call to instead take the pointer of the proc, you get a error, so I'm not entirely sure what's going on here.
The text was updated successfully, but these errors were encountered: