diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-07-21 00:38:28 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-07-23 14:53:23 -0700 |
commit | 6174b39a88cd48740c024cfb6035edb6ffed9f2d (patch) | |
tree | 07f2c3b7d17fa361cd5fa1252b14b4a739fb2c60 /t/bigmem | |
parent | ef54055c17bc9effcdf6a8135d2b375b7c35dd62 (diff) | |
download | perl-6174b39a88cd48740c024cfb6035edb6ffed9f2d.tar.gz |
[perl #72766] Allow huge pos() settings
This is part of #116907, too. It also fixes #72924 as a side effect;
the next commit will explain.
The value of pos($foo) was being stored as an I32, not allowing values
above I32_MAX. Change it to SSize_t (the signed equivalent of size_t,
representing the maximum string length the OS/compiler supports).
This is accomplished by changing the size of the entry in the magic
struct, which is the simplest fix.
Other parts of the code base can benefit from this, too.
We actually cast the pos value to STRLEN (size_t) when reading
it, to allow *very* long strings. Only the value -1 is special,
meaning there is no pos. So the maximum supported offset is
2**sizeof(size_t)-2.
The regexp engine itself still cannot handle large strings, so being
able to set pos to large values is useless right now. This is but one
piece in a larger puzzle.
Changing the size of mg->mg_len also requires that
Perl_hv_placeholders_p change its type. This function
should in fact not be in the API, since it exists
solely to implement the HvPLACEHOLDERS macro. See
<https://rt.perl.org/rt3/Ticket/Display.html?id=116907#txn-1237043>.
Diffstat (limited to 't/bigmem')
-rw-r--r-- | t/bigmem/pos.t | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/t/bigmem/pos.t b/t/bigmem/pos.t new file mode 100644 index 0000000000..aad93f636d --- /dev/null +++ b/t/bigmem/pos.t @@ -0,0 +1,25 @@ +#!perl +BEGIN { + chdir 't'; + unshift @INC, "../lib"; + require './test.pl'; +} + +use Config qw(%Config); + +$ENV{PERL_TEST_MEMORY} >= 2 + or skip_all("Need ~2Gb for this test"); +$Config{ptrsize} >= 8 + or skip_all("Need 64-bit pointers for this test"); + +plan(3); + +# [perl #116907] +# ${\2} to defeat constant folding, which in this case actually slows +# things down +my $x=" "x(${\2}**31+20); +pos $x = 2**31-5; +is pos $x, 2147483643, 'setting pos on large string'; +pos $x += 10; +is pos $x, 2147483653, 'reading lvalue pos after setting it > 2**31'; +is scalar(pos $x), 2147483653, 'reading it with pos() in rvalue context'; |