Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/c_lib/include/memory.h
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
#ifndef C_LIB_INCLUDE_MEMORY_H
21
#define C_LIB_INCLUDE_MEMORY_H
22
23
#include "interrupt.h"
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
static inline void* sage_malloc(size_t n)
30
{
31
sig_block();
32
void* ret = malloc(n);
33
sig_unblock();
34
return ret;
35
}
36
static inline void* sage_calloc(size_t nmemb, size_t size)
37
{
38
sig_block();
39
void* ret = calloc(nmemb, size);
40
sig_unblock();
41
return ret;
42
}
43
static inline void sage_free(void* ptr)
44
{
45
sig_block();
46
free(ptr);
47
sig_unblock();
48
}
49
static inline void* sage_realloc(void *ptr, size_t size)
50
{
51
sig_block();
52
void* ret = realloc(ptr, size);
53
sig_unblock();
54
return ret;
55
}
56
57
void init_memory_functions();
58
59
60
#ifdef __cplusplus
61
} /* extern "C" */
62
#endif
63
#endif /* C_LIB_INCLUDE_MEMORY_H */
64
65