Stop SVt_REGEXPs from being upgraded.
authorFather Chrysostomos <sprout@cpan.org>
Sat, 22 Jun 2013 07:51:14 +0000 (00:51 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 23 Jun 2013 06:16:41 +0000 (23:16 -0700)
Any code that is going to write over a REGEXP will call
sv_force_normal first, which converts it to

This code started crashing in 5.12:

$_ = qr//;
@INC = sub { $_ };
require foo;

Search pattern not terminated at /loader/0x7fe3b082c2e8/foo.pm line 1.
Compilation failed in require at - line 4.
Segmentation fault: 11

With current bleadperl:

foo.pm did not return a true value at - line 4.
Segmentation fault: 11

This change makes it like this instead:

Can't upgrade REGEXP (8) to 15 at - line 3.

which is certainly an improvement.  We shouldn’t be getting any error
at all (OK, just a syntax error because (?^:) is not a valid expres-
sion), and the next commit will fix that, but this commit at least
turns a crash into a panic, in case future changes accidentally send a
regexp through sv_upgrade(sv, SVt_PVIO).

sv.c

diff --git a/sv.c b/sv.c
index 52af1d2..db0fac5 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -921,7 +921,7 @@ static const struct body_details bodies_by_type[] = {
     { sizeof(regexp),
       sizeof(regexp),
       0,
-      SVt_REGEXP, FALSE, NONV, HASARENA,
+      SVt_REGEXP, TRUE, NONV, HASARENA,
       FIT_ARENA(0, sizeof(regexp))
     },