com php-src: Refactor stream_get_record to return zen d_string: ext/standard/streamsfuncs.c main/php_stre ams.h main/streams/streams.c

From: Date: Wed, 05 Mar 2014 03:41:21 +0000
Subject: com php-src: Refactor stream_get_record to return zen d_string: ext/standard/streamsfuncs.c main/php_stre ams.h main/streams/streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-77734@lists.php.net to get a copy of this message
Commit: 1c427513160eb88d5b73b2883c48eaf204ad20f4 Author: Xinchen Hui <laruence@gmail.com> Wed, 5 Mar 2014 11:41:21 +0800 Parents: 2cdc90bd94222e869980c14c7444390337fdcd0e Branches: phpng Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1c427513160eb88d5b73b2883c48eaf204ad20f4 Log: Refactor stream_get_record to return zend_string Changed paths: M ext/standard/streamsfuncs.c M main/php_streams.h M main/streams/streams.c Diff: diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index a8ce014..6933493 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 39a4a96..7e9b6a6 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 c375b67..9dde1cf 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; }

« previous php.cvs (#77734) next »