Commit 53cf41ec authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

dlmalloc now works on Linux. Addresses #1032, #1328, #1343.

git-svn-id: file:///svn/toku/tokudb.1032b+1343@8477 c7de825b-a66e-492c-adef-691d508d4ae1
parent f0932b7a
...@@ -42,7 +42,6 @@ BRT_SOURCES = \ ...@@ -42,7 +42,6 @@ BRT_SOURCES = \
brt \ brt \
brt-test-helpers \ brt-test-helpers \
cachetable \ cachetable \
dlmalloc \
fifo \ fifo \
fingerprint \ fingerprint \
key \ key \
......
...@@ -28,6 +28,7 @@ OBJS_RAW = \ ...@@ -28,6 +28,7 @@ OBJS_RAW = \
ydb_lib \ ydb_lib \
ydb \ ydb \
errors \ errors \
dlmalloc \
elocks \ elocks \
#\end #\end
#OBJS automatically defined. #OBJS automatically defined.
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
/* Test to see if setting malloc works, and if dlmalloc works. */
#define DONT_DEPRECATE_MALLOC
#include <valgrind/memcheck.h>
#include <toku_portability.h>
#include <memory.h>
#include <db.h>
#include <dlmalloc.h>
#include "test.h"
static int malloc_counter=0;
static int realloc_counter=0;
static int free_counter=0;
static void *
bmalloc (size_t s)
{
malloc_counter++;
return malloc(s);
}
static void
bfree (void*p)
{
free_counter++;
free(p);
}
static void*
brealloc (void*p, size_t s)
{
realloc_counter++;
return realloc(p,s);
}
void
test1 (void)
{
DB_ENV *env=0;
int r;
r = db_env_create(&env, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
assert(malloc_counter==0);
assert(free_counter==0);
assert(realloc_counter==0);
r = db_env_set_func_malloc(bmalloc); assert(r==0);
r = db_env_create(&env, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
assert(malloc_counter>0);
assert(free_counter==0);
assert(realloc_counter==0);
malloc_counter = realloc_counter = free_counter = 0;
r = db_env_set_func_free(bfree); assert(r==0);
r = db_env_set_func_malloc(NULL); assert(r==0);
r = db_env_create(&env, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
assert(malloc_counter==0);
assert(free_counter>=0);
assert(realloc_counter==0);
r = db_env_set_func_malloc(bmalloc); assert(r==0);
r = db_env_set_func_realloc(brealloc); assert(r==0);
r = db_env_set_func_free(bfree); assert(r==0);
malloc_counter = realloc_counter = free_counter = 0;
{
void *x = toku_malloc(5); assert(x); assert(malloc_counter==1 && free_counter==0 && realloc_counter==0);
x = toku_realloc(x, 6); assert(x); assert(malloc_counter==1 && free_counter==0 && realloc_counter==1);
toku_free(x); assert(malloc_counter==1 && free_counter==1 && realloc_counter==1);
}
r = db_env_set_func_malloc(dlmalloc); assert(r==0);
r = db_env_set_func_realloc(dlrealloc); assert(r==0);
r = db_env_set_func_free(dlfree); assert(r==0);
{
char *x = toku_malloc(5); assert(x);
x = toku_realloc(x, 6); assert(x);
toku_free(x);
}
}
int
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__)))
{
test1();
return 0;
}
...@@ -27,6 +27,7 @@ const char *toku_copyright_string = "Copyright (c) 2007, 2008 Tokutek Inc. All ...@@ -27,6 +27,7 @@ const char *toku_copyright_string = "Copyright (c) 2007, 2008 Tokutek Inc. All
#include "cachetable.h" #include "cachetable.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "memory.h"
#include "dlmalloc.h"
#ifdef TOKUTRACE #ifdef TOKUTRACE
#define DB_ENV_CREATE_FUN db_env_create_toku10 #define DB_ENV_CREATE_FUN db_env_create_toku10
...@@ -3664,3 +3665,9 @@ int db_env_set_func_realloc (void *(*f)(void*, size_t)) { ...@@ -3664,3 +3665,9 @@ int db_env_set_func_realloc (void *(*f)(void*, size_t)) {
int db_env_set_func_free (void (*f)(void*)) { int db_env_set_func_free (void (*f)(void*)) {
return toku_set_func_free(f); return toku_set_func_free(f);
} }
// Got to call dlmalloc, or else it won't get included.
void setup_dlmalloc (void) {
db_env_set_func_malloc(dlmalloc);
db_env_set_func_realloc(dlrealloc);
db_env_set_func_free(dlfree);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment