NFFT Logo 3.2.2
malloc.c
00001 /*
00002  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
00020 
00021 #include<stdlib.h>
00022 
00023 #include "api.h"
00024 
00025 X(malloc_type_function) X(malloc_hook) = 0;
00026 X(free_type_function) X(free_hook) = 0;
00027 X(die_type_function) X(die_hook) = 0;
00028 
00029 void *X(malloc)(size_t n)
00030 {
00031   void *p;
00032 
00033   if (X(malloc_hook))
00034     return nfft_malloc_hook(n);
00035 
00036   if (n == 0)
00037     n = 1;
00038 
00039   p = Z(malloc)(n);
00040 
00041   if (!p)
00042     X(die)(STRINGIZE(X(malloc)) ": out of memory\n");
00043 
00044   return p;
00045 }
00046 
00047 void X(free)(void *p)
00048 {
00049   if (p)
00050   {
00051     if (X(free_hook))
00052     {
00053       X(free_hook)(p);
00054       return;
00055     }
00056     Z(free)(p);
00057   }
00058 }
00059 
00060 void X(die)(char *s)
00061 {
00062   if (X(die_hook))
00063     X(die_hook)(s);
00064 
00065   exit(EXIT_FAILURE);
00066 }

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409