From bc9a525687b7ccee10de7bc6f6a729645b1058dd Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Mon, 23 May 2011 21:36:06 +0100 Subject: [PATCH] Don't allow study on an FBM scalar, to give more flexibility in SV flag usage. No real-world code would ever end up studying an FBM scalar, so this isn't a real pessimisation. --- ext/Devel-Peek/t/Peek.t | 26 ++++++++++++++++++++++++-- pp.c | 7 +++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ext/Devel-Peek/t/Peek.t b/ext/Devel-Peek/t/Peek.t index ec54405..7caccd0 100644 --- a/ext/Devel-Peek/t/Peek.t +++ b/ext/Devel-Peek/t/Peek.t @@ -778,6 +778,10 @@ SKIP: { or diag $@; } +# This is more a test of fbm_compile/pp_study (non) interaction than dumping +# prowess, but short of duplicating all the gubbins of this file, I can't see +# a way to make a better place for it: + use constant { perl => 'rules', beer => 'foamy', @@ -789,7 +793,7 @@ unless ($Config{useithreads}) { do_test('regular string constant', perl, 'SV = PV\\($ADDR\\) at $ADDR - REFCNT = 3 + REFCNT = 5 FLAGS = \\(PADMY,POK,READONLY,pPOK\\) PV = $ADDR "rules"\\\0 CUR = 5 @@ -804,7 +808,25 @@ unless ($Config{useithreads}) { do_test('string constant now an FBM', perl, 'SV = PVGV\\($ADDR\\) at $ADDR - REFCNT = 3 + REFCNT = 5 + FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\) + PV = $ADDR "rules"\\\0 + CUR = 5 + LEN = \d+ + MAGIC = $ADDR + MG_VIRTUAL = &PL_vtbl_bm + MG_TYPE = PERL_MAGIC_bm\\(B\\) + FLAGS = 0 + RARE = \d+ + PREVIOUS = 1 + USEFUL = 100 +'); + + is(study perl, '', "Not allowed to study an FBM"); + + do_test('string constant still an FBM', perl, +'SV = PVGV\\($ADDR\\) at $ADDR + REFCNT = 5 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\) PV = $ADDR "rules"\\\0 CUR = 5 diff --git a/pp.c b/pp.c index 3673abd..385f1be 100644 --- a/pp.c +++ b/pp.c @@ -718,12 +718,15 @@ PP(pp_study) RETPUSHYES; } s = (unsigned char*)(SvPV(sv, len)); - if (len == 0 || len > I32_MAX || !SvPOK(sv) || SvUTF8(sv)) { + if (len == 0 || len > I32_MAX || !SvPOK(sv) || SvUTF8(sv) || SvVALID(sv)) { /* No point in studying a zero length string, and not safe to study anything that doesn't appear to be a simple scalar (and hence might change between now and when the regexp engine runs without our set magic ever running) such as a reference to an object with overloaded - stringification. */ + stringification. Also refuse to study an FBM scalar, as this gives + more flexibility in SV flag usage. No real-world code would ever + end up studying an FBM scalar, so this isn't a real pessimisation. + */ RETPUSHNO; } pos = len; -- 2.7.4