Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/c_lib/src/memory.c
4024 views
1
/*
2
Wrappers for malloc(), calloc(), free(), realloc().
3
4
5
AUTHORS:
6
7
- Jeroen Demeyer (2011-01-13): initial version (#10258)
8
9
*/
10
11
/*****************************************************************************
12
* Copyright (C) 2011 Jeroen Demeyer <[email protected]>
13
*
14
* Distributed under the terms of the GNU General Public License (GPL)
15
* as published by the Free Software Foundation; either version 2 of
16
* the License, or (at your option) any later version.
17
* http://www.gnu.org/licenses/
18
****************************************************************************/
19
20
#include <mpir.h>
21
#include "memory.h"
22
23
/* mpir memory functions */
24
void* sage_mpir_malloc(size_t size)
25
{
26
return sage_malloc(size);
27
}
28
29
void* sage_mpir_realloc(void *ptr, size_t old_size, size_t new_size)
30
{
31
return sage_realloc(ptr, new_size);
32
}
33
34
void sage_mpir_free(void *ptr, size_t size)
35
{
36
sage_free(ptr);
37
}
38
39
void init_memory_functions()
40
{
41
#if 0
42
void* (*mpir_malloc)(size_t);
43
void* (*mpir_realloc)(void*, size_t, size_t);
44
void (*mpir_free)(void*, size_t);
45
mp_get_memory_functions(&mpir_malloc, &mpir_realloc, &mpir_free);
46
printf("MPIR memory functions BEFORE: %p %p %p\n", mpir_malloc, mpir_realloc, mpir_free);
47
#endif
48
mp_set_memory_functions(sage_mpir_malloc, sage_mpir_realloc, sage_mpir_free);
49
#if 0
50
mp_get_memory_functions(&mpir_malloc, &mpir_realloc, &mpir_free);
51
printf("MPIR memory functions AFTER: %p %p %p\n", mpir_malloc, mpir_realloc, mpir_free);
52
#endif
53
}
54
55