]> www.ginac.de Git - cln.git/blob - src/base/cl_malloc.cc
* Update copyright date.
[cln.git] / src / base / cl_malloc.cc
1 // malloc_hook, free_hook.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/malloc.h"
8
9
10 // Implementation.
11
12 #include <stdlib.h>
13 #include "cln/io.h"
14 #include "cln/abort.h"
15
16 #ifndef malloc
17   extern "C" void* malloc (size_t size);
18 #endif
19 #ifndef free
20   extern "C" void free (void* ptr);
21 #endif
22
23 namespace cln {
24
25 // Just like malloc() but never return NULL pointers.
26 static void* xmalloc (size_t size)
27 {
28         void* ptr = malloc(size);
29         if (ptr)
30                 return ptr;
31         fprint(std::cerr, "Out of virtual memory.\n");
32         cl_abort();
33 }
34
35 void* (*malloc_hook) (size_t size) = xmalloc;
36 void (*free_hook) (void* ptr)      = free;
37
38 }  // namespace cln