This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't allow study on an FBM scalar, to give more flexibility in SV flag usage.
authorNicholas Clark <nick@ccl4.org>
Mon, 23 May 2011 20:36:06 +0000 (21:36 +0100)
committerNicholas Clark <nick@ccl4.org>
Sat, 11 Jun 2011 07:40:01 +0000 (09:40 +0200)
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
pp.c

index ec54405..7caccd0 100644 (file)
@@ -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 (file)
--- 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;