PulseAudio 1.1
|
00001 #ifndef foomemoryhfoo 00002 #define foomemoryhfoo 00003 00004 /*** 00005 This file is part of PulseAudio. 00006 00007 Copyright 2004-2006 Lennart Poettering 00008 00009 PulseAudio is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published 00011 by the Free Software Foundation; either version 2.1 of the License, 00012 or (at your option) any later version. 00013 00014 PulseAudio is distributed in the hope that it will be useful, but 00015 WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with PulseAudio; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00022 USA. 00023 ***/ 00024 00025 #include <sys/types.h> 00026 #include <stdlib.h> 00027 #include <limits.h> 00028 #include <assert.h> 00029 00030 #include <pulse/cdecl.h> 00031 #include <pulse/gccmacro.h> 00032 #include <pulse/version.h> 00033 00038 PA_C_DECL_BEGIN 00039 00041 void* pa_xmalloc(size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(1); 00042 00044 void *pa_xmalloc0(size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(1); 00045 00047 void *pa_xrealloc(void *ptr, size_t size) PA_GCC_ALLOC_SIZE(2); 00048 00050 void pa_xfree(void *p); 00051 00053 char *pa_xstrdup(const char *s) PA_GCC_MALLOC; 00054 00056 char *pa_xstrndup(const char *s, size_t l) PA_GCC_MALLOC; 00057 00059 void* pa_xmemdup(const void *p, size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(2); 00060 00062 static void* _pa_xnew_internal(size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(1,2); 00063 00064 static inline void* _pa_xnew_internal(size_t n, size_t k) { 00065 assert(n < INT_MAX/k); 00066 return pa_xmalloc(n*k); 00067 } 00068 00070 #define pa_xnew(type, n) ((type*) _pa_xnew_internal((n), sizeof(type))) 00071 00073 static void* _pa_xnew0_internal(size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(1,2); 00074 00075 static inline void* _pa_xnew0_internal(size_t n, size_t k) { 00076 assert(n < INT_MAX/k); 00077 return pa_xmalloc0(n*k); 00078 } 00079 00081 #define pa_xnew0(type, n) ((type*) _pa_xnew0_internal((n), sizeof(type))) 00082 00084 static void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(2,3); 00085 00086 static inline void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) { 00087 assert(n < INT_MAX/k); 00088 return pa_xmemdup(p, n*k); 00089 } 00090 00092 #define pa_xnewdup(type, p, n) ((type*) _pa_xnewdup_internal((p), (n), sizeof(type))) 00093 00095 static void* _pa_xrenew_internal(void *p, size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(2,3); 00096 00097 static inline void* _pa_xrenew_internal(void *p, size_t n, size_t k) { 00098 assert(n < INT_MAX/k); 00099 return pa_xrealloc(p, n*k); 00100 } 00101 00103 #define pa_xrenew(type, p, n) ((type*) _pa_xrenew_internal(p, (n), sizeof(type))) 00104 00105 PA_C_DECL_END 00106 00107 #endif