Front page | perl.cvs.parrot |
Postings from December 2008
[svn:parrot] r34391 - trunk/src/io
From:
chromatic
Date:
December 26, 2008 10:00
Subject:
[svn:parrot] r34391 - trunk/src/io
Message ID:
20081226180005.DDF25CBA12@x12.develooper.com
Author: chromatic
Date: Fri Dec 26 10:00:05 2008
New Revision: 34391
Modified:
trunk/src/io/buffer.c
Log:
[IO] Made peeking on an unbuffered IO PMC promote the PMC to a buffered PMC.
See RT #61290 (François Perrad).
Modified: trunk/src/io/buffer.c
==============================================================================
--- trunk/src/io/buffer.c (original)
+++ trunk/src/io/buffer.c Fri Dec 26 10:00:05 2008
@@ -395,13 +395,11 @@
Parrot_io_peek_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle),
ARGOUT(STRING **buf))
{
- UINTVAL len = 1;
- size_t avail = 0;
-
- INTVAL buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
unsigned char *buffer_next;
-
- STRING * const s = Parrot_io_make_string(interp, buf, 1);
+ STRING * const s = Parrot_io_make_string(interp, buf, 1);
+ UINTVAL len = 1;
+ size_t avail = 0;
+ INTVAL buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
/* write buffer flush */
if (buffer_flags & PIO_BF_WRITEBUF) {
@@ -414,10 +412,12 @@
/* (re)fill the buffer */
if (! (buffer_flags & PIO_BF_READBUF)) {
size_t got;
- /* exception if we're unbuffered */
- if (Parrot_io_get_buffer_size(interp, filehandle) == 0)
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
- "Can't peek at unbuffered I/O");
+
+ /* promote to buffered if unbuffered */
+ if (Parrot_io_get_buffer_size(interp, filehandle) == 0) {
+ Parrot_io_setbuf(interp, filehandle, 1);
+ return Parrot_io_peek_buffer(interp, filehandle, buf);
+ }
/* Parrot_io_fill_readbuf() can return -1, but len should be positive */
got = Parrot_io_fill_readbuf(interp, filehandle);
@@ -432,11 +432,13 @@
}
/* if we got any data, then copy out the next byte */
- memcpy(s->strstart, buffer_next, len);
+ memmove(s->strstart, buffer_next, len);
s->bufused = s->strlen = len;
+
return len;
}
+
/*
=item C<size_t Parrot_io_readline_buffer>
-
[svn:parrot] r34391 - trunk/src/io
by chromatic