diff options
author | David Mitchell <davem@iabyn.com> | 2014-05-08 13:30:16 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2014-05-08 13:30:16 +0100 |
commit | 89c2544cd319141dbdce6c8408aa52896c2549f1 (patch) | |
tree | fc1fb838597e216abd09e798fa557b57f714fccc /cpan/Encode/Encode.xs | |
parent | c7981a06d5acac597f1bcbdd7664eb04ee6ad5bd (diff) | |
download | perl-89c2544cd319141dbdce6c8408aa52896c2549f1.tar.gz |
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.
Diffstat (limited to 'cpan/Encode/Encode.xs')
-rw-r--r-- | cpan/Encode/Encode.xs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/cpan/Encode/Encode.xs b/cpan/Encode/Encode.xs index 18c982ac47..e08101add5 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]) { |