From 312a3722a7e3774489f2b303b03e3c0d882dcc59 Mon Sep 17 00:00:00 2001 From: David Hows Date: Tue, 12 Jan 2016 15:52:10 +1100 Subject: WT-2326 - Add dcalloc, dmalloc and dstrdup to wtperf and replace all existing malloc, calloc and strncpy calls --- bench/wtperf/wtperf.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'bench/wtperf/wtperf.h') diff --git a/bench/wtperf/wtperf.h b/bench/wtperf/wtperf.h index 8a9be7a0938..9351ca0285e 100644 --- a/bench/wtperf/wtperf.h +++ b/bench/wtperf/wtperf.h @@ -289,7 +289,6 @@ void latency_insert(CONFIG *, uint32_t *, uint32_t *, uint32_t *); void latency_read(CONFIG *, uint32_t *, uint32_t *, uint32_t *); void latency_update(CONFIG *, uint32_t *, uint32_t *, uint32_t *); void latency_print(CONFIG *); -int enomem(const CONFIG *); int run_truncate( CONFIG *, CONFIG_THREAD *, WT_CURSOR *, WT_SESSION *, int *); int setup_log_file(CONFIG *); @@ -323,4 +322,55 @@ extract_key(char *key_buf, uint64_t *keynop) sscanf(key_buf, "%" SCNu64, keynop); } +/* + * die -- + * Print message and exit on failure. + */ +static inline void +die(int e, const char *str) +{ + fprintf(stderr, "Call to %s failed: %s", str, wiredtiger_strerror(e)); + exit(EXIT_FAILURE); +} + +/* + * dmalloc -- + * Call malloc, dying on failure. + */ +static inline void * +dmalloc(size_t len) +{ + void *p; + + if ((p = malloc(len)) == NULL) + die(errno, "malloc"); + return (p); +} + +/* + * dstrdup -- + * Call strdup, dying on failure. + */ +static inline char * +dstrdup(const char *str) +{ + char *p; + + if ((p = strdup(str)) == NULL) + die(errno, "strdup"); + return (p); +} +/* + * dcalloc -- + * Call calloc, dying on failure. + */ +static inline void * +dcalloc(size_t num, size_t len) +{ + void *p; + + if ((p = calloc(len, num)) == NULL) + die(errno, "calloc"); + return (p); +} #endif -- cgit v1.2.1