diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/Doxyfile.in | 2 | ||||
-rw-r--r-- | m4/attributes.m4 | 20 | ||||
-rw-r--r-- | src/xine-utils/attributes.h | 6 | ||||
-rw-r--r-- | src/xine-utils/xineutils.h | 12 |
5 files changed, 31 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index 5920e2ea1..1ccd1005b 100644 --- a/configure.ac +++ b/configure.ac @@ -2127,6 +2127,8 @@ CC_ATTRIBUTE_PACKED( AC_DEFINE([XINE_PACKED], [], [Dummy mark a structure as being packed])] ) +CC_ATTRIBUTE_MALLOC + CC_ATTRIBUTE_VISIBILITY([protected], [visibility_export="protected"], [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])] ) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 09e016c5b..59f04af46 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -796,7 +796,7 @@ INCLUDE_FILE_PATTERNS = # instead of the = operator. PREDEFINED = XINE_COMPILE XINE_PACKED= ATTR_ALIGN(x)= -PREDEFINED += XINE_PROTECTED= +PREDEFINED += XINE_PROTECTED= XINE_MALLOC= # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. diff --git a/m4/attributes.m4 b/m4/attributes.m4 index c46715d0e..23b5f2ee4 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -342,3 +342,23 @@ AC_DEFUN([CC_ATTRIBUTE_PACKED], [ ifelse([$2], , [:], [$2]) fi ]) + +AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ + AC_REQUIRE([CC_CHECK_WERROR]) + AC_CACHE_CHECK([if $CC supports __attribute__((__malloc__))], + [cc_cv_attribute_malloc], + [ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $cc_cv_werror" + AC_COMPILE_IFELSE([void *fooalloc(int size) __attribute__((__malloc__));], + [cc_cv_attribute_malloc=yes], + [cc_cv_attribute_malloc=no]) + CFLAGS="$ac_save_CFLAGS" + ]) + + if test x$cc_cv_attribute_malloc = xyes; then + AC_DEFINE([SUPPORT_ATTRIBUTE_MALLOC], 1, [Define this if the compiler supports __attribute__((__malloc__))]) + ifelse([$1], , [:], [$1]) + else + ifelse([$2], , [:], [$2]) + fi +]) diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h index 649c1aa43..e257a48dd 100644 --- a/src/xine-utils/attributes.h +++ b/src/xine-utils/attributes.h @@ -75,4 +75,10 @@ # define XINE_PACKED #endif +#ifdef SUPPORT_ATTRIBUTE_MALLOC +# define XINE_MALLOC __attributes__((__malloc__)) +#else +# define XINE_MALLOC +#endif + #endif /* ATTRIBUTE_H_ */ diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 20c3cb2dc..0be29ff63 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -624,17 +624,9 @@ void xine_profiler_print_results (void) XINE_PROTECTED; * Allocate and clean memory size_t 'size', then return the pointer * to the allocated memory. */ -#if !defined(__GNUC__) || __GNUC__ < 3 -void *xine_xmalloc(size_t size) XINE_PROTECTED; -#else -void *xine_xmalloc(size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED; -#endif +void *xine_xmalloc(size_t size) XINE_MALLOC XINE_PROTECTED; -#if !defined(__GNUC__) || __GNUC__ < 3 -void *xine_xcalloc(size_t nmemb, size_t size) XINE_PROTECTED; -#else -void *xine_xcalloc(size_t nmemb, size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED; -#endif +void *xine_xcalloc(size_t nmemb, size_t size) XINE_MALLOC XINE_PROTECTED; /* * Same as above, but memory is aligned to 'alignement'. |