summaryrefslogtreecommitdiff
path: root/legacy/eina/src/include/eina_safety_checks.h
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2008-12-26 18:31:14 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2008-12-26 18:31:14 +0000
commitab95d9183dbd3cfcf6caa96c3894607432bd951a (patch)
tree7e7f423e9ca5d86e6c336c8e7ea80c09509a605c /legacy/eina/src/include/eina_safety_checks.h
parentb0ee5696a65ed2216af6ffcf3052a0a913b5d0f0 (diff)
eina safety checks.
safety checks will report null pointers and other error conditions on public api's and can be disabled by compile time check. note that in order to have these checks working we need to make EINA_ARG_NONNULL() void, otherwise GCC can remove these checks since they're known to be false. This commit also make two minor changes: * list and hash accessors and iterators are created even for empty entities. This is correct in my point of view since NULL should indicate error. Having these in were an optimziation, but not worth it, these are not the most common case and hitting this path is not of much cost. * unmarked some parameters as nonnull, mainly on list and inlist. SVN revision: 38327
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/include/eina_safety_checks.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/legacy/eina/src/include/eina_safety_checks.h b/legacy/eina/src/include/eina_safety_checks.h
new file mode 100644
index 0000000000..620eb20930
--- /dev/null
+++ b/legacy/eina/src/include/eina_safety_checks.h
@@ -0,0 +1,119 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2008 Gustavo Sverzut Barbieri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef EINA_SAFETY_CHECKS_H_
20#define EINA_SAFETY_CHECKS_H_
21#ifdef EINA_SAFETY_CHECKS
22
23#include "eina_error.h"
24
25#define EINA_SAFETY_ON_NULL_RETURN(exp) \
26 do \
27 { \
28 if (EINA_UNLIKELY((exp) == NULL)) \
29 { \
30 EINA_ERROR_PERR("%s", "safety check failed: " #exp " == NULL\n"); \
31 return; \
32 } \
33 } \
34 while (0)
35
36#define EINA_SAFETY_ON_NULL_RETURN_VAL(exp, val) \
37 do \
38 { \
39 if (EINA_UNLIKELY((exp) == NULL)) \
40 { \
41 EINA_ERROR_PERR("%s", "safety check failed: " #exp " == NULL\n"); \
42 return (val); \
43 } \
44 } \
45 while (0)
46
47#define EINA_SAFETY_ON_TRUE_RETURN(exp) \
48 do \
49 { \
50 if (EINA_UNLIKELY(exp)) \
51 { \
52 EINA_ERROR_PERR("%s", "safety check failed: " #exp " is true\n"); \
53 return; \
54 } \
55 } \
56 while (0)
57
58#define EINA_SAFETY_ON_TRUE_RETURN_VAL(exp, val) \
59 do \
60 { \
61 if (EINA_UNLIKELY(exp)) \
62 { \
63 EINA_ERROR_PERR("%s", "safety check failed: " #exp " is true\n"); \
64 return val; \
65 } \
66 } \
67 while (0)
68
69#define EINA_SAFETY_ON_FALSE_RETURN(exp) \
70 do \
71 { \
72 if (EINA_UNLIKELY(!(exp))) \
73 { \
74 EINA_ERROR_PERR("%s", "safety check failed: " #exp " is false\n"); \
75 return; \
76 } \
77 } \
78 while (0)
79
80#define EINA_SAFETY_ON_FALSE_RETURN_VAL(exp, val) \
81 do \
82 { \
83 if (EINA_UNLIKELY(!(exp))) \
84 { \
85 EINA_ERROR_PERR("%s", "safety check failed: " #exp " is false\n"); \
86 return val; \
87 } \
88 } \
89 while (0)
90
91#ifdef EINA_ARG_NONNULL
92/* make EINA_ARG_NONNULL void so GCC does not optimize safety checks */
93#undef EINA_ARG_NONNULL
94#define EINA_ARG_NONNULL(idx, ...)
95#endif
96
97
98#else /* no safety checks */
99
100#define EINA_SAFETY_ON_NULL_RETURN(exp) \
101 do { (void)((exp) == NULL) } while (0)
102
103#define EINA_SAFETY_ON_NULL_RETURN_VAL(exp, val) \
104 do { if (0 && (exp) == NULL) (void)val; } while (0)
105
106#define EINA_SAFETY_ON_TRUE_RETURN(exp) \
107 do { (void)(exp) } while (0)
108
109#define EINA_SAFETY_ON_TRUE_RETURN_VAL(exp, val) \
110 do { if (0 && (exp)) (void)val; } while (0)
111
112#define EINA_SAFETY_ON_FALSE_RETURN(exp) \
113 do { (void)((!exp)) } while (0)
114
115#define EINA_SAFETY_ON_FALSE_RETURN_VAL(exp, val) \
116 do { if (0 && !(exp)) (void)val; } while (0)
117
118#endif /* safety checks macros */
119#endif /* EINA_SAFETY_CHECKS_H_ */