Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 095599f

Browse files
committed
PerlIO-encoding-0.26_01
1 parent 89e6c11 commit 095599f

File tree

6 files changed

+61
-53
lines changed

6 files changed

+61
-53
lines changed

dist/Module-CoreList/lib/Module/CoreList.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17556,6 +17556,7 @@ our %delta = (
1755617556
'IPC::Cmd' => '1.02',
1755717557
'Net::Ping' => '2.70',
1755817558
'NEXT' => '0.67_01',
17559+
'PerlIO::encoding' => '0.26_01',
1755917560
'PerlIO::scalar' => '0.29',
1756017561
'List::Util' => '1.50_11',
1756117562
'List::Util::XS' => '1.50_11',

ext/PerlIO-encoding/encoding.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package PerlIO::encoding;
22

33
use strict;
4-
our $VERSION = '0.24';
4+
our $VERSION = '0.26_01';
5+
our $XS_VERSION = $VERSION;
6+
$VERSION = eval $VERSION;
57
our $DEBUG = 0;
68
$DEBUG and warn __PACKAGE__, " called by ", join(", ", caller), "\n";
79

ext/PerlIO-encoding/encoding.xs

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
#include "EXTERN.h"
33
#include "perl.h"
44
#include "XSUB.h"
5+
56
#define U8 U8
7+
#ifndef get_svs
8+
# define get_svs(str, flags) get_sv((str), (flags))
9+
# define get_avs(str, flags) get_av((str), (flags))
10+
# define get_hvs(str, flags) get_hv((str), (flags))
11+
#endif
12+
#ifndef SvPVCLEAR
13+
# define SvPVCLEAR(sv) sv_setpvs(sv, "")
14+
#endif
615

716
#define OUR_DEFAULT_FB "Encode::PERLQQ"
817

@@ -163,7 +172,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs *
163172
PerlIOBase(f)->flags |= PERLIO_F_UTF8;
164173
}
165174

166-
e->chk = newSVsv(get_sv("PerlIO::encoding::fallback", 0));
175+
e->chk = newSVsv(get_svs("PerlIO::encoding::fallback", 0));
167176
e->inEncodeCall = 0;
168177

