[SLOF] [PATCH v2 1/3] libc: Add a simple implementation of an assert() function

Alexey Kardashevskiy aik at ozlabs.ru
Thu Jun 7 16:49:10 AEST 2018


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 at 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 at 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 :)



-- 
Alexey


More information about the SLOF mailing list