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 52772 - Proposal: g_friendly_assert (g_assert_with_message)
Proposal: g_friendly_assert (g_assert_with_message)
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2001-04-02 04:19 UTC by Idcmp
Modified: 2011-02-18 16:14 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
New API g_assert_msg(expr, format...) (3.10 KB, patch)
2005-03-12 00:58 UTC, Samuel Abels
none Details | Review
Fixed formatting (3.09 KB, patch)
2005-03-13 11:58 UTC, Samuel Abels
none Details | Review

Description Idcmp 2001-04-02 04:19:23 UTC
A version of g_assert() which, along with the expr, takes a string which is
printed along with the assert.  Essentially a nicer version of:

#define g_friendly_assert(expr,str) g_assert(expr && str)

Asserts are different than g_warning()'s as assert's by definition are not
complied into release binaries (for speed/size reasons).

As glib provides many creature comforts, g_friendly_assert (or whatever the
proposed name would be) would definately be welcome.
Comment 1 Matthias Clasen 2003-07-31 07:07:34 UTC
To make this useful, it would have to be at least


g_assert_msg (expr, fmt, ...);


so that you can write:


g_assert_msg(x == 5, "expected 5, but got %d", x);
Comment 2 Samuel Abels 2005-03-12 00:58:16 UTC
Created attachment 38578 [details] [review]
New API g_assert_msg(expr, format...)

The appended patch implements this API.
On failed assertions, it produces the following output:

** ERROR **: file test.c: line 6 (main): This is working correctly.
aborting...

The gcc code is tested, but since I have no non-GNU compiler available someone
else still needs to test that part of the patch.
Comment 3 Samuel Abels 2005-03-13 11:58:42 UTC
Created attachment 38633 [details] [review]
Fixed formatting

I have now tested the patch with both, gcc and non-gcc and it works fine.
Anyway, I have appended a patch that fixes the previously broken formatting.
Comment 4 Snark 2007-11-12 09:43:50 UTC
This looks interesting : any reason why it is stuck ?
Comment 5 Matthias Clasen 2008-07-06 03:48:39 UTC
We added a bunch of message-enhanced assert macros with the new test framework, so I think this can be closed.