Change 34773 by [EMAIL PROTECTED] on 2008/11/08 04:02:03

        Subject: Re: [perl #57322] perlbug AutoReply: ungetc() to :scalar might 
cause problems
        From: "Goro Fuji" <[EMAIL PROTECTED]>
        Date: Sun, 27 Jul 2008 14:37:45 +0900
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/MANIFEST#1746 edit
... //depot/perl/ext/PerlIO/scalar/scalar.pm#10 edit
... //depot/perl/ext/PerlIO/scalar/scalar.xs#20 edit
... //depot/perl/ext/PerlIO/scalar/t/scalar_ungetc.t#1 add

Differences ...

==== //depot/perl/MANIFEST#1746 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#1745~34769~   2008-11-07 12:20:21.000000000 -0800
+++ perl/MANIFEST       2008-11-07 20:02:03.000000000 -0800
@@ -965,6 +965,7 @@
 ext/PerlIO/scalar/Makefile.PL  PerlIO layer for scalars
 ext/PerlIO/scalar/scalar.pm    PerlIO layer for scalars
 ext/PerlIO/scalar/scalar.xs    PerlIO layer for scalars
+ext/PerlIO/scalar/t/scalar_ungetc.t    Tests for PerlIO layer for scalars
 ext/PerlIO/t/encoding.t                See if PerlIO encoding conversion works
 ext/PerlIO/t/fail.t            See if bad layers fail
 ext/PerlIO/t/fallback.t                See if PerlIO fallbacks work

==== //depot/perl/ext/PerlIO/scalar/scalar.pm#10 (text) ====
Index: perl/ext/PerlIO/scalar/scalar.pm
--- perl/ext/PerlIO/scalar/scalar.pm#9~33621~   2008-03-31 15:25:19.000000000 
-0700
+++ perl/ext/PerlIO/scalar/scalar.pm    2008-11-07 20:02:03.000000000 -0800
@@ -1,5 +1,5 @@
 package PerlIO::scalar;
-our $VERSION = '0.06';
+our $VERSION = '0.07';
 use XSLoader ();
 XSLoader::load 'PerlIO::scalar';
 1;

==== //depot/perl/ext/PerlIO/scalar/scalar.xs#20 (text) ====
Index: perl/ext/PerlIO/scalar/scalar.xs
--- perl/ext/PerlIO/scalar/scalar.xs#19~34700~  2008-11-03 01:13:16.000000000 
-0800
+++ perl/ext/PerlIO/scalar/scalar.xs    2008-11-07 20:02:03.000000000 -0800
@@ -125,17 +125,6 @@
 }
 
 SSize_t
-PerlIOScalar_unread(pTHX_ PerlIO * f, const void *vbuf, Size_t count)
-{
-    PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar);
-    char *dst = SvGROW(s->var, (STRLEN)s->posn + count);
-    s->posn -= count;
-    Move(vbuf, dst + s->posn, count, char);
-    SvPOK_on(s->var);
-    return count;
-}
-
-SSize_t
 PerlIOScalar_write(pTHX_ PerlIO * f, const void *vbuf, Size_t count)
 {
     if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) {
@@ -289,7 +278,7 @@
     PerlIOScalar_fileno,
     PerlIOScalar_dup,
     PerlIOBase_read,
-    PerlIOScalar_unread,
+    NULL, /* unread */
     PerlIOScalar_write,
     PerlIOScalar_seek,
     PerlIOScalar_tell,

==== //depot/perl/ext/PerlIO/scalar/t/scalar_ungetc.t#1 (text) ====
Index: perl/ext/PerlIO/scalar/t/scalar_ungetc.t
--- /dev/null   2008-11-04 07:18:13.288883315 -0800
+++ perl/ext/PerlIO/scalar/t/scalar_ungetc.t    2008-11-07 20:02:03.000000000 
-0800
@@ -0,0 +1,36 @@
+#!perl -w
+use strict;
+use IO::Handle; # ungetc()
+
+use Test::More tests => 20;
+
+require_ok q{PerlIO::scalar};
+
+my $s = 'foo';
+Internals::SvREADONLY($s, 1);
+eval{
+       $s = 'bar';
+};
+like $@, qr/Modification of a read-only value/, '$s is readonly';
+
+ok open(my $io, '<', \$s), 'open';
+
+getc $io;
+
+my $a = ord 'A';
+
+diag "buffer[$s]";
+is $io->ungetc($a), $a, 'ungetc';
+diag "buffer[$s]";
+
+is getc($io), chr($a), 'getc';
+
+is $s, 'foo', '$s remains "foo"';
+
+is getc($io), 'o', 'getc/2';
+is getc($io), 'o', 'getc/3';
+is getc($io), undef, 'getc/4';
+
+for my $c($a .. ($a+10)){
+       is $io->ungetc($c), $c, "ungetc($c)";
+}
\ No newline at end of file
End of Patch.

Reply via email to