Message ID | 1528193509-7063-2-git-send-email-thuth@redhat.com |
---|---|
State | Accepted |
Headers | show |
Series | Clean-up and fix-up patches for pxelinux.cfg | expand |
On Tue, 5 Jun 2018 12:11:47 +0200 Thomas Huth <thuth@redhat.com> wrote: > ... useful for "this should never happen" situations, where > you want to make sure that it really never happens. > > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > lib/libc/include/assert.h | 37 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 37 insertions(+) > create mode 100644 lib/libc/include/assert.h > > diff --git a/lib/libc/include/assert.h b/lib/libc/include/assert.h > new file mode 100644 > index 0000000..e0e02ac > --- /dev/null > +++ b/lib/libc/include/assert.h > @@ -0,0 +1,37 @@ > +/***************************************************************************** > + * assert() macro definition > + * > + * Copyright 2018 Red Hat, Inc. > + * > + * This program and the accompanying materials are made available under > + * the terms of the BSD License which accompanies this distribution, and > + * is available at http://www.opensource.org/licenses/bsd-license.php > + * > + * Contributors: > + * Thomas Huth, Red Hat Inc. - initial implementation > + *****************************************************************************/ > + > +#ifndef SLIMLINE_ASSERT_H > +#define SLIMLINE_ASSERT_H > + > + > +#ifdef NDEBUG > + > +#define assert(cond) (void) > + > +#else > + > +#define assert(cond) \ > + do { \ > + if (!(cond)) { \ > + fprintf(stderr, \ > + "ERROR: Assertion '" #cond "' failed!\n" \ > + "(function %s, file " __FILE__ ", line %i)\n", \ > + __func__, __LINE__); \ > + while (1) {}; \ The semicolon isn't needed after an empty block. Alternatively you could drop the empty block and keep the semicolon. It works anyway so, Reviewed-by: Greg Kurz <groug@kaod.org> > + } \ > + } while (0) > + > +#endif > + > +#endif /* SLIMLINE_ASSERT_H */
On 05.06.2018 13:00, Greg Kurz wrote: > On Tue, 5 Jun 2018 12:11:47 +0200 > Thomas Huth <thuth@redhat.com> wrote: > >> ... useful for "this should never happen" situations, where >> you want to make sure that it really never happens. >> >> Signed-off-by: Thomas Huth <thuth@redhat.com> >> --- >> lib/libc/include/assert.h | 37 +++++++++++++++++++++++++++++++++++++ >> 1 file changed, 37 insertions(+) >> create mode 100644 lib/libc/include/assert.h >> >> diff --git a/lib/libc/include/assert.h b/lib/libc/include/assert.h >> new file mode 100644 >> index 0000000..e0e02ac >> --- /dev/null >> +++ b/lib/libc/include/assert.h >> @@ -0,0 +1,37 @@ >> +/***************************************************************************** >> + * assert() macro definition >> + * >> + * Copyright 2018 Red Hat, Inc. >> + * >> + * This program and the accompanying materials are made available under >> + * the terms of the BSD License which accompanies this distribution, and >> + * is available at http://www.opensource.org/licenses/bsd-license.php >> + * >> + * Contributors: >> + * Thomas Huth, Red Hat Inc. - initial implementation >> + *****************************************************************************/ >> + >> +#ifndef SLIMLINE_ASSERT_H >> +#define SLIMLINE_ASSERT_H >> + >> + >> +#ifdef NDEBUG >> + >> +#define assert(cond) (void) >> + >> +#else >> + >> +#define assert(cond) \ >> + do { \ >> + if (!(cond)) { \ >> + fprintf(stderr, \ >> + "ERROR: Assertion '" #cond "' failed!\n" \ >> + "(function %s, file " __FILE__ ", line %i)\n", \ >> + __func__, __LINE__); \ >> + while (1) {}; \ > > The semicolon isn't needed after an empty block. Alternatively you could > drop the empty block and keep the semicolon. Oops, right. Alexey, in case there are no other reasons to respin, could you fix this up when you pick up the patch? Or do you prefer if I resend a v3? > It works anyway so, > > Reviewed-by: Greg Kurz <groug@kaod.org> Thanks! Thomas
On 5/6/18 9:14 pm, Thomas Huth wrote: > On 05.06.2018 13:00, Greg Kurz wrote: >> On Tue, 5 Jun 2018 12:11:47 +0200 >> Thomas Huth <thuth@redhat.com> wrote: >> >>> ... useful for "this should never happen" situations, where >>> you want to make sure that it really never happens. >>> >>> Signed-off-by: Thomas Huth <thuth@redhat.com> >>> --- >>> lib/libc/include/assert.h | 37 +++++++++++++++++++++++++++++++++++++ >>> 1 file changed, 37 insertions(+) >>> create mode 100644 lib/libc/include/assert.h >>> >>> diff --git a/lib/libc/include/assert.h b/lib/libc/include/assert.h >>> new file mode 100644 >>> index 0000000..e0e02ac >>> --- /dev/null >>> +++ b/lib/libc/include/assert.h >>> @@ -0,0 +1,37 @@ >>> +/***************************************************************************** >>> + * assert() macro definition >>> + * >>> + * Copyright 2018 Red Hat, Inc. >>> + * >>> + * This program and the accompanying materials are made available under >>> + * the terms of the BSD License which accompanies this distribution, and >>> + * is available at http://www.opensource.org/licenses/bsd-license.php >>> + * >>> + * Contributors: >>> + * Thomas Huth, Red Hat Inc. - initial implementation >>> + *****************************************************************************/ >>> + >>> +#ifndef SLIMLINE_ASSERT_H >>> +#define SLIMLINE_ASSERT_H >>> + >>> + >>> +#ifdef NDEBUG >>> + >>> +#define assert(cond) (void) >>> + >>> +#else >>> + >>> +#define assert(cond) \ >>> + do { \ >>> + if (!(cond)) { \ >>> + fprintf(stderr, \ >>> + "ERROR: Assertion '" #cond "' failed!\n" \ >>> + "(function %s, file " __FILE__ ", line %i)\n", \ >>> + __func__, __LINE__); \ >>> + while (1) {}; \ >> >> The semicolon isn't needed after an empty block. Alternatively you could >> drop the empty block and keep the semicolon. > > Oops, right. Alexey, in case there are no other reasons to respin, could > you fix this up when you pick up the patch? Or do you prefer if I resend > a v3? Nah, I fixed the commit and pushed out to github, thanks. I'll send an update for qemu shortly, just to make sure I won't miss the cutoff this time :)
diff --git a/lib/libc/include/assert.h b/lib/libc/include/assert.h new file mode 100644 index 0000000..e0e02ac --- /dev/null +++ b/lib/libc/include/assert.h @@ -0,0 +1,37 @@ +/***************************************************************************** + * assert() macro definition + * + * Copyright 2018 Red Hat, Inc. + * + * This program and the accompanying materials are made available under + * the terms of the BSD License which accompanies this distribution, and + * is available at http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * Thomas Huth, Red Hat Inc. - initial implementation + *****************************************************************************/ + +#ifndef SLIMLINE_ASSERT_H +#define SLIMLINE_ASSERT_H + + +#ifdef NDEBUG + +#define assert(cond) (void) + +#else + +#define assert(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, \ + "ERROR: Assertion '" #cond "' failed!\n" \ + "(function %s, file " __FILE__ ", line %i)\n", \ + __func__, __LINE__); \ + while (1) {}; \ + } \ + } while (0) + +#endif + +#endif /* SLIMLINE_ASSERT_H */
... useful for "this should never happen" situations, where you want to make sure that it really never happens. Signed-off-by: Thomas Huth <thuth@redhat.com> --- lib/libc/include/assert.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/libc/include/assert.h