![]() |
|
00001 /* 00002 * Copyright (c) 2002, 2009 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: malloc.c 3169 2009-04-15 14:22:15Z keiner $ */ 00020 00021 #include "nfft3.h" 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 00025 nfft_malloc_type_function nfft_malloc_hook = 0; 00026 nfft_free_type_function nfft_free_hook = 0; 00027 nfft_die_type_function nfft_die_hook = 0; 00028 00029 void *nfft_malloc(size_t n) 00030 { 00031 void *p; 00032 00033 if (nfft_malloc_hook) 00034 return nfft_malloc_hook(n); 00035 00036 if (n == 0) 00037 n = 1; 00038 00039 p = fftw_malloc(n); 00040 00041 if (!p) 00042 { 00043 fprintf(stderr,"nfft_malloc: n = %d.\n",n); 00044 nfft_die("nfft_malloc: out of memory\n"); 00045 } 00046 00047 return p; 00048 } 00049 00050 void nfft_free(void *p) 00051 { 00052 if (p) 00053 { 00054 if (nfft_free_hook) 00055 { 00056 nfft_free_hook(p); 00057 return; 00058 } 00059 fftw_free(p); 00060 } 00061 } 00062 00063 void nfft_die(const char *s) 00064 { 00065 if (nfft_die_hook) 00066 nfft_die_hook(s); 00067 00068 fflush(stdout); 00069 fprintf(stderr, "nfft: %s", s); 00070 exit(EXIT_FAILURE); 00071 }