Merge HUGE set of changes temporarily into a branch, to allow me to move them from...
[profile/ivi/pulseaudio-panda.git] / src / pulsecore / macro.h
1 #ifndef foopulsemacrohfoo
2 #define foopulsemacrohfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of PulseAudio.
8
9   Copyright 2004-2006 Lennart Poettering
10
11   PulseAudio is free software; you can redistribute it and/or modify
12   it under the terms of the GNU Lesser General Public License as published
13   by the Free Software Foundation; either version 2 of the License,
14   or (at your option) any later version.
15
16   PulseAudio is distributed in the hope that it will be useful, but
17   WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   General Public License for more details.
20
21   You should have received a copy of the GNU Lesser General Public License
22   along with PulseAudio; if not, write to the Free Software
23   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24   USA.
25 ***/
26
27 #include <sys/types.h>
28 #include <pulsecore/log.h>
29
30 static inline size_t pa_align(size_t l) {
31     return (((l + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*));
32 }
33
34 #define PA_ALIGN(x) (pa_align(x))
35
36 #define PA_ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
37
38 #define SA_MAX(a, b) ((a) > (b) ? (a) : (b))
39 #define SA_MIN(a, b) ((a) < (b) ? (a) : (b))
40
41 #ifdef __GNUC__
42 #define PA_PRETTY_FUNCTION __PRETTY_FUNCTION__
43 #else
44 #define PA_PRETTY_FUNCTION ""
45 #endif
46
47 #define pa_return_if_fail(expr) \
48     do { \
49         if (!(expr)) { \
50             pa_log_debug("%s: Assertion <%s> failed.\n", PA_PRETTY_FUNCTION, #expr ); \
51             return; \
52         } \
53     } while(0)
54
55 #define pa_return_val_if_fail(expr, val) \
56     do { \
57         if (!(expr)) { \
58             pa_log_debug("%s: Assertion <%s> failed.\n", PA_PRETTY_FUNCTION, #expr ); \
59             return (val); \
60         } \
61     } while(0)
62
63 #define pa_return_null_if_fail(expr) pa_return_val_if_fail(expr, NULL)
64
65 #define pa_assert assert
66
67 #define pa_assert_not_reached() pa_assert(!"Should not be reached.")
68
69 /* An assert which guarantees side effects of x */
70 #define pa_assert_se(x) do {                  \
71         int _r = !!(x);                       \
72         pa_assert(_r);                        \
73     } while(0)
74
75 #define PA_PTR_TO_UINT(p) ((unsigned int) (unsigned long) (p))
76 #define PA_UINT_TO_PTR(u) ((void*) (unsigned long) (u))
77 #define PA_PTR_TO_UINT32(p) ((uint32_t) PA_PTR_TO_UINT(p))
78 #define PA_UINT32_TO_PTR(u) PA_UINT_TO_PTR(u)
79
80 #endif