From: Xinchen Hui Date: Wed, 5 Mar 2014 03:41:21 +0000 (+0800) Subject: Refactor stream_get_record to return zend_string X-Git-Tag: POST_PHPNG_MERGE~412^2~421^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c427513160eb88d5b73b2883c48eaf204ad20f4;p=php Refactor stream_get_record to return zend_string --- diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index a8ce014a9c..69334933d4 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1298,8 +1298,7 @@ PHP_FUNCTION(stream_get_line) int str_len = 0; long max_length; zval *zstream; - char *buf; - size_t buf_size; + zend_string *buf; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|s", &zstream, &max_length, &str, &str_len) == FAILURE) { @@ -1316,9 +1315,8 @@ PHP_FUNCTION(stream_get_line) php_stream_from_zval(stream, zstream); - if ((buf = php_stream_get_record(stream, max_length, &buf_size, str, str_len TSRMLS_CC))) { -//??? RETURN_STRINGL(buf, buf_size, 0); - RETURN_STRINGL(buf, buf_size); + if ((buf = php_stream_get_record(stream, max_length, str, str_len TSRMLS_CC))) { + RETURN_STR(buf); } else { RETURN_FALSE; } diff --git a/main/php_streams.h b/main/php_streams.h index 39a4a961e7..7e9b6a6c26 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -322,7 +322,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, #define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC) #define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC) -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC); +PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len TSRMLS_DC); /* CAREFUL! this is equivalent to puts NOT fputs! */ PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC); diff --git a/main/streams/streams.c b/main/streams/streams.c index c375b672b9..9dde1cfe19 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1015,13 +1015,13 @@ static const char *_php_stream_search_delim(php_stream *stream, } } -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC) +PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len TSRMLS_DC) { - char *ret_buf; /* returned buffer */ + zend_string *ret_buf; /* returned buffer */ const char *found_delim = NULL; size_t buffered_len, tent_ret_len; /* tentative returned length */ - int has_delim = delim_len > 0; + int has_delim = delim_len > 0; if (maxlen == 0) { return NULL; @@ -1090,16 +1090,16 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re } } - ret_buf = emalloc(tent_ret_len + 1); + ret_buf = STR_ALLOC(tent_ret_len, 0); /* php_stream_read will not call ops->read here because the necessary * data is guaranteedly buffered */ - *returned_len = php_stream_read(stream, ret_buf, tent_ret_len); + ret_buf->len = php_stream_read(stream, ret_buf->val, tent_ret_len); if (found_delim) { stream->readpos += delim_len; stream->position += delim_len; } - ret_buf[*returned_len] = '\0'; + ret_buf->val[ret_buf->len] = '\0'; return ret_buf; }