1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: mmstd.c,v 1.5 2009-03-17 09:01:46 Singular Exp $ */ |
---|
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 | #include "omalloc.h" |
---|
14 | #include "../Singular/static.h" |
---|
15 | |
---|
16 | // we provide these functions, so that the settings of OM_CHECK |
---|
17 | // and OM_TRACK are used, but only provide them if omalloc is not based |
---|
18 | // on them |
---|
19 | // already provided in libomalloc |
---|
20 | #if !defined(OMALLOC_USES_MALLOC) && !defined(X_OMALLOC) && !defined(HAVE_STATIC) |
---|
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 */ |
---|
25 | |
---|
26 | // define this so that all addr allocated there are marked |
---|
27 | // as static, i.e. not metioned by omPrintUsedAddr |
---|
28 | #define OM_MALLOC_MARK_AS_STATIC |
---|
29 | #define strdup_ strdup__ |
---|
30 | #include <omalloc.c> |
---|
31 | #else |
---|
32 | #include <stdlib.h> |
---|
33 | void freeSize(void* addr, size_t size) |
---|
34 | { |
---|
35 | if (addr) free(addr); |
---|
36 | } |
---|
37 | |
---|
38 | void* reallocSize(void* old_addr, size_t old_size, size_t new_size) |
---|
39 | { |
---|
40 | if (old_addr && new_size) |
---|
41 | { |
---|
42 | return realloc(old_addr, new_size); |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | freeSize(old_addr, old_size); |
---|
47 | return malloc(new_size); |
---|
48 | } |
---|
49 | } |
---|
50 | #endif |
---|
51 | |
---|