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 22, 2017, 23:58 UTC
Message-ID
<20171122235851.GE8577@sigill>
In-Reply-To
<20171122234532.GI11671@aiede.mtv.corp.google.com>
On Wed, Nov 22, 2017 at 03:45:32PM -0800, Jonathan Nieder wrote:
Show 6 quoted lines
> Jeff King wrote:
> 
> > Yes. I'd be fine having a single-argument BUG_ON() like that. But then,
> > I'm not sure what it's buying us over assert().
> 
> It lets you build with NDEBUG.
But why do you want to build with NDEBUG if nothing uses assert()? ;)

I'm being a little glib, but I think there really is a chicken-and-egg question here. Why are people building with NDEBUG if they don't want to disable asserts? Do they do it out of habit? A misguided sense of performance optimization? Does it do something else I'm not aware of?

> It also goes through our own die()
> handler, which means that e.g. the error message gets propagated over
> remote transports.

BUG() doesn't go through our die handler. It hits vreportf(), which does do some minor munging, but it always goes to stderr. Error message propagation over the remote protocol happens either:

  1. From a parent process muxing our stderr onto the sideband.
  2. Via special wrappers like receive-pack's rp_error().

The only program I know that sets a custom die handler to change the reporting is git-http-backend (and there it only applies to die("BUG"), not BUG(), so with the latter you'd get a hard hangup instead of an attempt at an http 500).

Show 6 quoted lines
> Please please please, don't rely on side-effects from assert().  They
> will cause me to run into pain over time.  This issue alone might be
> worth banning use of assert() in the codebase, if we can't trust
> reviewers to catch problematic examples (fortunately reviewers have
> been pretty good about that so far, but banning it would free up their
> attention to focus on other aspects of a patch).

Yes, obviously side effects in an assert() are horrible. But I haven't noticed that being a problem in our code base.

For the record, I'm totally fine with banning assert() in favor of a custom equivalent. I just don't think we've seen any real problems with assert in our codebase so far.

-Peff
Previous: Jonathan NiederNext: Jonathan Nieder
Message 14 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.