GNOME Bugzilla – Bug 664530
g_io_error_from_errno() generates wrong C code which doesn't compile.
Last modified: 2018-05-22 14:14:40 UTC
g_io_error_from_errno() returns an unowned IOError according to gio-2.0.vapi. However, this generates wrong C code which doesn't compile. In C, g_io_error_from_errno() returns a numeric id of the error. Then generated code pass the numeric value to a GError pointer, which is completely wrong.
It will be weird to bind this function. We could return at most an int from it, as we don't have an IOErrorEnum.
Maybe we could talk the GIO people into a version of this function which returns a GError* and calls strerror to get the error string...
*** Bug 670430 has been marked as a duplicate of this bug. ***
(In reply to comment #2) > Maybe we could talk the GIO people into a version of this function which > returns a GError* and calls strerror to get the error string... We aren't going to add IOErrorEnum anyway, we can think of writing our own wrapper. GIO sources often use g_io_error_from_errno + g_strerror to create a GError. Also we'd want to add bindings for g_prefix_error to let people add a prefix string to the returned error.
We should integrate something as follows into our bindings: [CCode (cheader_filename = "gio/gio.h")] GLib.Quark g_io_error_quark (); [CCode (cheader_filename = "gio/gio.h")] int g_io_error_from_errno (int err_no); public GLib.IOError io_error_from_errno (int err_no) { return (GLib.IOError) new GLib.Error (g_io_error_quark (), g_io_error_from_errno (err_no), "%s", GLib.strerror (err_no)); } The main issue is missing support for custom method bodies in generated bindings.
*** Bug 710085 has been marked as a duplicate of this bug. ***
I just ran into this now, and it was reported on the list a little while ago: https://mail.gnome.org/archives/vala-list/2015-November/msg00001.html Jürg/Rico, does this limitation (custom method bodies) still exist? Adding the following to Gio-2.0-custom.vala following sort-of works for me, allowing the call "throw GLib.ioerror_from_errno(GLib.errno)" to compile (but it fails to link): > [CCode (cheader_filename = "gio/gio.h")] > private static int g_io_error_from_errno_impl (int err_no); > > [CCode (cheader_filename = "gio/gio.h")] > private static GLib.Quark g_io_error_quark_impl (); > > public static GLib.IOError ioerror_from_errno (int err_no) { > return (GLib.IOError) new GLib.Error (g_io_error_quark_impl (), > g_io_error_from_errno_impl (err_no), > "%s", GLib.strerror (err_no)); > } I can't work out how to make that a static method on the GLib.IOError errordomain, either.
Created attachment 372279 [details] [review] gio-2.0: Add custom IOError.from_errno() to make it work as expected
Out of curiosity, what's the dummy value needed for? It doesn't seem to get used anywhere?
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/253.