After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 664530 - g_io_error_from_errno() generates wrong C code which doesn't compile.
g_io_error_from_errno() generates wrong C code which doesn't compile.
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Bindings: GLib
unspecified
Other All
: Normal major
: ---
Assigned To: Vala maintainers
Vala maintainers
: 670430 710085 (view as bug list)
Depends on: 658859
Blocks:
 
 
Reported: 2011-11-22 03:44 UTC by Hong Jen Yee
Modified: 2018-05-22 14:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio-2.0: Add custom IOError.from_errno() to make it work as expected (3.72 KB, patch)
2018-05-21 09:09 UTC, Rico Tzschichholz
none Details | Review

Description Hong Jen Yee 2011-11-22 03:44:07 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.
Comment 1 Luca Bruno 2011-11-22 14:34:11 UTC
It will be weird to bind this function. We could return at most an int from it, as we don't have an IOErrorEnum.
Comment 2 Evan Nemerson 2012-01-14 08:17:24 UTC
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...
Comment 3 Luca Bruno 2012-02-20 10:33:28 UTC
*** Bug 670430 has been marked as a duplicate of this bug. ***
Comment 4 Luca Bruno 2012-02-20 10:36:42 UTC
(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.
Comment 5 Jürg Billeter 2012-07-12 14:55:25 UTC
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.
Comment 6 Rico Tzschichholz 2016-09-18 12:43:46 UTC
*** Bug 710085 has been marked as a duplicate of this bug. ***
Comment 7 Michael Gratton 2018-05-21 02:51:56 UTC
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.
Comment 8 Rico Tzschichholz 2018-05-21 09:09:20 UTC
Created attachment 372279 [details] [review]
gio-2.0: Add custom IOError.from_errno() to make it work as expected
Comment 9 Michael Gratton 2018-05-22 12:55:03 UTC
Out of curiosity, what's the dummy value needed for? It doesn't seem to get used anywhere?
Comment 10 GNOME Infrastructure Team 2018-05-22 14:14:40 UTC
-- 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.