diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-12-02 16:01:10 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-12-02 16:06:09 +0000 |
commit | c2123ae380a372d506d1b6938667bd785fd8728b (patch) | |
tree | 68d6297e99a7e461c2c1e90a5f28c268f5f0988f /pp_hot.c | |
parent | 99f78760b2efe944c387d081557a95783f362f6a (diff) | |
download | perl-c2123ae380a372d506d1b6938667bd785fd8728b.tar.gz |
Ensure that pp_qr returns a new regexp SV each time. Resolves RT #69852.
Instead of returning a(nother) reference to the (pre-compiled) regexp in the
optree, use reg_temp_copy() to create a copy of it, and return a reference to
that. This resolves issues about Regexp::DESTROY not being called in a timely
fashion (the original bug tracked by RT #69852), as well as bugs related to
blessing regexps, and of assigning to regexps, as described in correspondence
added to the ticket.
It transpires that we also need to undo the SvPVX() sharing when ithreads
cloning a Regexp SV, because mother_re is set to NULL, instead of a cloned
copy of the mother_re. This change might fix bugs with regexps and threads in
certain other situations, but as yet neither tests nor bug reports have
indicated any problems, so it might not actually be an edge case that it's
possible to reach.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -1209,10 +1209,13 @@ PP(pp_qr) SV * const rv = sv_newmortal(); SvUPGRADE(rv, SVt_IV); - /* This RV is about to own a reference to the regexp. (In addition to the - reference already owned by the PMOP. */ - ReREFCNT_inc(rx); - SvRV_set(rv, MUTABLE_SV(rx)); + /* For a subroutine describing itself as "This is a hacky workaround" I'm + loathe to use it here, but it seems to be the right fix. Or close. + The key part appears to be that it's essential for pp_qr to return a new + object (SV), which implies that there needs to be an effective way to + generate a new SV from the existing SV that is pre-compiled in the + optree. */ + SvRV_set(rv, MUTABLE_SV(reg_temp_copy(NULL, rx))); SvROK_on(rv); if (pkg) { |