develooper Front page | perl.perl5.porters | Postings from September 2003

[PATCH #2] Re: [perl #23576] valgrind errors for /(?{})/ in t/op/pat.t

Thread Previous
From:
Dave Mitchell
Date:
September 19, 2003 11:35
Subject:
[PATCH #2] Re: [perl #23576] valgrind errors for /(?{})/ in t/op/pat.t
Message ID:
20030919183544.GA14563@fdgroup.com
On Fri, Sep 19, 2003 at 01:26:26AM +0100, hv@crypt.org wrote:
> Dave Mitchell <davem@fdgroup.com> wrote:
> :Perl_sv_compile_2op() is trying to distinguish between compile-time and
> :runtime behaviour, ie between
> :
> :    /(?{1})/
> :and
> :    $x = '(?{1})'; /$x/
> :
> :with the following line (written by me a few months ago):
> :
> :    /* we get here either during compilation, or via pp_regcomp at runtime */
> :    runtime = PL_op && (PL_op->op_type == OP_REGCOMP);
> :
> :But in the compoile-time case, PL_op isn't guaranteed to be pointing to
> :anything sensible (eg in the test code that valgrind is complaining about,
> :it happens to point to a recently-freed op).
> :
> :Does anyone know of a safe way that I can distinguish between compile-time
> :and run-time calls to sv_compile_2op() ?
> 
> I'm not sure that I understand there _is_ a difference: I mean, both
> of those could be wrapped in an either an eval or a BEGIN block, right?

The difference is whether the CV that contains the regex currently being
compiled can be found in PL_compcv or by looking on the CX stack; this CV
is needed to locate outer lexicals. From my perspective, I would regard
the following two lines as respectively compile-time and run-time calls to
Perl_sv_compile_2op():

    eval '/(?{1})/'
    eval '$x="(?{1})"; /$x/'

> Are you just trying to determine from which of two places sv_compile_2op()
> is being called?

Unfortunately it is only directly called from one place, S_reg. It is much
further up the call stack that the difference occurs.

On Thu, Sep 18, 2003 at 09:27:47AM +0200, Rafael Garcia-Suarez wrote:
> (Maybe a silly idea)
> Compare PL_curcop and &PL_compiling ?

Seems to work, ie gives the same results as my previous method in all the
test suite, but without the valgrind errors.

So here's the patch:

-- 
Thank God I'm an atheist.....


--- pp_ctl.c-	Fri Sep 19 19:17:55 2003
+++ pp_ctl.c	Fri Sep 19 19:13:38 2003
@@ -2710,7 +2710,7 @@ Perl_sv_compile_2op(pTHX_ SV *sv, OP** s
     PL_hints &= HINT_UTF8;
 
     /* we get here either during compilation, or via pp_regcomp at runtime */
-    runtime = PL_op && (PL_op->op_type == OP_REGCOMP);
+    runtime = (PL_curcop != &PL_compiling);
     if (runtime)
 	runcv = find_runcv(NULL);
 

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About