/* ... Thread safety and multiplicity ...................................... */
+/* Safe unless stated otherwise in Makefile.PL */
+#ifndef REP_FORKSAFE
+# define REP_FORKSAFE 1
+#endif
+
#ifndef REP_MULTIPLICITY
# if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT)
# define REP_MULTIPLICITY 1
ptable_store(ud->tbl, ent->key, h2);
}
-#include "reap.h"
-
STATIC void rep_thread_cleanup(pTHX_ void *ud) {
dMY_CXT;
ptable_free(MY_CXT.tbl);
}
+STATIC int rep_endav_free(pTHX_ SV *sv, MAGIC *mg) {
+ SAVEDESTRUCTOR_X(rep_thread_cleanup, NULL);
+
+ return 0;
+}
+
+STATIC MGVTBL rep_endav_vtbl = {
+ 0,
+ 0,
+ 0,
+ 0,
+ rep_endav_free
+#if MGf_COPY
+ , 0
+#endif
+#if MGf_DUP
+ , 0
+#endif
+#if MGf_LOCAL
+ , 0
+#endif
+};
+
#endif /* REP_THREADSAFE */
STATIC SV *rep_validate_callback(SV *code) {
STATIC SV *rep_tag(pTHX_ SV *comp, SV *exec) {
#define rep_tag(C, E) rep_tag(aTHX_ (C), (E))
rep_hint_t *h;
- dMY_CXT;
h = PerlMemShared_malloc(sizeof *h);
h->comp = rep_validate_callback(comp);
* already set up all the stuff we're going to to need for
* subsequent exec and other calls */
if (h->comp) {
- ENTER;
+ ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(obj);
PUTBACK;
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(rx->pprivate);
XPUSHs(sv);
PUTBACK;
call_sv(self->cb_exec, G_SCALAR);
-
+
SPAGAIN;
ret = POPs;
void
Plugin_free(pTHX_ REGEXP * const RX)
{
- struct regexp *rx = rxREGEXP(RX);
- GET_SELF_FROM_PPRIVATE(rx->pprivate);
+ struct regexp *rx;
+ re__engine__Plugin self;
+
+ if (PL_dirty)
+ return;
+
+ rx = rxREGEXP(RX);
+ SELF_FROM_PPRIVATE(self, rx->pprivate);
SvREFCNT_dec(self->pattern);
SvREFCNT_dec(self->str);
if (callback) {
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(rx->pprivate);
PUTBACK;
if (callback) {
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(rx->pprivate);
XPUSHs(sv_2mortal(newSViv(paren)));
PUTBACK;
items = call_sv(callback, G_SCALAR);
-
+
if (items == 1) {
SV *ret;
if (callback) {
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(rx->pprivate);
XPUSHs(sv_2mortal(newSViv(paren)));
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(rx->pprivate);
XPUSHs(sv_2mortal(newSViv(paren)));
BOOT:
{
if (!rep_booted++) {
+ HV *stash;
+
PERL_HASH(rep_hash, __PACKAGE__, __PACKAGE_LEN__);
+
+ stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
+ newCONSTSUB(stash, "REP_THREADSAFE", newSVuv(REP_THREADSAFE));
+ newCONSTSUB(stash, "REP_FORKSAFE", newSVuv(REP_FORKSAFE));
}
rep_setup();
CLONE(...)
PREINIT:
ptable *t;
+ GV *gv;
PPCODE:
{
rep_ptable_clone_ud ud;
MY_CXT.tbl = t;
MY_CXT.owner = aTHX;
}
- reap(3, rep_thread_cleanup, NULL);
+ gv = gv_fetchpv(__PACKAGE__ "::_THREAD_CLEANUP", 0, SVt_PVCV);
+ if (gv) {
+ CV *cv = GvCV(gv);
+ if (!PL_endav)
+ PL_endav = newAV();
+ SvREFCNT_inc(cv);
+ if (!av_store(PL_endav, av_len(PL_endav) + 1, (SV *) cv))
+ SvREFCNT_dec(cv);
+ sv_magicext((SV *) PL_endav, NULL, PERL_MAGIC_ext, &rep_endav_vtbl, NULL, 0);
+ }
+ XSRETURN(0);
+
+void
+_THREAD_CLEANUP(...)
+PROTOTYPE: DISABLE
+PPCODE:
+ rep_thread_cleanup(aTHX_ NULL);
XSRETURN(0);
#endif /* REP_THREADSAFE */