com php-src: Only call stream_flush if anything was w ritten This avoids flushing in readonly mode upon close: main/php_streams.h
main/streams/streams.c

From: Date: Tue, 30 Jun 2015 01:49:54 +0000
Subject: com php-src: Only call stream_flush if anything was w ritten This avoids flushing in readonly mode upon close: main/php_streams.h
main/streams/streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-87638@lists.php.net to get a copy of this message
Commit: 6ad9cd5367734276d624d6d2a03406ed0d0cd08b Author: Bob Weinand <bobwei9@hotmail.com> Tue, 30 Jun 2015 03:49:54 +0200 Parents: 4a2e40bb861bc3cf5fb6863e57486ed60316e97c Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6ad9cd5367734276d624d6d2a03406ed0d0cd08b Log: Only call stream_flush if anything was written This avoids flushing in readonly mode upon close Changed paths: M main/php_streams.h M main/streams/streams.c Diff: diff --git a/main/php_streams.h b/main/php_streams.h index 0ee3ff5..81822a7 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -166,24 +166,26 @@ struct _php_stream_wrapper { int is_url; /* so that PG(allow_url_fopen) can be respected */ }; -#define PHP_STREAM_FLAG_NO_SEEK 1 -#define PHP_STREAM_FLAG_NO_BUFFER 2 +#define PHP_STREAM_FLAG_NO_SEEK 0x1 +#define PHP_STREAM_FLAG_NO_BUFFER 0x2 -#define PHP_STREAM_FLAG_EOL_UNIX 0 /* also includes DOS */ -#define PHP_STREAM_FLAG_DETECT_EOL 4 -#define PHP_STREAM_FLAG_EOL_MAC 8 +#define PHP_STREAM_FLAG_EOL_UNIX 0x0 /* also includes DOS */ +#define PHP_STREAM_FLAG_DETECT_EOL 0x4 +#define PHP_STREAM_FLAG_EOL_MAC 0x8 /* set this when the stream might represent "interactive" data. * When set, the read buffer will avoid certain operations that * might otherwise cause the read to block for much longer than * is strictly required.. */ -#define PHP_STREAM_FLAG_AVOID_BLOCKING 16 +#define PHP_STREAM_FLAG_AVOID_BLOCKING 0x10 -#define PHP_STREAM_FLAG_NO_CLOSE 32 +#define PHP_STREAM_FLAG_NO_CLOSE 0x20 -#define PHP_STREAM_FLAG_IS_DIR 64 +#define PHP_STREAM_FLAG_IS_DIR 0x40 -#define PHP_STREAM_FLAG_NO_FCLOSE 128 +#define PHP_STREAM_FLAG_NO_FCLOSE 0x80 + +#define PHP_STREAM_FLAG_WAS_WRITTEN 0x80000000 struct _php_stream { php_stream_ops *ops; diff --git a/main/streams/streams.c b/main/streams/streams.c index b6a2887..e8fa1e8 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -434,8 +434,10 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov (close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0); #endif - /* make sure everything is saved */ - _php_stream_flush(stream, 1); + if (stream->flags & PHP_STREAM_FLAG_WAS_WRITTEN) { + /* make sure everything is saved */ + _php_stream_flush(stream, 1); + } /* If not called from the resource dtor, remove the stream from the resource list. */ if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) == 0 && stream->res) { @@ -1205,6 +1207,8 @@ PHPAPI int _php_stream_flush(php_stream *stream, int closing) _php_stream_write_filtered(stream, NULL, 0, closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC ); } + stream->flags &= ~PHP_STREAM_FLAG_WAS_WRITTEN; + if (stream->ops->flush) { ret = stream->ops->flush(stream); } @@ -1214,15 +1218,23 @@ PHPAPI int _php_stream_flush(php_stream *stream, int closing) PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count) { + size_t bytes; + if (buf == NULL || count == 0 || stream->ops->write == NULL) { return 0; } if (stream->writefilters.head) { - return _php_stream_write_filtered(stream, buf, count, PSFS_FLAG_NORMAL); + bytes = _php_stream_write_filtered(stream, buf, count, PSFS_FLAG_NORMAL); } else { - return _php_stream_write_buffer(stream, buf, count); + bytes = _php_stream_write_buffer(stream, buf, count); } + + if (bytes) { + stream->flags |= PHP_STREAM_FLAG_WAS_WRITTEN; + } + + return bytes; } PHPAPI size_t _php_stream_printf(php_stream *stream, const char *fmt, ...)

« previous php.cvs (#87638) next »