From 89c2544cd319141dbdce6c8408aa52896c2549f1 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Thu, 8 May 2014 13:30:16 +0100 Subject: [PATCH] Fix Encode 2.60 with g++ The recently added Encode 2.60 won't compile with g++, due to assigning a const char * const pointer to a char* struct field. The intent of the code itself is a bit unclear, but it appears to be to set SvPVX as a read-only alias of a const string, using the SvLEN()=0 trick to avoid it being freed. Fix the g++ builds by casting away the constness, and add some asserts and comments to make it less unclear what's going on. --- Porting/Maintainers.pl | 18 ++++++++++++++++++ cpan/Encode/Byte/Makefile.PL | 5 ++++- cpan/Encode/CN/Makefile.PL | 5 ++++- cpan/Encode/EBCDIC/Makefile.PL | 5 ++++- cpan/Encode/Encode.pm | 2 +- cpan/Encode/Encode.xs | 5 ++++- cpan/Encode/Encode/Makefile_PL.e2x | 5 ++++- cpan/Encode/JP/Makefile.PL | 5 ++++- cpan/Encode/KR/Makefile.PL | 5 ++++- cpan/Encode/Symbol/Makefile.PL | 5 ++++- cpan/Encode/TW/Makefile.PL | 5 ++++- cpan/Encode/bin/enc2xs | 5 ++++- t/porting/customized.dat | 11 +++++++++++ 13 files changed, 70 insertions(+), 11 deletions(-) diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index 32083ef..df005a0 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -390,6 +390,24 @@ use File::Glob qw(:case); 'Encode' => { 'DISTRIBUTION' => 'DANKOGAI/Encode-2.60.tar.gz', 'FILES' => q[cpan/Encode], + 'CUSTOMIZED' => [ + # Waiting to be merged upstream: see CPAN RT#95130 and + # Message-Id: <201405062058.s46KwdCZ013775@m-l.org> + qw( + Byte/Makefile.PL + CN/Makefile.PL + EBCDIC/Makefile.PL + Encode.pm + Encode.xs + Encode/Makefile_PL.e2x + JP/Makefile.PL + KR/Makefile.PL + Symbol/Makefile.PL + TW/Makefile.PL + bin/enc2xs + ), + ], + }, 'encoding::warnings' => { diff --git a/cpan/Encode/Byte/Makefile.PL b/cpan/Encode/Byte/Makefile.PL index 58deaf3..0cc5ece 100644 --- a/cpan/Encode/Byte/Makefile.PL +++ b/cpan/Encode/Byte/Makefile.PL @@ -120,8 +120,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/CN/Makefile.PL b/cpan/Encode/CN/Makefile.PL index efd2edb..5e689cb 100644 --- a/cpan/Encode/CN/Makefile.PL +++ b/cpan/Encode/CN/Makefile.PL @@ -96,8 +96,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/EBCDIC/Makefile.PL b/cpan/Encode/EBCDIC/Makefile.PL index 7a3a4cb..50ae0df 100644 --- a/cpan/Encode/EBCDIC/Makefile.PL +++ b/cpan/Encode/EBCDIC/Makefile.PL @@ -77,8 +77,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/Encode.pm b/cpan/Encode/Encode.pm index 9dc970b..5d477f6 100644 --- a/cpan/Encode/Encode.pm +++ b/cpan/Encode/Encode.pm @@ -4,7 +4,7 @@ package Encode; use strict; use warnings; -our $VERSION = sprintf "%d.%02d", q$Revision: 2.60 $ =~ /(\d+)/g; +our $VERSION = sprintf "%d.%02d", q$Revision: 2.60_01 $ =~ /(\d+)/g; use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG}; use XSLoader (); XSLoader::load( __PACKAGE__, $VERSION ); diff --git a/cpan/Encode/Encode.xs b/cpan/Encode/Encode.xs index 18c982a..e08101a 100644 --- a/cpan/Encode/Encode.xs +++ b/cpan/Encode/Encode.xs @@ -47,8 +47,11 @@ Encode_XSEncoding(pTHX_ encode_t * enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) { diff --git a/cpan/Encode/Encode/Makefile_PL.e2x b/cpan/Encode/Encode/Makefile_PL.e2x index b786567..c17a509 100644 --- a/cpan/Encode/Encode/Makefile_PL.e2x +++ b/cpan/Encode/Encode/Makefile_PL.e2x @@ -113,8 +113,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/JP/Makefile.PL b/cpan/Encode/JP/Makefile.PL index cb671b6..6ec73ea 100644 --- a/cpan/Encode/JP/Makefile.PL +++ b/cpan/Encode/JP/Makefile.PL @@ -96,8 +96,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/KR/Makefile.PL b/cpan/Encode/KR/Makefile.PL index fa6f0d8..0790ed0 100644 --- a/cpan/Encode/KR/Makefile.PL +++ b/cpan/Encode/KR/Makefile.PL @@ -94,8 +94,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/Symbol/Makefile.PL b/cpan/Encode/Symbol/Makefile.PL index b525610..2dec60d 100644 --- a/cpan/Encode/Symbol/Makefile.PL +++ b/cpan/Encode/Symbol/Makefile.PL @@ -82,8 +82,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/TW/Makefile.PL b/cpan/Encode/TW/Makefile.PL index c7711d9..69b3e96 100644 --- a/cpan/Encode/TW/Makefile.PL +++ b/cpan/Encode/TW/Makefile.PL @@ -92,8 +92,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/cpan/Encode/bin/enc2xs b/cpan/Encode/bin/enc2xs index 966c456..c44487d 100644 --- a/cpan/Encode/bin/enc2xs +++ b/cpan/Encode/bin/enc2xs @@ -316,8 +316,11 @@ Encode_XSEncoding(pTHX_ encode_t *enc) SV *iv = newSViv(PTR2IV(enc)); SV *sv = sv_bless(newRV_noinc(iv),stash); int i = 0; + /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's + constness, in the hope that perl won't mess with it. */ + assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); SvFLAGS(iv) |= SVp_POK; - SvPVX(iv) = enc->name[0]; + SvPVX(iv) = (char*) enc->name[0]; PUSHMARK(sp); XPUSHs(sv); while (enc->name[i]) diff --git a/t/porting/customized.dat b/t/porting/customized.dat index cd4bdde..0563c3f 100644 --- a/t/porting/customized.dat +++ b/t/porting/customized.dat @@ -1,4 +1,15 @@ Digest::MD5 cpan/Digest-MD5/t/files.t bdbe05b705d9da305fedce7a9f4b6ba63250c7cf +Encode cpan/Encode/bin/enc2xs f60036fd3574ec05c9aab7f4db00a828d5dea92d +Encode cpan/Encode/Byte/Makefile.PL 0986e25f981a3bf182a13a0060d28d4efedd87e6 +Encode cpan/Encode/CN/Makefile.PL 5507a49d822d0c1d14e967f4595e29e9c873540b +Encode cpan/Encode/EBCDIC/Makefile.PL 574289638393eb6b1109eb9a6874bfe8c5d2ddea +Encode cpan/Encode/Encode.pm fc26f74b44148a4f0c9e8ec2b0a9c20eae96249d +Encode cpan/Encode/Encode.xs 9ee24e3915319bdec044535667a39e3dc531fdcf +Encode cpan/Encode/Encode/Makefile_PL.e2x 4d0420b19cea75c513842329c1906221130bdb6b +Encode cpan/Encode/JP/Makefile.PL a9ca9c836424cc2ecbefa4933d9da5db54131b98 +Encode cpan/Encode/KR/Makefile.PL 0e46ded62ec6b128e5562277658132700425a48c +Encode cpan/Encode/Symbol/Makefile.PL 4beddbbd00f638b7de9c6cd0821d9d38020a8218 +Encode cpan/Encode/TW/Makefile.PL 0cc44f95e59f45c0fb3b66bde41525f13c19a25c Module::Build cpan/Module-Build/lib/Module/Build/ConfigData.pm 85eb9656e68d1f256737dc52d86b5d0fed28f832 PerlIO::via::QuotedPrint cpan/PerlIO-via-QuotedPrint/t/QuotedPrint.t ca39f0146e89de02c746e199c45dcb3e5edad691 Text::Balanced cpan/Text-Balanced/t/01_compile.t 1598cf491a48fa546260a2ec41142abe84da533d -- 2.7.4