]> granicus.if.org Git - php/commitdiff
Fixed stream_select (incompeleted)
authorXinchen Hui <laruence@gmail.com>
Tue, 4 Mar 2014 11:12:43 +0000 (19:12 +0800)
committerXinchen Hui <laruence@gmail.com>
Tue, 4 Mar 2014 11:12:43 +0000 (19:12 +0800)
ext/standard/file.c
ext/standard/streamsfuncs.c
main/streams/userspace.c

index 036705617246da664b5fcb290a2f74a7b5390dc1..79fa1b52ae0cc9538b99a0331924a38a62ca6c50 100644 (file)
@@ -1030,16 +1030,15 @@ PHPAPI PHP_FUNCTION(fgets)
 
        /* resize buffer if it's much larger than the result.
         * Only needed if the user requested a buffer size. */
-       if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) {
+//??   if (argc > 1 && line_len < len / 2) {
 //???          
-               ZVAL_STRINGL(return_value, buf, line_len + 1);
-               Z_STRLEN_P(return_value)--;
-               efree(buf);
-       } else {
-//???
                ZVAL_STRINGL(return_value, buf, line_len);
                efree(buf);
-       }
+//??   } else {
+//???
+//???          ZVAL_STRINGL(return_value, buf, line_len);
+//???  efree(buf);
+//???  }
        return;
 
 exit_failed:
index 08c9ef9df6472eff9b8922d5346acea5fcfa73d4..1e08f6806f03f312ff32eb1f80de52a395d8aee3 100644 (file)
@@ -601,6 +601,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
        if (Z_TYPE_P(stream_array) != IS_ARRAY) {
                return 0;
        }
+
        for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
                 (elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) != NULL;
                 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
@@ -778,6 +779,7 @@ PHP_FUNCTION(stream_select)
        FD_ZERO(&efds);
 
        if (r_array != NULL) {
+               r_array = Z_REFVAL_P(r_array);
                set_count = stream_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC);
                if (set_count > max_set_count)
                        max_set_count = set_count;
@@ -785,6 +787,7 @@ PHP_FUNCTION(stream_select)
        }
 
        if (w_array != NULL) {
+               w_array = Z_REFVAL_P(w_array);
                set_count = stream_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC);
                if (set_count > max_set_count)
                        max_set_count = set_count;
@@ -792,6 +795,7 @@ PHP_FUNCTION(stream_select)
        }
 
        if (e_array != NULL) {
+               e_array = Z_REFVAL_P(e_array);
                set_count = stream_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC);
                if (set_count > max_set_count)
                        max_set_count = set_count;
index f0f8e165482d71ecc9733a95f0f0532862bd0344..459da11770614cfeea11065092846476d528ce9a 100644 (file)
@@ -374,7 +374,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
        ZVAL_STRING(&zfuncname, USERSTREAM_OPEN);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &zfuncname,
                        &zretval,
                        4, args,
@@ -399,6 +399,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
        /* destroy everything else */
        if (stream == NULL) {
                zval_ptr_dtor(&us->object);
+               ZVAL_UNDEF(&us->object);
                efree(us);
        }
        zval_ptr_dtor(&zretval);
@@ -448,7 +449,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
        ZVAL_STRING(&zfuncname, USERSTREAM_DIR_OPEN);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &zfuncname,
                        &zretval,
                        2, args,
@@ -468,6 +469,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
        /* destroy everything else */
        if (stream == NULL) {
                zval_ptr_dtor(&us->object);
+               ZVAL_UNDEF(&us->object);
                efree(us);
        }
        zval_ptr_dtor(&zretval);
@@ -597,7 +599,7 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t
        ZVAL_STRINGL(&args[0], (char*)buf, count);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        1, args,
@@ -643,7 +645,7 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
        ZVAL_LONG(&args[0], count);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        1, args,
@@ -674,7 +676,7 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
        ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL, 0, NULL TSRMLS_CC);
@@ -706,7 +708,7 @@ static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC
        ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1);
 
        call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL, 0, NULL TSRMLS_CC);
@@ -715,6 +717,7 @@ static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC
        zval_ptr_dtor(&func_name);
 
        zval_ptr_dtor(&us->object);
