From db2039c0db5b714256e2cf86379d42c7f17d64f0 Mon Sep 17 00:00:00 2001 From: "Bradley C. Kuszmaul" Date: Tue, 16 Apr 2013 23:57:34 -0400 Subject: [PATCH] Compile better on linux, and more dlmalloc fixing. Addresses #1343. git-svn-id: file:///svn/toku/tokudb.1032b+1343@8553 c7de825b-a66e-492c-adef-691d508d4ae1 --- Makefile | 3 +- db-benchmark-test-cxx/Makefile | 17 ++++++++-- include/memory.h | 5 +-- include/toku_portability.h | 6 ++-- linux/Makefile | 3 +- linux/memory.c | 6 ++++ src/tests/test_db_cursor.c | 1 - src/tests/test_db_dbt_appmalloc.c | 1 - src/tests/test_db_remove.c | 34 +++++++++++++++++++ .../test_db_txn_locks_read_uncommitted.c | 6 ++-- 10 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 src/tests/test_db_remove.c diff --git a/Makefile b/Makefile index 14628951596..1b7dac22467 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,7 @@ summarize: check check: $(CHECKS) -clean: - $(MAYBEATSIGN)for d in $(SRCDIRS); do (cd $$d && $(MAKE) -k clean); done +clean: $(patsubst %,%.dir.clean,$(SRCDIRS)) $(MAYBEATSIGN)rm -rf lib/*.$(SOEXT) lib/*.$(AEXT) install: diff --git a/db-benchmark-test-cxx/Makefile b/db-benchmark-test-cxx/Makefile index 7d16a25d1e0..9e89bd8081b 100644 --- a/db-benchmark-test-cxx/Makefile +++ b/db-benchmark-test-cxx/Makefile @@ -1,8 +1,21 @@ +# -*- Mode: Makefile -*- #ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." # standard build: make # build with Berkeley DB 4.1: make BDBDIR=/usr/local/BerkeleyDB.4.1 # build with TokuDB: make BDBDIR=~/svn/tokudb +# build with g++: make CC=g++ + +.DEFAULT_GOAL= build +TOKUROOT=../ +INCLUDEDIRS=-I. -I../ -I$(TOKUROOT)newbrt -I../range_tree -I../lock_tree +DEPEND_COMPILE += \ + ./*.h \ +#end + +SKIP_NORETURN=1 #Do not add the -Wmissing-noreturn flag +HERE = db-benchmark-test-cxx +include $(TOKUROOT)include/Makefile.include BENCHDBS = bench.bdb/ bench.tokudb @@ -11,7 +24,7 @@ CXXFLAGS = -Wall -Werror -g $(OPTFLAGS) $(GCOV_FLAGS) # CFLAGS += -pg ifdef BDBDIR -BDB_CPPFLAGS = -I$(BDBDIR)/include +BDB_CPPFLAGS = -I$(BDBDIR)/include -DHAVE_CXX_STDHEADERS BDB_LDFLAGS = -L$(BDBDIR)/lib -ldb_cxx -Wl,-rpath,$(BDBDIR)/lib -lpthread else BDB_CPPFLAGS = @@ -43,7 +56,7 @@ check-x: $(TARGET_TDB) $(VALGRIND) ./$(TARGET_TDB) -x $(QUIET) $(SUMMARIZE_CMD) clean: - rm -rf $(TARGETS) $(BENCHDBS) *.gcno *.gcda *.gcov + $(MAYBEATSIGN)rm -rf $(TARGETS) $(BENCHDBS) *.gcno *.gcda *.gcov db-benchmark-test-tokudb: ../lib/libtokudb_cxx.a db-benchmark-test-tokudb: db-benchmark-test.cpp diff --git a/include/memory.h b/include/memory.h index 0c76b021624..e079b218241 100644 --- a/include/memory.h +++ b/include/memory.h @@ -29,6 +29,7 @@ void *toku_malloc(size_t size) __attribute__((__visibility__("default"))); // xmalloc aborts instead of return NULL if we run out of memory void *toku_xmalloc(size_t size); +void *toku_xrealloc(void*, size_t size); /* toku_tagmalloc() performs a malloc(size), but fills in the first 4 bytes with typ. * This "tag" is useful if you are debugging and run across a void* that is @@ -63,8 +64,8 @@ void *toku_realloc(void *, size_t size) __attribute__((__visibility__("default" // XMALLOC macros are like MALLOC except they abort if the operation fails #define XMALLOC(v) v = toku_xmalloc(sizeof(*v)) -#define XMALLOC_N(n,v) v = toku_malloc((n)*sizeof(*v)) -#define XREALLOC_N(n,v) v = toku_realloc(v, (n)*sizeof(*v)) +#define XMALLOC_N(n,v) v = toku_xmalloc((n)*sizeof(*v)) +#define XREALLOC_N(n,v) v = toku_xrealloc(v, (n)*sizeof(*v)) /* If you have a type such as * struct pma *PMA; diff --git a/include/toku_portability.h b/include/toku_portability.h index 562ea649152..21021f1ad23 100644 --- a/include/toku_portability.h +++ b/include/toku_portability.h @@ -72,7 +72,7 @@ extern "C" { // Deprecated functions. #if !defined(TOKU_ALLOW_DEPRECATED) # if defined(__ICL) //Windows Intel Compiler -# pragma deprecated (fstat, getpid, syscall, sysconf, mkdir, strdup); +# pragma deprecated (fstat, getpid, syscall, sysconf, mkdir, strdup) # ifndef DONT_DEPRECATE_MALLOC # pragma deprecated (malloc, free, realloc) # endif @@ -88,11 +88,11 @@ int mkdir() __attribute__((__deprecated__)); char* strdup(const char *) __attribute__((__deprecated__)); #undef __strdup char* __strdup(const char *) __attribute__((__deprecated__)); -#ifndef DONT_DEPRECATE_MALLOC +# ifndef DONT_DEPRECATE_MALLOC void *malloc(size_t) __attribute__((__deprecated__)); void free(void*) __attribute__((__deprecated__)); void *realloc(void*, size_t) __attribute__((__deprecated__)); -#endif +# endif # endif #endif diff --git a/linux/Makefile b/linux/Makefile index 749dcf5cf44..dcf7b010a77 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -21,4 +21,5 @@ $(TARGET): $(OBJS) clean: $(MAYBEATSIGN)rm -rf $(TARGET) $(LIBPORTABILITY) -build: $(OBJS) +# For build, do nothing +build: diff --git a/linux/memory.c b/linux/memory.c index 33be4713dd7..1bb788fcf0d 100644 --- a/linux/memory.c +++ b/linux/memory.c @@ -44,6 +44,12 @@ void *toku_xmalloc(size_t size) { return r; } +void *toku_xrealloc(void *v, size_t size) { + void *r = toku_realloc(v, size); + if (r==0) abort(); + return r; +} + void *toku_tagmalloc(size_t size, enum typ_tag typtag) { //printf("%s:%d tagmalloc\n", __FILE__, __LINE__); void *r = toku_malloc(size); diff --git a/src/tests/test_db_cursor.c b/src/tests/test_db_cursor.c index da28450bff8..42d1801aa5d 100644 --- a/src/tests/test_db_cursor.c +++ b/src/tests/test_db_cursor.c @@ -369,4 +369,3 @@ test_main (int argc, const char *argv[]) { return 0; } - diff --git a/src/tests/test_db_dbt_appmalloc.c b/src/tests/test_db_dbt_appmalloc.c index 6afa801ac3f..939698bb3da 100644 --- a/src/tests/test_db_dbt_appmalloc.c +++ b/src/tests/test_db_dbt_appmalloc.c @@ -163,4 +163,3 @@ test_main(int argc, const char *argv[]) { lastmalloced = NULL; return 0; } - diff --git a/src/tests/test_db_remove.c b/src/tests/test_db_remove.c new file mode 100644 index 00000000000..5e3377410ee --- /dev/null +++ b/src/tests/test_db_remove.c @@ -0,0 +1,34 @@ +#include +#include +#include "test.h" + +DB_ENV * const null_env = 0; +DB *db1, *db2; +DB_TXN * const null_txn = 0; + +const char * const fname = ENVDIR "/" "test_db_remove.brt"; + +void test_db_remove (void) { + int r; + system("rm -rf " ENVDIR); + r=toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); assert(r==0); + + // create the DB + r = db_create(&db1, null_env, 0); assert(r == 0); + r = db1->open(db1, null_txn, fname, 0, DB_BTREE, DB_CREATE, 0666); assert(r == 0); + + // Now remove it. + r = db_create(&db2, null_env, 0); assert(r==0); + r = db2->remove(db2, fname, 0, 0); assert(r==0); + + r = db1->close(db1, 0); assert(r==0); +} + +int +test_main(int argc, const char *argv[]) { + parse_args(argc, argv); + + test_db_remove(); + + return 0; +} diff --git a/src/tests/test_db_txn_locks_read_uncommitted.c b/src/tests/test_db_txn_locks_read_uncommitted.c index 2a2f55f6fee..32df1c178ac 100644 --- a/src/tests/test_db_txn_locks_read_uncommitted.c +++ b/src/tests/test_db_txn_locks_read_uncommitted.c @@ -167,6 +167,8 @@ table_prelock(char txn, BOOL success) { int r; #if defined USE_TDB && USE_TDB r = db->pre_acquire_table_lock(db, txns[(int)txn]); + if (success) CKERR(r); + else CKERR2s(r, DB_LOCK_NOTGRANTED, DB_LOCK_DEADLOCK); #else DBT key; DBT data; @@ -182,9 +184,9 @@ table_prelock(char txn, BOOL success) { dbt_init(&data, 0, 0), DB_NEXT | DB_RMW); } -#endif - if (success) CKERR(r); + if (success) CKERR2(r, DB_NOTFOUND); else CKERR2s(r, DB_LOCK_NOTGRANTED, DB_LOCK_DEADLOCK); +#endif } static void