summaryrefslogtreecommitdiff
path: root/t/op/splice.t
Commit message (Collapse)AuthorAgeFilesLines
* RT#131000: splice doesn't honour read-only flagAaron Crane2017-10-151-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 for several unit testsNicolas R2016-08-181-1/+1
| | | | | | | | | | | | | | | 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.
* Tired of looking up old bug numbersFather Chrysostomos2016-07-291-2/+2
| | | | | Some of this is ugly, but that’s because I wrote a one-liner to do it. It’s good enough for practical purposes.
* Delete experimental autoderef featureAaron Crane2015-07-131-4/+0
|
* fix splice+isa test that got mangled when making splice.t use test.plTobias Leich2014-01-201-1/+1
| | | | See ce6d40e02d52b9152b44a5fc2180efda15a7d069
* Make key/push $scalar experimentalFather Chrysostomos2014-01-141-1/+1
| | | | | We need a better name for the experimental category, but I have not thought of one, even after sleeping on it.
* Make pp_splice handle nonexistent array elementsFather Chrysostomos2013-09-061-0/+10
| | | | | | | 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.
* Refactor t/op/splice.t to use t/test.pl instead of making TAP by hand.Colin Kuskie2012-07-031-44/+40
|
* Make push/shift $scalar accept only unblessed aryrefsFather Chrysostomos2011-04-181-3/+3
| | | | See ticket #80626.
* Allow push/pop/keys/etc to act on referencesDavid Golden2010-10-311-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Make splice invoke set magicFlorian Ragwitz2010-10-151-1/+11
|
* Mark all .t and .pm files as non executableRafael Garcia-Suarez2009-06-061-0/+0
|
* Re: [perl #30568] splice generates undef? [PATCH]LAUN Wolfgang2004-07-131-1/+31
| | | | | Message-ID: <DF27CDCBD2581D4B88431901094E4B4D02B0C7D2@attmsx1.aut.alcatel.at> p4raw-id: //depot/perl@23092
* PATCH: "splice() offset past end of array" warning. (take 2) Jarkko Hietaniemi2002-03-021-1/+1
| | | | | | | | | | | | 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
* [ID 20010711.005] in Tie::Array, SPLICE ignores context, breaking SHIFT daniel@biz.bitpusher.com2001-07-121-1/+15
| | | | | Message-Id: <200107120625.f6C6PkJ13065@biz.bitpusher.com> p4raw-id: //depot/perl@11306
* RE: [20000223.001] no test cases for splice(@array) Richard Soderberg2001-05-281-1/+7
| | | | | Message-ID: <NAEKLNAAHLMBPMPNBMLEOEFLDFAA.rs@crystalflame.net> p4raw-id: //depot/perl@10265
* avoid creation of %^RIlya Zakharevich1998-06-281-0/+0
| | | | | | Message-Id: <199806241825.OAA06346@monk.mps.ohio-state.edu> Subject: Re: [5.004_68] What is %^R ? [PATCH?] p4raw-id: //depot/perl@1238
* Negative LENGTH argument to spliceGisle Aas1998-06-281-0/+34
Message-ID: <m3g1gvc5bs.fsf@furu.g.aas.no> p4raw-id: //depot/perl@1237