This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
10 years agogv.c:newGP: assert that PL_curcop is not NULL
Father Chrysostomos [Sat, 10 Aug 2013 18:55:11 +0000 (11:55 -0700)]
gv.c:newGP: assert that PL_curcop is not NULL

It should never be null here, and we want to know if it is.  (It can
be set to null in op.c:S_cop_free, but it should always have been set
to something else by the time newGP is called.)

Nevertheless, we should leave the null checks in place, to avoid sabo-
taging non-debugging builds if there are any remaining bugs here.

10 years agogv.c:newGP: merge some threaded and non-threaded code
Father Chrysostomos [Sat, 10 Aug 2013 17:51:07 +0000 (10:51 -0700)]
gv.c:newGP: merge some threaded and non-threaded code

The previous commit cause the two alternate pieces of code to be
nearly identical.

10 years agoRestore NULL check to gv.c:newGP, removed by 19bad673
Father Chrysostomos [Sat, 10 Aug 2013 17:46:43 +0000 (10:46 -0700)]
Restore NULL check to gv.c:newGP, removed by 19bad673

1df5f7c195 added checks to newGP to account for PL_curcop being NULL.
19bad673 inadvertently removed the NULL check for non-threaded builds,
except in one spot.

Since S_cop_free now sets PL_curcop to NULL as of the previous commit
(something 1df5f7c195 was meant to do but didn’t), this check is a
good idea, even though PL_curcop is never NULL here.

See also <20130805200313.GS3729@plum.flirble.org>.

10 years agoSet PL_curcop to NULL in op.c:S_cop_free
Father Chrysostomos [Sat, 10 Aug 2013 17:41:11 +0000 (10:41 -0700)]
Set PL_curcop to NULL in op.c:S_cop_free

Having PL_curcop pointing to a freed op is a Bad Idea and something
that has caused bugs in the past.

The intent of commit 1df5f7c195 was to do this, but this part of
the commit was accidentally omitted.

See <20130805200313.GS3729@plum.flirble.org>.

10 years agoMake ++ handle regexps and vstrings
Father Chrysostomos [Sat, 10 Aug 2013 17:38:08 +0000 (10:38 -0700)]
Make ++ handle regexps and vstrings

