From: Hallvard Furuseth Date: Fri, 21 Jan 2011 11:41:45 +0000 (+0000) Subject: Support $NO_RS_ASSERT. Add comments. X-Git-Tag: MIGRATION_CVS2GIT~185 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fb6aa52870c5e5f298ec52849688159636dfbdb9;p=openldap Support $NO_RS_ASSERT. Add comments. Use a private rs_assert_() helper function instead of libc assert. --- diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 35b0fa1ed1..dc05dae818 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1543,7 +1543,17 @@ LDAP_SLAPD_F (int) get_alias_dn LDAP_P(( * result.c */ #if USE_RS_ASSERT /*defined(USE_RS_ASSERT)?(USE_RS_ASSERT):defined(LDAP_TEST)*/ -# define RS_ASSERT assert +#ifdef __GNUC__ +# define RS_FUNC_ __FUNCTION__ +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 199901L +# define RS_FUNC_ __func__ +#else +# define rs_assert_(file, line, func, cond) rs_assert__(file, line, cond) +#endif +LDAP_SLAPD_V(int) rs_suppress_assert; +LDAP_SLAPD_F(void) rs_assert_(const char*, unsigned, const char*, const char*); +# define RS_ASSERT(cond) ((rs_suppress_assert > 0 || (cond)) \ + ? (void) 0 : rs_assert_(__FILE__, __LINE__, RS_FUNC_, #cond)) #else # define RS_ASSERT(cond) ((void) 0) # define rs_assert_ok(rs) ((void) (rs)) diff --git a/servers/slapd/result.c b/servers/slapd/result.c index 6767fa4ff5..20c05d29d8 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -134,6 +134,38 @@ slap_req2res( ber_tag_t tag ) /* SlapReply debugging, prodo-slap.h overrides it in OpenLDAP releases */ #if defined(LDAP_TEST) || (defined(USE_RS_ASSERT) && (USE_RS_ASSERT)) + +int rs_suppress_assert = 0; + +/* RS_ASSERT() helper function */ +void rs_assert_(const char*file, unsigned line, const char*fn, const char*cond) +{ + int no_assert = rs_suppress_assert, save_errno = errno; + const char *s; + + if ( no_assert >= 0 ) { + if ( no_assert == 0 && (s = getenv( "NO_RS_ASSERT" )) && *s ) { + no_assert = rs_suppress_assert = atoi( s ); + } + if ( no_assert > 0 ) { + errno = save_errno; + return; + } + } + +#ifdef rs_assert_ /* proto-slap.h #defined away the fn parameter */ + fprintf( stderr,"%s:%u: " "RS_ASSERT(%s) failed.\n", file,line,cond ); +#else + fprintf( stderr,"%s:%u: %s: RS_ASSERT(%s) failed.\n", file,line,fn,cond ); +#endif + fflush( stderr ); + + errno = save_errno; + /* $NO_RS_ASSERT > 0: ignore rs_asserts, 0: abort, < 0: just warn */ + if ( !no_assert /* from $NO_RS_ASSERT */ ) abort(); +} + +/* SlapReply is consistent */ void (rs_assert_ok)( const SlapReply *rs ) { @@ -161,6 +193,8 @@ void #endif #endif } + +/* Ready for calling a new backend operation */ void (rs_assert_ready)( const SlapReply *rs ) { @@ -178,6 +212,8 @@ void RS_ASSERT( !(rs->sr_flags & REP_ENTRY_MASK) ); #endif } + +/* Backend operation done */ void (rs_assert_done)( const SlapReply *rs ) { @@ -188,6 +224,7 @@ void RS_ASSERT( !(rs->sr_flags & REP_ENTRY_MUSTFLUSH) ); #endif } + #endif /* LDAP_TEST || USE_RS_ASSERT */ /* Reset a used SlapReply whose contents has been flushed (freed/released) */