New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't warn for splice(@a,MAX_LEN) #10742
Comments
From @ikegamiHi,
The intent of splice(@a,MAX_LEN) is quite clearly to truncate the array if Patch coming in seconds. Thanks, |
From @ikegamiPatch attached. |
From @ikegami0001-Don-t-warn-for-splice-a-MAX_LEN-RT-78462.patchFrom b82d83cdc63017718313fbbc5c692cd9e7b48554 Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Tue, 19 Oct 2010 18:34:17 -0700
Subject: [PATCH] Don't warn for splice(@a,MAX_LEN) [RT#78462]
The intent of splice(@a,MAX_LEN) is quite clearly to truncate
the array if it's too large. There's no reason to warn if the
array is currently smaller than the max length.
---
pod/perldelta.pod | 5 +++++
pp.c | 3 ++-
t/lib/warnings/pp | 13 +++++++++++++
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 3715fe4..fbe5eaa 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -124,6 +124,11 @@ You can now use the C<keys>, C<values>, C<each> builtin functions on arrays
This is actually a change introduced in perl 5.12.0, but it was missed from
that release's perldelta.
+=head2 C<splice()> doesn't warn when truncating
+
+You can now limit the size of an array using C<splice(@a,MAX_LEN)> without
+worrying about warnings.
+
=head1 Security
XXX Any security-related notices go here. In particular, any security
diff --git a/pp.c b/pp.c
index b777f39..ad0611f 100644
--- a/pp.c
+++ b/pp.c
@@ -5198,7 +5198,8 @@ PP(pp_splice)
length = AvMAX(ary) + 1;
}
if (offset > AvFILLp(ary) + 1) {
- Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "splice() offset past end of array" );
+ if (SP - MARK)
+ Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "splice() offset past end of array" );
offset = AvFILLp(ary) + 1;
}
after = AvFILLp(ary) + 1 - (offset + length);
diff --git a/t/lib/warnings/pp b/t/lib/warnings/pp
index d158144..838274e 100644
--- a/t/lib/warnings/pp
+++ b/t/lib/warnings/pp
@@ -46,6 +46,19 @@ EXPECT
Attempt to use reference as lvalue in substr at - line 5.
########
# pp.c
+use warnings 'misc' ;
+@a = qw( a b c );
+splice(@a, 4, 0, 'e') ;
+use warnings 'misc' ;
+@a = qw( a b c );
+splice(@a, 4) ;
+no warnings 'misc' ;
+@a = qw( a b c );
+splice(@a, 4, 0, 'e') ;
+EXPECT
+splice() offset past end of array at - line 4.
+########
+# pp.c
use warnings 'uninitialized' ;
*x = *{ undef() };
no warnings 'uninitialized' ;
--
1.7.1.1
|
@ikegami - Status changed from 'new' to 'open' |
From @rgarciaOn 20 October 2010 04:50, Eric Brine via RT <perlbug-followup@perl.org> wrote:
I notice that this patch also removes the warning for C<splice @array, |
From @ikegamiOn Sat, Oct 23, 2010 at 4:47 PM, Rafael Garcia-Suarez <rgs@consttype.org>wrote:
I knew I was missing something. I'll update the patch. |
From @cpansproutRT seemed to be down for a while and missed the latest patch. It is at: nntp://nntp.perl.org/AANLkTikLovBP1CsJ5t6tEZ8hNCpH+_HnPmprTrURgNTf@mail.gmail.com |
From @cpansproutOn Nov 8, 2010, at 11:08 AM, Eric Brine wrote:
I’ve just had a look. The tests are checking that the number of warnings is the same for splice @non-magical and tied(@ary)->SPLICE. So it’s the module itself, not the tests, that needs changing.
Get a Mac? I really don’t know. Configure -d works for me. Do you have BerkeleyDB installed? |
From @ikegami
I got DB_File updated upstream, and it was incorporated into blead. Rebased patch attached. Thanks, |
From @ikegami0001-The-intent-of-splice-a-MAX_LEN-is-quite-clearly-to-t.patchFrom 3893fef7fda5b2563eb64f8a2a6d66d815bf3108 Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Wed, 2 Mar 2011 17:30:17 -0500
Subject: [PATCH] The intent of splice(@a,MAX_LEN) is quite clearly to truncate
the array if it's too large. There's no reason to warn if it's
currently smaller than the max length.
---
pod/perldelta.pod | 5 +++++
pp.c | 4 +++-
t/lib/warnings/pp | 19 +++++++++++++++++++
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 5a020c9..78a6a04 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -27,6 +27,11 @@ L<feature.pm|feature>, even outside the scope of C<use feature>. Relevant
documentation files L<CORE>, L<feature>, L<perlfunc>, L<perlsub>, and
L<perlsyn> have been updated.
+=head2 C<splice()> doesn't warn when truncating
+
+You can now limit the size of an array using C<splice(@a,MAX_LEN)> without
+worrying about warnings.
+
=head2 C<continue> no longer requires the "switch" feature
The C<continue> keyword has two meanings. It can introduce a C<continue>
diff --git a/pp.c b/pp.c
index 385f1be..d3d4cc8 100644
--- a/pp.c
+++ b/pp.c
@@ -5434,6 +5434,7 @@ S_deref_plain_array(pTHX_ AV *ary)
PP(pp_splice)
{
dVAR; dSP; dMARK; dORIGMARK;
+ int num_args = (SP - MARK);
register AV *ary = DEREF_PLAIN_ARRAY(MUTABLE_AV(*++MARK));
register SV **src;
register SV **dst;
@@ -5477,7 +5478,8 @@ PP(pp_splice)
length = AvMAX(ary) + 1;
}
if (offset > AvFILLp(ary) + 1) {
- Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "splice() offset past end of array" );
+ if (num_args > 2)
+ Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "splice() offset past end of array" );
offset = AvFILLp(ary) + 1;
}
after = AvFILLp(ary) + 1 - (offset + length);
diff --git a/t/lib/warnings/pp b/t/lib/warnings/pp
index d158144..2251b94 100644
--- a/t/lib/warnings/pp
+++ b/t/lib/warnings/pp
@@ -46,6 +46,25 @@ EXPECT
Attempt to use reference as lvalue in substr at - line 5.
########
# pp.c
+use warnings 'misc' ;
+@a = qw( a b c );
+splice(@a, 4, 0, 'e') ;
+@a = qw( a b c );
+splice(@a, 4, 1) ;
+@a = qw( a b c );
+splice(@a, 4) ;
+no warnings 'misc' ;
+@a = qw( a b c );
+splice(@a, 4, 0, 'e') ;
+@a = qw( a b c );
+splice(@a, 4, 1) ;
+@a = qw( a b c );
+splice(@a, 4) ;
+EXPECT
+splice() offset past end of array at - line 4.
+splice() offset past end of array at - line 6.
+########
+# pp.c
use warnings 'uninitialized' ;
*x = *{ undef() };
no warnings 'uninitialized' ;
--
1.7.2.5
|
From @cpansproutOn Mon Jun 20 12:54:48 2011, ikegami@adaelis.com wrote:
Thank you. Applied as 5cd408a. |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#78462 (status was 'resolved')
Searchable as RT78462$
The text was updated successfully, but these errors were encountered: