Commit 316c7f11 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Add {{{db_env_set_func_malloc}}}, {{{db_env_set_func_realloc}}}, and...

Add {{{db_env_set_func_malloc}}}, {{{db_env_set_func_realloc}}}, and {{{db_env_set_func_free}}}.  Addresses #1343, #1032, #1328.  Tests don't pass

git-svn-id: file:///svn/toku/tokudb.1032b+1343@8474 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8bb6a173
......@@ -284,6 +284,9 @@ int log_compare (const DB_LSN*, const DB_LSN *) __attribute__((__visibility__("d
int db_env_set_func_fsync (int (*)(int)) __attribute__((__visibility__("default")));
int toku_set_trace_file (char *fname) __attribute__((__visibility__("default")));
int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_free (void *(*)(void*)) __attribute__((__visibility__("default")));
#if defined(__cplusplus)
}
#endif
......
......@@ -300,6 +300,9 @@ int log_compare (const DB_LSN*, const DB_LSN *) __attribute__((__visibility__("d
int db_env_set_func_fsync (int (*)(int)) __attribute__((__visibility__("default")));
int toku_set_trace_file (char *fname) __attribute__((__visibility__("default")));
int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_free (void *(*)(void*)) __attribute__((__visibility__("default")));
#if defined(__cplusplus)
}
#endif
......
......@@ -306,6 +306,9 @@ int log_compare (const DB_LSN*, const DB_LSN *) __attribute__((__visibility__("d
int db_env_set_func_fsync (int (*)(int)) __attribute__((__visibility__("default")));
int toku_set_trace_file (char *fname) __attribute__((__visibility__("default")));
int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_free (void *(*)(void*)) __attribute__((__visibility__("default")));
#if defined(__cplusplus)
}
#endif
......
......@@ -306,6 +306,9 @@ int log_compare (const DB_LSN*, const DB_LSN *) __attribute__((__visibility__("d
int db_env_set_func_fsync (int (*)(int)) __attribute__((__visibility__("default")));
int toku_set_trace_file (char *fname) __attribute__((__visibility__("default")));
int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_free (void *(*)(void*)) __attribute__((__visibility__("default")));
#if defined(__cplusplus)
}
#endif
......
......@@ -11,9 +11,9 @@ extern "C" {
#define TOKUDB 1
#define DB_VERSION_MAJOR 4
#define DB_VERSION_MINOR 6
#define DB_VERSION_PATCH 19
#define DB_VERSION_PATCH 21
#ifndef _TOKUDB_WRAP_H
#define DB_VERSION_STRING "Tokutek: TokuDB 4.6.19"
#define DB_VERSION_STRING "Tokutek: TokuDB 4.6.21"
#else
#define DB_VERSION_STRING_ydb "Tokutek: TokuDB (wrapped bdb)"
#endif
......@@ -311,6 +311,9 @@ int log_compare (const DB_LSN*, const DB_LSN *) __attribute__((__visibility__("d
int db_env_set_func_fsync (int (*)(int)) __attribute__((__visibility__("default")));
int toku_set_trace_file (char *fname) __attribute__((__visibility__("default")));
int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_free (void *(*)(void*)) __attribute__((__visibility__("default")));
#if defined(__cplusplus)
}
#endif
......
......@@ -354,6 +354,9 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__un
printf("int db_env_set_func_fsync (int (*)(int)) %s;\n", VISIBLE);
printf("int toku_set_trace_file (char *fname) %s;\n", VISIBLE);
printf("int toku_close_trace_file (void) %s;\n", VISIBLE);
printf("int db_env_set_func_malloc (void *(*)(size_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_realloc (void *(*)(void*, size_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_free (void *(*)(void*)) %s;\n", VISIBLE);
printf("#if defined(__cplusplus)\n}\n#endif\n");
printf("#endif\n");
return 0;
......
......@@ -16,16 +16,28 @@ int toku_malloc_counter = 0;
int toku_realloc_counter = 0;
int toku_free_counter = 0;
void *toku_calloc(size_t nmemb, size_t size) {
toku_calloc_counter++;
return calloc(nmemb, size);
}
typedef void *(*malloc_fun_t)(size_t);
typedef void (*free_fun_t)(void*);
typedef void *(*realloc_fun_t)(void*,size_t);
static malloc_fun_t t_malloc = 0;
static free_fun_t t_free = 0;
static realloc_fun_t t_realloc = 0;
void *toku_malloc(size_t size) {
toku_malloc_counter++;
if (t_malloc)
return t_malloc(size);
else
return malloc(size);
}
void *toku_calloc(size_t nmemb, size_t size) {
toku_calloc_counter++;
return toku_malloc(nmemb*size);
}
void *toku_xmalloc(size_t size) {
void *r = toku_malloc(size);
if (r==0) abort();
......@@ -43,11 +55,17 @@ void *toku_tagmalloc(size_t size, enum typ_tag typtag) {
void *toku_realloc(void *p, size_t size) {
toku_realloc_counter++;
if (t_realloc)
return t_realloc(p, size);
else
return realloc(p, size);
}
void toku_free(void* p) {
toku_free_counter++;
if (t_free)
t_free(p);
else
free(p);
}
......@@ -77,3 +95,21 @@ void toku_malloc_report (void) {
void toku_malloc_cleanup (void) {
}
int
toku_set_func_malloc(malloc_fun_t f) {
t_malloc = f;
return 0;
}
int
toku_set_func_realloc(realloc_fun_t f) {
t_realloc = f;
return 0;
}
int
toku_set_func_free(free_fun_t f) {
t_free = f;
return 0;
}
......@@ -249,8 +249,6 @@ int toku_testsetup_get_sersize(BRT brt, BLOCKNUM); // Return the size on disk.
int toku_testsetup_insert_to_leaf (BRT brt, BLOCKNUM, char *key, int keylen, char *val, int vallen, u_int32_t *leaf_fingerprint);
int toku_testsetup_insert_to_nonleaf (BRT brt, BLOCKNUM, enum brt_cmd_type, char *key, int keylen, char *val, int vallen, u_int32_t *subtree_fingerprint);
int toku_set_func_fsync (int (*fsync_function)(int));
// These two go together to do lookups in a brtnode using the keys in a command.
struct cmd_leafval_heaviside_extra {
BRT t;
......
......@@ -121,4 +121,9 @@ void toku_pwrite_lock_destroy(void);
void maybe_preallocate_in_file (int fd, u_int64_t size);
// Effect: If file size is less than SIZE, make it bigger by either doubling it or growing by 16MB whichever is less.
int toku_set_func_fsync (int (*fsync_function)(int));
int toku_set_func_malloc (void *(*)(size_t));
int toku_set_func_realloc (void *(*)(void*,size_t));
int toku_set_func_free (void *(*)(void*));
#endif
......@@ -6,6 +6,8 @@
db_version;
log_compare;
db_env_set_func_fsync;
db_env_set_func_malloc;
db_env_set_func_free;
toku_get_maxrss;
......@@ -16,6 +18,7 @@
toku_add_trace_mem;
toku_print_trace_mem;
toku_free;
toku_malloc;
toku_os_get_file_size;
......
......@@ -3655,3 +3655,12 @@ int db_env_set_func_fsync (int (*fsync_function)(int)) {
return toku_set_func_fsync(fsync_function);
}
int db_env_set_func_malloc (void *(*f)(size_t)) {
return toku_set_func_malloc(f);
}
int db_env_set_func_realloc (void *(*f)(void*, size_t)) {
return toku_set_func_realloc(f);
}
int db_env_set_func_free (void *(*f)(void*)) {
return toku_set_func_free(f);
}
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