diff options
-rw-r--r-- | src/common.c | 36 | ||||
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/createfp.c | 13 | ||||
-rw-r--r-- | src/fingerprint.c | 10 | ||||
-rw-r--r-- | src/libtextcat.map | 1 | ||||
-rw-r--r-- | src/testtextcat.c | 6 | ||||
-rw-r--r-- | src/textcat.c | 41 | ||||
-rw-r--r-- | src/wg_mempool.c | 6 |
8 files changed, 22 insertions, 93 deletions
diff --git a/src/common.c b/src/common.c index edfe065..32396f5 100644 --- a/src/common.c +++ b/src/common.c @@ -57,23 +57,6 @@ extern void wgmem_error(const char *fmt, ...) va_end(ap); } -extern void *wg_malloc(size_t size) -{ - void *result; - if (!size) - { - wgmem_error("Error mallocing 0 bytes.\n"); - } - - result = malloc(size); - if (!result) - { - wgmem_error("Error while mallocing %u bytes.\n", size); - } - - return result; -} - extern void *wg_calloc(size_t nmemb, size_t size) { void *result; @@ -122,25 +105,6 @@ extern char *wg_strdup(const char *s) return (result); } -extern void *wg_realloc(void *ptr, size_t size) -{ - void *result; - - if (!size) - { - wgmem_error("Error reallocing 0 bytes.\n"); - } - - result = realloc(ptr, size); - - if (!result) - { - wgmem_error("Error while reallocing %u bytes.\n", size); - } - - return (result); -} - extern char *wg_getline(char *line, int size, FILE * fp) { char *p; diff --git a/src/common.h b/src/common.h index ad79bfb..7ad6bcc 100644 --- a/src/common.h +++ b/src/common.h @@ -69,11 +69,9 @@ extern "C" typedef int8_t boole; - extern void *wg_malloc(size_t size); extern void *wg_calloc(size_t nmemb, size_t size); extern void *wg_zalloc(size_t size); extern char *wg_strdup(const char *s); - extern void *wg_realloc(void *ptr, size_t size); extern char *wg_getline(char *line, int size, FILE * fp); diff --git a/src/createfp.c b/src/createfp.c index 78c669d..8b16a08 100644 --- a/src/createfp.c +++ b/src/createfp.c @@ -36,15 +36,8 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef HAVE_STRINGS_H -#include <strings.h> -#endif -#ifdef HAVE_STRING_H #include <string.h> -#endif -#ifdef HAVE_STDLIB_H #include <stdlib.h> -#endif #include "fingerprint.h" #include "common_impl.h" @@ -57,7 +50,7 @@ char *myread(FILE * fp) size_t size = 0; size_t maxsize = BLOCKSIZE * 2; - buf = (char *)wg_malloc(maxsize); + buf = (char *)malloc(maxsize); do { size_t hasread = fread(buf + size, 1, BLOCKSIZE, fp); @@ -65,14 +58,14 @@ char *myread(FILE * fp) if (size + BLOCKSIZE > maxsize) { maxsize *= 2; - buf = (char *)wg_realloc(buf, maxsize); + buf = (char *)realloc(buf, maxsize); } } while (!feof(stdin)); buf[size] = '\0'; - buf = (char *)wg_realloc(buf, size + 1); + buf = (char *)realloc(buf, size + 1); return buf; } diff --git a/src/fingerprint.c b/src/fingerprint.c index 9bea69a..4320d5b 100644 --- a/src/fingerprint.c +++ b/src/fingerprint.c @@ -349,7 +349,7 @@ static table_t *inittable(uint4 maxngrams) result->table = (entry_t **) wg_zalloc(sizeof(entry_t *) * TABLESIZE); result->pool = wgmempool_Init(10000, 10); - result->heap = (entry_t *) wg_malloc(sizeof(entry_t) * maxngrams); + result->heap = (entry_t *) malloc(sizeof(entry_t) * maxngrams); result->heapsize = maxngrams; result->size = 0; @@ -414,7 +414,7 @@ extern const char *fp_Name(void *handle) static char *prepbuffer(const char *src, size_t bufsize) { const char *p = src; - char *dest = (char *)wg_malloc(bufsize + 3); + char *dest = (char *)malloc(bufsize + 3); char *w = dest; char *wlimit = dest + bufsize + 1; @@ -617,7 +617,7 @@ extern int fp_Create(void *handle, const char *buffer, uint4 bufsize, table2heap(t); maxngrams = WGMIN(maxngrams, t->size); - h->fprint = (ngram_t *) wg_malloc(sizeof(ngram_t) * maxngrams); + h->fprint = (ngram_t *) malloc(sizeof(ngram_t) * maxngrams); h->size = maxngrams; /*** Pull n-grams out of heap (backwards) ***/ @@ -670,7 +670,7 @@ extern int fp_Read(void *handle, const char *fname, int maxngrams) return 0; } - h->fprint = (ngram_t *) wg_malloc(maxngrams * sizeof(ngram_t)); + h->fprint = (ngram_t *) malloc(maxngrams * sizeof(ngram_t)); while (cnt < maxngrams && wg_getline(line, 1024, fp)) { @@ -712,7 +712,7 @@ extern void fp_Print(void *handle, FILE * fp) { uint4 i; fp_t *h = (fp_t *) handle; - ngram_t *tmp = (ngram_t *) wg_malloc(sizeof(ngram_t) * h->size); + ngram_t *tmp = (ngram_t *) malloc(sizeof(ngram_t) * h->size); /*** Make a temporary and sort it on rank ***/ memcpy(tmp, h->fprint, h->size * sizeof(ngram_t)); diff --git a/src/libtextcat.map b/src/libtextcat.map index 02b1b04..dcf5e35 100644 --- a/src/libtextcat.map +++ b/src/libtextcat.map @@ -26,7 +26,6 @@ heapextract wg_calloc wg_getline - wg_malloc wg_split wg_strdup wg_strgmov diff --git a/src/testtextcat.c b/src/testtextcat.c index c753c40..a8b30ca 100644 --- a/src/testtextcat.c +++ b/src/testtextcat.c @@ -60,7 +60,7 @@ char *myread(FILE * fp) size_t size = 0; size_t maxsize = BLOCKSIZE * 2; - buf = (char *)wg_malloc(maxsize); + buf = (char *)malloc(maxsize); do { size_t hasread = fread(buf + size, 1, BLOCKSIZE, fp); @@ -68,14 +68,14 @@ char *myread(FILE * fp) if (size + BLOCKSIZE > maxsize) { maxsize *= 2; - buf = (char *)wg_realloc(buf, maxsize); + buf = (char *)realloc(buf, maxsize); } } while (!feof(stdin)); buf[size] = '\0'; - buf = (char *)wg_realloc(buf, size + 1); + buf = (char *)realloc(buf, size + 1); return buf; } diff --git a/src/textcat.c b/src/textcat.c index 216e4e4..180adf3 100644 --- a/src/textcat.c +++ b/src/textcat.c @@ -56,15 +56,7 @@ #endif #include <stdlib.h> -#ifdef HAVE_STRINGS_H -#include <strings.h> -#endif -#ifdef HAVE_STRING_H #include <string.h> -#endif -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif #include "common_impl.h" #include "fingerprint.h" @@ -140,18 +132,12 @@ extern void *special_textcat_Init(const char *conffile, const char *prefix) return NULL; } - h = (textcat_t *) wg_malloc(sizeof(textcat_t)); + h = (textcat_t *) malloc(sizeof(textcat_t)); h->size = 0; h->maxsize = 16; - h->fprint = (void **)wg_malloc(sizeof(void *) * h->maxsize); - h->fprint_disable = (unsigned char *)wg_malloc(sizeof(unsigned char) * h->maxsize); /* added - to - store - the - state - of - languages */ - + h->fprint = (void **)malloc(sizeof(void *) * h->maxsize); + h->fprint_disable = (unsigned char *)malloc(sizeof(unsigned char) * h->maxsize); + /* added to store the state of languages */ while (wg_getline(line, 1024, fp)) { char *p; @@ -174,9 +160,9 @@ extern void *special_textcat_Init(const char *conffile, const char *prefix) { h->maxsize *= 2; h->fprint = - (void **)wg_realloc(h->fprint, sizeof(void *) * h->maxsize); + (void **)realloc(h->fprint, sizeof(void *) * h->maxsize); h->fprint_disable = - (unsigned char *)wg_realloc(h->fprint_disable, + (unsigned char *)realloc(h->fprint_disable, sizeof(unsigned char) * h->maxsize); } @@ -215,25 +201,17 @@ extern void *special_textcat_Init(const char *conffile, const char *prefix) } - extern char *textcat_Classify(void *handle, const char *buffer, size_t size) { textcat_t *h = (textcat_t *) handle; int minscore = MAXSCORE; int threshold = minscore; char *result = h->output; + void *unknown; uint4 i, cnt; -#ifdef HAVE_ALLOCA candidate_t *candidates = - (candidate_t *) alloca(sizeof(candidate_t) * h->size); -#else - candidate_t *candidates = - (candidate_t *) wg_malloc(sizeof(candidate_t) * h->size); -#define SHOULD_FREE 1 -#endif - - void *unknown; + (candidate_t *) malloc(sizeof(candidate_t) * h->size); unknown = fp_Init(NULL); if (fp_Create(unknown, buffer, size, MAXNGRAMS) == 0) @@ -302,10 +280,7 @@ extern char *textcat_Classify(void *handle, const char *buffer, size_t size) } READY: fp_Done(unknown); -#ifdef SHOULD_FREE free(candidates); -#undef SHOULD_FREE -#endif return result; } diff --git a/src/wg_mempool.c b/src/wg_mempool.c index dd1cd23..f217919 100644 --- a/src/wg_mempool.c +++ b/src/wg_mempool.c @@ -77,8 +77,8 @@ static void addblock(mempool_t * h) else { /*** Make a new block ***/ - block = (memblock_t *) wg_malloc(sizeof(memblock_t)); - block->pool = (char *)wg_malloc(h->blocksize); + block = (memblock_t *) malloc(sizeof(memblock_t)); + block->pool = (char *)malloc(h->blocksize); } block->p = block->pool; @@ -90,7 +90,7 @@ static void addblock(mempool_t * h) extern void *wgmempool_Init(size_t blocksize, size_t maxstrsize) { - mempool_t *result = (mempool_t *) wg_malloc(sizeof(mempool_t)); + mempool_t *result = (mempool_t *) malloc(sizeof(mempool_t)); result->first = NULL; result->spare = NULL; |