cataphract Wed, 13 Oct 2010 03:13:29 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=304354
Log:
- Fixed forward stream seeking emulation in streams that don't support seeking
in situations where the read operation gives back less data than requested
and when there was data in the buffer before the emulation started. Also made
more consistent its behavior -- should return failure every time less data
than was requested was skipped.
- Small performance improvement by correcting off-by-one error that generate an
invalid call to the seek handler or read handler. in _php_stream_seek.
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/main/streams/streams.c
U php/php-src/trunk/main/streams/streams.c
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2010-10-13 03:13:19 UTC (rev 304353)
+++ php/php-src/branches/PHP_5_3/NEWS 2010-10-13 03:13:29 UTC (rev 304354)
@@ -28,6 +28,11 @@
- Fixed inconsistent backlog default value (-1) in FPM on many systems. (fat)
- Fixed bug in the Windows implementation of dns_get_record, where the two
last parameters wouldn't be filled unless the type were DNS_ANY (Gustavo).
+- Fixed forward stream seeking emulation in streams that don't support seeking
+ in situations where the read operation gives back less data than requested
+ and when there was data in the buffer before the emulation started. Also made
+ more consistent its behavior -- should return failure every time less data
+ than was requested was skipped. (Gustavo)
- Fixed bug #53021 (In html_entity_decode, failure to convert numeric entities
with ENT_NOQUOTES and ISO-8859-1). Fixed and extended the fix of ENT_NOQUOTES
Modified: php/php-src/branches/PHP_5_3/main/streams/streams.c
===================================================================
--- php/php-src/branches/PHP_5_3/main/streams/streams.c 2010-10-13 03:13:19 UTC
(rev 304353)
+++ php/php-src/branches/PHP_5_3/main/streams/streams.c 2010-10-13 03:13:29 UTC
(rev 304354)
@@ -1097,8 +1097,8 @@
if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
switch(whence) {
case SEEK_CUR:
- if (offset > 0 && offset < stream->writepos -
stream->readpos) {
- stream->readpos += offset;
+ if (offset > 0 && offset <= stream->writepos -
stream->readpos) {
+ stream->readpos += offset; /* if offset
= ..., then readpos = writepos */
stream->position += offset;
stream->eof = 0;
return 0;
@@ -1106,7 +1106,7 @@
break;
case SEEK_SET:
if (offset > stream->position &&
- offset < stream->position +
stream->writepos - stream->readpos) {
+ offset <= stream->position +
stream->writepos - stream->readpos) {
stream->readpos += offset -
stream->position;
stream->position = offset;
stream->eof = 0;
@@ -1149,15 +1149,13 @@
/* emulate forward moving seeks with reads */
if (whence == SEEK_CUR && offset > 0) {
char tmp[1024];
- while(offset >= sizeof(tmp)) {
- if (php_stream_read(stream, tmp, sizeof(tmp)) == 0) {
+ size_t didread;
+ while(offset > 0) {
+ if ((didread = php_stream_read(stream, tmp, MIN(offset,
sizeof(tmp)))) == 0) {
return -1;
}
- offset -= sizeof(tmp);
+ offset -= didread;
}
- if (offset && (php_stream_read(stream, tmp, offset) == 0)) {
- return -1;
- }
stream->eof = 0;
return 0;
}
Modified: php/php-src/trunk/main/streams/streams.c
===================================================================
--- php/php-src/trunk/main/streams/streams.c 2010-10-13 03:13:19 UTC (rev
304353)
+++ php/php-src/trunk/main/streams/streams.c 2010-10-13 03:13:29 UTC (rev
304354)
@@ -1097,8 +1097,8 @@
if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
switch(whence) {
case SEEK_CUR:
- if (offset > 0 && offset < stream->writepos -
stream->readpos) {
- stream->readpos += offset;
+ if (offset > 0 && offset <= stream->writepos -
stream->readpos) {
+ stream->readpos += offset; /* if offset
= ..., then readpos = writepos */
stream->position += offset;
stream->eof = 0;
return 0;
@@ -1106,7 +1106,7 @@
break;
case SEEK_SET:
if (offset > stream->position &&
- offset < stream->position +
stream->writepos - stream->readpos) {
+ offset <= stream->position +
stream->writepos - stream->readpos) {
stream->readpos += offset -
stream->position;
stream->position = offset;
stream->eof = 0;
@@ -1149,15 +1149,13 @@
/* emulate forward moving seeks with reads */
if (whence == SEEK_CUR && offset > 0) {
char tmp[1024];
- while(offset >= sizeof(tmp)) {
- if (php_stream_read(stream, tmp, sizeof(tmp)) == 0) {
+ size_t didread;
+ while(offset > 0) {
+ if ((didread = php_stream_read(stream, tmp, MIN(offset,
sizeof(tmp)))) == 0) {
return -1;
}
- offset -= sizeof(tmp);
+ offset -= didread;
}
- if (offset && (php_stream_read(stream, tmp, offset) == 0)) {
- return -1;
- }
stream->eof = 0;
return 0;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php