]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/macro.h
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / macro.h
index bffcc2642383bfcd3b4933aec0ba837d9be45842..4d5e80f4e057c67ace657ae103c3a2cd5b111c82 100644 (file)
@@ -30,8 +30,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
-#include <pulse/gccmacro.h>
+#include <stdbool.h>
 
 #ifndef PACKAGE
 #error "Please include config.h before including this file!"
@@ -86,6 +85,10 @@ static inline size_t PA_PAGE_ALIGN(size_t l) {
     #define PA_DECLARE_ALIGNED(n,t,v)      t v
 #endif
 
+#ifdef __GNUC__
+#define typeof __typeof__
+#endif
+
 /* The users of PA_MIN and PA_MAX, PA_CLAMP, PA_ROUND_UP should be
  * aware that these macros on non-GCC executed code with side effects
  * twice. It is thus considered misuse to use code with side effects
@@ -174,21 +177,6 @@ static inline size_t PA_PAGE_ALIGN(size_t l) {
 #define PA_CLIP_SUB(a, b) ((a) > (b) ? (a) - (b) : 0)
 #endif
 
-/* This type is not intended to be used in exported APIs! Use classic "int" there! */
-#ifdef HAVE_STD_BOOL
-typedef _Bool pa_bool_t;
-#else
-typedef int pa_bool_t;
-#endif
-
-#ifndef FALSE
-#define FALSE ((pa_bool_t) 0)
-#endif
-
-#ifndef TRUE
-#define TRUE (!FALSE)
-#endif
-
 #ifdef __GNUC__
 #define PA_PRETTY_FUNCTION __PRETTY_FUNCTION__
 #else
@@ -201,7 +189,7 @@ typedef int pa_bool_t;
             pa_log_debug("Assertion '%s' failed at %s:%u, function %s.\n", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
             return;                                                     \
         }                                                               \
-    } while(FALSE)
+    } while(false)
 
 #define pa_return_val_if_fail(expr, val)                                \
     do {                                                                \
@@ -209,7 +197,7 @@ typedef int pa_bool_t;
             pa_log_debug("Assertion '%s' failed at %s:%u, function %s.\n", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
             return (val);                                               \
         }                                                               \
-    } while(FALSE)
+    } while(false)
 
 #define pa_return_null_if_fail(expr) pa_return_val_if_fail(expr, NULL)
 
@@ -221,10 +209,10 @@ typedef int pa_bool_t;
             pa_log_error("Assertion '%s' failed at %s:%u, function %s(). Aborting.", #expr , __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
             abort();                                                    \
         }                                                               \
-    } while (FALSE)
+    } while (false)
 
 /* Does exactly nothing */
-#define pa_nop() do {} while (FALSE)
+#define pa_nop() do {} while (false)
 
 /* pa_assert() is an assert that may be optimized away by defining
  * NDEBUG. pa_assert_fp() is an assert that may be optimized away by
@@ -249,7 +237,7 @@ typedef int pa_bool_t;
     do {                                                                \
         pa_log_error("Code should not be reached at %s:%u, function %s(). Aborting.", __FILE__, __LINE__, PA_PRETTY_FUNCTION); \
         abort();                                                        \
-    } while (FALSE)
+    } while (false)
 #endif
 
 /* A compile time assertion */
@@ -260,7 +248,7 @@ typedef int pa_bool_t;
             case !!(expr):                         \
                 ;                                  \
         }                                          \
-    } while (FALSE)
+    } while (false)
 
 #define PA_PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
 #define PA_UINT_TO_PTR(u) ((void*) ((uintptr_t) (u)))
@@ -304,6 +292,18 @@ typedef int pa_bool_t;
 #define pa_memzero(x,l) (memset((x), 0, (l)))
 #define pa_zero(x) (pa_memzero(&(x), sizeof(x)))
 
+#define PA_INT_TYPE_SIGNED(type) (!!((type) 0 > (type) -1))
+
+#define PA_INT_TYPE_MAX(type)                                          \
+    ((type) (PA_INT_TYPE_SIGNED(type)                                  \
+             ? ~(~(type) 0 << (8*sizeof(type)-1))                      \
+             : (type) -1))
+
+#define PA_INT_TYPE_MIN(type)                                          \
+    ((type) (PA_INT_TYPE_SIGNED(type)                                  \
+             ? (~(type) 0 << (8*sizeof(type)-1))                       \
+             : (type) 0))
+
 /* We include this at the very last place */
 #include <pulsecore/log.h>