169178
FREETMPS;
@@ -203,7 +212,7 @@ PerlIOEncode_get_base(pTHX_ PerlIO * f)
203212
e->base.bufsiz = 1024;
204213
if (!e->bufsv) {
205214
e->bufsv = newSV(e->base.bufsiz);
206-
sv_setpvn(e->bufsv, "", 0);
215+
SvPVCLEAR(e->bufsv);
207216
}
208217
e->base.buf = (STDCHAR *) SvPVX(e->bufsv);
209218
if (!e->base.ptr)
@@ -307,42 +316,19 @@ PerlIOEncode_fill(pTHX_ PerlIO * f)
307316
goto end_of_file;
308317
}
309318
}
310-
if (SvCUR(e->dataSV)) {
311-
/* something left over from last time - create a normal
312-
SV with new data appended
313-
*/
314-
if (use + SvCUR(e->dataSV) > e->base.bufsiz) {
315-
if (e->flags & NEEDS_LINES) {
316-
/* Have to grow buffer */
317-
e->base.bufsiz = use + SvCUR(e->dataSV);
318-
PerlIOEncode_get_base(aTHX_ f);
319-
}
320-
else {
321-
use = e->base.bufsiz - SvCUR(e->dataSV);
322-
}
323-
}
324-
sv_catpvn(e->dataSV,(char*)ptr,use);
325-
}
326-
else {
327-
/* Create a "dummy" SV to represent the available data from layer below */
328-
if (SvLEN(e->dataSV) && SvPVX_const(e->dataSV)) {
329-
Safefree(SvPVX_mutable(e->dataSV));
330-
}
331-
if (use > (SSize_t)e->base.bufsiz) {
332-
if (e->flags & NEEDS_LINES) {
333-
/* Have to grow buffer */
334-
e->base.bufsiz = use;
335-
PerlIOEncode_get_base(aTHX_ f);
336-
}
337-
else {
338-
use = e->base.bufsiz;
319+
if (!SvCUR(e->dataSV))
320+
SvPVCLEAR(e->dataSV);
321+
if (use + SvCUR(e->dataSV) > e->base.bufsiz) {
322+
if (e->flags & NEEDS_LINES) {
323+
/* Have to grow buffer */
324+
e->base.bufsiz = use + SvCUR(e->dataSV);
325+
PerlIOEncode_get_base(aTHX_ f);
339326
}
327+
else {
328+
use = e->base.bufsiz - SvCUR(e->dataSV);
340329
}
341-
SvPV_set(e->dataSV, (char *) ptr);
342-
SvLEN_set(e->dataSV, 0); /* Hands off sv.c - it isn't yours */
343-
SvCUR_set(e->dataSV,use);
344-
SvPOK_only(e->dataSV);
345330
}
331+
sv_catpvn(e->dataSV,(char*)ptr,use);
346332
SvUTF8_off(e->dataSV);
347333
PUSHMARK(sp);
348334
XPUSHs(e->enc);
@@ -661,7 +647,7 @@ PROTOTYPES: ENABLE
661647

662648
BOOT:
663649
{
664-
SV *chk = get_sv("PerlIO::encoding::fallback", GV_ADD|GV_ADDMULTI);
650+
SV *chk = get_svs("PerlIO::encoding::fallback", GV_ADD|GV_ADDMULTI);
665651
/*
666652
* we now "use Encode ()" here instead of
667653
* PerlIO/encoding.pm. This avoids SEGV when ":encoding()"

ext/PerlIO-encoding/t/encoding.t

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BEGIN {
1616
require "../../t/charset_tools.pl";
1717
}
1818

19-
use Test::More tests => 24;
19+
use Test::More tests => 27;
2020

2121
my $grk = "grk$$";
2222
my $utf = "utf$$";
@@ -25,7 +25,7 @@ my $fail2 = "fb$$";
2525
my $russki = "koi8r$$";
2626
my $threebyte = "3byte$$";
2727

28-
if (open(GRK, ">$grk")) {
28+
if (open(GRK, '>', $grk)) {
2929
binmode(GRK, ":bytes");
3030
# alpha beta gamma in ISO 8859-7
3131
print GRK "\xe1\xe2\xe3";
@@ -40,7 +40,7 @@ if (open(GRK, ">$grk")) {
4040
close($i);
4141
}
4242

43-
if (open(UTF, "<$utf")) {
43+
if (open(UTF, '<', $utf)) {
4444
binmode(UTF, ":bytes");
4545

4646
# alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
@@ -57,7 +57,7 @@ if (open(UTF, "<$utf")) {
5757
close($i);
5858
}
5959

60-
if (open(GRK, "<$grk")) {
60+
if (open(GRK, '<', $grk)) {
6161
binmode(GRK, ":bytes");
6262
is(scalar <GRK>, "\xe1\xe2\xe3");
6363
close GRK;
@@ -68,10 +68,10 @@ $SIG{__WARN__} = sub {$warn .= $_[0]};
6868
is (open(FAIL, ">:encoding(NoneSuch)", $fail1), undef, 'Open should fail');
6969
like($warn, qr/^Cannot find encoding "NoneSuch" at/);
7070

71-
is(open(RUSSKI, ">$russki"), 1);
71+
is(open(RUSSKI, '>', $russki), 1);
7272
print RUSSKI "\x3c\x3f\x78";
7373
close RUSSKI or die "Could not close: $!";
74-
open(RUSSKI, "$russki");
74+
open(RUSSKI, '<', $russki);
7575
binmode(RUSSKI, ":raw");
7676
my $buf1;
7777
read(RUSSKI, $buf1, 1);
@@ -231,6 +231,16 @@ is $x, "To hymn him who heard her herd herd\n",
231231

232232
} # SKIP
233233

234+
# decoding shouldn't mutate the original bytes [perl #132833]
235+
{
236+
my $b = "a\0b\0\n\0";
237+
open my $fh, "<:encoding(UTF16-LE)", \$b or die;
238+
is scalar(<$fh>), "ab\n";
239+
is $b, "a\0b\0\n\0";
240+
close $fh or die;
241+
is $b, "a\0b\0\n\0";
242+
}
243+
234244
END {
235245
1 while unlink($grk, $utf, $fail1, $fail2, $russki, $threebyte);
236246
}

ext/PerlIO-encoding/t/fallback.t

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BEGIN {
1616
import Encode qw(:fallback_all);
1717
}
1818

19-
use Test::More tests => 9;
19+
use Test::More tests => 10;
2020

2121
# $PerlIO::encoding = 0; # WARN_ON_ERR|PERLQQ;
2222

@@ -33,7 +33,7 @@ my $file = "fallback$$.txt";
3333
like($message, qr/does not map to iso-8859-1/o, "FB_WARN message");
3434
}
3535

36-
open($fh,$file) || die "File cannot be re-opened";
36+
open($fh,'<',$file) || die "File cannot be re-opened";
3737
my $line = <$fh>;
3838
is($line,"\\x{20ac}0.02\n","perlqq escapes");
3939
close($fh);
@@ -45,14 +45,14 @@ my $str = "\x{20AC}";
4545
print $fh $str,"0.02\n";
4646
close($fh);
4747

48-
open($fh,$file) || die "File cannot be re-opened";
48+
open($fh,'<',$file) || die "File cannot be re-opened";
4949
my $line = <$fh>;
5050
is($line,"&#8364;0.02\n","HTML escapes");
5151
close($fh);
5252

5353
{
5454
no utf8;
55-
open($fh,">$file") || die "File cannot be re-opened";
55+
open($fh,'>',$file) || die "File cannot be re-opened";
5656
binmode($fh);
5757
print $fh "\xA30.02\n";
5858
close($fh);
@@ -64,13 +64,20 @@ printf "# %x\n",ord($line);
6464
is($line,"\\xA30.02\n","Escaped non-mapped char");
6565
close($fh);
6666

67-
$PerlIO::encoding::fallback = Encode::WARN_ON_ERROR;
67+
{
68+
my $message = '';
69+
local $SIG{__WARN__} = sub { $message = $_[0] };
6870

69-
ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
70-
my $line = <$fh>;
71-
printf "# %x\n",ord($line);
72-
is($line,"\x{FFFD}0.02\n","Unicode replacement char");
73-
close($fh);
71+
$PerlIO::encoding::fallback = Encode::WARN_ON_ERR;
72+
73+
ok(open($fh,"<encoding(US-ASCII)",$file),"Opened as ASCII");
74+
my $line = <$fh>;
75+
printf "# %x\n",ord($line);
76+
is($line,"\x{FFFD}0.02\n","Unicode replacement char");
77+
close($fh);
78+
79+
like($message, qr/does not map to Unicode/o, "FB_WARN message");
80+
}
7481

7582
END {
7683
1 while unlink($file);

pod/perlcdelta.pod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ better icmpv6 support.
430430

431431
Fix for GLOB stubs [cpan #123002].
432432

433+
=item L<PerlIO::encoding> 0.26_01
434+
433435
=item L<PerlIO::scalar> 0.29
434436

435437
check invariant at compile time.

0 commit comments

Comments
 (0)