[FFmpeg-devel] [RFC] av_assert

Michael Niedermayer michaelni
Thu May 17 22:55:00 CEST 2007


Hi

On Thu, May 17, 2007 at 10:14:46PM +0200, Alex Beregszaszi wrote:
> Hi,
> 
> as we av_abort, and we are using assert not only for debug, I propose to
> have an own av_assert macro. A pro is that now it uses av_log, thus in
> some applications the error doesn't gets along unnoticed (as it could
> happen with fprintf), think about a GUI based application.
> 
> The attached patch adds the macro, but doesn't changes the assert()'s to
> av_assert() in the code.

[...]
> Index: libavutil/internal.h
> ===================================================================
> --- libavutil/internal.h	(revision 9050)
> +++ libavutil/internal.h	(working copy)
> @@ -141,8 +141,9 @@
>  #if !defined(DEBUG) && !defined(NDEBUG)
>  #    define NDEBUG
>  #endif
> -#include <assert.h>
>  
> +#include "log.h"
> +
>  /* dprintf macros */
>  #ifdef DEBUG
>  #    define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
> @@ -152,6 +153,14 @@
>  
>  #define av_abort()      do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
>  
> +
> +#define av_assert(x) do { \
> +     if (!(x)) { \
> +        av_log(NULL, AV_LOG_ERROR, "Assertion '" #x "' failed in %s at %s:%d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
> +	abort(); \
> +     } \
> +} while(0)

i think the context should not be NULL but rather a argument from
av_assert()

id like to have 3 different classes of asserts

1. av_slow_assert()
    This assert occurs in non speed critical code and can stay enabled even
    if we want as fast as possible libav*
2. av_fast_assert()
    This assert occurs in speed critical code and should be disabled in non
    debug builds
3. av_security_assert()
    This assert checks a security related assumtation and should always be
    enabled unless the user explicitly disables such asserts

we could also choose different names for the 3 or passing a int type ...

note assuming a bugfree libav / ffmpeg no assert should ever be false no matter
what random or systematic input is feeded to it (it cant hurt to say this
more often than needed, too many people missuse asserts)

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have often repented speaking, but never of holding my tongue.
-- Xenocrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070517/c7a66a4d/attachment.pgp>



More information about the ffmpeg-devel mailing list