]> git.sur5r.net Git - openldap/commitdiff
Provide global assert solution. <ac/assert.h> (new) is now included
authorKurt Zeilenga <kurt@openldap.org>
Sat, 20 Mar 1999 03:13:24 +0000 (03:13 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sat, 20 Mar 1999 03:13:24 +0000 (03:13 +0000)
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()).

include/ac/assert.h [new file with mode: 0644]
include/portable.h.in
libraries/liblber/Makefile.in
libraries/liblber/assert.c [new file with mode: 0644]
libraries/liblber/io.c
libraries/liblber/sockbuf.c
servers/slapd/daemon.c
servers/slapd/operation.c
servers/slapd/slap.h

diff --git a/include/ac/assert.h b/include/ac/assert.h
new file mode 100644 (file)
index 0000000..7a9044d
--- /dev/null
@@ -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 */
index 8e07edabc8cacc5f8fe684c3f6de5a0860dab8c6..f47863139468c172df5641ecdd10ddc14b4c516d 100644 (file)
 
 /* 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
 #include "ldap_cdefs.h"
 #include "ldap_features.h"
 
+#include "ac/assert.h"
+
 #endif /* _LDAP_PORTABLE_H */
index 9a17b3335bbb835090efc4c09c7aabac85f5611e..1b5523d2f6d112baf9cb94c4e73cf2b034d85090 100644 (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
diff --git a/libraries/liblber/assert.c b/libraries/liblber/assert.c
new file mode 100644 (file)
index 0000000..1ee56cc
--- /dev/null
@@ -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
index 7d529500d784c4eed2581d88df30f0a7b186cd8a..92d4242418ad8645d66486ede07b43bb8f22d20a 100644 (file)
 
 #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 ));
 
index c693fdc2de1cf8b5789804cae65219f4490fa7fe..d07926e08e59f6a5953f8425df6e251827fd6c86 100644 (file)
 
 #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
index e55eaf1d087723919d7af48f348a386b87a7f21c..4596840b005c99385285656f93cc8cb2e51b024a 100644 (file)
 #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))
index 404e20d888c1b48a5b4df5c1dac178e332ceb52d..7848357a935b8c7639437ff75346c3117a07f99e 100644 (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 );
 
index c9e9ad7338446f2549821325f994b850f31b9267..837de9025b67a202f61e37aa0089117be78b14f3 100644 (file)
@@ -13,9 +13,6 @@
 #include <ac/syslog.h>
 #include <ac/regex.h>
 
-#undef NDEBUG
-#include <assert.h>
-
 #include "avl.h"
 
 #ifndef ldap_debug