Changeset 77125cc


Ignore:
Timestamp:
Sep 29, 2022, 3:15:20 PM (4 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
master
Children:
f58522b0
Parents:
5f9c42b
Message:

Added support for warnf, like verifyf but doesn't abort.
Will not warn multiple times.

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/assert.cfa

    r5f9c42b r77125cc  
    2525
    2626        #define CFA_ASSERT_FMT "Cforall Assertion error \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\""
     27        #define CFA_WARNING_FMT "Cforall Assertion warning \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\""
    2728
    2829        // called by macro assert in assert.h
     
    4849                abort();
    4950        }
     51
     52        // called by macro warnf
     53        // would be cool to remove libcfa_public but it's needed for libcfathread
     54        void __assert_warn_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) libcfa_public {
     55                __cfaabi_bits_acquire();
     56                __cfaabi_bits_print_nolock( STDERR_FILENO, CFA_WARNING_FMT ": ", assertion, __progname, function, line, file );
     57
     58                va_list args;
     59                va_start( args, fmt );
     60                __cfaabi_bits_print_vararg( STDERR_FILENO, fmt, args );
     61                va_end( args );
     62
     63                __cfaabi_bits_print_nolock( STDERR_FILENO, "\n" );
     64                __cfaabi_bits_release();
     65        }
    5066}
    5167
  • libcfa/src/stdhdr/assert.h

    r5f9c42b r77125cc  
    2727        #define assertf( expr, fmt, ... ) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
    2828
     29        void __assert_warn_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) __attribute__((format( printf, 5, 6) ));
    2930        void __assert_fail_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) __attribute__((noreturn, format( printf, 5, 6) ));
    3031#endif
    3132
    3233#if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))
     34        #define __CFA_WITH_VERIFY__
    3335        #define verify(x) assert(x)
    3436        #define verifyf(x, ...) assertf(x, __VA_ARGS__)
    3537        #define verifyfail(...)
    36         #define __CFA_WITH_VERIFY__
     38        #define warnf( expr, fmt, ... ) ({ static bool check_once##__LINE__ = false; if( false == check_once##__LINE__ && false == (expr)) { check_once##__LINE__ = true; __assert_warn_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ); } })
    3739#else
    3840        #define verify(x)
    3941        #define verifyf(x, ...)
    4042        #define verifyfail(...)
     43        #define warnf( expr, fmt, ... )
    4144#endif
    4245
Note: See TracChangeset for help on using the changeset viewer.