]> granicus.if.org Git - php/commitdiff
MFB context refcounting and text-mode fopen fixes
authorWez Furlong <wez@php.net>
Wed, 21 May 2003 13:33:55 +0000 (13:33 +0000)
committerWez Furlong <wez@php.net>
Wed, 21 May 2003 13:33:55 +0000 (13:33 +0000)
ext/standard/file.c
ext/standard/streamsfuncs.c
main/streams/plain_wrapper.c
main/streams/streams.c

index 886a5a6c887c14ed4587e09ea10a2c5a9917e7b6..055e83bd437c1339e02b0f91b1389f756a743615 100644 (file)
@@ -693,7 +693,9 @@ PHP_NAMED_FUNCTION(php_if_fopen)
 
        php_stream_to_zval(stream, return_value);
 
-       return;
+       if (zcontext) {
+               zend_list_addref(Z_RESVAL_P(zcontext));
+       }
 }
 /* }}} */
 
index ee57d0da86126c1d38381bc0feb12dd158c2aab2..6eceb7cd5bc8017ccf68244891a1215469c7c420 100644 (file)
@@ -123,6 +123,10 @@ PHP_FUNCTION(stream_socket_client)
        }
        
        php_stream_to_zval(stream, return_value);
+
+       if (zcontext) {
+               zend_list_addref(Z_RESVAL_P(zcontext));
+       }
 }
 /* }}} */
 
@@ -185,6 +189,9 @@ PHP_FUNCTION(stream_socket_server)
        
        php_stream_to_zval(stream, return_value);
 
+       if (zcontext) {
+               zend_list_addref(Z_RESVAL_P(zcontext));
+       }
 }
 /* }}} */
 
@@ -752,7 +759,6 @@ PHP_FUNCTION(stream_context_set_option)
                /* handle the array syntax */
                RETVAL_BOOL(parse_context_options(context, options) == SUCCESS);
        } else {
-               ZVAL_ADDREF(zvalue);
                php_stream_context_set_option(context, wrappername, optionname, zvalue);
                RETVAL_TRUE;
        }
index 075cc70e45e73ed0b0361ea5af7240d08fc1c94f..31de27ea7056db3b029c730030f9e1acdf503fda 100644 (file)
@@ -74,7 +74,11 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
                flags |= O_BINARY;
        }
 #endif
-       
+#ifdef _O_TEXT
+       if (strchr(mode, 't')) {
+               flags |= _O_TEXT;
+       }
+#endif
        *open_flags = flags;
        return SUCCESS;
 }
index 5d6ef4fc219e7f63a4237f9ef0d06118a362120b..b0ddf37de66f4b7a3648ff9a8830fd476fd76efe 100755 (executable)
@@ -53,6 +53,14 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash()
        return &url_stream_wrappers_hash;
 }
 
+static int _php_stream_release_context(list_entry *le, void *pContext TSRMLS_DC)
+{
+       if (le->ptr == pContext) {
+               return --le->refcount == 0;
+       }
+       return 0;
+}
+
 static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC)
 {
        php_stream *stream;
@@ -69,6 +77,13 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream);
 
        stream->rsrc_id = FAILURE;
 
+       if (stream->context) {
+               zend_hash_apply_with_argument(&EG(regular_list),
+                               (apply_func_arg_t) _php_stream_release_context,
+                               stream->context TSRMLS_CC);
+               stream->context = NULL;
+       }
+       
        return 0;
 }
 
@@ -1643,8 +1658,12 @@ PHPAPI int php_stream_context_set_option(php_stream_context *context,
                const char *wrappername, const char *optionname, zval *optionvalue)
 {
        zval **wrapperhash;
-       zval *category;
+       zval *category, *copied_val;
 
+       ALLOC_INIT_ZVAL(copied_val);
+       *copied_val = *optionvalue;
+       zval_copy_ctor(copied_val);
+       
        if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) {
                
                MAKE_STD_ZVAL(category);
@@ -1656,7 +1675,7 @@ PHPAPI int php_stream_context_set_option(php_stream_context *context,
                ZVAL_ADDREF(optionvalue);
                wrapperhash = &category;
        }
-       return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&optionvalue, sizeof(zval *), NULL);
+       return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL);
 }
 /* }}} */