[Mesa-dev] [PATCH mesa 16/16] util: use NDEBUG to guard asserts

Dylan Baker dylan at pnwbakers.com
Mon Nov 27 18:46:59 UTC 2017


Quoting Eric Engestrom (2017-11-27 09:46:57)
> On Saturday, 2017-11-25 18:45:14 +0100, Gert Wollny wrote:
> > Am Freitag, den 24.11.2017, 18:07 +0000 schrieb Eric Engestrom:
> > > Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
> > > ---
> > >  src/util/ralloc.c | 18 +++++++++---------
> > >  src/util/slab.c   |  4 ++--
> > >  2 files changed, 11 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/src/util/ralloc.c b/src/util/ralloc.c
> > > index 42cfa2e391d52df68db2..b52079ac075a0fe11944 100644
> > > --- a/src/util/ralloc.c
> > > +++ b/src/util/ralloc.c
> > > @@ -61,7 +61,7 @@ struct
> > >  #endif
> > >     ralloc_header
> > >  {
> > > -#ifdef DEBUG
> > > +#ifndef NDEBUG
> > >     /* A canary value used to determine whether a pointer is
> > > ralloc'd. */
> > >     unsigned canary;
> > >  #endif
> > > @@ -88,7 +88,7 @@ get_header(const void *ptr)
> > >  {
> > >     ralloc_header *info = (ralloc_header *) (((char *) ptr) -
> > >                                         sizeof(ralloc_header));
> > > -#ifdef DEBUG
> > > +#ifndef NDEBUG
> > >     assert(info->canary == CANARY);
> > >  #endif
> > 
> > With NDEBUG defined "assert" already translates to a no-op, hence the
> > extra "#ifndef NDEBUG" block is not needed (same for the other asserts
> > below and in the other patches). 
> 
> Indeed, I did so many of those conversions that I wasn't thinking about
> that anymore. Thanks for catching that, I'll remove the include guards
> altogether around plain asserts()s.

Is that true in this case? info->canary is only defined if NDEBUG is not
defined, so this will fail to compile since those symbols are undefined, right?

Dylan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171127/8940f72d/attachment-0001.sig>


More information about the mesa-dev mailing list