+       ZVAL_UNDEF(&us->object);
 
        efree(us);
 
@@ -733,7 +736,7 @@ static int php_userstreamop_flush(php_stream *stream TSRMLS_DC)
        ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL, 0, NULL TSRMLS_CC);
@@ -765,7 +768,7 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o
        ZVAL_LONG(&args[1], whence);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        2, args,
@@ -800,7 +803,7 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o
        ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1);
 
        call_result = call_user_function_ex(NULL,
-               &us->object,
+               ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                &func_name,
                &retval,
                0, NULL, 0, NULL TSRMLS_CC);
@@ -878,7 +881,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR
        ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL, 0, NULL TSRMLS_CC);
@@ -911,7 +914,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
        switch (option) {
        case PHP_STREAM_OPTION_CHECK_LIVENESS:
                ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1);
-               call_result = call_user_function_ex(NULL, &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
+               call_result = call_user_function_ex(NULL, ZVAL_IS_UNDEF(&us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
                if (call_result == SUCCESS && Z_TYPE(retval) == IS_BOOL) {
                        ret = zval_is_true(&retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
                } else {
@@ -946,10 +949,10 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
                ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1);
 
                call_result = call_user_function_ex(NULL,
-                                                                                       &us->object,
-                                                                                       &func_name,
-                                                                                       &retval,
-                                                                                       1, args, 0, NULL TSRMLS_CC);
+                                               ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
+                                               &func_name,
+                                               &retval,
+                                               1, args, 0, NULL TSRMLS_CC);
 
                if (call_result == SUCCESS && Z_TYPE(retval) == IS_BOOL) {
                        ret = !Z_LVAL(retval);
@@ -974,8 +977,9 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
 
                switch (value) {
                case PHP_STREAM_TRUNCATE_SUPPORTED:
-                       if (zend_is_callable_ex(&func_name, &us->object, IS_CALLABLE_CHECK_SILENT,
-                                       NULL, NULL, NULL TSRMLS_CC))
+                       if (zend_is_callable_ex(&func_name,
+                                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
+                                       IS_CALLABLE_CHECK_SILENT, NULL, NULL, NULL TSRMLS_CC))
                                ret = PHP_STREAM_OPTION_RETURN_OK;
                        else
                                ret = PHP_STREAM_OPTION_RETURN_ERR;
@@ -986,10 +990,10 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
                        if (new_size >= 0 && new_size <= (ptrdiff_t)LONG_MAX) {
                                ZVAL_LONG(&args[0], (long)new_size);
                                call_result = call_user_function_ex(NULL,
-                                                                                                       &us->object,
-                                                                                                       &func_name,
-                                                                                                       &retval,
-                                                                                                       1, args, 0, NULL TSRMLS_CC);
+                                                               ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
+                                                               &func_name,
+                                                               &retval,
+                                                               1, args, 0, NULL TSRMLS_CC);
                                if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
                                        if (Z_TYPE(retval) == IS_BOOL) {
                                                ret = Z_LVAL(retval) ? PHP_STREAM_OPTION_RETURN_OK :
@@ -1050,7 +1054,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
                }
 
                call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        3, args, 0, NULL TSRMLS_CC);
@@ -1404,7 +1408,7 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou
        ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1);
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL,
@@ -1437,7 +1441,7 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS
        ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1);
 
        call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL, 0, NULL TSRMLS_CC);
@@ -1445,6 +1449,7 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS
        zval_ptr_dtor(&retval);
        zval_ptr_dtor(&func_name);
        zval_ptr_dtor(&us->object);
+       ZVAL_UNDEF(&us->object);
 
        efree(us);
 
@@ -1460,7 +1465,7 @@ static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int when
        ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1);
 
        call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        0, NULL, 0, NULL TSRMLS_CC);
@@ -1494,7 +1499,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T
        }
 
        call_result = call_user_function_ex(NULL,
-                       &us->object,
+                       ZVAL_IS_UNDEF(&us->object)? NULL : &us->object,
                        &func_name,
                        &retval,
                        1, args, 0, NULL TSRMLS_CC);