[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
[75f460] | 5 | * ABSTRACT: standard version of C-memory management alloc func |
---|
[35aab3] | 6 | * i.e. (malloc/realloc/free) |
---|
| 7 | */ |
---|
| 8 | |
---|
[9f7665] | 9 | |
---|
| 10 | |
---|
| 11 | |
---|
[a4b31c] | 12 | #include "kernel/mod2.h" |
---|
| 13 | #include "omalloc/omalloc.h" |
---|
[715936] | 14 | |
---|
[f89565] | 15 | /* we provide these functions, so that the settings of OM_CHECK |
---|
| 16 | * and OM_TRACK are used, but only provide them if omalloc is not based |
---|
| 17 | * on them |
---|
| 18 | * already provided in libomalloc */ |
---|
[b54aa2d] | 19 | #if !defined(OMALLOC_USES_MALLOC) && !defined(X_OMALLOC) |
---|
[715936] | 20 | |
---|
| 21 | /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */ |
---|
| 22 | /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */ |
---|
| 23 | /* solution: correctly check OMALLOC_USES_MALLOC from omalloc.h, */ |
---|
| 24 | /* do not rely on the default in Singular as libsingular may be different */ |
---|
[35aab3] | 25 | |
---|
[75f460] | 26 | /* define this so that all addr allocated there are marked |
---|
[f89565] | 27 | * as static, i.e. not metioned by omPrintUsedAddr*/ |
---|
[35aab3] | 28 | #define OM_MALLOC_MARK_AS_STATIC |
---|
[30b8381] | 29 | #define strdup_ strdup__ |
---|
[a4b31c] | 30 | #include "omalloc/omalloc.c" /// UGLY!!!!!!!!!!!!!!!! |
---|
[715936] | 31 | |
---|
[35aab3] | 32 | #else |
---|
[a4b31c] | 33 | #include "Singular/mmalloc.h" |
---|
[bd795d] | 34 | |
---|
[35aab3] | 35 | void freeSize(void* addr, size_t size) |
---|
| 36 | { |
---|
[2e4ec14] | 37 | (void) size; |
---|
[35aab3] | 38 | if (addr) free(addr); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | void* reallocSize(void* old_addr, size_t old_size, size_t new_size) |
---|
| 42 | { |
---|
| 43 | if (old_addr && new_size) |
---|
| 44 | { |
---|
| 45 | return realloc(old_addr, new_size); |
---|
| 46 | } |
---|
[75f460] | 47 | else |
---|
[35aab3] | 48 | { |
---|
| 49 | freeSize(old_addr, old_size); |
---|
| 50 | return malloc(new_size); |
---|
| 51 | } |
---|
| 52 | } |
---|
[b54aa2d] | 53 | |
---|
| 54 | #endif |
---|
[35aab3] | 55 | |
---|