master hovercats/oakiss / pkg / netsurf / libwapcaplet / patch / 0001-Use-static-inline-functions-instead-of-macros.patch
  1From f0f43a3ad6ee46d6e6378325fc03b1adadd35c41 Mon Sep 17 00:00:00 2001
  2From: Michael Forney <mforney@mforney.org>
  3Date: Mon, 1 Jul 2019 23:13:26 -0700
  4Subject: [PATCH] Use static inline functions instead of macros
  5
  6---
  7 include/libwapcaplet/libwapcaplet.h | 102 +++++++++++-----------------
  8 1 file changed, 39 insertions(+), 63 deletions(-)
  9
 10diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h
 11index 57e2e48..96dd7aa 100644
 12--- a/include/libwapcaplet/libwapcaplet.h
 13+++ b/include/libwapcaplet/libwapcaplet.h
 14@@ -133,17 +133,21 @@ extern lwc_error lwc_string_tolower(lwc_string *str, lwc_string **ret);
 15  * @note Use this if copying the string and intending both sides to retain
 16  * ownership.
 17  */
 18-#if defined(STMTEXPR)
 19-#define lwc_string_ref(str) ({lwc_string *__lwc_s = (str); assert(__lwc_s != NULL); __lwc_s->refcnt++; __lwc_s;})
 20-#else
 21-static inline lwc_string *
 22-lwc_string_ref(lwc_string *str)
 23+static inline lwc_string *lwc_string_ref(lwc_string *str)
 24 {
 25 	assert(str != NULL);
 26 	str->refcnt++;
 27 	return str;
 28 }
 29-#endif
 30+
 31+/**
 32+ * Destroy an unreffed lwc_string.
 33+ *
 34+ * This destroys an lwc_string whose reference count indicates that it should be.
 35+ *
 36+ * @param str The string to unref.
 37+ */
 38+extern void lwc_string_destroy(lwc_string *str);
 39 
 40 /**
 41  * Release a reference on an lwc_string.
 42@@ -156,23 +160,14 @@ lwc_string_ref(lwc_string *str)
 43  *       freed. (Ref count of 1 where string is its own insensitve match
 44  *       will also result in the string being freed.)
 45  */
 46-#define lwc_string_unref(str) {						\
 47-		lwc_string *__lwc_s = (str);				\
 48-		assert(__lwc_s != NULL);				\
 49-		__lwc_s->refcnt--;						\
 50-		if ((__lwc_s->refcnt == 0) ||					\
 51-		    ((__lwc_s->refcnt == 1) && (__lwc_s->insensitive == __lwc_s)))	\
 52-			lwc_string_destroy(__lwc_s);				\
 53-	}
 54-	
 55-/**
 56- * Destroy an unreffed lwc_string.
 57- *
 58- * This destroys an lwc_string whose reference count indicates that it should be.
 59- *
 60- * @param str The string to unref.
 61- */
 62-extern void lwc_string_destroy(lwc_string *str);
 63+static inline void lwc_string_unref(lwc_string *str)
 64+{
 65+	assert(str != NULL);
 66+	str->refcnt--;
 67+	if ((str->refcnt == 0) ||
 68+	    ((str->refcnt == 1) && (str->insensitive == str)))
 69+		lwc_string_destroy(str);
 70+}
 71 
 72 /**
 73  * Check if two interned strings are equal.
 74@@ -183,8 +178,12 @@ extern void lwc_string_destroy(lwc_string *str);
 75  * @return     Result of operation, if not ok then value pointed to
 76  *	       by \a ret will not be valid.
 77  */
 78-#define lwc_string_isequal(str1, str2, ret) \
 79-	((*(ret) = ((str1) == (str2))), lwc_error_ok)
 80+static inline lwc_error lwc_string_isequal(
 81+	lwc_string *str1, lwc_string *str2, bool *ret)
 82+{
 83+	*ret = (str1 == str2);
 84+	return lwc_error_ok;
 85+}
 86 
 87 /**
 88  * Intern a caseless copy of the passed string.
 89@@ -200,7 +199,6 @@ extern void lwc_string_destroy(lwc_string *str);
 90 extern lwc_error
 91 lwc__intern_caseless_string(lwc_string *str);
 92 
 93-#if defined(STMTEXPR)
 94 /**
 95  * Check if two interned strings are case-insensitively equal.
 96  *
 97@@ -210,33 +208,6 @@ lwc__intern_caseless_string(lwc_string *str);
 98  * @return Result of operation, if not ok then value pointed to by \a ret will
 99  *	    not be valid.
100  */
101-#define lwc_string_caseless_isequal(_str1,_str2,_ret) ({                \
102-            lwc_error __lwc_err = lwc_error_ok;                         \
103-            lwc_string *__lwc_str1 = (_str1);                           \
104-            lwc_string *__lwc_str2 = (_str2);                           \
105-            bool *__lwc_ret = (_ret);                                   \
106-                                                                        \
107-            if (__lwc_str1->insensitive == NULL) {                      \
108-                __lwc_err = lwc__intern_caseless_string(__lwc_str1);    \
109-            }                                                           \
110-            if (__lwc_err == lwc_error_ok && __lwc_str2->insensitive == NULL) { \
111-                __lwc_err = lwc__intern_caseless_string(__lwc_str2);    \
112-            }                                                           \
113-            if (__lwc_err == lwc_error_ok)                              \
114-                *__lwc_ret = (__lwc_str1->insensitive == __lwc_str2->insensitive); \
115-            __lwc_err;                                                  \
116-        })
117-	
118-#else
119-/**
120- * Check if two interned strings are case-insensitively equal.
121- *
122- * @param str1 The first string in the comparison.
123- * @param str2 The second string in the comparison.
124- * @param ret  A pointer to a boolean to be filled out with the result.
125- * @return Result of operation, if not ok then value pointed to by \a ret will
126- *         not be valid.
127- */
128 static inline lwc_error
129 lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
130 {
131@@ -251,13 +222,6 @@ lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
132            *ret = (str1->insensitive == str2->insensitive);
133        return err;
134 }
135-#endif
136-
137-#if defined(STMTEXPR)
138-#define lwc__assert_and_expr(str, expr) ({assert(str != NULL); expr;})
139-#else
140-#define lwc__assert_and_expr(str, expr) (expr)
141-#endif
142 	
143 /**
144  * Retrieve the data pointer for an interned string.
145@@ -271,7 +235,11 @@ lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
146  *	 in future.  Any code relying on it currently should be
147  *	 modified to use ::lwc_string_length if possible.
148  */
149-#define lwc_string_data(str) lwc__assert_and_expr(str, (const char *)((str)+1))
150+static inline const char *lwc_string_data(lwc_string *str)
151+{
152+	assert(str != NULL);
153+	return (const char *)(str + 1);
154+}
155 
156 /**
157  * Retrieve the data length for an interned string.
158@@ -279,7 +247,11 @@ lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
159  * @param str The string to retrieve the length of.
160  * @return    The length of \a str.
161  */
162-#define lwc_string_length(str) lwc__assert_and_expr(str, (str)->len)
163+static inline size_t lwc_string_length(lwc_string *str)
164+{
165+	assert(str != NULL);
166+	return str->len;
167+}
168 
169 /**
170  * Retrieve (or compute if unavailable) a hash value for the content of the string.
171@@ -293,7 +265,11 @@ lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
172  *	 to be stable between invocations of the program. Never use the hash
173  *	 value as a way to directly identify the value of the string.
174  */
175-#define lwc_string_hash_value(str) lwc__assert_and_expr(str, (str)->hash)
176+static inline lwc_hash lwc_string_hash_value(lwc_string *str)
177+{
178+	assert(str != NULL);
179+	return str->hash;
180+}
181 
182 /**
183  * Retrieve a hash value for the caseless content of the string.
184-- 
1852.26.2
186