diff options
author | David Mitchell <davem@iabyn.com> | 2012-06-04 13:52:05 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2012-06-13 13:32:55 +0100 |
commit | 497d0a962eb278e5235610fab370cb59f4a5d7c4 (patch) | |
tree | a0b5234799a208523e151f56ff6c310c3218f46d /regexec.c | |
parent | e4bfbed39bdcbc5cd76c9cdfdeb3314c3710ad62 (diff) | |
download | perl-497d0a962eb278e5235610fab370cb59f4a5d7c4.tar.gz |
handle (??{}) returning an overloaded value
In this case, always pass the object to the regex compiler, which
knows how handle this.
(The diff looks more complex than it actually is: it just wraps
the whole (logical == 2) branch with an 'if (!SvAMAGIC(ret))'.)
Diffstat (limited to 'regexec.c')
-rw-r--r-- | regexec.c | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -4406,8 +4406,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog) /* before restoring everything, evaluate the returned * value, so that 'uninit' warnings don't use the wrong - * PL_op or pad. Also need to process any magic vars (e.g. - * $1 *before* parentheses are restored */ + * PL_op or pad. Also need to process any magic vars + * (e.g. $1) *before* parentheses are restored */ PL_op = NULL; @@ -4418,22 +4418,26 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog) logical = 0; } else { /* /(??{}) */ - SV *sv = ret; re_sv = NULL; - if (SvROK(sv)) - sv = SvRV(sv); - if (SvTYPE(sv) == SVt_REGEXP) - re_sv = (REGEXP*) sv; - else if (SvSMAGICAL(sv)) { - MAGIC *mg = mg_find(sv, PERL_MAGIC_qr); - if (mg) - re_sv = (REGEXP *) mg->mg_obj; - } + /* if its overloaded, let the regex compiler handle + * it; otherwise extract regex, or stringify */ + if (!SvAMAGIC(ret)) { + SV *sv = ret; + if (SvROK(sv)) + sv = SvRV(sv); + if (SvTYPE(sv) == SVt_REGEXP) + re_sv = (REGEXP*) sv; + else if (SvSMAGICAL(sv)) { + MAGIC *mg = mg_find(sv, PERL_MAGIC_qr); + if (mg) + re_sv = (REGEXP *) mg->mg_obj; + } - /* force any magic, undef warnings here */ - if (!re_sv && !SvAMAGIC(ret)) { - ret = sv_mortalcopy(ret); - (void) SvPV_force_nolen(ret); + /* force any magic, undef warnings here */ + if (!re_sv) { + ret = sv_mortalcopy(ret); + (void) SvPV_force_nolen(ret); + } } } |