[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[3e5387] | 4 | /* $Id: mmstd.c,v 1.4 2007-03-21 17:45:27 Singular Exp $ */ |
---|
[35aab3] | 5 | /* |
---|
| 6 | * ABSTRACT: standard version of C-memory management alloc func |
---|
| 7 | * i.e. (malloc/realloc/free) |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "mod2.h" |
---|
| 11 | |
---|
| 12 | #define OM_NO_MALLOC_MACROS |
---|
| 13 | #ifdef ix86_Win |
---|
| 14 | #define OMALLOC_USES_MALLOC |
---|
| 15 | #endif |
---|
| 16 | #ifdef ppcMac_darwin |
---|
| 17 | #define OMALLOC_USES_MALLOC |
---|
| 18 | #endif |
---|
[55b5cfd] | 19 | #ifdef ix86Mac_darwin |
---|
| 20 | #define OMALLOC_USES_MALLOC |
---|
| 21 | #endif |
---|
[35aab3] | 22 | #include "omalloc.h" |
---|
[3e5387] | 23 | #include "../Singular/static.h" |
---|
[35aab3] | 24 | |
---|
| 25 | // we provide these functions, so that the settings of OM_CHECK |
---|
| 26 | // and OM_TRACK are used, but only provide them if omalloc is not based |
---|
| 27 | // on them |
---|
[30b8381] | 28 | // already provided in libomalloc |
---|
[3e5387] | 29 | #if !defined(OMALLOC_USES_MALLOC) && !defined(X_OMALLOC) && !defined(HAVE_STATIC) |
---|
[35aab3] | 30 | |
---|
| 31 | // define this so that all addr allocated there are marked |
---|
| 32 | // as static, i.e. not metioned by omPrintUsedAddr |
---|
| 33 | #define OM_MALLOC_MARK_AS_STATIC |
---|
[30b8381] | 34 | #define strdup_ strdup__ |
---|
[35aab3] | 35 | #include <omalloc.c> |
---|
| 36 | #else |
---|
| 37 | #include <stdlib.h> |
---|
| 38 | void freeSize(void* addr, size_t size) |
---|
| 39 | { |
---|
| 40 | if (addr) free(addr); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | void* reallocSize(void* old_addr, size_t old_size, size_t new_size) |
---|
| 44 | { |
---|
| 45 | if (old_addr && new_size) |
---|
| 46 | { |
---|
| 47 | return realloc(old_addr, new_size); |
---|
| 48 | } |
---|
| 49 | else |
---|
| 50 | { |
---|
| 51 | freeSize(old_addr, old_size); |
---|
| 52 | return malloc(new_size); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | #endif |
---|
| 56 | |
---|