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 792903 - Clarification between g_try_.. functions and their counterparts
Clarification between g_try_.. functions and their counterparts
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: docs
unspecified
Other Linux
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-01-25 16:52 UTC by Pavlo Solntsev
Modified: 2018-01-31 22:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (996 bytes, patch)
2018-01-25 16:52 UTC, Pavlo Solntsev
none Details | Review
Rewritten patch (1.69 KB, patch)
2018-01-27 05:33 UTC, Pavlo Solntsev
none Details | Review
One more iteration for the patch (1.47 KB, patch)
2018-01-27 18:21 UTC, Pavlo Solntsev
committed Details | Review

Description Pavlo Solntsev 2018-01-25 16:52:12 UTC
Created attachment 367426 [details] [review]
Proposed patch

I just moved the clarification to the beginning of the page. It is more convenient to provide this difference at the beginning. Every time when I see malloc like functions, I think about checking for NULL, but it looks like it is not a case for g_malloc. It works or it fails. It should help to avoid unnecessary NULL check structures in the code. 

Every g_try_... unction still has the same wording. I may be left there for convenience.
Comment 1 Philip Withnall 2018-01-26 18:28:46 UTC
Review of attachment 367426 [details] [review]:

::: glib/gmem.c
@@ +74,3 @@
  * constructors and destructors).
+ *
+ * g_try_... family of functions returns %NULL on failure, contrast to their counterparts: 

s/contrast/in contrast/

@@ +75,3 @@
+ *
+ * g_try_... family of functions returns %NULL on failure, contrast to their counterparts: 
+ * #g_malloc(), #g_malloc0(), #g_malloc0_n(), #g_realloc(),#g_realloc_n(), which aborts 

No need for the `#` before the function names. gtk-doc syntax is for functions to be indicated using a trailing `()`. i.e. `g_malloc()` rather than `#g_malloc()`.

Missing space after one of the commas.

s/aborts/abort/

s/of failure/on failure/

@@ +76,3 @@
+ * g_try_... family of functions returns %NULL on failure, contrast to their counterparts: 
+ * #g_malloc(), #g_malloc0(), #g_malloc0_n(), #g_realloc(),#g_realloc_n(), which aborts 
+ * the program of failure.

I’d move the paragraph to be just below the previous one, which mentions that the normal memory allocation functions terminate the application on failure. That allows the two paragraphs to be contrasted better.
Comment 2 Pavlo Solntsev 2018-01-27 05:33:57 UTC
Created attachment 367502 [details] [review]
Rewritten patch

Thank you, Philip, for comments and suggestions. I went over once again and I think the new version looks better. Take a look, please.
Comment 3 Philip Withnall 2018-01-27 12:28:17 UTC
Review of attachment 367502 [details] [review]:

::: glib/gmem.c
@@ +64,3 @@
  * These functions provide support for allocating and freeing memory.
  * 
+ * If call to allocate memory using functions g_new(), g_new0(), g_renew(),

s/If call/If any call/

@@ +67,3 @@
+ * g_malloc(), g_malloc0(), g_malloc0_n(), g_realloc(), and g_realloc_n() 
+ * fails, the application is terminated. This also means that there is no 
+ * need to check if the call succeeded. On the other hand, g_try_... family 

s/hand, g_try_.../hand, the g_try_…()/

@@ +78,3 @@
  * since these allocators may use different memory pools (and new/delete call
  * constructors and destructors).
+ *

You introduced a spurious empty line.
Comment 4 Pavlo Solntsev 2018-01-27 18:21:15 UTC
Created attachment 367531 [details] [review]
One more iteration for the patch

OK, should be better. Thanks.
Comment 5 Philip Withnall 2018-01-31 22:09:54 UTC
Review of attachment 367531 [details] [review]:

Thanks very much.
Comment 6 Philip Withnall 2018-01-31 22:11:35 UTC
Pushed to master.