about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-09-15 20:31:59 +0000
committerEric Wong <e@80x24.org>2022-09-20 22:35:03 +0000
commitad099a42014469ed4369613f9f179f433e6b61b2 (patch)
treeadb2019ecd518835b0e644a0d7aa6cd273a8ab45
parent3197316f33fdc5d487c5bdbb9eb029d443d3c8bf (diff)
downloadmwrap-ad099a42014469ed4369613f9f179f433e6b61b2.tar.gz
This is needed to avoid segfaults in non-Perl processes
such as `cmake'.

Fixes: 3197316f33fdc5d4 "create the `totals' rculfhash as early as possible"
-rw-r--r--Mwrap.xs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Mwrap.xs b/Mwrap.xs
index 092aaf4..31e9394 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -344,18 +344,20 @@ update_stats_rcu_lock(size_t *generation, size_t size, uintptr_t caller)
         struct src_loc *k, *ret = 0;
         static const size_t xlen = sizeof(caller);
         char *dst;
-        const COP *cop;
+        const COP *cop = NULL;
         struct cds_lfht *t = CMM_LOAD_SHARED(totals);
 
         if (caa_unlikely(!t)) return 0;
         if (locating++) goto out; /* do not recurse into another *alloc */
 
         *generation = uatomic_add_return(&total_bytes_inc, size);
+        if (&PL_thr_key) { /* are we even in a Perl process? */
 #ifdef PERL_IMPLICIT_CONTEXT
-        cop = aTHX ? PL_curcop : 0;
+                if (aTHX) cop = PL_curcop;
 #else
-        cop = &locating == root_locating ? PL_curcop : 0;
+                if (&locating == root_locating) cop = PL_curcop;
 #endif
+        }
         rcu_read_lock();
         if (cop) {
                 const char *ptr = OutCopFILE(cop);