NFFT Logo 3.2.3
malloc.c
1 /*
2  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
20 
21 #include<stdlib.h>
22 
23 #include "api.h"
24 
25 X(malloc_type_function) X(malloc_hook) = 0;
26 X(free_type_function) X(free_hook) = 0;
27 X(die_type_function) X(die_hook) = 0;
28 
29 void *X(malloc)(size_t n)
30 {
31  void *p;
32 
33  if (X(malloc_hook))
34  return nfft_malloc_hook(n);
35 
36  if (n == 0)
37  n = 1;
38 
39  p = Z(malloc)(n);
40 
41  if (!p)
42  X(die)(STRINGIZE(X(malloc)) ": out of memory\n");
43 
44  return p;
45 }
46 
47 void X(free)(void *p)
48 {
49  if (p)
50  {
51  if (X(free_hook))
52  {
53  X(free_hook)(p);
54  return;
55  }
56  Z(free)(p);
57  }
58 }
59 
60 void X(die)(char *s)
61 {
62  if (X(die_hook))
63  X(die_hook)(s);
64 
65  exit(EXIT_FAILURE);
66 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1