![]() |
NFFT
3.3.1
|
00001 /* 00002 * Copyright (c) 2002, 2016 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 #include<stdlib.h> 00020 00021 #include "api.h" 00022 00023 Y(malloc_type_function) Y(malloc_hook) = 0; 00024 Y(free_type_function) Y(free_hook) = 0; 00025 Y(die_type_function) Y(die_hook) = 0; 00026 00027 void *Y(malloc)(size_t n) 00028 { 00029 void *p; 00030 00031 if (Y(malloc_hook)) 00032 return Y(malloc_hook)(n); 00033 00034 if (n == 0) 00035 n = 1; 00036 00037 p = FFTW(malloc)(n); 00038 00039 if (!p) 00040 Y(die)(STRINGIZE(Y(malloc)) ": out of memory\n"); 00041 00042 return p; 00043 } 00044 00045 void Y(free)(void *p) 00046 { 00047 if (p) 00048 { 00049 if (Y(free_hook)) 00050 { 00051 Y(free_hook)(p); 00052 return; 00053 } 00054 FFTW(free)(p); 00055 } 00056 } 00057 00058 void Y(die)(const char *s) 00059 { 00060 if (Y(die_hook)) 00061 Y(die_hook)(s); 00062 00063 exit(EXIT_FAILURE); 00064 }