00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00032 #ifndef BSP_ALLOC_H
00033 #define BSP_ALLOC_H
00034 
00035 #include <config.h>
00036 #include <stdlib.h>
00037 #include "bsp_abort.h"
00038 
00040 #define bsp_malloc( n, sz) bsp_mallocx((n), (sz), \
00041                           __func__, __FILE__, __LINE__ )
00042 
00044 #define bsp_calloc( n, sz) bsp_callocx((n), (sz), \
00045                           __func__, __FILE__, __LINE__ )
00046 
00057 static inline void *
00058 bsp_mallocx (const size_t n, const size_t sz, 
00059             const char *func, const char *file, int line)
00060 {
00061   void *result;
00062 
00063   if (n * sz == 0)
00064     return NULL;
00065   
00066   result = (void *) malloc (n * sz);
00067   if (result == NULL)
00068     bsp_intern_abort (ERR_NOT_ENOUGH_MEMORY, func, file, line);
00069   
00070   return result;
00071 }
00072 
00082 static inline void *
00083 bsp_callocx (const size_t n, const size_t sz, 
00084              const char *func, const char *file, int line)
00085 {
00086   void *result;
00087 
00088   if (n * sz == 0)
00089     return NULL;
00090     
00091   result = (void *) calloc (n, sz);
00092   if (result == NULL)
00093     bsp_intern_abort (ERR_NOT_ENOUGH_MEMORY, func, file, line);
00094    
00095   return result;
00096 }
00097 
00101 static inline void
00102 bsp_free (void *ptr)
00103 {
00104   if (ptr != NULL)
00105     free (ptr);
00106 }
00107 
00108 #endif