Provide global assert solution. <ac/assert.h> (new) is now included

by portable.h with NDEBUG undefined.  This makes assert() is always
available and automatically disables itself when LDAP_DEBUG is undefined.
I've included a basic assert() for pre-STDC compilers.  It relies on
abort() which may not actually be available.  (well replace abort()
with whatever is appropriate if and when we're faced with a pre-STDC
compiler that doesn't have assert()).
This commit is contained in:
Kurt Zeilenga 1999-03-20 03:13:24 +00:00
parent ab64c237f7
commit f999e1350d
9 changed files with 92 additions and 25 deletions

41
include/ac/assert.h Normal file
View File

@ -0,0 +1,41 @@
/* Generic assert.h */
/*
* Copyright 1999 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted only
* as authorized by the OpenLDAP Public License. A copy of this
* license is available at http://www.OpenLDAP.org/license.html or
* in file LICENSE in the top-level directory of the distribution.
*/
#ifndef _AC_ASSERT_H
#define _AC_ASSERT_H
#ifdef LDAP_DEBUG
#if defined( HAVE_ASSERT_H ) || defined( STDC_HEADERS )
#undef NDEBUG
#include <assert.h>
#else
#define LDAP_NEED_ASSERT 1
/*
* no assert()... must be a very old compiler.
* create a replacement and hope it works
*/
void lber_pvt_assert(char* file, int line, char* test);
#define assert(test) \
((test) \
? (void)0 \
: lber_pvt_assert( __FILE__, __LINE__, LDAP_STRING(test)) )
#endif
#else
/* no asserts */
#define assert(test) ((void)0)
#endif
#endif /* _AC_ASSERT_H */

View File

@ -680,6 +680,17 @@
/* begin of postamble */
/*
* DEVEL implies TEST implies DEBUG
*/
#if !defined( LDAP_TEST) && defined( LDAP_DEVEL )
#define LDAP_TEST
#endif
#if !defined( LDAP_DEBUG) && defined( LDAP_TEST )
#define LDAP_DEBUG
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
@ -687,4 +698,6 @@
#include "ldap_cdefs.h"
#include "ldap_features.h"
#include "ac/assert.h"
#endif /* _LDAP_PORTABLE_H */

View File

@ -7,8 +7,8 @@
LIBRARY = liblber.la
XLIBRARY = ../liblber.a
SRCS= decode.c encode.c io.c bprint.c options.c sockbuf.c
OBJS= decode.lo encode.lo io.lo bprint.lo options.lo sockbuf.lo
SRCS= assert.c decode.c encode.c io.c bprint.c options.c sockbuf.c
OBJS= assert.lo decode.lo encode.lo io.lo bprint.lo options.lo sockbuf.lo
XSRCS= version.c
PROGRAMS= dtest etest idtest

View File

@ -0,0 +1,34 @@
/*
* Copyright 1999 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted only
* as authorized by the OpenLDAP Public License. A copy of this
* license is available at http://www.OpenLDAP.org/license.html or
* in file LICENSE in the top-level directory of the distribution.
*/
#include "portable.h"
#ifdef LDAP_NEED_ASSERT
#include <ac/stdio.h>
/*
* helper for our private assert() macro
*
* note: if assert() doesn't exist, like abort() or raise() won't either.
* could use kill() but that might be problematic. I'll just ignore this
* issue for now.
*/
void lber_pvt_assert(char* file, int line, char* test)
{
fprintf(stderr,
"Assertion failed: %s, file %s, line %d\n",
test, file, line);
abort();
}
#endif

View File

@ -32,12 +32,6 @@
#include "lber-int.h"
#ifdef LDAP_DEBUG
#include <assert.h>
#else
#define assert(cond)
#endif
static long BerRead LDAP_P(( Sockbuf *sb, char *buf, long len ));
static int ber_realloc LDAP_P(( BerElement *ber, unsigned long len ));

View File

@ -27,12 +27,9 @@
#include "lber-int.h"
#ifdef LDAP_DEBUG
#include <assert.h>
#ifdef LDAP_TEST
#undef TEST_PARTIAL_READ
#undef TEST_PARTIAL_WRITE
#else
#define assert( cond )
#endif
#define MAX_BUF_SIZE 65535

View File

@ -26,12 +26,6 @@
#include <sys/ioctl.h>
#endif
#ifdef LDAP_DEBUG
#include <assert.h>
#else
#define assert( cond )
#endif
#ifdef HAVE_TCPD
#include <tcpd.h>
@ -165,9 +159,8 @@ slapd_daemon(
if ( (c[i].c_state != SLAP_C_INACTIVE)
&& (c[i].c_state != SLAP_C_CLOSING) )
{
#ifdef LDAP_DEBUG
assert(lber_pvt_sb_in_use( &c[i].c_sb ));
#endif
FD_SET( lber_pvt_sb_get_desc(&c[i].c_sb),
&readfds );
if (lber_pvt_sb_data_ready(&c[i].c_sb))

View File

@ -13,9 +13,7 @@
void
slap_op_free( Operation *op )
{
#ifdef LDAP_DEBUG
assert( op->o_next == NULL );
#endif
ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );

View File

@ -13,9 +13,6 @@
#include <ac/syslog.h>
#include <ac/regex.h>
#undef NDEBUG
#include <assert.h>
#include "avl.h"
#ifndef ldap_debug