Below is a patch that moves REGEXP out of PMOPs and into an PL_regex_padav.
The offset is stored in PMOP->op_pmoffset.
As soon as Perl_re_dup is finished (incoming later from AMS) this will clone all
regexes to be
thread specific. This does not put them on the pad as Sarathy suggest, putting
the regexes
on the pad changes semantics of perl and is rather non trivial compared to this.
It can however be done later.
Problems might be the pm flags, if so we will have to move them out of this and
onto a seperate list.
I don't fully grok the flags and left them as existing. Could somone comment on
this?
All tests pass, my threads test pass, I suggest applying it.
Artur
--- perl-current-copy/sv.c Wed Jul 11 11:50:54 2001
+++ perl-current/sv.c Wed Jul 11 13:53:02 2001
@@ -9693,6 +9693,19 @@
PL_statusvalue_vms = proto_perl->Istatusvalue_vms;
#endif
+ /* Clone the regex array */
+ PL_regex_padav = newAV();
+ {
+ I32 len = av_len((AV*)proto_perl->Iregex_padav);
+ SV** regexen = AvARRAY((AV*)proto_perl->Iregex_padav);
+ for(i = 0; i <= len; i++) {
+ av_push(PL_regex_padav,
+ newSViv((IV)re_dup((REGEXP*) SvIV(regexen[i])) ));
+ }
+ }
+ PL_regex_pad = AvARRAY(PL_regex_padav);
+
+
/* shortcuts to various I/O objects */
PL_stdingv = gv_dup(proto_perl->Istdingv, param);
PL_stderrgv = gv_dup(proto_perl->Istderrgv, param);
--- perl-current-copy/op.h Wed Jul 11 11:50:53 2001
+++ perl-current/op.h Wed Jul 11 12:38:10 2001
@@ -235,7 +235,11 @@
OP * op_pmreplroot;
OP * op_pmreplstart;
PMOP * op_pmnext; /* list of all scanpats */
- REGEXP * op_pmregexp; /* compiled expression */
+#ifdef USE_ITHREADS
+ I32 op_pmoffset;
+#else
+ REGEXP * op_pmregexp; /* compiled expression */
+#endif
U16 op_pmflags;
U16 op_pmpermflags;
U8 op_pmdynflags;
@@ -246,8 +250,13 @@
#endif
};
+#ifdef USE_ITHREADS
+#define PM_GETRE(o) ((REGEXP*)SvIV(PL_regex_pad[(o)->op_pmoffset]))
+#define PM_SETRE(o,r) (sv_setiv(PL_regex_pad[(o)->op_pmoffset], (IV)r))
+#else
#define PM_GETRE(o) ((o)->op_pmregexp)
#define PM_SETRE(o,r) ((o)->op_pmregexp = (r))
+#endif
#define PMdf_USED 0x01 /* pm has been used once already */
#define PMdf_TAINTED 0x02 /* pm compiled from tainted pattern */
--- perl-current-copy/op.c Wed Jul 11 11:50:53 2001
+++ perl-current/op.c Wed Jul 11 12:38:16 2001
@@ -2952,7 +2952,16 @@
pmop->op_pmpermflags |= PMf_LOCALE;
pmop->op_pmflags = pmop->op_pmpermflags;
- /* link into pm list */
+ #ifdef USE_ITHREADS
+ {
+ SV* repointer = newSViv(0);
+ av_push(PL_regex_padav,repointer);
+ pmop->op_pmoffset = av_len(PL_regex_padav);
+ PL_regex_pad = AvARRAY(PL_regex_padav);
+ }
+ #endif
+
+ /* link into pm list */
if (type != OP_TRANS && PL_curstash) {
pmop->op_pmnext = HvPMROOT(PL_curstash);
HvPMROOT(PL_curstash) = pmop;
--- perl-current-copy/intrpvar.h Wed Jul 11 11:50:53 2001
+++ perl-current/intrpvar.h Wed Jul 11 12:22:10 2001
@@ -475,6 +475,11 @@
#endif
+#if defined(USE_ITHREADS)
+PERLVAR(Iregex_pad, SV**) /* All regex objects */
+PERLVAR(Iregex_padav, AV*) /* All regex objects */
+#endif
+
/* New variables must be added to the very end for binary compatibility.
* XSUB.h provides wrapper functions via perlapi.h that make this
* irrelevant, but not all code may be expected to #include XSUB.h. */
--- perl-current-copy/perl.c Wed Jul 11 11:50:53 2001
+++ perl-current/perl.c Wed Jul 11 12:23:53 2001
@@ -312,7 +312,9 @@
PL_fdpid = newAV(); /* for remembering popen pids by fd */
PL_modglobal = newHV(); /* pointers to per-interpreter module
globals */
PL_errors = newSVpvn("",0);
-
+#ifdef USE_ITHREADS
+ PL_regex_padav = newAV();
+#endif
ENTER;
}