Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CvEVAL_COMPILED() flag and fix closure bug. #22097

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cv.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ See L<perlguts/Autoloading with XSUBs>.
CVf_METHOD; now CVf_NOWARN_AMBIGUOUS */
#define CVf_XS_RCSTACK 0x200000 /* the XS function understands a
reference-counted stack */
#define CVf_EVAL_COMPILED 0x400000 /* an eval CV is fully compiled */

/* This symbol for optimised communication between toke.c and op.c: */
#define CVf_BUILTIN_ATTRS (CVf_NOWARN_AMBIGUOUS|CVf_LVALUE|CVf_ANONCONST)
Expand Down Expand Up @@ -266,6 +267,10 @@ Helper macro to turn off the C<CvREFCOUNTED_ANYSV> flag.
#define CvXS_RCSTACK_on(cv) (CvFLAGS(cv) |= CVf_XS_RCSTACK)
#define CvXS_RCSTACK_off(cv) (CvFLAGS(cv) &= ~CVf_XS_RCSTACK)

#define CvEVAL_COMPILED(cv) (CvFLAGS(cv) & CVf_EVAL_COMPILED)
#define CvEVAL_COMPILED_on(cv) (CvFLAGS(cv) |= CVf_EVAL_COMPILED)
#define CvEVAL_COMPILED_off(cv) (CvFLAGS(cv) &= ~CVf_EVAL_COMPILED)

/* Back-compat */
#ifndef PERL_CORE
# define CVf_METHOD CVf_NOWARN_AMBIGUOUS
Expand Down
3 changes: 2 additions & 1 deletion dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,8 @@ const struct flag_to_name cv_flags_names[] = {
{CVf_SIGNATURE, "SIGNATURE,"},
{CVf_REFCOUNTED_ANYSV, "REFCOUNTED_ANYSV,"},
{CVf_IsMETHOD, "IsMETHOD,"},
{CVf_XS_RCSTACK, "XS_RCSTACK,"}
{CVf_XS_RCSTACK, "XS_RCSTACK,"},
{CVf_EVAL_COMPILED, "EVAL_COMPILED,"},
};

const struct flag_to_name hv_flags_names[] = {
Expand Down
1 change: 1 addition & 0 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -4702,6 +4702,7 @@ Perl_newPROG(pTHX_ OP *o)
SAVEFREEOP(o);
ENTER;
S_process_optree(aTHX_ NULL, PL_eval_root, start);
CvEVAL_COMPILED_on(PL_compcv); /* this eval is now fully compiled */
LEAVE;
PL_savestack_ix = i;
}
Expand Down
5 changes: 3 additions & 2 deletions pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,9 @@ index into the parent pad.
*/

/* the CV has finished being compiled. This is not a sufficient test for
* all CVs (eg XSUBs), but suffices for the CVs found in a lexical chain */
#define CvCOMPILED(cv) CvROOT(cv)
* all CVs (eg XSUBs), but suffices for the CVs found in a lexical chain.
* Note that a fully-compiled eval doesn't get CvROOT() set. */
#define CvCOMPILED(cv) (CvROOT(cv) || CvEVAL_COMPILED(cv))

/* the CV does late binding of its lexicals */
#define CvLATE(cv) (CvANON(cv) || CvCLONE(cv) || SvTYPE(cv) == SVt_PVFM)
Expand Down
19 changes: 18 additions & 1 deletion t/op/eval.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
set_up_inc('../lib');
}

plan(tests => 169);
plan(tests => 170);

eval 'pass();';

Expand Down Expand Up @@ -768,3 +768,20 @@ pass("eval in freed package does not crash");
);
}
}

# The first inner eval finds the $v and adds a fake entry to the
# outer eval's pad. The second inner eval finds the fake $c entry,
# but was incorrectly concluding that the outer eval was in fact a
# non-live anon prototype and issuing the warning
# 'Variable "$v" is not available'/

{
use warnings;
my $w = 0;
local $SIG{__WARN__} = sub { $w++ };
sub {
my $v;
eval q( eval '$v'; eval '$v';);
}->();
is($w, 0, "nested eval and closure");
}
Loading