From 4abb5ba31dfffb08d04641b932222543ee438225 Mon Sep 17 00:00:00 2001 From: "Bradley C. Kuszmaul" Date: Fri, 8 Feb 2008 03:17:38 +0000 Subject: [PATCH] Use toku_assert instead of assert. Addresses #354. git-svn-id: file:///svn/tokudb@2167 c7de825b-a66e-492c-adef-691d508d4ae1 --- newbrt/Makefile | 12 +++++++++--- newbrt/benchmark-test.c | 2 +- newbrt/brt-serialize-test.c | 2 +- newbrt/brt-serialize.c | 2 +- newbrt/brt-test.c | 4 ++-- newbrt/brt-verify.c | 3 +-- newbrt/brt.c | 2 +- newbrt/brtdump.c | 3 ++- newbrt/cachetable-test.c | 2 +- newbrt/cachetable-test2.c | 2 +- newbrt/cachetable.c | 17 +++++++++-------- newbrt/fifo-test.c | 6 +++--- newbrt/fifo.c | 2 +- newbrt/fingerprint.c | 6 ++++-- newbrt/key.c | 3 ++- newbrt/list-test.c | 6 +++--- newbrt/log-internal.h | 7 +++---- newbrt/log-test.c | 6 +++--- newbrt/logformat.c | 2 +- newbrt/memory.c | 2 +- newbrt/mempool.c | 4 ++-- newbrt/memtest.c | 2 +- newbrt/myassert.c | 12 ------------ newbrt/myassert.h | 13 ------------- newbrt/pma-test.c | 12 ++++++------ newbrt/pma.c | 2 +- newbrt/primes.c | 16 ++++++++-------- newbrt/randdb4.c | 2 +- newbrt/recover.c | 13 ++++++------- newbrt/tdb_logprint.c | 9 ++++----- newbrt/test-assert.c | 9 ++++++++- newbrt/test_oexcl.c | 2 +- newbrt/toku_assert.c | 2 +- newbrt/toku_assert.h | 12 ++++++------ newbrt/wbuf.h | 6 +++--- newbrt/ybt-test.c | 2 +- 36 files changed, 99 insertions(+), 110 deletions(-) delete mode 100644 newbrt/myassert.c delete mode 100644 newbrt/myassert.h diff --git a/newbrt/Makefile b/newbrt/Makefile index 575b583f3dc..12ad8e5419c 100644 --- a/newbrt/Makefile +++ b/newbrt/Makefile @@ -127,22 +127,24 @@ pma-test benchmark-test brt-test brt-serialize-test brtdump: LDFLAGS+=-lz BRT_INTERNAL_H_INCLUDES = brt-internal.h cachetable.h fifo.h pma.h brt.h brttypes.h yerror.h ybt.h log.h ../include/db.h kv-pair.h memory.h crc.h key.o: brttypes.h key.h +list-test: list-test.o toku_assert.o pma-test.o: $(BRT_INTERNAL_H_INCLUDES) pma-internal.h pma.h list.h mempool.h pma-test: pma.o memory.o key.o ybt.o log.o mempool.o fingerprint.o brt-serialize.o fifo.o primes.o toku_assert.o log_code.o roll.o brt.o cachetable.o brt-verify.o pma.o: pma.h yerror.h pma-internal.h memory.h key.h ybt.h brttypes.h log.h ../include/db.h log_header.h ybt.o: ybt.h brttypes.h ../include/db.h -ybt-test: ybt-test.o ybt.o memory.o +ybt-test: ybt-test.o ybt.o memory.o toku_assert.o ybt-test.o: ybt.h ../include/db.h cachetable.o: cachetable.h hashfun.h memory.h brt-test: ybt.o brt.o fifo.o pma.o memory.o brt-serialize.o cachetable.o ybt.o key.o primes.o toku_assert.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o log.o: log_header.h log-internal.h log.h wbuf.h crc.h brttypes.h $(BRT_INTERNAL_H_INCLUDES) +logformat: logformat.o toku_assert.o brt-test.o brt.o: brt.h ../include/db.h fifo.h pma.h brttypes.h cachetable.h memory.h brt-serialize-test.o: $(BRT_INTERNAL_H_INCLUDES) brt.o: $(BRT_INTERNAL_H_INCLUDES) key.h log_header.h fifo.o: fifo.h brttypes.h memory.o: memory.h primes.o: primes.h toku_assert.h -fifo-test: fifo.o memory.o +fifo-test: fifo.o memory.o toku_assert.o brt-serialize.o: $(BRT_INTERNAL_H_INCLUDES) key.h wbuf.h rbuf.h brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o fifo.o brt-serialize.o brt-bigtest.o: brt.h ../include/db.h @@ -152,7 +154,7 @@ fingerprint.o: $(BRT_INTERNAL_H_INCLUDES) toku_assert.o: toku_assert.h brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o fifo.o pma.o key.o ybt.o brt.o cachetable.o primes.o toku_assert.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o -test_toku_malloc_plain_free: memory.o +test_toku_malloc_plain_free: memory.o toku_assert.o cachetable-test.o: cachetable.h memory.h @@ -170,6 +172,9 @@ test-assert: test-assert.o toku_assert.o brtdump: brtdump.o brt-serialize.o memory.o pma.o key.o fingerprint.o log.o log_code.o roll.o cachetable.o primes.o toku_assert.o brt.o ybt.o fifo.o mempool.o brt-verify.o +test_oexcl: test_oexcl.o toku_assert.o + + checko2: ifeq ($(OPTFLAGS),-O2) @echo OPTFLAGS=$(OPTFLAGS) ok @@ -182,6 +187,7 @@ clean: rm -rf test_oexcl.c.tmp *.brt randdb4: LOADLIBES=-ldb +randdb4: randdb4.o toku_assert.o randbrt: brt.o fifo.o cachetable.o memory.o brt-serialize.o # After doing (cd ../src/tests;make test_log5.recover), run these. The files should have no differences. diff --git a/newbrt/benchmark-test.c b/newbrt/benchmark-test.c index 71dde55a5d4..147a1b7b99c 100644 --- a/newbrt/benchmark-test.c +++ b/newbrt/benchmark-test.c @@ -5,7 +5,7 @@ #include "brt.h" #include "key.h" #include "memory.h" -#include +#include "toku_assert.h" #include #include #include diff --git a/newbrt/brt-serialize-test.c b/newbrt/brt-serialize-test.c index d4d55f4b22e..590f5300cf7 100644 --- a/newbrt/brt-serialize-test.c +++ b/newbrt/brt-serialize-test.c @@ -1,10 +1,10 @@ /* -*- mode: C; c-basic-offset: 4 -*- */ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." +#include "assert.h" #include "brt-internal.h" #include -#include #include #include #include diff --git a/newbrt/brt-serialize.c b/newbrt/brt-serialize.c index 9f3416eb9f2..f7e6b519810 100644 --- a/newbrt/brt-serialize.c +++ b/newbrt/brt-serialize.c @@ -4,12 +4,12 @@ #define _XOPEN_SOURCE 500 //#include "pma.h" +#include "toku_assert.h" #include "brt-internal.h" #include "key.h" #include "rbuf.h" #include "wbuf.h" -#include #include #include #include diff --git a/newbrt/brt-test.c b/newbrt/brt-test.c index f30701cad80..5b5bfc15531 100644 --- a/newbrt/brt-test.c +++ b/newbrt/brt-test.c @@ -5,9 +5,9 @@ #include "key.h" #include "pma.h" #include "brt-internal.h" - #include "memory.h" -#include +#include "toku_assert.h" + #include #include #include diff --git a/newbrt/brt-verify.c b/newbrt/brt-verify.c index c5f0e7b21bf..8bfcde8a1e1 100644 --- a/newbrt/brt-verify.c +++ b/newbrt/brt-verify.c @@ -16,8 +16,7 @@ */ #include "brt-internal.h" - -#include +#include "toku_assert.h" static void verify_local_fingerprint (BRTNODE node) { u_int32_t fp=0; diff --git a/newbrt/brt.c b/newbrt/brt.c index 139b386154f..fdc914f1133 100644 --- a/newbrt/brt.c +++ b/newbrt/brt.c @@ -25,7 +25,6 @@ */ #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include +#include "toku_assert.h" #include "brt-internal.h" #include "key.h" #include "log_header.h" diff --git a/newbrt/brtdump.c b/newbrt/brtdump.c index 1826591e342..63cba95aff3 100644 --- a/newbrt/brtdump.c +++ b/newbrt/brtdump.c @@ -1,8 +1,9 @@ /* Tell me the diff between two brt files. */ -#include #include #include #include + +#include "toku_assert.h" #include "key.h" #include "brt-internal.h" diff --git a/newbrt/cachetable-test.c b/newbrt/cachetable-test.c index 46f8a29459d..3b8e5767238 100644 --- a/newbrt/cachetable-test.c +++ b/newbrt/cachetable-test.c @@ -1,13 +1,13 @@ /* -*- mode: C; c-basic-offset: 4 -*- */ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." -#include #include #include #include #include #include +#include "toku_assert.h" #include "memory.h" #include "cachetable.h" #include "test.h" diff --git a/newbrt/cachetable-test2.c b/newbrt/cachetable-test2.c index beae00d053d..29c08d424b2 100644 --- a/newbrt/cachetable-test2.c +++ b/newbrt/cachetable-test2.c @@ -3,8 +3,8 @@ #include "memory.h" #include "cachetable.h" +#include "toku_assert.h" -#include #include #include #include diff --git a/newbrt/cachetable.c b/newbrt/cachetable.c index 5e67ebbccfa..5bbea42bbf3 100644 --- a/newbrt/cachetable.c +++ b/newbrt/cachetable.c @@ -2,16 +2,17 @@ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #include "cachetable.h" -#include "memory.h" -#include "yerror.h" -#include -#include -#include -#include -#include -#include #include "hashfun.h" +#include "memory.h" #include "primes.h" +#include "toku_assert.h" +#include "yerror.h" + +#include +#include +#include +#include +#include //#define TRACE_CACHETABLE #ifdef TRACE_CACHETABLE diff --git a/newbrt/fifo-test.c b/newbrt/fifo-test.c index c3356065570..b5d8820df9d 100644 --- a/newbrt/fifo-test.c +++ b/newbrt/fifo-test.c @@ -1,9 +1,9 @@ +#include "fifo.h" +#include "memory.h" +#include "toku_assert.h" #include #include #include -#include -#include "memory.h" -#include "fifo.h" int verbose; diff --git a/newbrt/fifo.c b/newbrt/fifo.c index a2c15b1c80b..c30b8004333 100644 --- a/newbrt/fifo.c +++ b/newbrt/fifo.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include "toku_assert.h" #include "memory.h" #include "fifo.h" diff --git a/newbrt/fingerprint.c b/newbrt/fingerprint.c index a7e90cd4dcd..bb70bd9a3b8 100644 --- a/newbrt/fingerprint.c +++ b/newbrt/fingerprint.c @@ -2,8 +2,8 @@ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #include -#include #include "brt-internal.h" +#include "toku_assert.h" // Calculate the fingerprint for a kvpair static inline u_int32_t toku_calc_more_crc32_kvpair (u_int32_t crc, const void *key, int keylen, const void *val, int vallen) { @@ -35,6 +35,8 @@ u_int32_t toku_calccrc32_cmd (int type, TXNID xid, const void *key, int keylen, u_int32_t toku_calccrc32_cmdstruct (BRT_CMD cmd) { if (cmd->type <= BRT_DELETE_BOTH) return toku_calccrc32_cmd (cmd->type, cmd->xid, cmd->u.id.key->data, cmd->u.id.key->size, cmd->u.id.val->data, cmd->u.id.val->size); - else + else { assert(0); /* Should not have come here. */ + return 0; + } } diff --git a/newbrt/key.c b/newbrt/key.c index a8fc69d23b2..2eb67bbbaa8 100644 --- a/newbrt/key.c +++ b/newbrt/key.c @@ -2,7 +2,7 @@ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #include "brt-internal.h" -#include +#include "toku_assert.h" #include #if 0 @@ -108,4 +108,5 @@ int toku_default_compare_fun (DB *db __attribute__((__unused__)), const DBT *a, int toku_dont_call_this_compare_fun (DB *db __attribute__((__unused__)), const DBT *a __attribute__((__unused__)), const DBT*b __attribute__((__unused__))) { assert(0); + return 0; } diff --git a/newbrt/list-test.c b/newbrt/list-test.c index a2deb9aa0d0..0e80461ac4a 100644 --- a/newbrt/list-test.c +++ b/newbrt/list-test.c @@ -1,8 +1,8 @@ +#include "list.h" +#include "toku_assert.h" +#include #include #include -#include -#include -#include "list.h" struct testlist { struct list next; diff --git a/newbrt/log-internal.h b/newbrt/log-internal.h index 54d3f0ce094..fc5deaaa4da 100644 --- a/newbrt/log-internal.h +++ b/newbrt/log-internal.h @@ -1,12 +1,11 @@ #ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." -#include +#include "log.h" +#include "toku_assert.h" +#include "yerror.h" #include #include -#include "yerror.h" -#include "log.h" - #define LOGGER_BUF_SIZE (1<<24) struct tokulogger { int is_open; diff --git a/newbrt/log-test.c b/newbrt/log-test.c index f5c91d9e162..91585818852 100644 --- a/newbrt/log-test.c +++ b/newbrt/log-test.c @@ -2,11 +2,11 @@ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #include "log-internal.h" +#include "toku_assert.h" +#include +#include #include #include -#include -#include -#include #include #define dname "log-test-dir" diff --git a/newbrt/logformat.c b/newbrt/logformat.c index 3354508c7e4..178cdc2ed41 100644 --- a/newbrt/logformat.c +++ b/newbrt/logformat.c @@ -9,7 +9,7 @@ * The struct definitions. * The Latex documentation. */ -#include +#include "toku_assert.h" #include #include #include diff --git a/newbrt/memory.c b/newbrt/memory.c index d8933001582..c24a8ecdf10 100644 --- a/newbrt/memory.c +++ b/newbrt/memory.c @@ -2,7 +2,7 @@ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #include "memory.h" -#include +#include "toku_assert.h" #include #include #include diff --git a/newbrt/mempool.c b/newbrt/mempool.c index 6430d83f0fe..3bc6483af76 100644 --- a/newbrt/mempool.c +++ b/newbrt/mempool.c @@ -1,9 +1,9 @@ /* -*- mode: C; c-basic-offset: 4 -*- */ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." -#include -#include #include "mempool.h" +#include "toku_assert.h" +#include void toku_mempool_init(struct mempool *mp, void *base, int size) { // printf("mempool_init %p %p %d\n", mp, base, size); diff --git a/newbrt/memtest.c b/newbrt/memtest.c index aff05269e73..2cd28e1c0bb 100644 --- a/newbrt/memtest.c +++ b/newbrt/memtest.c @@ -3,7 +3,7 @@ #include #include -#include +#include "toku_assert.h" #include "memory.h" #include "mempool.h" diff --git a/newbrt/myassert.c b/newbrt/myassert.c deleted file mode 100644 index e9fde703c45..00000000000 --- a/newbrt/myassert.c +++ /dev/null @@ -1,12 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4 -*- */ -#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." - -#include "myassert.h" -#include -#include - -#ifdef TESTER -void my_assert(int a, const char *f, int l) { - if (!a) { fprintf(stderr, "Assertion failed at %s:%d\n", f, l); abort(); } -} -#endif diff --git a/newbrt/myassert.h b/newbrt/myassert.h deleted file mode 100644 index 685734e17aa..00000000000 --- a/newbrt/myassert.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef MYASSERT_H -#define MYASSERT_H - -#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." - -#ifndef TESTER -#include -#else -extern void my_assert(int, const char *, int); -#define assert(x) my_assert(x, __FILE__, __LINE__) -#endif - -#endif diff --git a/newbrt/pma-test.c b/newbrt/pma-test.c index 91ab97c70d0..75f98deed1c 100644 --- a/newbrt/pma-test.c +++ b/newbrt/pma-test.c @@ -3,15 +3,15 @@ #include "brt-internal.h" #include "key.h" -#include -#include -#include -#include -#include +#include "kv-pair.h" #include "list.h" #include "pma-internal.h" -#include "kv-pair.h" #include "test.h" +#include "toku_assert.h" +#include +#include +#include +#include /* we use pma cursors for testing the pma_search function. otherwise, there are no pma cursors */ #include "pma-cursor.h" diff --git a/newbrt/pma.c b/newbrt/pma.c index c03879c1b3b..bc27dd07b3f 100644 --- a/newbrt/pma.c +++ b/newbrt/pma.c @@ -8,7 +8,7 @@ #include "key.h" #include "memory.h" -#include "myassert.h" +#include "toku_assert.h" #include "../include/db.h" #include #include diff --git a/newbrt/primes.c b/newbrt/primes.c index 7acffc7b172..0ed65c2ffb0 100644 --- a/newbrt/primes.c +++ b/newbrt/primes.c @@ -26,16 +26,16 @@ int toku_get_prime (unsigned int idx) { primes[i]=j; } } - toku_assert(idx +#include "toku_assert.h" #include #include #include diff --git a/newbrt/recover.c b/newbrt/recover.c index b344d391896..41060572bd0 100644 --- a/newbrt/recover.c +++ b/newbrt/recover.c @@ -7,15 +7,14 @@ // cd ../src/tests/tmpdir // ../../../newbrt/recover ../dir.test_log2.c.tdb -#include -#include -#include -#include - -#include "log_header.h" -#include "log-internal.h" #include "cachetable.h" #include "key.h" +#include "log-internal.h" +#include "log_header.h" +#include "toku_assert.h" +#include +#include +#include int main (int argc, char *argv[]) { const char *dir; diff --git a/newbrt/tdb_logprint.c b/newbrt/tdb_logprint.c index 6250c8101e8..35b8089e85a 100644 --- a/newbrt/tdb_logprint.c +++ b/newbrt/tdb_logprint.c @@ -2,8 +2,11 @@ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." /* Dump the log from stdin to stdout. */ +#include "brttypes.h" +#include "log-internal.h" +#include "log_header.h" +#include "toku_assert.h" #include -#include #include #include #include @@ -11,10 +14,6 @@ #include #include -#include "brttypes.h" -#include "log-internal.h" -#include "log_header.h" - #if 0 static u_int32_t crc=0; static u_int32_t actual_len=0; diff --git a/newbrt/test-assert.c b/newbrt/test-assert.c index 9ce51ab78ef..e05a119202b 100644 --- a/newbrt/test-assert.c +++ b/newbrt/test-assert.c @@ -1,11 +1,18 @@ +/* -*- mode: C; c-basic-offset: 4 -*- */ #include "toku_assert.h" +#include #include #include #include +static void catch_abort (int sig __attribute__((__unused__))) { + exit(1); +} + int main (int argc, const char *argv[]) { + signal (SIGABRT, catch_abort); if (argc!=2) { printf("argcount should be 2.\n"); exit(1); } const char *str=argv[1]; - toku_assert(strcmp(str,"ok")==0); + assert(strcmp(str,"ok")==0); return 0; } diff --git a/newbrt/test_oexcl.c b/newbrt/test_oexcl.c index c68b5ca2429..5500c161f7b 100644 --- a/newbrt/test_oexcl.c +++ b/newbrt/test_oexcl.c @@ -1,7 +1,7 @@ /* -*- mode: C; c-basic-offset: 4 -*- */ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." -#include +#include "toku_assert.h" #include #include #include diff --git a/newbrt/toku_assert.c b/newbrt/toku_assert.c index 517b4b767c6..97424471407 100644 --- a/newbrt/toku_assert.c +++ b/newbrt/toku_assert.c @@ -2,7 +2,7 @@ #include #include -void toku_do_assert(int expr,const char* expr_as_string,const char *function,const char*file,int line) { +void toku_do_assert(long expr,const char* expr_as_string,const char *function,const char*file,int line) { if (expr==0) { fprintf(stderr, "%s:%d %s: Assertion `%s' failed\n", file,line,function,expr_as_string); abort(); diff --git a/newbrt/toku_assert.h b/newbrt/toku_assert.h index 09ac0281844..1fe75e46817 100644 --- a/newbrt/toku_assert.h +++ b/newbrt/toku_assert.h @@ -1,3 +1,5 @@ +#ifndef TOKU_ASSERT_H +#define TOKU_ASSERT_H /* The problem with assert.h: If NDEBUG is set then it doesn't execute the function, if NDEBUG isn't set then we get a branch that isn't taken. */ /* This version will complain if NDEBUG is set. */ /* It evaluates the argument and then calls a function toku_do_assert() which takes all the hits for the branches not taken. */ @@ -6,13 +8,11 @@ #error NDEBUG should not be set #endif -void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/); +void toku_do_assert(long,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/); #ifndef FAST_ASSERT -#define toku_assert(expr) toku_do_assert(expr, #expr, __FUNCTION__, __FILE__, __LINE__) +#define assert(expr) toku_do_assert((long)(expr), #expr, __FUNCTION__, __FILE__, __LINE__) #else -#define toku_assert(expr) ({ int __assert_expr = expr; if (__assert_expr==0) toku_do_assert(0, #expr, __FUNCTION__, __FILE__, __LINE__); }) +#define assert(expr) ({ long __assert_expr = (int)(expr); if (__assert_expr==0) toku_do_assert(0, #expr, __FUNCTION__, __FILE__, __LINE__); }) +#endif #endif - -void dontuseassert (int) __attribute__((deprecated)); -#define assert(barf) dontuseassert(barf) diff --git a/newbrt/wbuf.h b/newbrt/wbuf.h index 4e7dd69e307..06406b73c64 100644 --- a/newbrt/wbuf.h +++ b/newbrt/wbuf.h @@ -3,10 +3,10 @@ #ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." -#include -#include -#include #include "memory.h" +#include "toku_assert.h" +#include +#include //#define CRC_NO #define CRC_INCR diff --git a/newbrt/ybt-test.c b/newbrt/ybt-test.c index ee5116085a4..c6c73b54579 100644 --- a/newbrt/ybt-test.c +++ b/newbrt/ybt-test.c @@ -5,7 +5,7 @@ #include "ybt.h" #include "memory.h" -#include +#include "toku_assert.h" #include static void ybt_test0 (void) {