about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-12-02 11:17:15 +0000
committerEric Wong <e@80x24.org>2022-12-09 01:46:05 +0000
commitb44d333bb1a8067680d87b287554770e626cbb86 (patch)
tree6b8f31969d95f41d30970ddf515112a984e74c10
parente635277df62231d2e3cd9bf61b6b079ab0f900e1 (diff)
downloadmwrap-b44d333bb1a8067680d87b287554770e626cbb86.tar.gz
Relying on assert() is difficult since we may be linked
into non-Perl processes via LD_PRELOAD, and Perl headers
will have assert() working on Perl-only symbols which cause
runtime failures during symbol resolution.

Instead of tracking down every potentially assert()-ed symbol
and marking it as weak, it's easier to name our own assert
as `mwrap_assert' and use that everywhere during development.
-rw-r--r--Mwrap.xs4
-rw-r--r--check.h7
-rw-r--r--mwrap_core.h7
-rw-r--r--mymalloc.h2
4 files changed, 10 insertions, 10 deletions
diff --git a/Mwrap.xs b/Mwrap.xs
index 367a4c3..568c246 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -114,7 +114,7 @@ CODE:
                         }
                         if (err)
                                 break;
-                        assert(rcu_read_ongoing());
+                        mwrap_assert(rcu_read_ongoing());
                 }
         }
         if (SvTRUE(ERRSV))
@@ -325,7 +325,7 @@ CODE:
                         LEAVE;
                         if (err)
                                 break;
-                        assert(rcu_read_ongoing());
+                        mwrap_assert(rcu_read_ongoing());
                 }
         }
         if (SvTRUE(ERRSV))
diff --git a/check.h b/check.h
index 1adbf5d..f4f4ac5 100644
--- a/check.h
+++ b/check.h
@@ -3,20 +3,19 @@
 #include "gcc.h"
 #include <stdlib.h>
 #include <assert.h>
-#undef assert
 /*
  * standard assert may malloc, but NDEBUG behavior is standardized,
  * however Perl headers add some weirdness if we undef NDEBUG, so
  * keep NDEBUG defined and use MWRAP_NO_DEBUG
  */
 #if defined(NDEBUG) && defined(MWRAP_NO_DEBUG)
-#  define assert(expr)
+#  define mwrap_assert(expr)
 #  define CHECK(type, expect, expr) (void)(expr)
 #else
-#  define assert(expr) do { if (caa_unlikely(!(expr))) abort(); } while (0)
+#  define mwrap_assert(x) do { if (caa_unlikely(!(x))) abort(); } while (0)
 #  define CHECK(type, expect, expr) do { \
         type checkvar = (expr); \
-        assert(checkvar==(expect)&& "BUG" && __FILE__ && __LINE__); \
+        mwrap_assert(checkvar==(expect)&& "BUG" && __FILE__ && __LINE__); \
         (void)checkvar; \
         } while (0)
 #endif
diff --git a/mwrap_core.h b/mwrap_core.h
index e7723c2..772026f 100644
--- a/mwrap_core.h
+++ b/mwrap_core.h
@@ -228,7 +228,7 @@ static struct src_loc *totals_add_rcu(struct src_loc *k)
 again:
         t = CMM_LOAD_SHARED(totals);
         if (!t) return l;
-        assert(rcu_read_ongoing());
+        mwrap_assert(rcu_read_ongoing());
         cds_lfht_lookup(t, k->hval, loc_eq, k, &iter);
         cur = cds_lfht_iter_get_node(&iter);
         if (cur) {
@@ -314,7 +314,7 @@ static struct src_loc *assign_line(size_t size, const char *file, unsigned line)
         else
                 dst = uint2str(line, dst, &uint_size);
 
-        assert(dst && "bad math");
+        mwrap_assert(dst && "bad math");
         *dst = 0;        /* terminate string */
         k->capa = (uint32_t)(dst - k->k + 1);
         hash_loc(k, k->capa);
@@ -690,7 +690,8 @@ static void dump_destructor(void)
                 char *end = strchr(dump_path, ',');
                 if (end) {
                         char *tmp = tsd.kbuf;
-                        assert((end - dump_path) < sizeof(tsd.kbuf));
+                        mwrap_assert((end - dump_path) <
+                                        (intptr_t)sizeof(tsd.kbuf));
                         end = mempcpy(tmp, dump_path, end - dump_path);
                         *end = 0;
                         dump_path = tmp;
diff --git a/mymalloc.h b/mymalloc.h
index 7b18486..72cb013 100644
--- a/mymalloc.h
+++ b/mymalloc.h
@@ -188,7 +188,7 @@ static size_t remote_free_step(mstate ms)
                         mspace_free(ms, node);
                 }
         }
-        assert(ret != CDS_WFCQ_RET_DEST_NON_EMPTY);
+        mwrap_assert(ret != CDS_WFCQ_RET_DEST_NON_EMPTY);
 
         return nfree;
 }