Skip Menu |

This queue is for tickets about the Encode CPAN distribution.

Report information
The Basics
Id: 51263
Status: resolved
Priority: 0/
Queue: Encode

People
Owner: Nobody in particular
Requestors: TONYC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.37
Fixed in: (no value)



Subject: set magic is not applied when modifying encode arguments
For the unicode encodings, set magic is not supplied when the encode() method modifies its arguments. Typically this could be fixed by adding an OUTPUT clause to the XS function listing any modified parameters, but the explicit XSRETURN means that the code generated by this clause would not be executed. In my patch I've added an explicit SvSETMAGIC() to apply set magic. This diff also fixes the issue reported in: http://rt.perl.org/rt3//Ticket/Display.html?id=60472 It's possible encode() methods for other encodings have the same issue, I haven't checked.
Subject: encode-magic.diff
Only in Encode-2.37/Byte: Makefile.old Only in Encode-2.37/CN: Makefile.old Only in Encode-2.37/EBCDIC: Makefile.old Only in Encode-2.37/JP: Makefile.old Only in Encode-2.37/KR: Makefile.old Only in Encode-2.37/: Makefile.old Only in Encode-2.37/Symbol: Makefile.old diff -ur Encode-2.37-orig/t/Unicode.t Encode-2.37/t/Unicode.t --- Encode-2.37-orig/t/Unicode.t 2009-09-07 00:32:25.000000000 +1000 +++ Encode-2.37/t/Unicode.t 2009-11-10 18:52:10.000000000 +1100 @@ -20,8 +20,8 @@ use strict; #use Test::More 'no_plan'; -use Test::More tests => 37; -use Encode qw(encode decode); +use Test::More tests => 38; +use Encode qw(encode decode find_encoding); # # see @@ -131,5 +131,35 @@ is(decode("UTF-7", encode("UTF-7", $content)), $content, "UTF-7 RT:$file"); } + +# Magic +{ + # see http://rt.perl.org/rt3//Ticket/Display.html?id=60472 + my $work = chr(0x100); + my $encoding = find_encoding("UTF16-BE"); + my $tied; + tie $tied, SomeScalar => \$work; + my $result = $encoding->encode($tied, 1); + is($work, "", "check set magic was applied"); +} + +package SomeScalar; +use Tie::Scalar; +use vars qw(@ISA); +BEGIN { @ISA = 'Tie::Scalar' } + +sub TIESCALAR { + my ($class, $ref) = @_; + return bless $ref, $class; +} + +sub FETCH { + ${$_[0]} +} + +sub STORE { + ${$_[0]} = $_[1]; +} + 1; __END__ Only in Encode-2.37/t: Unicode.t~ Only in Encode-2.37/TW: Makefile.old Only in Encode-2.37/Unicode: Makefile.old diff -ur Encode-2.37-orig/Unicode/Unicode.xs Encode-2.37/Unicode/Unicode.xs --- Encode-2.37-orig/Unicode/Unicode.xs 2009-09-07 00:32:25.000000000 +1000 +++ Encode-2.37/Unicode/Unicode.xs 2009-11-10 18:52:42.000000000 +1100 @@ -377,5 +377,7 @@ if (!temp_result) shrink_buffer(result); + SvSETMAGIC(utf8); + XSRETURN(1); }
Thanks, applied in my repository. Excellent patch with t/. Dan the Maintainer Thereof On Tue Nov 10 03:04:14 2009, TONYC wrote: Show quoted text
> For the unicode encodings, set magic is not supplied when the encode() > method modifies its arguments. > > Typically this could be fixed by adding an OUTPUT clause to the XS > function listing any modified parameters, but the explicit XSRETURN > means that the code generated by this clause would not be executed. > > In my patch I've added an explicit SvSETMAGIC() to apply set magic. > > This diff also fixes the issue reported in: > > http://rt.perl.org/rt3//Ticket/Display.html?id=60472 > > It's possible encode() methods for other encodings have the same issue, > I haven't checked.