$ ./perl -Ilib -e 'use Devel::Peek; $x = v97; ++$x; Dump $x'
SV = PVMG(0x7fbfa402b698) at 0x7fbfa402eed8
  REFCNT = 1
  FLAGS = (RMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x7fbfa3c066a8 "b"\0
  CUR = 1
  LEN = 24
  MAGIC = 0x7fbfa3c06348
    MG_VIRTUAL = 0
    MG_TYPE = PERL_MAGIC_vstring(V)
    MG_LEN = 3
    MG_PTR = 0x7fbfa3c13ee8 "v97"

The vstring magic is still attached (with something that does not
match the contents of the string), even after modifying it.  I
probably broke that in 5.18 after fixing it in 5.16, but I am too
lazy to check.

$ ./perl -le '$x = ${qr//}; $x++; print "$x"'
Assertion failed: (PL_valid_types_IVX[SvTYPE(_svivx) & SVt_MASK]), function Perl_sv_2pv_flags, file sv.c, line 2908.
Abort trap: 6

That I broke when I stopped regexps from being POK in perl 5.18.0.

It was creating a corrupt SV by setting the IOK flag on something of
type SVt_REGEXP.

10 years agoStop -- from crashing on regexps
Father Chrysostomos [Sat, 10 Aug 2013 17:01:06 +0000 (10:01 -0700)]
Stop -- from crashing on regexps

I mean dereferenced regexps, as returned by ${ qr// }.

It was creating a corrupt SV by setting the IOK flag on something
of type SVt_REGEXP.

This is something I broke when I stopped regexps from being POK
in perl 5.18.0.

10 years agoMake PL_hints an alias for PL_compiling.cop_hints
Father Chrysostomos [Sun, 11 Aug 2013 15:08:08 +0000 (08:08 -0700)]
Make PL_hints an alias for PL_compiling.cop_hints

PL_hints stores the hints at compile time that get copied into the
cop_hints field of each COP (in newSTATEOP).

Since perl-5.8.0-8053-gd5ec298, COPs have stored all the hints.

Before that, COPs used to store only some of the hints.  The hints
were copied here and there into PL_compiling, a static COP-shaped buf-
fer used during compilation, so that things like constant folding
would see the correct hints.  a0ed51b3 back in 1998 did that.

Now that COPs can store all the hints, we can just use
PL_compiling.cop_hints to avoid having to copy them from PL_hints from
time to time.

This simplifies the code and avoids creating bugs like those that
a547fd219 and 1c75beb82 fixed.

10 years agoModifying ${^OPEN} changes the value of $^H:
Father Chrysostomos [Sat, 10 Aug 2013 16:49:28 +0000 (09:49 -0700)]
Modifying ${^OPEN} changes the value of $^H:

$ ./perl -le 'BEGIN { print $^H; ${^OPEN} = "a\0b"; print $^H}'
256
917760

So changing $^H back should change the value of ${^OPEN} back to undef, right?

$ ./perl -le 'BEGIN { ${^OPEN} = "a\0b"; $^H=256; print ${^OPEN}//"undef"}'
ab
$ ./perl -le 'BEGIN { ${^OPEN} = "a\0b"; $^H=256;}BEGIN{ print ${^OPEN}//"undef"}'
undef

Apparently you have to hop from one BEGIN block to another to see
the changes.

This happens because compile-time hints are stored in PL_hints (which
$^H sets) but ${^OPEN} looks in PL_compiling.cop_hints.  Setting
${^OPEN} sets both.  The contents of PL_hints are assigned to
PL_compiling.cop_hints at certain points (the start of a BEGIN block
sees the right value because newSTATEOP sets it), but the two are not
always kept in synch.

The smallest fix here is to have $^H set PL_compiling.cop_hints as
well as PL_hints, but the ultimate fix--to come later--is to merge the
two and stop storing hints in two different places.

10 years agosv.c: Remove more ro exceptions that c72a4ee missed.
Father Chrysostomos [Sat, 10 Aug 2013 13:07:07 +0000 (06:07 -0700)]
sv.c: Remove more ro exceptions that c72a4ee missed.

10 years agoFix booleanness of regexps
Father Chrysostomos [Sat, 10 Aug 2013 12:30:41 +0000 (05:30 -0700)]
Fix booleanness of regexps

I broke this when I stopped regexps from being POK in 5.18.

10 years agoMake SvPVbyte work on tied non-PV
Father Chrysostomos [Sat, 10 Aug 2013 11:48:17 +0000 (04:48 -0700)]
Make SvPVbyte work on tied non-PV

The magic check came too late.  sv_utf8_downgrade does nothing if the
argument is not a PV.

So in the test added to svpv.t the returned string was in utf8,
not bytes.

10 years ago[Merge] Handle @INC filter return values better
Father Chrysostomos [Sun, 11 Aug 2013 14:51:25 +0000 (07:51 -0700)]
[Merge] Handle @INC filter return values better

10 years agopp_ctl.c:S_run_user_filter: remove GMAGICAL check
Father Chrysostomos [Sat, 10 Aug 2013 01:14:31 +0000 (18:14 -0700)]
pp_ctl.c:S_run_user_filter: remove GMAGICAL check

We have already called get-magic at this point, so SvOK will give
the right answer even for magical variables.  Concatenating it when
gmagical could give an uninitialised warning if it is undef, so
we don’t want to do that, as it would cause magical and non-mag-
ical undefs to behave differently.  I don’t know how to write a
test for this.

10 years agoHandle magical return values from @INC filter
Father Chrysostomos [Fri, 9 Aug 2013 20:32:30 +0000 (13:32 -0700)]
Handle magical return values from @INC filter

An @INC filter (a subroutined returned by a subroutine in @INC) could
be an lvalue sub that returns a magical scalar for the status.  We
need to account for that.

If we don’t call get-magic (FETCH), we’ll get the last value assigned
to or returned from that scalar.

10 years agoSetting $_ to multiline glob in @INC filter
Father Chrysostomos [Fri, 9 Aug 2013 20:01:39 +0000 (13:01 -0700)]
Setting $_ to multiline glob in @INC filter

This commit corrects the one remaining code path in
pp_ctl.c:S_run_user_filter that was not handling non-PVs.

If we have to truncate $_ and keep the remainder in a cache (because
it has more than one line), we need to make sure we don’t assume it is
a PV when it comes to truncating it.

$ ./perl -Ilib -e '@INC = sub { sub { return 0 if $|--; $_ = *{"foo;\nbar"}; return 1 } }; do "foo"'
Assertion failed: (!isGV_with_GP(upstream)), function S_run_user_filter, file pp_ctl.c, line 5494.
Abort trap: 6

10 years agoincfilter.t: squelch warning
Father Chrysostomos [Fri, 9 Aug 2013 15:43:16 +0000 (08:43 -0700)]
incfilter.t: squelch warning

10 years agoTying $_ in @INC filter
Father Chrysostomos [Fri, 9 Aug 2013 15:42:32 +0000 (08:42 -0700)]
Tying $_ in @INC filter

Crazy?  Probably.  But the existing code partially handles magic val-
ues already; it’s just buggy.  Also, the magic value could come from
another source filter that is not registered via @INC, and this is one
way to test that code path.

10 years agoHandle non-PV $_ in @INC filters
Father Chrysostomos [Thu, 8 Aug 2013 19:49:57 +0000 (12:49 -0700)]
Handle non-PV $_ in @INC filters

@INC filters (code refs returned by code refs in @INC) are given the
current line of code in $_ and can modify it.  The C code that invokes
the Perl filter is in pp_ctl.c:S_run_user_filter.  It was not taking
into account that $_ might not have a PV pointer when it is returned,
and so this could result in crashes or assertion failures.

This commit forces the scalar to be a string before returning it to
the lexer, unless it is undef.  If we force it to be a string when it
is undef, then existing tests start producing uninitialized warnings.

The logic is still faulty in places.  Subsequent commits will
address that.

10 years agoop.c: Force shared hash key optimisation for existing COWs
Father Chrysostomos [Wed, 7 Aug 2013 15:52:23 +0000 (08:52 -0700)]
op.c: Force shared hash key optimisation for existing COWs

If COW scalars are becoming more prevalent (they are), the hash key
optimisation will be less and less likely to kick in if it is skipped
for anything already SvIsCOW.

The assumption is that such a scalar is already a shared hash key sca-
lar.  That is not true for copy-on-write scalars made such by the new
mechanism that allows existing non-COW scalar to be upgraded to such.

The purpose of using shared hash keys scalars here is that the precom-
puted hash is already stored in the scalar (ok, it points to it indi-
rectly), speeding up hash lookup.

New COW scalars don’t have that and offer no speedup here.

So skip the optimisation only when the COW scalar is a shared hash
key scalar.

All of the above applies to methods as well.

10 years ago[Merge] Read-only COWs
Father Chrysostomos [Sun, 11 Aug 2013 14:41:45 +0000 (07:41 -0700)]
[Merge] Read-only COWs

Commit 9a0a85075 made shared hash key constants read-only.  This meant
that copy-on-write scalars (shared hash key scalars are one type
of this) could have the read-only flag set, which could not hap-
pen before.

Much code still assumed that read-only && !cow was the proper way to
check for read-onliness (which was correct before perl 5.18, when
READONLY+FAKE meant COW).

This branch fixes up all the instances if SvIsCOW to work correctly
with read-only COWs.

It also allows Internals::SvREADONLY to make a COW read-only without
stopping it from being a COW (affecting constant.pm and Hash::Util).

I also went and fixed up tests under -DPERL_OLD_COPY_ON_WRITE and
-DPERL_NO_COW, in the process of making sure I wasn’t breaking those.

10 years agoDon’t allow read-only COWs to be blessed
Father Chrysostomos [Sat, 10 Aug 2013 20:06:26 +0000 (13:06 -0700)]
Don’t allow read-only COWs to be blessed

The logic exempting copy-on-write scalars from read-only checks in
sv_bless was left over from when READONLY+FAKE meant copy-on-write.

10 years agoIn sv.c:sv_magic don’t allow tying ro COWs
Father Chrysostomos [Sat, 10 Aug 2013 13:06:56 +0000 (06:06 -0700)]
In sv.c:sv_magic don’t allow tying ro COWs

Read-only COWs are read-only and should not be treated as though they
were not.  This logic is left over from when READONLY+FAKE meant
copy-on-write.

10 years agoStop system select from croaking on read-only COW ""
Father Chrysostomos [Sat, 10 Aug 2013 03:22:29 +0000 (20:22 -0700)]
Stop system select from croaking on read-only COW ""

System select (select with 4 arguments) does not allow any of its
first three arguments to be read-only unless they are undef or
empty strings.

It does not work properly for read-only copy-on-write empty strings,
because it passes all copy-on-write through sv_force_normal under the
expectation that they will shortly be modified.  It should not be
doing that for read-only empty strings.

10 years agoRead-only COWs should not be exempt from s/// croaking
Father Chrysostomos [Sat, 10 Aug 2013 01:36:39 +0000 (18:36 -0700)]
Read-only COWs should not be exempt from s/// croaking

$  ./miniperl -Ilib -e 'for(__PACKAGE__) { s/a/a/ }'
Modification of a read-only value attempted at -e line 1.
$  ./miniperl -Ilib -e 'for(__PACKAGE__) { s/b/b/ }'
$  ./miniperl -Ilib -e 'for("main") { s/a/a/ }'
Modification of a read-only value attempted at -e line 1.
$  ./miniperl -Ilib -e 'for("main") { s/b/b/ }'
Modification of a read-only value attempted at -e line 1.

When I pass the constant "main" to s///, it croaks whether the regular
expression matches or not.

When I pass __PACKAGE__, which has the same content and is also read-
only, it only croaks when the pattern matches.

This commit removes some logic that is left over from when
READONLY+FAKE meant copy-on-write.  Read-only does mean read-only now,
so copy-on-write scalars should not be exempt from read-only checks.

10 years agoRemove SvIsCOW checks from mg.c:mg_localize
Father Chrysostomos [Wed, 7 Aug 2013 15:12:27 +0000 (08:12 -0700)]
Remove SvIsCOW checks from mg.c:mg_localize

It no longer needs to worry about SvIsCOW.  This logic is left over
from when READONLY+FAKE was used for COWs.

Since it is possible for COWs to be read-only now, this logic is actu-
ally faulty, as it doesn’t temporarily stop read-only COWs from being
read-only, as it does for other read-only values.

This actually causes discrepancies with scalar-tied locked hash keys,
which differ in readonliness when localised depending on whether the previous value used copy-on-write.

Whether such scalars should be read-only after localisation is open
to debate, but it should not differ based on the means of storing the
previous value.

10 years agoRemove SvIsCOW checks from mg.c:S_save_magic
Father Chrysostomos [Wed, 7 Aug 2013 07:56:32 +0000 (00:56 -0700)]
Remove SvIsCOW checks from mg.c:S_save_magic

It no longer needs to worry about SvIsCOW.  This logic is left over
from when READONLY+FAKE was used for COWs.

Since it is possible for COWs to be read-only now, this logic is actu-
ally faulty, as it doesn’t temporarily stop read-only COWs from being
read-only, as it does for other read-only values.

This actually causes bugs with scalar-tied locked hash keys, which
croak on FETCH.

10 years agoDon’t treat COWs specially in locked hashes
Father Chrysostomos [Wed, 7 Aug 2013 01:19:08 +0000 (18:19 -0700)]
Don’t treat COWs specially in locked hashes

This is left over from when READONLY+FAKE meant copy-on-write.

Read-only copy-on-write scalars (which could not occur with the old
way of flagging things) must not be exempt from hash key restrictions.

10 years agoMake tr/a/b/ croak on read-only null COWs
Father Chrysostomos [Tue, 6 Aug 2013 20:05:20 +0000 (13:05 -0700)]
Make tr/a/b/ croak on read-only null COWs

$ ./perl -Ilib -e 'use constant nullrocow => (keys%{{""=>undef}})[0]; for(nullrocow) { y/a/b/ }'
$ ./perl -Ilib -e 'use constant nullro => ""; for(nullro) { y/a/b/ }'
Modification of a read-only value attempted at -e line 1.

It should croak on COW scalars that are read-only, even if they are
zero-length, just as it does on non-COW scalars.

This logic is left over from when READONLY+FAKE meant COW.

10 years agoFix up Peek.t for alternate COW configurations
Father Chrysostomos [Sun, 11 Aug 2013 01:19:55 +0000 (18:19 -0700)]
Fix up Peek.t for alternate COW configurations

I.e., -DPERL_OLD_COPY_ON_WRITE and -DPERL_NO_COW

10 years agoMake OLD_COPY_ON_WRITE handle SvLEN==0 scalars
Father Chrysostomos [Sun, 11 Aug 2013 06:30:33 +0000 (23:30 -0700)]
Make OLD_COPY_ON_WRITE handle SvLEN==0 scalars

SvLEN==0 means the scalar does not own the buffer.

PERL_OLD_COPY_ON_WRITE can’t do its copy-on-write with those, as
SvIsCOW && SvLEN==0 means a shared hash key scalar.

PerlIO::encoding passes such scalars to the Encode object’s
encode method.

Why am I even fixing this?  I was trying to make sure that I wasn’t
breaking PERL_OLD_COPY_ON_WRITE with other changes.  I got assertion
failures from encoding.t so I looked to see what the problem might be,
thinking it could affect other configurations.  It turns out not to be
specific to PERL_OLD_COPY_ON_WRITE, but since I have found the problem
I might as well fix it anyway.

10 years agouniversal.c: Ignore SvIsCOW in XS_Internals_SvREADONLY
Father Chrysostomos [Tue, 6 Aug 2013 13:25:59 +0000 (06:25 -0700)]
universal.c: Ignore SvIsCOW in XS_Internals_SvREADONLY

SvIsCOW used to check SVf_READONLY|SVf_FAKE.  e3918bb703ca changed
that, but did not change the assumptions that code already made (that
there could be not truly read-only COWs.

Now SvREADONLY actually means read-only, so Internals::SvREADONLY
should not be saying that read-ony COWs are not, nor does it need to
flatten COWs when making them read-only.  Hence, locking hash values
no longer has a speed and memory hit if that hash contains COWs.

Part of the code is left in place for PERL_OLD_COPY_ON_WRITE, to avoid
making read-only COWs under that configuration.  See the previous com-
mit for why.

10 years agoop.c:ck_svconst: Don’t allow ro COWs under old COW
Father Chrysostomos [Sat, 10 Aug 2013 23:28:40 +0000 (16:28 -0700)]
op.c:ck_svconst: Don’t allow ro COWs under old COW

Under PERL_OLD_COPY_ON_WRITE, allowing COWs to become read-only will
complicate things elsewhere.  It uses the IV slot of an SV to point
to a loop of SVs sharing the same buffer.  sv_2iv cannot cache the IV
without running the SV through sv_force_normal, but that will croak on
read-only values.  I could change it to S_sv_uncow, but there are more
cases elsewhere that would have to be audited, I don’t think it’s
worth spending time on improving PERL_OLD_COPY_ON_WRITE as it’s ‘dead
code, never intended to go live’ according to its author.  I am
bothering with at least this much because I don’t want to break it
knowingly.

10 years agotest.pl's runperl() can now optionally redirect STDIN from /dev/null
Nicholas Clark [Wed, 7 Aug 2013 10:23:57 +0000 (12:23 +0200)]
test.pl's runperl() can now optionally redirect STDIN from /dev/null

There is existing code to pipe fixed input to the test perl's STDIN, which
means that STDIN can be made to be an immediate end-of-file by giving an
empty string. However, it turns out that on platforms which use ksh as
/bin/sh, ksh's setup of shell pipelines differs from a traditional Bourne
shell (and bash), using one less process in total, with the result that the
test perl starts with a child process already - the process piping to its
STDIN. This unexpected child process confuses tests for wait() which are
only expecting to see return values from processes that the test script
itself started.

As the problem case is specifically for setting up STDIN to be at EOF, it's
easier to it by enhancing test.pl's runperl() to be able to redirect STDIN
from the null device than by making the tests themselves more complex.
This approach also avoids spawning a process for quite a few of the tests.
Fortuitously it seems that the string /dev/null is portable enough to work
with the command line parsing code on VMS and Win32 too.

Thanks to Zefram for helping diagnose the problem.

It turns out that this also fixes regressions on VMS, where the pipe
implementation returns the exit code of the process at the front of the
pipeline, not the end. The result is that adding a pipeline messes up any
test using OPTION FATAL to check exit status.

10 years agoRemove the two "VMS adjustments" from test.pl's _fresh_perl
Nicholas Clark [Wed, 7 Aug 2013 09:57:09 +0000 (11:57 +0200)]
Remove the two "VMS adjustments" from test.pl's _fresh_perl

These were added by commit ed6b3797850720f7 ("make t/op/misc.t work on VMS")
in Jan 2001 back when the relevant code was in t/op/misc.t

The two adjustments each only applied to one test in t/run/fresh_perl.t

Was:    system './perl -ne "print if eof" /dev/null'
Became: system './perl -ne "print if eof" NL:'

Was:    print "ok\n" if (-e _ and -f _ and -r _);
Became: print "ok\n" if (-e _ and -f _);

The latter had the comment "VMS file locking".

It seems that neither is needed now. Perl will recognise "/dev/null" as
the null device, and -r returns true on a file opened for reading.

The "adjustments", particularly the second, should have been done all along
in the code for the test itself, not by complicating the test runner.

10 years agoProbe for shm* routines in configure.com.
Craig A. Berry [Sun, 11 Aug 2013 13:45:49 +0000 (08:45 -0500)]
Probe for shm* routines in configure.com.

They became available in ACRTL ECO V0100 on VMS v8.4, but aren't
quite ready for prime time yet.  Specifically, shmget fails
unless IPC_CREAT is set in the third argument, but Perl has tests
that explicitly check that this is not necessary.

So construct the probe such that we won't enable these routines
until the CRTL bug has been fixed.

10 years agot/re/re_tests: Move vim hints to eof
Karl Williamson [Sun, 11 Aug 2013 04:12:28 +0000 (22:12 -0600)]
t/re/re_tests: Move vim hints to eof

Commit c30fc27b appended lines in the file to after the editor hints
lines.  This caused my vim to not notice them.

10 years agoregcomp.h, sv.c, utf8.c: Comment nits
Karl Williamson [Fri, 2 Aug 2013 20:13:16 +0000 (14:13 -0600)]
regcomp.h, sv.c, utf8.c: Comment nits

Remove obsolete comment, typos in others, plus reflow one block to fit
into 79 columns

10 years agoadd adjust_size_and_find_bucket to embed.fnc
Lukas Mai [Sat, 10 Aug 2013 22:44:09 +0000 (00:44 +0200)]
add adjust_size_and_find_bucket to embed.fnc

10 years agoRemove some effect-less code.
Shlomi Fish [Sat, 10 Aug 2013 07:24:00 +0000 (10:24 +0300)]
Remove some effect-less code.

Discussed in RT #41461

10 years agoFix RT #41461 (with a test).
Shlomi Fish [Sat, 10 Aug 2013 07:21:16 +0000 (10:21 +0300)]
Fix RT #41461 (with a test).

A problem with the perl debugger of writing to an undef $LINEINFO.
Bump $VERSION to 1.42.

For: RT #41461

10 years agoAdd two "ld" variables missing from configure.com.
Craig A. Berry [Sat, 10 Aug 2013 13:07:18 +0000 (08:07 -0500)]
Add two "ld" variables missing from configure.com.

This should close [perl #119197].

10 years agoFunction name typo in malloc.c
Sergey Alekseev [Fri, 9 Aug 2013 13:55:59 +0000 (19:55 +0600)]
Function name typo in malloc.c

Error was also spotted by mauke.

For: RT #119213

10 years agoMake constant folding use the right hints
Father Chrysostomos [Fri, 9 Aug 2013 21:24:23 +0000 (14:24 -0700)]
Make constant folding use the right hints

This was brought up in ticket #117855.

PL_compiling is a cop-sized static buffer (inside the interpreter
struct under threads) that stores information during compile time
(such as file name and line number) that gets copied to each cop (con-
trol op; aka state op or nextstate op) as it is created.

Some values are not actually stored in PL_compiling, such as the
current stash (PL_curstash is used instead) and the current hints
(PL_hints is used).

The ops in each statement are created before that statement’s cop
is created.

At run time, each cop is executed at the start of the statement and
sets PL_curcop to point to itself, so that operators within that
statement can get information from PL_curcop.

Constant folding was copying the contents of PL_compiling into a tem-
porary cop used to execute the ops being folded.  That constant fold-
ing happened of course before the cop was created for that statement.

Now it just happened that commit a0ed51b321 back in 1998 modified
newSTATEOP to copy hints to PL_compiling in addition to the new cop
being created.  Presumably that was to fix the type of bug that this
commit is addressing.  (Presumably this commit renders those changes
unnecessary.)  That meant that most of the time constant folding would
see the right hints.

That fails, though, when it comes to the first statement in a string
eval.  When you do eval("uc(ä)"), the constant folding happens when
PL_compiling.cop_hints still points to whatever value it had before
the eval was executed; i.e., an unpredictable value.  Slight changes
to unrelated scopes (and, apparently, using a different compiler*) can
cause the result of that string eval to change.

The solution is to set the hints from PL_hints explicitly when doing
constant folding.

* <https://rt.perl.org/rt3/Ticket/Display.html?id=117855#txn-1241613>ff.
  I never got to the bottom of why the compiler would make a diffe-
  rence here.  Finding out would involve setting a watchpoint on
  PL_compiling.cop_hints in a C debugger and then stepping through
  the thousands of times PL_compiling changes, which is too much
  work.  Nevertheless, I know this fix is correct, as it changes
  PL_compiling.cop_hints from having a non-deterministic value during
  constant folding to having a predictable one.

10 years agotoke.c:S_incline: avoid vivifying GV under threads
Father Chrysostomos [Sat, 10 Aug 2013 01:00:22 +0000 (18:00 -0700)]
toke.c:S_incline: avoid vivifying GV under threads

Since c82ecf346 has been reverted by the previous commit, under
threads we are back to storing the name of the current file in the
cop, rather than a pointer to the GV.  This means the GV may not even
have been created, so CopFILEGV will autovivify it.  We can avoid
autovivifying it in those cases where we are not going to be copying
the lines anyway, which S_incline only does for string eval (when it
sees a #line directive).  Even if the GV already exists, this makes
the check faster, as we no longer have to look it up by name when
parsing a file.

10 years agoRevert "[perl #117855] Store CopFILEGV in a pad under ithreads"
Father Chrysostomos [Sat, 6 Jul 2013 05:51:50 +0000 (22:51 -0700)]
Revert "[perl #117855] Store CopFILEGV in a pad under ithreads"

This reverts commit c82ecf346.

It turn out to be faulty, because a location shared betweens threads
(the cop) was holding a reference count on a pad entry in a particu-
lar thread.  So when you free the cop, how do you know where to do
SvREFCNT_dec?

In reverting c82ecf346, this commit still preserves the bug fix from
1311cfc0a7b, but shifts it around.

10 years agoRevert "toke.c:incline: Avoid duplicate symbol lookup"
Father Chrysostomos [Fri, 9 Aug 2013 21:44:35 +0000 (14:44 -0700)]
Revert "toke.c:incline: Avoid duplicate symbol lookup"

This reverts commit 05c9917c892c03577828027ff71c6282a2eabe29.

This is in preparation for reverting c82ecf346, which will remove the
CopFILEGV_set macro under threads.

10 years agodump.c: Dump contents of regexps’ mother_re field
Father Chrysostomos [Fri, 9 Aug 2013 19:56:03 +0000 (12:56 -0700)]
dump.c: Dump contents of regexps’ mother_re field

This can make debugging easier if one needs to see the reference count
of the parent regular expression.

10 years agoop.c:ck_eval: remove redundant null check
Father Chrysostomos [Thu, 8 Aug 2013 21:17:08 +0000 (14:17 -0700)]
op.c:ck_eval: remove redundant null check

op_first is never null when OPf_KIDS is set.

10 years agoAvoid assert fail with s// $target = \3 /e
Father Chrysostomos [Thu, 8 Aug 2013 01:21:00 +0000 (18:21 -0700)]
Avoid assert fail with s// $target = \3 /e

When the substitution target is assigned to in pp_substcont, it is
assumed that SvPV_free and SvPOK_only_UTF8 can be used on that target.
Only COW scalars are sent through sv_force_normal.

Changing the target in the replacement code can render those assump-
tions untrue:

$  ./perl -Ilib -e '$h = 3; $h =~ s/3/$h=\3;4/e'
Assertion failed: (!((targ)->sv_flags & 0x00000800) || !(*({ SV *const _svrv = ((SV *)({ void *_p = (targ); _p; })); (__builtin_expect(!(PL_valid_types_RV[((svtype)((_svrv)->sv_flags & 0xff)) & 0xf]), 0) ? __assert_rtn(__func__, "pp_ctl.c", 269, "PL_valid_types_RV[SvTYPE(_svrv) & SVt_MASK]") : (void)0); (__builtin_expect(!(!((((_svrv)->sv_flags & (0x00004000|0x00008000)) == 0x00008000) && (((svtype)((_svrv)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((_svrv)->sv_flags & 0xff)) == SVt_PVLV))), 0) ? __assert_rtn(__func__, "pp_ctl.c", 269, "!isGV_with_GP(_svrv)") : (void)0); (__builtin_expect(!(!(((svtype)((_svrv)->sv_flags & 0xff)) == SVt_PVIO && !(((XPVIO*) (_svrv)->sv_any)->xio_flags & 64))), 0) ? __assert_rtn(__func__, "pp_ctl.c", 269, "!(SvTYPE(_svrv) == SVt_PVIO && !(IoFLAGS(_svrv) & IOf_FAKE_DIRP))") : (void)0); &((_svrv)->sv_u.svu_rv); }))), function Perl_pp_substcont, file pp_ctl.c, line 269.
Abort trap: 6

Also, matching against a hash key and locking that key with Hash::Util
within the replacement code can cause the substitution to modify that
hash key without triggering ‘Modification of a read-only value’.  But
this only happens if it is not a copy-on-write scalar:

$ ./perl -Ilib -MHash::Util=lock_hash -le '$h{foo} = 3; $h{foo} =~ s/3/$h{foo} = 3; lock_hash %h; 4/e; print $h{foo}'
4

We need to do a regular SV_THINKFIRST_COW_DROP check here, just as we
do in sv_setsv with regular scalar assignment.

Also, we need to take into account real globs:

$ ./perl -Ilib -MHash::Util=lock_hash -le '$::{foo} =~ s//*{"foo"}; 4/e'
Assertion failed: (!isGV_with_GP(targ)), function Perl_pp_substcont, file pp_ctl.c, line 259.
Abort trap: 6

10 years agoRespect SvLEN==0 and SvOOK in sv.c:sv_sethek
Father Chrysostomos [Wed, 7 Aug 2013 16:04:20 +0000 (09:04 -0700)]
Respect SvLEN==0 and SvOOK in sv.c:sv_sethek

SvLEN==0 means this scalar does not own the buffer, so it should
not free it.

SvOOK means that SvPVX does not point to the start of the buffer
because we have cheated with s/...// or substr and not copied the
string back.

I don’t believe any such scalars currently make their way into
sv_sethek and get past the THINKFIRST check in that state, but we
should still play it safe.

SvPV_free handles both cases.

10 years agoDon’t stringify undef hash keys at compile time
Father Chrysostomos [Wed, 7 Aug 2013 15:46:52 +0000 (08:46 -0700)]
Don’t stringify undef hash keys at compile time

$ ./perl -wIlib -Mconstant' u=>undef' -e '()=$a{+u} if $a'
Use of uninitialized value at -e line 1.

Well, I didn’t even execute that hash lookup, so why is it warning me
about an uninitialized value?

This is a compile-time optimisation to turn hash keys into shared hash
key scalars (containing precomputed hashes) to speed up key lookup.
It stringifies the hash key at compile time as part of the process.

The value should not be stringified if that would cause observable
difference with tied hashes.  Commit 04698ff67 fixed this for refs,
globs and regexps, but missed undef scalars.

This could be considered part of bug #79178.

10 years agoExtUtils::ParseXS: Version consistency
Steffen Mueller [Fri, 9 Aug 2013 17:07:27 +0000 (19:07 +0200)]
ExtUtils::ParseXS: Version consistency

10 years agoUpdate versions and dates in release announcement template
Steve Hay [Fri, 9 Aug 2013 12:00:37 +0000 (13:00 +0100)]
Update versions and dates in release announcement template

10 years agoperldelta for b4bf645b3d
Tony Cook [Fri, 9 Aug 2013 06:46:00 +0000 (16:46 +1000)]
perldelta for b4bf645b3d

10 years agoCarp now handles objects with string overloads.
Darin McBride [Fri, 9 Aug 2013 06:17:08 +0000 (16:17 +1000)]
Carp now handles objects with string overloads.

It also allows objects to specify how they appear in the stack dump with
a CARP_TRACE method, and also allows the user to specify their own
formatter for objects without CARP_TRACE as well as other references.
[perl #92446]

Minor fix, commit message reformatting and manifest update by Tony Cook.

10 years agoperldelta for da1929e75
Tony Cook [Fri, 9 Aug 2013 02:10:06 +0000 (12:10 +1000)]
perldelta for da1929e75

10 years ago[perl #117793] remove dangerous functions and improve SvREFCNT()
Tony Cook [Fri, 9 Aug 2013 01:41:26 +0000 (11:41 +1000)]
[perl #117793] remove dangerous functions and improve SvREFCNT()

This allows Devel::Peek::SvREFCNT() to work on any variable, not just
scalars, but has a chance of breaking backward compatibility.

Also changes the type of SvREFCNT() to U32 to match the type returned by
the underlying macro

10 years agoUpgrade libnet from 1.22 to 1.22_02
Steve Hay [Thu, 8 Aug 2013 20:21:42 +0000 (21:21 +0100)]
Upgrade libnet from 1.22 to 1.22_02

This is the latest (development) release on CPAN. It will shortly be
superseded by 1.23.

Note that Makefile.PL is only customized -- not excluded as well! Two
customized test files (actually, one changed and one added) which blead
had (but were not noted in the Maintainers.pl file!) are incorporated in
this release.

Also, change the UPSTREAM status from undef to 'blead' to reflect the fact
that GBARR is no longer actively maintaining libnet and for the immediate
future new CPAN releases are only likely to be rolled to keep in sync with
changes in blead, plus occasional simple patches from the CPAN RT queue.

10 years agoDocument non-destructive substitution: the '/r' modifier.
James E Keenan [Tue, 6 Aug 2013 01:12:55 +0000 (21:12 -0400)]
Document non-destructive substitution: the '/r' modifier.

Per bug report filed by Jacinta Richardson++.

For: RT #119151

10 years agoAdd missing versioned Config to Module::CoreList
Chris 'BinGOs' Williams [Wed, 7 Aug 2013 22:48:21 +0000 (23:48 +0100)]
Add missing versioned Config to Module::CoreList

10 years agoConfig has a VERSION, corelist.pl should set it
Chris 'BinGOs' Williams [Wed, 7 Aug 2013 22:34:14 +0000 (23:34 +0100)]
Config has a VERSION, corelist.pl should set it

10 years agoUpdate the Porting/bisect.pl documentation.
Nicholas Clark [Wed, 7 Aug 2013 16:58:00 +0000 (18:58 +0200)]
Update the Porting/bisect.pl documentation.

As of commit c8fde7fafa0a9cec (merged to blead with commit 4724da031eae31b4)
bisect.pl can be run in-place if the checkout is clean.

The most recent stable release that it will try is now v5.18.0.

10 years agoReport the perl executable path in the error if Config.pm is out of sync.
Nicholas Clark [Wed, 7 Aug 2013 12:46:05 +0000 (14:46 +0200)]
Report the perl executable path in the error if Config.pm is out of sync.

If the version that Config.pm was built for differs from the version of the
perl executable running it, Config.pm aborts with an error message. The
error message was updated to include $0 (the script filename) in Aug 2010 by
commit b982c5de5a0d9f6f. Somewhat misleadingly the commit message says
"include the path of the perl executable in the error message." which $0 is
not.

This commit adds $^X to the error message - the path of the perl executable.
The error message also shows the script name, as this might also be useful
in diagnosing the cause of the problem.

10 years agoA comment in Storable.xs was words missing two words.
Nicholas Clark [Wed, 7 Aug 2013 12:29:50 +0000 (14:29 +0200)]
A comment in Storable.xs was words missing two words.

10 years agoUpgrade IPC::Cmd from 0.82 to 0.84
Steve Hay [Wed, 7 Aug 2013 11:39:59 +0000 (12:39 +0100)]
Upgrade IPC::Cmd from 0.82 to 0.84

10 years agoClarify documentation re switch expecting an argument but none is provided.
James E Keenan [Sun, 4 Aug 2013 02:30:42 +0000 (22:30 -0400)]
Clarify documentation re switch expecting an argument but none is provided.

When a switch is expecting an argument but fails to be provided with one, the
value of the corresponding element in the options hash is set to the undefined
value.  The documentation did not make this clear.

The documentation for getopts() and getopt() has been revised and additional
tests have been provided to demonstrate the point.  Tweaked in response to
feedback from Karl Williamson++.

Also, unit tests found in lib/Getopt/Std.t actually for Getopt::Long have been
removed.  A patch holding those tests has been submitted to Getopt-Long's bug
queue on rt.cpan.org.

For: RT #41359

10 years agoMerge the refactoring of B which silences Solaris compiler warnings.
Nicholas Clark [Wed, 7 Aug 2013 09:30:05 +0000 (11:30 +0200)]
Merge the refactoring of B which silences Solaris compiler warnings.

10 years agoIn B::OP::next, flag special cases with a type, instead of an offset of -1.
Nicholas Clark [Tue, 6 Aug 2013 12:07:42 +0000 (14:07 +0200)]
In B::OP::next, flag special cases with a type, instead of an offset of -1.

This permits the offset structure member to be unsigned instead of signed,
which feels more natural. The refactoring also reduces code size by about
100 bytes on x86_64.

10 years agoRe-indent a switch statement in B::OP::next
Nicholas Clark [Tue, 6 Aug 2013 11:55:27 +0000 (13:55 +0200)]
Re-indent a switch statement in B::OP::next

This is the whitespace-only part of the next commit separated out.

10 years agoChange all B's unsigned constants from IVs to UVs.
Nicholas Clark [Tue, 6 Aug 2013 11:15:13 +0000 (13:15 +0200)]
Change all B's unsigned constants from IVs to UVs.

Apart from HEf_SVKEY, all constants are actually unsigned, so this change
avoids 2 warnings "initializer does not fit or is out of range" from the
Solaris C compiler for the two constants with the value 0x80000000

10 years agoIn B.xs use I16 to avoid an "initializer will be sign-extended" warning.
Nicholas Clark [Tue, 6 Aug 2013 10:56:04 +0000 (12:56 +0200)]
In B.xs use I16 to avoid an "initializer will be sign-extended" warning.

The Solaris C compiler warns 30 times that -1 will be sign-extended, when
it is assigned to a struct member of type size_t. Instead, use I16 (No offset
will actually be larger than 1024), and reduce the size of the types used for
other structure members.

Change SVp (etc) to be constants in the range 0x0 to 0x7, instead of 0x00000
to 0x70000, now that most use cases no longer involve to or-ing with other
values. This makes two switch statements simpler.

As well as quietening warnings, the combined changes reduce the object size
by about 800 bytes on x86_64.

10 years agoTeach makedef.pl that Perl_allocfilegv does not exist without ithreads.
Nicholas Clark [Tue, 6 Aug 2013 16:22:42 +0000 (18:22 +0200)]
Teach makedef.pl that Perl_allocfilegv does not exist without ithreads.

This linker skip was missed by commit c82ecf346a8512f2, which did add the 3
PL_ variables it added for ithreads builds.

10 years agoDon't multiply define Perl__invlist_dump.
Craig A. Berry [Wed, 7 Aug 2013 02:09:40 +0000 (21:09 -0500)]
Don't multiply define Perl__invlist_dump.

It doesn't need to be in the extension if it's already in the core
top-level code.  Defining it more than once leads to linker errors
for linkers that care about such things, namely VMS.

Broken in ad3f05adb1975.

10 years agoFix t/porting/customized.t --regen not to add DOS EOLs on Windows
Steve Hay [Tue, 6 Aug 2013 21:47:50 +0000 (22:47 +0100)]
Fix t/porting/customized.t --regen not to add DOS EOLs on Windows

10 years agoreparse compile-time /(?{})/ in right scope
David Mitchell [Tue, 6 Aug 2013 15:34:50 +0000 (16:34 +0100)]
reparse compile-time /(?{})/ in right scope

When a compile-time regex like /...(?{ code-block }) .../
is compiled in the presence of constant and concat overloading,
this can cause (still at compile-time) for the pattern to be evaled and
re-compiled, in order to re-compile any code-blocks that got messed up
during the overloading and thus whose text no longer matches that which
the perl parser previously compiled.

When this happens, eval_sv() happens to be called when the perl parser is
still in compiling state; normally its called from running state.
This tickles an undiscovered bug in Perl_find_runcv_where(), which
finds the current cop sequence by looking at PL_curcop->cop_seq.
At compile time, we need to get it from PL_cop_seqmax instead.

10 years ago[perl #119169] index with __PACKAGE__ for 2nd argument
Father Chrysostomos [Tue, 6 Aug 2013 13:08:21 +0000 (06:08 -0700)]
[perl #119169] index with __PACKAGE__ for 2nd argument

The refactoring of fbm_compile in 66379c06cd to prepare for
c72a4eedff1 put in an SvIsCOW check before doing SvPV_force.  I sim-
ply changed the logic there so that SvPV_force would continue to have
its effect but without tripping up on read-only variables for which
SvPV_force would not need to make any changes anyway.

Now, if a COW scalar is read-only, we can’t call SvPV_force on it,
because it will die.

It turns out that we don’t actually need to call SvPV_force on COWs.
We can just go ahead and attach the BM magic and continue sharing
the buffer.

10 years agosv.h: Add comment about gv_check and SvIsCOW
Father Chrysostomos [Tue, 6 Aug 2013 12:57:26 +0000 (05:57 -0700)]
sv.h: Add comment about gv_check and SvIsCOW

So that future refactorings don’t make use of 0x00010000 on
hashes without modifying gv_check to account.

10 years ago[perl #2726] Prototype is not applied until BLOCK is defined
Peter Martini [Tue, 6 Aug 2013 07:16:35 +0000 (03:16 -0400)]
[perl #2726] Prototype is not applied until BLOCK is defined

In the case of a sub definition with a prototype, the prototype
is not attached to the sub until after the body is completely
defined.  This means that any sub which calls itself will
not honor its prototype unless the prototype was declared prior to
the sub's definition.  Whether or not this behavior is desirable is
debatable, but its far too late to do anything about it other than
document it and test to make sure it doesn't change.

10 years agoStop ‘used once’ warnings from crashing on circularities
Father Chrysostomos [Mon, 5 Aug 2013 16:17:32 +0000 (09:17 -0700)]
Stop ‘used once’ warnings from crashing on circularities

gv_check was only checking for stashes nested directly inside them-
selves (*foo:: = *foo::foo) and the main stash.

Other stash circularities would cause infinite recursion, blowing the
C stack and crashing.

10 years agoUpgrade Scalar-List-Utils from 1.29 to 1.30
Steve Hay [Mon, 5 Aug 2013 17:06:23 +0000 (18:06 +0100)]
Upgrade Scalar-List-Utils from 1.29 to 1.30

10 years agoStorable should not assume that sizeof(mg_len) is 4.
Nicholas Clark [Wed, 31 Jul 2013 10:43:51 +0000 (12:43 +0200)]
Storable should not assume that sizeof(mg_len) is 4.

Commit 6174b39a88cd4874 changed mg_len from I32 to SSize_t. sizeof(I32) is 4
everywhere (except certain Crays, for which Storable has work-around code).
In the version object serialisation code, Storable was passing mg->len
directly to the macro WLEN(), and and it turns out that some paths through
this macro is relying on the assumption that the value passed in is 32 bits.
This is now invalid on on 64 bit systems, but only triggered an error with
the existing tests on big endian systems.

The easiest fix is to assign the value to a temporary variable of the
correct size, and process that. However, a lot of the code makes a lot of
unwarranted assumptions about sizeof(int), and ideally should be audited and
rewritten to use more appropriate types.

10 years agoRestore Storable's DEBUGME build after commit 591596833b093b3c
Nicholas Clark [Wed, 31 Jul 2013 10:32:27 +0000 (12:32 +0200)]
Restore Storable's DEBUGME build after commit 591596833b093b3c

Storable.xs can conditionally compile debugging code if the C pre-processor
macro DEBUGME is defined. By default, it is not.

Commit 591596833b093b3c changed the name and purpose of the second argument
to the macro BLESS(), but missed updating the name in one location, within
code conditionally enabled by DEBUGME, hence breaking compilation with
DEBUGME.

Fix compilation by correcting that code to use the new macro parameter name.

10 years agoop.c:newCONSTSUB: Stop using CopFILESV for CvFILE
Father Chrysostomos [Mon, 5 Aug 2013 09:14:39 +0000 (02:14 -0700)]
op.c:newCONSTSUB: Stop using CopFILESV for CvFILE

CopFILESV points to *{"_<filename"}, which can be modified
from perl space.  CopFILE points to the third character of
*{"_<filename"}{NAME}.

Ithreads were already using CopFILE.  Make non-threaded builds do the
same.  This makes things a little more robust.

CvFILE is not actually used anywhere as far as I can tell, so I cannot
easily test this.

10 years agoDon’t use CopFILESV for ‘once’ warnings
Father Chrysostomos [Mon, 5 Aug 2013 08:55:31 +0000 (01:55 -0700)]
Don’t use CopFILESV for ‘once’ warnings

CopFILESV points to ${"_<filename"}, which can be modified by Perl
code.  Under non-threaded builds, newGP (which records the file name
used by ‘used once’ warnings) was using CopFILESV for the file name.
It is safer just to use the name of the GV itself.

10 years agoop.c:aassign_common_vars: merge duplicate code
Father Chrysostomos [Mon, 5 Aug 2013 08:35:36 +0000 (01:35 -0700)]
op.c:aassign_common_vars: merge duplicate code

We are just asking for bugs to creep in by repeating it like this.

10 years agoop.c: correct comment
Father Chrysostomos [Mon, 5 Aug 2013 08:32:33 +0000 (01:32 -0700)]
op.c: correct comment

10 years agoRemove SAVEt_STACK_CXPOS
Father Chrysostomos [Mon, 5 Aug 2013 08:22:46 +0000 (01:22 -0700)]
Remove SAVEt_STACK_CXPOS

81ed78b25c4b removed the only use of this.

10 years agoHandle SAVEt_READONLY_OFF in ss_dup
Father Chrysostomos [Mon, 5 Aug 2013 08:13:21 +0000 (01:13 -0700)]
Handle SAVEt_READONLY_OFF in ss_dup

20d5dc239d1 added SAVEt_READONLY_OFF without adding it to ss_dup.

10 years agoHandle SAVEt_ADELETE in ss_dup
Father Chrysostomos [Mon, 5 Aug 2013 08:10:21 +0000 (01:10 -0700)]
Handle SAVEt_ADELETE in ss_dup

c68ec7a9f95 added SAVEt_ADELETE without adding it to ss_dup.

10 years agoTest that ss_dup handles all savestack items
Father Chrysostomos [Mon, 5 Aug 2013 08:02:23 +0000 (01:02 -0700)]
Test that ss_dup handles all savestack items

It is far too easy to overlook it when adding new savestack types.

10 years agotoke.c: s/below/above/
Father Chrysostomos [Mon, 5 Aug 2013 07:39:32 +0000 (00:39 -0700)]
toke.c: s/below/above/

The condition this refers to was moved in commit 4efe39d21.

10 years agotoke.c:incline: Avoid duplicate symbol lookup
Father Chrysostomos [Mon, 5 Aug 2013 07:36:50 +0000 (00:36 -0700)]
toke.c:incline: Avoid duplicate symbol lookup

If we have already looked up the GV for *{"_<newfilename"}, we
can set CopFILEGV to that instead of having CopFILE_setn look it
up itself.

10 years agotoke.c:incline: Don’t stringify a GV to look it up
Father Chrysostomos [Mon, 5 Aug 2013 07:28:48 +0000 (00:28 -0700)]
toke.c:incline: Don’t stringify a GV to look it up

If we already have the GV, there is no need to stringify it and then
look it up again.

10 years agoMake eval "#line" account for ${"_<foo"} changes
Father Chrysostomos [Mon, 5 Aug 2013 07:13:40 +0000 (00:13 -0700)]
Make eval "#line" account for ${"_<foo"} changes

If a BEGIN block in the eval modifies the ${"_<foo"} scalar where
‘foo’ is the file name in the eval, then subsequent #line directives
that change the file name won’t cause the lines to be copied to
@{"_<newname"}.  (This copying usually happens under the debugger.)

Just use the name of the GV itself, rather than CopFILESV, since the
GV name cannot be changed from Perl space.

10 years agotoke.c:incline: Move code into the block that uses it
Father Chrysostomos [Mon, 5 Aug 2013 06:54:59 +0000 (23:54 -0700)]
toke.c:incline: Move code into the block that uses it

Setting up the values of these variables is pointless if we are not
going to be using them.  They are only used inside the ‘if’ block that
this patch moves them into.

10 years agoPrevent __FILE__ corruption when ${"_<..."} is modified
Father Chrysostomos [Mon, 5 Aug 2013 06:52:20 +0000 (23:52 -0700)]
Prevent __FILE__ corruption when ${"_<..."} is modified

This fixes a longstanding bug under non-threaded builds that was
extended to threaded builds by the previous commit.

Modifying the SV slot of the file gv can cause CopFILE to violate
memory discipline, giving random strings.

Since the GV is named after the file, too, and since its name can-
not be changed from Perl space, use that for CopFILE instead.

10 years ago[perl #117855] Store CopFILEGV in a pad under ithreads
Father Chrysostomos [Sat, 6 Jul 2013 05:51:50 +0000 (22:51 -0700)]
[perl #117855] Store CopFILEGV in a pad under ithreads

This saves having to allocate a separate string buffer for every cop
(control op; every statement has one).

Under non-threaded builds, every cop has a pointer to the GV for that
source file, namely *{"_<filename"}.

Under threaded builds, the name of the GV used to be stored instead.

Now we store an offset into the per-interpreter PL_filegvpad, which
points to the GV.

This makes no significant speed difference, but it reduces mem-
ory usage.

10 years agoDon’t let list const modification affect future retvals
Father Chrysostomos [Sun, 4 Aug 2013 18:22:03 +0000 (11:22 -0700)]
Don’t let list const modification affect future retvals

In commit f99a5f08f203, I inadvertently made modifications to val-
ues return by list ‘constants’ affect what values are returned sub-
sequently.

It’s for this type of situation that PADTMP exists (values are never
referenced, but copied).  So use it.

This is similar to 5608dcc62, which fixed #3105.

10 years ago[perl #119043] Allow utf8 up/downgrade on ro COWs
Father Chrysostomos [Sun, 4 Aug 2013 06:58:56 +0000 (23:58 -0700)]
[perl #119043] Allow utf8 up/downgrade on ro COWs

Commit 1913067 allowed COW constants to be read-only.  This broke
Glib, so I reverted it with ba36554e02.  That caused this bug to reë-
merge (I hadn’t realised that I had fixed it in 1913067):

perl -e 'for(1..10){for(__PACKAGE__){warn $_; $_++}}'
main at -e line 1.
maio at -e line 1.
maip at -e line 1.
maiq at -e line 1.
mair at -e line 1.

so I reverted the revert two commits ago.

Glib was triggering a read-only error because it called
sv_utf8_upgrade on a read-only COW scalar, and sv_utf8_upgrade does
sv_force_normal on COWs to de-COW them.  sv_force_normal croaks on
read-only scalars.

The real problem here is that sv_force_normal means ‘I am going to
modify this scalar’, yet sv_utf8_upgrade conceptually does not modify
the scalar, but only changes the internal representation.

Having to call sv_force_normal to get the *side effect* of de-COWing
without triggering the various other things it does is no good.

What we need is a separate sv_uncow function that sv_force_normal
uses.  This commit introduces such a function.

10 years agoTest that __PACKAGE__ is read-only
Father Chrysostomos [Sun, 4 Aug 2013 06:08:42 +0000 (23:08 -0700)]
Test that __PACKAGE__ is read-only

I.e., test that this bug is fixed:

$ perl -e 'for(1..10){for(__PACKAGE__){warn $_; $_++}}'
main at -e line 1.
maio at -e line 1.
maip at -e line 1.
maiq at -e line 1.
mair at -e line 1.
mais at -e line 1.
mait at -e line 1.
maiu at -e line 1.
maiv at -e line 1.
maiw at -e line 1.

for my$p(__PACKAGE__){$p++for+1..55664
,;!print"Just another \u$p hacker,\n"}