From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C9A461F601 for ; Fri, 2 Dec 2022 11:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1669979835; bh=cAE1dl501ifCEt8Eh2TWCPiovJy0cm59MQFfBTL5P/4=; h=From:To:Subject:Date:From; b=fpFqaxQ5fBfb6nBu4zc8P+AW7kQ0Zl7pQtM+TVHhTcG6DHgiwQWzyvbUMVef96tk7 j9C8QHMuzSqPou+wCE5BkYrQAV9rWyVLk4+DDG+Hf+kKVr0oELfHPEXhCAtrqLi2jP fbtoEwWESoDQmdUh1JCxP/b4o6F46Vf/AMaK1Gcw= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH] provide mwrap_assert due to Perl header conflicts Date: Fri, 2 Dec 2022 11:17:15 +0000 Message-Id: <20221202111715.822960-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- Mwrap.xs | 4 ++-- check.h | 7 +++---- mwrap_core.h | 6 +++--- mymalloc.h | 2 +- 4 files changed, 9 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 #include -#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..11b7346 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,7 @@ 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) < 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; }