blob: c6466cda4db9bab191042758c2d077bda6258eba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
$NetBSD: patch-cc,v 1.1 2009/12/01 08:49:46 manu Exp $
--- lasso/utils.h.orig 2009-11-30 18:54:46.000000000 +0100
+++ lasso/utils.h 2009-11-30 19:31:22.000000000 +0100
@@ -336,4 +336,73 @@
g_return_val_if_fail(name != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
+/**
+ * The following macros are made to create some formalism for function's cleanup code.
+ *
+ * The exit label should be called 'cleanup'. And for functions returning an integer error code, the
+ * error code should be named 'rc' and 'return rc;' should be the last statement of the function.
+ */
+
+/**
+ * goto_cleanup_with_rc:
+ * @rc_value: integer return value
+ *
+ * This macro jump to the 'cleanup' label and set the return value to @rc_value.
+ *
+ */
+#define goto_cleanup_with_rc(rc_value) \
+ {\
+ rc = (rc_value); \
+ goto cleanup; \
+ }
+
+/**
+ * goto_cleanup_if_fail:
+ * @condition: a boolean condition
+ *
+ * Jump to the 'cleanup' label if the @condition is FALSE.
+ *
+ */
+#define goto_cleanup_if_fail(condition) \
+ {\
+ if (! (condition) ) {\
+ goto cleanup; \
+ } \
+ }
+
+/**
+ * goto_cleanup_if_fail_with_rc:
+ * @condition: a boolean condition
+ * @rc_value: integer return value
+ *
+ * Jump to the 'cleanup' label if the @condition is FALSE and set the return value to
+ * @rc_value.
+ *
+ */
+#define goto_cleanup_if_fail_with_rc(condition, rc_value) \
+ {\
+ if (! (condition) ) {\
+ rc = (rc_value); \
+ goto cleanup; \
+ } \
+ }
+
+/**
+ * goto_cleanup_if_fail_with_rc_with_warning:
+ * @condition: a boolean condition
+ * @rc_value: integer return value
+ *
+ * Jump to the 'cleanup' label if the @condition is FALSE and set the return value to
+ * @rc_value. Also emit a warning, showing the condition and the return value.
+ *
+ */
+#define goto_cleanup_if_fail_with_rc_with_warning(condition, rc_value) \
+ {\
+ if (! (condition) ) {\
+ g_warning("%s failed, returning %s", __STRING(condition), __STRING(rc_value));\
+ rc = (rc_value); \
+ goto cleanup; \
+ } \
+ }
+
#define goto_exit_with_rc(rc_value) \
{\
|