| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The push and unshift builtins were correctly throwing a "Modification of a
read-only value attempted" exception when modifying a read-only array, but
splice was silently modifying the array. This commit adds tests that all
three builtins throw such an exception.
One discrepancy between the three remains: push has long silently accepted
a push of no elements onto an array, whereas unshift throws an exception in
that situation. This seems to have been originally a coincidence. The
pp_unshift implementation first makes space for the elements it unshifts
(which croaks for a read-only array), then copies the new values into the
space thus created. The pp_push implementation, on the other hand, calls
av_push() individually on each element; that implicitly croaks, but only one
there's at least one element being pushed.
The pp_push implementation has subsequently been changed: read-only checking
is now done first, but that was done to fix a memory leak. (If the av_push()
itself failed, then the new SV that had been allocated for pushing onto the
array would get leaked.) That leak fix specifically grandfathered in the
acceptance of empty-push-to-readonly-array, to avoid changing behaviour.
I'm not fond of the inconsistency betwen push on the one hand and unshift &
splice on the other, but I'm disinclined to make empty-push-to-readonly
suddenly start throwing an exception after all these years, and it seems
best not to extend that exemption-from-exception to the other builtins.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Use set_up_inc when require.pl is loaded
move plan outside of BEGIN block
when no tests are run at BEGIN time.
Using set_up_inc allow to run these tests under minitest
but also compile them using B::C.
This also has the advantage to use a single
control point for @INC setup.
Note: some tests cannot use 'require test.pl',
unshfit is then used for them.
|
|
|
|
|
| |
Some of this is ugly, but that’s because I wrote a one-liner to do
it. It’s good enough for practical purposes.
|
| |
|
|
|
|
| |
See ce6d40e02d52b9152b44a5fc2180efda15a7d069
|
|
|
|
|
| |
We need a better name for the experimental category, but I have not
thought of one, even after sleeping on it.
|
|
|
|
|
|
|
| |
Commit ce0d59f changed AVs to use NULLs for nonexistent elements.
pp_splice needs to take that into account and avoid pushing NULLs on
to the stack.
|
| |
|
|
|
|
| |
See ticket #80626.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
All built-in functions that operate directly on array or hash
containers now also accept hard references to arrays or hashes:
|----------------------------+---------------------------|
| Traditional syntax | Terse syntax |
|----------------------------+---------------------------|
| push @$arrayref, @stuff | push $arrayref, @stuff |
| unshift @$arrayref, @stuff | unshift $arrayref, @stuff |
| pop @$arrayref | pop $arrayref |
| shift @$arrayref | shift $arrayref |
| splice @$arrayref, 0, 2 | splice $arrayref, 0, 2 |
| keys %$hashref | keys $hashref |
| keys @$arrayref | keys $arrayref |
| values %$hashref | values $hashref |
| values @$arrayref | values $arrayref |
| ($k,$v) = each %$hashref | ($k,$v) = each $hashref |
| ($k,$v) = each @$arrayref | ($k,$v) = each $arrayref |
|----------------------------+---------------------------|
This allows these built-in functions to act on long dereferencing
chains or on the return value of subroutines without needing to wrap
them in C<@{}> or C<%{}>:
push @{$obj->tags}, $new_tag; # old way
push $obj->tags, $new_tag; # new way
for ( keys %{$hoh->{genres}{artists}} ) {...} # old way
for ( keys $hoh->{genres}{artists} ) {...} # new way
For C<push>, C<unshift> and C<splice>, the reference will auto-vivify
if it is not defined, just as if it were wrapped with C<@{}>.
Calling C<keys> or C<values> directly on a reference gives a
substantial performance improvement over explicit dereferencing.
For C<keys>, C<values>, C<each>, when overloaded dereferencing is
present, the overloaded dereference is used instead of dereferencing
the underlying reftype. Warnings are issued about assumptions made in
the following three ambiguous cases:
(a) If both %{} and @{} overloading exists, %{} is used
(b) If %{} overloading exists on a blessed arrayref, %{} is used
(c) If @{} overloading exists on a blessed hashref, @{} is used
|
| |
|
| |
|
|
|
|
|
| |
Message-ID: <DF27CDCBD2581D4B88431901094E4B4D02B0C7D2@attmsx1.aut.alcatel.at>
p4raw-id: //depot/perl@23092
|
|
|
|
|
|
|
|
|
|
|
|
| |
From: Schuyler Erle <schuyler@oreilly.com>
Date: Fri, 01 Mar 2002 14:22:19 -0800
Message-ID: <3C7FFF1B.E74979B1@oreilly.com>
Subject: Re: PATCH: "splice() offset past end of array" warning.
From: Mark-Jason Dominus <mjd@plover.com>
Date: Fri, 01 Mar 2002 17:19:49 -0500
Message-ID: <20020301221949.7610.qmail@plover.com>
p4raw-id: //depot/perl@14939
|
|
|
|
|
| |
Message-Id: <200107120625.f6C6PkJ13065@biz.bitpusher.com>
p4raw-id: //depot/perl@11306
|
|
|
|
|
| |
Message-ID: <NAEKLNAAHLMBPMPNBMLEOEFLDFAA.rs@crystalflame.net>
p4raw-id: //depot/perl@10265
|
|
|
|
|
|
| |
Message-Id: <199806241825.OAA06346@monk.mps.ohio-state.edu>
Subject: Re: [5.004_68] What is %^R ? [PATCH?]
p4raw-id: //depot/perl@1238
|
|
Message-ID: <m3g1gvc5bs.fsf@furu.g.aas.no>
p4raw-id: //depot/perl@1237
|