The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: What policy for BUG_ON()?
@ 2004-08-31 15:06 Albert Cahalan
  2004-08-31 16:52 ` Linus Torvalds
  0 siblings, 1 reply; 12+ messages in thread
From: Albert Cahalan @ 2004-08-31 15:06 UTC (permalink / raw)
  To: linux-kernel mailing list; +Cc: bunk, arjanv, axboe, torvalds

On Mon, 30 Aug 2004, Adrian Bunk wrote:

> Let me try to summarize the different options regarding BUG_ON, 
> concerning whether the argument to BUG_ON might contain side effects, 
> and whether it should be allowed in some "do this only if you _really_ 
> know what you are doing" situations to let BUG_ON do nothing.
> 
> Options:
> 1. BUG_ON must not be defined to do nothing
> 1a. side effects are allowed in the argument of BUG_ON
> 1b. side effects are not allowed in the argument of BUG_ON
> 2. BUG_ON is allowed to be defined to do nothing
> 2a. side effects are allowed in the argument of BUG_ON
> 2b. side effects are not allowed in the argument of BUG_ON

It comes down to the relative importance of:

i.  BUG_ON(expensive_and_unneeded_debug_test())
ii. BUG_ON(something_that_must_execute())

I think case i should get priority, since then the
removal of side effects is a nice way to eliminate
the expensive code for non-debug builds.

For case ii, it's easy enough to split out the
need-to-execute code and assign results to a
variable that can be checked later. Since it is
something that must execute, you probably need
the return value anyway.

The normal expectation for non-debug builds
would be this:

#define BUG_ON(x)



^ permalink raw reply	[flat|nested] 12+ messages in thread
* What policy for BUG_ON()?
@ 2004-08-30 20:15 Adrian Bunk
  2004-08-30 20:22 ` Arjan van de Ven
  2004-08-31  0:25 ` Linus Torvalds
  0 siblings, 2 replies; 12+ messages in thread
From: Adrian Bunk @ 2004-08-30 20:15 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton, Jens Axboe, Matt Mackall; +Cc: linux-kernel

Let me try to summarize the different options regarding BUG_ON, 
concerning whether the argument to BUG_ON might contain side effects, 
and whether it should be allowed in some "do this only if you _really_ 
know what you are doing" situations to let BUG_ON do nothing.

Options:
1. BUG_ON must not be defined to do nothing
1a. side effects are allowed in the argument of BUG_ON
1b. side effects are not allowed in the argument of BUG_ON
2. BUG_ON is allowed to be defined to do nothing
2a. side effects are allowed in the argument of BUG_ON
2b. side effects are not allowed in the argument of BUG_ON

It would be good if there was a decision which of the four choices 
should become documented policy.


<--  snip  -->

My personal opinions:

IMHO, 1b doesn't make much sense, since in the case of 1. side effects 
are never a problem.

IMHO, 2b is bad since it might cause nasty heisenbugs if BUG_ON does  
nothing, and preserving the side effects is easy.

<--  snip  -->


cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-08-31 23:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-31 15:06 What policy for BUG_ON()? Albert Cahalan
2004-08-31 16:52 ` Linus Torvalds
2004-08-31 17:39   ` Albert Cahalan
2004-08-31 21:30     ` Kyle Moffett
2004-08-31 22:16       ` Michael Buesch
2004-08-31 23:32         ` Kyle Moffett
  -- strict thread matches above, loose matches on Subject: below --
2004-08-30 20:15 Adrian Bunk
2004-08-30 20:22 ` Arjan van de Ven
2004-08-31  6:28   ` Jens Axboe
2004-08-31 11:14     ` Paulo Marques
2004-08-31  0:25 ` Linus Torvalds
2004-08-31 11:28   ` Adrian Bunk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox