git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/3] Introduce BUG_ON(cond, msg) MACRO

From
Jeff King <peff@peff.net>
Date
Nov 23, 2017, 05:00 UTC
Message-ID
<20171123050009.GA22218@sigill>
In-Reply-To
<xmqqefopsrk0.fsf@gitster.mtv.corp.google.com>
On Thu, Nov 23, 2017 at 10:38:07AM +0900, Junio C Hamano wrote:
Show 8 quoted lines
> > FWIW I think we've done fine at using assert so far.  But if I
> > understand correctly, the point of this series is to stop having to
> > worry about it.
> 
> I recalled that there was at least one, and "log -Sassert" piped to
> "less" that looks for "/^[ ^I]*assert\(" caught me one recent one.
> 
>     08414938 ("mailinfo.c: move side-effects outside of assert", 2016-12-19)

Thanks, I forgot about that one. There's some discussion about NDEBUG in the surrounding thread if anybody is interested:

  https://public-inbox.org/git/900a55073f78a9f19daca67e468d334@3c843fe6ba8f3c586a21345a2783aa0/

(but it's long and there's really no resolution, so you may want to skip it).

Show 10 quoted lines
> Even though I do not personally mind
> 
> 	assert(flags & EXPECTED_BIT);
> 	assert(remaining_doshes == 0);
> 
> left as a reminder primarily for coders, we can do just as well do
> so with
> 
> 	if (remaining_doshes != 0)
> 		BUG("the gostak did not distim all doshes???");

Yeah, agreed. The reason I do not mind the assert() form is that if you have nothing useful to say in the BUG() sentence, it's a bit more compact.

> So I am fine if we want to move to reduce the use of assert()s or
> get rid of them.  I personally prefer (like Peff, if I am not
> mistaken) an explicit use of the usual control structure, as it is
> easy to follow.

To clarify my position, I think BUG_ON(cond, msg) from this series provides basically no value over "if (cond) BUG(msg)". But I could see value in "BUG_ON(cond)" that allows the compact form but doesn't respect NDEBUG.

-Peff
Previous: Junio C Hamano
Message 18 of 18 in “Introduce BUG_ON(cond, msg) MACRO”
  1. 0/3 Introduce BUG_ON(cond, msg) MACROStefan Beller, Nov 22, 2017
  2. 2/3 git-compat: introduce BUG_ON(condition, fmt, ...) macroStefan Beller, Nov 22, 2017
  3. Jonathan NiederNov 22, 2017
  4. Jeff KingNov 22, 2017
  5. 3/3 contrib/coccinelle: convert all conditional bugs to bug_onStefan Beller, Nov 22, 2017
  6. 1/3 Documentation/CodingGuidelines: explain why assert is badStefan Beller, Nov 22, 2017
  7. Jonathan NiederNov 22, 2017
  8. Stefan BellerNov 22, 2017
  9. Jonathan NiederNov 22, 2017
  10. Jeff KingNov 22, 2017
  11. Jonathan NiederNov 22, 2017
  12. Jeff KingNov 22, 2017
  13. Jonathan NiederNov 22, 2017
  14. Jeff KingNov 22, 2017
  15. Jonathan NiederNov 23, 2017
  16. Jeff KingNov 23, 2017
  17. Junio C HamanoNov 23, 2017
  18. Jeff KingNov 23, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.