logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Use-static-inline-functions-instead-of-macros.patch (6692B)


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