[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ basic_functions.c streamsfuncs.c streamsfuncs.h var_unserializer.c

2010-04-12 Thread Pierre Joye
pajoye   Mon, 12 Apr 2010 08:25:50 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=297865

Log:
- [doc] add stream_set_read_buffer, equivalent of stream_set_write_buffer for 
read operations. Fixing possible bad effects while reading devices. full 
context support is under work.

Changed paths:
U   php/php-src/trunk/ext/standard/basic_functions.c
U   php/php-src/trunk/ext/standard/streamsfuncs.c
U   php/php-src/trunk/ext/standard/streamsfuncs.h
U   php/php-src/trunk/ext/standard/var_unserializer.c

Modified: php/php-src/trunk/ext/standard/basic_functions.c
===
--- php/php-src/trunk/ext/standard/basic_functions.c2010-04-12 07:34:30 UTC 
(rev 297864)
+++ php/php-src/trunk/ext/standard/basic_functions.c2010-04-12 08:25:50 UTC 
(rev 297865)
@@ -2100,6 +2100,11 @@
 ZEND_END_ARG_INFO()
 #endif

+ZEND_BEGIN_ARG_INFO(arginfo_stream_set_read_buffer, 0)
+   ZEND_ARG_INFO(0, fp)
+   ZEND_ARG_INFO(0, buffer)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO(arginfo_stream_set_write_buffer, 0)
ZEND_ARG_INFO(0, fp)
ZEND_ARG_INFO(0, buffer)
@@ -3101,6 +3106,7 @@
PHP_FE(fputcsv, 
arginfo_fputcsv)
PHP_FE(flock,   
arginfo_flock)
PHP_FE(get_meta_tags,   
arginfo_get_meta_tags)
+   PHP_FE(stream_set_read_buffer,  
arginfo_stream_set_read_buffer)
PHP_FE(stream_set_write_buffer, 
arginfo_stream_set_write_buffer)
PHP_FALIAS(set_file_buffer, stream_set_write_buffer,
arginfo_stream_set_write_buffer)


Modified: php/php-src/trunk/ext/standard/streamsfuncs.c
===
--- php/php-src/trunk/ext/standard/streamsfuncs.c   2010-04-12 07:34:30 UTC 
(rev 297864)
+++ php/php-src/trunk/ext/standard/streamsfuncs.c   2010-04-12 08:25:50 UTC 
(rev 297865)
@@ -1372,16 +1372,8 @@
size_t buff;
php_stream *stream;

-   switch (ZEND_NUM_ARGS()) {
-   case 2:
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rl, 
arg1, arg2) == FAILURE) {
-   RETURN_FALSE;
-   }
-   break;
-   default:
-   WRONG_PARAM_COUNT;
-   /* NOTREACHED */
-   break;
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rl, arg1, 
arg2) == FAILURE) {
+   RETURN_FALSE;
}

php_stream_from_zval(stream, arg1);
@@ -1399,6 +1391,35 @@
 }
 /* }}} */

+/* {{{ proto int stream_set_read_buffer(resource fp, int buffer)
+   Set file write buffer */
+PHP_FUNCTION(stream_set_read_buffer)
+{
+   zval *arg1;
+   int ret;
+   long arg2;
+   size_t buff;
+   php_stream *stream;
+
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rl, arg1, 
arg2) == FAILURE) {
+   RETURN_FALSE;
+   }
+
+   php_stream_from_zval(stream, arg1);
+
+   buff = arg2;
+
+   /* if buff is 0 then set to non-buffered */
+   if (buff == 0) {
+   ret = php_stream_set_option(stream, 
PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
+   } else {
+   ret = php_stream_set_option(stream, 
PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_FULL, buff);
+   }
+
+   RETURN_LONG(ret == 0 ? 0 : EOF);
+}
+/* }}} */
+
 /* {{{ proto int stream_socket_enable_crypto(resource stream, bool enable [, 
int cryptokind [, resource sessionstream]])
Enable or disable a specific kind of crypto on the stream */
 PHP_FUNCTION(stream_socket_enable_crypto)

Modified: php/php-src/trunk/ext/standard/streamsfuncs.h
===
--- php/php-src/trunk/ext/standard/streamsfuncs.h   2010-04-12 07:34:30 UTC 
(rev 297864)
+++ php/php-src/trunk/ext/standard/streamsfuncs.h   2010-04-12 08:25:50 UTC 
(rev 297865)
@@ -36,6 +36,7 @@
 PHP_FUNCTION(stream_set_blocking);
 PHP_FUNCTION(stream_select);
 PHP_FUNCTION(stream_set_timeout);
+PHP_FUNCTION(stream_set_read_buffer);
 PHP_FUNCTION(stream_set_write_buffer);
 PHP_FUNCTION(stream_get_transports);
 PHP_FUNCTION(stream_get_wrappers);

Modified: php/php-src/trunk/ext/standard/var_unserializer.c
===
--- php/php-src/trunk/ext/standard/var_unserializer.c   2010-04-12 07:34:30 UTC 
(rev 297864)
+++ php/php-src/trunk/ext/standard/var_unserializer.c   2010-04-12 

Re: [PHP-CVS] svn: /php/php-src/trunk/ext/standard/ basic_functions.c streamsfuncs.c streamsfuncs.h var_unserializer.c

2010-04-12 Thread Johannes Schlüter
Hi,

On Mon, 2010-04-12 at 08:25 +, Pierre Joye wrote:
 - switch (ZEND_NUM_ARGS()) {
 - case 2:
 - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rl, 
 arg1, arg2) == FAILURE) {
 - RETURN_FALSE;
 - }
 - break;
 - default:
 - WRONG_PARAM_COUNT;
 - /* NOTREACHED */
 - break;
 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rl, arg1, 
 arg2) == FAILURE) {
 + RETURN_FALSE;
   }

This is a small change to the behavior: With the old code it would have
returned NULL on wrong param count and FALSE in case the parsing failed,
with the new code it returns FALSE in both cases.

I'd prefer NULL in both cases as that's how we react usually (see
http://php.net/functions.internal)

Doubt it makes any difference in real life though.


Other than that: No test case possible for this new function?

johannes


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php