From: Vincent Pit Date: Sun, 4 Oct 2009 14:42:55 +0000 (+0200) Subject: Introduce VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID and fix 5.11.0 compatibility X-Git-Tag: v0.38~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=6a204757f3b9c5d10bc57e21cbb65c0e29688066;p=perl%2Fmodules%2FVariable-Magic.git Introduce VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID and fix 5.11.0 compatibility --- diff --git a/Magic.xs b/Magic.xs index 1dada02..db8e230 100644 --- a/Magic.xs +++ b/Magic.xs @@ -148,13 +148,22 @@ STATIC SV *vmg_clone(pTHX_ SV *sv, tTHX owner) { # define VMG_UVAR 0 #endif -/* Applied to dev-5.9 as 25854, integrated to maint-5.8 as 28160 */ -#ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN -# if VMG_HAS_PERL_MAINT(5, 8, 9, 28160) || VMG_HAS_PERL_MAINT(5, 9, 3, 25854) || VMG_HAS_PERL(5, 10, 0) +/* Applied to dev-5.9 as 25854, integrated to maint-5.8 as 28160, partially + * reverted to dev-5.11 as 9cdcb38b */ +#if VMG_HAS_PERL_MAINT(5, 8, 9, 28160) || VMG_HAS_PERL_MAINT(5, 9, 3, 25854) || VMG_HAS_PERL(5, 10, 0) +# ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN # define VMG_COMPAT_ARRAY_PUSH_NOLEN 1 -# else +# endif +# ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID +# define VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID 1 +# endif +#else +# ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN # define VMG_COMPAT_ARRAY_PUSH_NOLEN 0 # endif +# ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID +# define VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID 0 +# endif #endif /* Applied to dev-5.11 as 34908 */ @@ -1260,6 +1269,8 @@ BOOT: newCONSTSUB(stash, "VMG_UVAR", newSVuv(VMG_UVAR)); newCONSTSUB(stash, "VMG_COMPAT_ARRAY_PUSH_NOLEN", newSVuv(VMG_COMPAT_ARRAY_PUSH_NOLEN)); + newCONSTSUB(stash, "VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID", + newSVuv(VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID)); newCONSTSUB(stash, "VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID", newSVuv(VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID)); newCONSTSUB(stash, "VMG_COMPAT_ARRAY_UNDEF_CLEAR", diff --git a/Makefile.PL b/Makefile.PL index 644bb90..d541a7c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,6 +19,7 @@ if (defined $pl && length $pl) { push @DEFINES, '-DVMG_PERL_PATCHLEVEL=' . $pl; print $pl, "\n"; } else { + $pl = undef; print "none\n"; } @@ -40,6 +41,17 @@ if ($^V eq v5.8.8) { } print $is_as ? "yes\n" : "no\n"; +my $is_5110rel = 0; +print "Checking if this is a released perl 5.11.0... "; +if ($^V eq v5.11.0 and not defined $pl) { + my $describe = $Config{git_describe}; + if (defined $describe and $describe !~ /^GitLive-/) { + $is_5110rel = 1; + push @DEFINES, '-DVMG_COMPAT_ARRAY_PUSH_NOLEN=0'; + } +} +print $is_5110rel ? "yes\n" : "no\n"; + # Threads, Windows and 5.8.x don't seem to be best friends if ($^O eq 'MSWin32' && $^V lt v5.9.0) { push @DEFINES, '-DVMG_MULTIPLICITY=0'; diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index 0d6f132..fe96a19 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -452,6 +452,11 @@ When this constant is true, you can use the C callbac =head2 C True for perls that don't call 'len' magic when you push an element in a magical array. +Starting from perl 5.11.0, this only refers to pushes in non-void context and hence is false. + +=head2 C + +True for perls that don't call 'len' magic when you push in void context an element in a magical array. =head2 C @@ -539,6 +544,8 @@ I : 'len' magic is no longer invoked when calling C with a magic I : 'len' magic is no longer called when pushing / unshifting an element into a magical array in void context. The C part was already covered by I. +I : 'len' magic is called again when pushing into a magical array in non-void context. + =back =head1 EXPORT @@ -557,7 +564,10 @@ our %EXPORT_TAGS = ( 'funcs' => [ qw/wizard gensig getsig cast getdata dispell/ ], 'consts' => [ qw/SIG_MIN SIG_MAX SIG_NBR MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/, - qw/VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID VMG_COMPAT_ARRAY_UNDEF_CLEAR VMG_COMPAT_SCALAR_LENGTH_NOLEN/, + qw/VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID/, + qw/VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID/, + qw/VMG_COMPAT_ARRAY_UNDEF_CLEAR/, + qw/VMG_COMPAT_SCALAR_LENGTH_NOLEN/, qw/VMG_PERL_PATCHLEVEL/, qw/VMG_THREADSAFE VMG_FORKSAFE/, qw/VMG_OP_INFO_NAME VMG_OP_INFO_OBJECT/ diff --git a/t/01-import.t b/t/01-import.t index 8b6e055..5dc418d 100644 --- a/t/01-import.t +++ b/t/01-import.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2 * 22; +use Test::More tests => 2 * 23; require Variable::Magic; @@ -17,8 +17,10 @@ my %syms = ( map { $_ => '' } qw/ SIG_MIN SIG_MAX SIG_NBR MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR - VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID - VMG_COMPAT_ARRAY_UNDEF_CLEAR VMG_COMPAT_SCALAR_LENGTH_NOLEN + VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID + VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID + VMG_COMPAT_ARRAY_UNDEF_CLEAR + VMG_COMPAT_SCALAR_LENGTH_NOLEN VMG_PERL_PATCHLEVEL VMG_THREADSAFE VMG_FORKSAFE VMG_OP_INFO_NAME VMG_OP_INFO_OBJECT diff --git a/t/31-array.t b/t/31-array.t index cf1ac0b..b5ff1ed 100644 --- a/t/31-array.t +++ b/t/31-array.t @@ -5,7 +5,7 @@ use warnings; use Test::More tests => 2 * 27 + 13 + 1; -use Variable::Magic qw/cast dispell VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID VMG_COMPAT_ARRAY_UNDEF_CLEAR/; +use Variable::Magic qw/cast dispell VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID VMG_COMPAT_ARRAY_UNDEF_CLEAR/; use lib 't/lib'; use Variable::Magic::TestWatcher; @@ -53,10 +53,12 @@ watch { $b = $#a } { len => 1 }, 'length $#'; is $b, 2, 'array: length $# correctly'; watch { push @a, 'x'; () } - { set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN },'push (void)'; + { set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID }, + 'push (void)'; $b = watch { push @a, 'y' } - { set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN }, 'push (scalar)'; + { set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN }, + 'push (scalar)'; is $b, 5, 'array: push (scalar) correctly'; $b = watch { pop @a } { set => 1, len => 1 }, 'pop';