Sunday, 22 March 2020

libwapcaplet portability fixes (re: plan 9 port)

Hey,

I'm one of the people who's been helping port netsurf to
plan9, and I've started rebasing changes that we did against
3.9 to master, so that we can start submitting what makes sense.

First off, thanks for a wonderfully portable codebase -- it's
great how small the patches are to get most of the libraries
working.

I'm hoping that we can get things to the point where we need to
carry very few patches forward, though I don't expect you'll want
to maintain our build system (ie, the mkfiles), so I'm going to
leave them out of patches.

Here's the first patch.

>From b02d1e93846df7f135bc8c1c82c9a2e3291480cf
From: Ori Bernstein <ori@eigenstate.org>
Date: Sun, 22 Mar 2020 17:47:46 -0700
Subject: [PATCH] portability fixes for Plan 9


The plan 9 compilers are not gcc, and do not handle many
gcc extensions like expression templates. this change
replaces them with either plain macros, or with static
inline functions, which are already in use elsewhere in
the project.
diff -urN a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h
--- a/include/libwapcaplet/libwapcaplet.h Sat Sep 7 06:59:40 2019
+++ b/include/libwapcaplet/libwapcaplet.h Sun Mar 22 17:47:46 2020
@@ -133,7 +133,12 @@
* @note Use this if copying the string and intending both sides to retain
* ownership.
*/
-#define lwc_string_ref(str) ({lwc_string *__lwc_s = (str); assert(__lwc_s != NULL); __lwc_s->refcnt++; __lwc_s;})
+static inline lwc_string *
+lwc_string_ref(lwc_string *str)
+{
+ str->refcnt++;
+ return str;
+}

/**
* Release a reference on an lwc_string.
@@ -177,32 +182,6 @@
((*(ret) = ((str1) == (str2))), lwc_error_ok)

/**
- * Check if two interned strings are case-insensitively equal.
- *
- * @param _str1 The first string in the comparison.
- * @param _str2 The second string in the comparison.
- * @param _ret A pointer to a boolean to be filled out with the result.
- * @return Result of operation, if not ok then value pointed to by \a ret will
- * not be valid.
- */
-#define lwc_string_caseless_isequal(_str1,_str2,_ret) ({ \
- lwc_error __lwc_err = lwc_error_ok; \
- lwc_string *__lwc_str1 = (_str1); \
- lwc_string *__lwc_str2 = (_str2); \
- bool *__lwc_ret = (_ret); \
- \
- if (__lwc_str1->insensitive == NULL) { \
- __lwc_err = lwc__intern_caseless_string(__lwc_str1); \
- } \
- if (__lwc_err == lwc_error_ok && __lwc_str2->insensitive == NULL) { \
- __lwc_err = lwc__intern_caseless_string(__lwc_str2); \
- } \
- if (__lwc_err == lwc_error_ok) \
- *__lwc_ret = (__lwc_str1->insensitive == __lwc_str2->insensitive); \
- __lwc_err; \
- })
-
-/**
* Intern a caseless copy of the passed string.
*
* @param str The string to intern the caseless copy of.
@@ -215,6 +194,30 @@
*/
extern lwc_error
lwc__intern_caseless_string(lwc_string *str);
+
+/**
+ * Check if two interned strings are case-insensitively equal.
+ *
+ * @param _str1 The first string in the comparison.
+ * @param _str2 The second string in the comparison.
+ * @param _ret A pointer to a boolean to be filled out with the result.
+ * @return Result of operation, if not ok then value pointed to by \a ret will
+ * not be valid.
+ */
+static inline lwc_error
+lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
+{
+ lwc_error err = lwc_error_ok;
+ if (str1->insensitive == NULL) {
+ err = lwc__intern_caseless_string(str1);
+ }
+ if (err == lwc_error_ok && str2->insensitive == NULL) {
+ err = lwc__intern_caseless_string(str2);
+ }
+ if (err == lwc_error_ok)
+ *ret = (str1->insensitive == str2->insensitive);
+ return err;
+}

/**
* Retrieve the data pointer for an interned string.
@@ -228,7 +231,7 @@
* in future. Any code relying on it currently should be
* modified to use ::lwc_string_length if possible.
*/
-#define lwc_string_data(str) ({assert(str != NULL); (const char *)((str)+1);})
+#define lwc_string_data(str) ((const char *)((str)+1))

/**
* Retrieve the data length for an interned string.
@@ -236,7 +239,7 @@
* @param str The string to retrieve the length of.
* @return The length of \a str.
*/
-#define lwc_string_length(str) ({assert(str != NULL); (str)->len;})
+#define lwc_string_length(str) ((str)->len)

/**
* Retrieve (or compute if unavailable) a hash value for the content of the string.
@@ -250,7 +253,7 @@
* to be stable between invocations of the program. Never use the hash
* value as a way to directly identify the value of the string.
*/
-#define lwc_string_hash_value(str) ({assert(str != NULL); (str)->hash;})
+#define lwc_string_hash_value(str) ((str)->hash)

/**
* Retrieve a hash value for the caseless content of the string.
@@ -260,8 +263,8 @@
* @return Result of operation, if not ok then value pointed to by \a ret will
* not be valid.
*/
-static inline lwc_error lwc_string_caseless_hash_value(
- lwc_string *str, lwc_hash *hash)
+static inline lwc_error
+lwc_string_caseless_hash_value(lwc_string *str, lwc_hash *hash)
{
if (str->insensitive == NULL) {
lwc_error err = lwc__intern_caseless_string(str);

No comments:

Post a Comment