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