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 771959 - gtk_init_with_args fails when no display is found / does not comply with its documentation
gtk_init_with_args fails when no display is found / does not comply with its ...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
3.22.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 783624 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-09-25 21:22 UTC by Steef Hegeman
Modified: 2017-08-07 17:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch proposal (1.30 KB, patch)
2016-09-26 16:34 UTC, Steef Hegeman
none Details | Review
docs: gtk_init_check will also fail if the commandline was invalid (1.72 KB, patch)
2017-07-21 15:26 UTC, Debarshi Ray
committed Details | Review
docs: gtk_init_with_args will also fail if the commandline was invalid (1.01 KB, patch)
2017-07-21 15:30 UTC, Debarshi Ray
committed Details | Review
main: Set the error if gtk_init_with_args fails (1.58 KB, patch)
2017-07-21 16:07 UTC, Debarshi Ray
committed Details | Review

Description Steef Hegeman 2016-09-25 21:22:52 UTC
The documentation for gtk_init_with_args: "This function does the same work as gtk_init_check()."

However, contrary to gtk_init_check, gtk_init_with_args fails when no display can be found.

I'm not sure whether this is a documentation bug or an implementation bug. If it's an implementation bug, it can probably be solved quite easily: the function currently contains the following line: "gtk_group = gtk_get_option_group (TRUE);", the argument for gtk_get_option_group should be FALSE.

Furthermore, the function currently returns the return value of g_option_context_parse, while the documentation states: "Returns TRUE if the windowing system has been successfully initialized, FALSE otherwise".

I wouldn't mind writing a patch, but as I already mentioned, I'm not sure whether this is a case of buggy documentation or buggy implementation.
Comment 1 Matthias Clasen 2016-09-26 15:35:41 UTC
The documentation should probably say: This function does the same work as gtk_init().
Comment 2 Steef Hegeman 2016-09-26 16:31:36 UTC
(In reply to Matthias Clasen from comment #1)
> The documentation should probably say: This function does the same work as
> gtk_init().

That makes it easy then. I'm not sure if I'm getting the line width style right, but I made a small patch to fix the documentation.

I'm not quite sure how to describe the return value, it can mean multiple things right now I believe but usually whether parsing succeeded or not so I went with that.

Should it describe the odd case scenarios as well? (e.g. if gtk_initialized is true). Maybe "TRUE if GTK+ was already initialized or if parsing succeeded, FALSE if initialization failed or parsing errors occurred"?

Sorry for blowing up a trivial issue.
Comment 3 Steef Hegeman 2016-09-26 16:34:12 UTC
Created attachment 336280 [details] [review]
Patch proposal

As mentioned in the comment I made earlier (https://bugzilla.gnome.org/show_bug.cgi?id=771959#c2)
Comment 4 Matthias Clasen 2016-09-27 19:12:31 UTC
I decided to go the other way instead, and make the function do what the docs say.
Comment 5 Debarshi Ray 2017-07-21 15:25:10 UTC
Found this via bug 783624.

(In reply to Steef Hegeman from comment #0)
> The documentation for gtk_init_with_args: "This function does the same work
> as gtk_init_check()."
> 
> However, contrary to gtk_init_check, gtk_init_with_args fails when no
> display can be found.
> 
> I'm not sure whether this is a documentation bug or an implementation bug.
> If it's an implementation bug, it can probably be solved quite easily: the
> function currently contains the following line: "gtk_group =
> gtk_get_option_group (TRUE);", the argument for gtk_get_option_group should
> be FALSE.

I don't understand why that should be so.

With gtk_get_option_group (TRUE), the following g_option_context_parse call will try to parse the commandline arguments, and try to open a display. If any of those two things fail it will return FALSE and set the error. At least that's my understanding from the reading gtk/gtkmain.c and glib/goption.c. This seems correct to me.

> Furthermore, the function currently returns the return value of
> g_option_context_parse, while the documentation states: "Returns TRUE if the
> windowing system has been successfully initialized, FALSE otherwise".

That's a good point. :)

gtk_init_check and gtk_init_with_args should return TRUE only when both the commandline is valid and a display could be opened. The documentation seems to suggest that the outcome of parsing the commandline doesn't matter, but that's not true. It doesn't match with the implementation or the behaviour people have gotten used to.
Comment 6 Debarshi Ray 2017-07-21 15:26:19 UTC
Created attachment 356124 [details] [review]
docs: gtk_init_check will also fail if the commandline was invalid
Comment 7 Debarshi Ray 2017-07-21 15:30:01 UTC
Created attachment 356125 [details] [review]
docs: gtk_init_with_args will also fail if the commandline was invalid
Comment 8 Debarshi Ray 2017-07-21 15:57:41 UTC
*** Bug 783624 has been marked as a duplicate of this bug. ***
Comment 9 Debarshi Ray 2017-07-21 16:07:59 UTC
Created attachment 356128 [details] [review]
main: Set the error if gtk_init_with_args fails
Comment 10 Debarshi Ray 2017-07-21 16:24:29 UTC
All this is strictly gtk-3-22 material. gtk_init_with_args is gone, and gtk_init_check doesn't handle commandline arguments anymore.
Comment 11 Matthias Clasen 2017-08-07 17:28:43 UTC
Review of attachment 356124 [details] [review]:

ok
Comment 12 Matthias Clasen 2017-08-07 17:29:56 UTC
Review of attachment 356125 [details] [review]:

sure
Comment 13 Matthias Clasen 2017-08-07 17:32:22 UTC
Review of attachment 356128 [details] [review]:

ok