* [PATCH] provide mwrap_assert due to Perl header conflicts
@ 2022-12-02 11:17 Eric Wong
2022-12-09 1:45 ` Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2022-12-02 11:17 UTC (permalink / raw)
To: mwrap-perl
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 <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..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;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] provide mwrap_assert due to Perl header conflicts
2022-12-02 11:17 [PATCH] provide mwrap_assert due to Perl header conflicts Eric Wong
@ 2022-12-09 1:45 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2022-12-09 1:45 UTC (permalink / raw)
To: mwrap-perl
Eric Wong <e@80x24.org> wrote:
> diff --git a/mwrap_core.h b/mwrap_core.h
> index e7723c2..11b7346 100644
> --- a/mwrap_core.h
> +++ b/mwrap_core.h
> @@ -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));
-Wsign-compare alerted me to this:
diff --git a/mwrap_core.h b/mwrap_core.h
index 11b7346..772026f 100644
--- a/mwrap_core.h
+++ b/mwrap_core.h
@@ -690,7 +690,8 @@ static void dump_destructor(void)
char *end = strchr(dump_path, ',');
if (end) {
char *tmp = tsd.kbuf;
- mwrap_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;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-09 1:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02 11:17 [PATCH] provide mwrap_assert due to Perl header conflicts Eric Wong
2022-12-09 1:45 ` Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap-perl.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).