Index: ext/openssl/xp_ssl.c =================================================================== RCS file: /repository/php-src/ext/openssl/xp_ssl.c,v retrieving revision 1.22.2.3.2.9.2.2 diff -u -r1.22.2.3.2.9.2.2 xp_ssl.c --- ext/openssl/xp_ssl.c 29 Sep 2007 11:24:05 -0000 1.22.2.3.2.9.2.2 +++ ext/openssl/xp_ssl.c 11 Dec 2007 23:08:52 -0000 @@ -557,7 +557,9 @@ xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+"); if (xparam->outputs.client) { - xparam->outputs.client->context = stream->context; + if (stream->context) { + zend_list_addref(stream->context->rsrc_id); + } } } Index: ext/standard/file.c =================================================================== RCS file: /repository/php-src/ext/standard/file.c,v retrieving revision 1.409.2.6.2.28.2.6 diff -u -r1.409.2.6.2.28.2.6 file.c --- ext/standard/file.c 13 Nov 2007 10:31:24 -0000 1.409.2.6.2.28.2.6 +++ ext/standard/file.c 11 Dec 2007 23:08:53 -0000 @@ -872,10 +872,6 @@ } php_stream_to_zval(stream, return_value); - - if (zcontext) { - zend_list_addref(Z_RESVAL_P(zcontext)); - } } /* }}} */ Index: ext/standard/streamsfuncs.c =================================================================== RCS file: /repository/php-src/ext/standard/streamsfuncs.c,v retrieving revision 1.58.2.6.2.15.2.7 diff -u -r1.58.2.6.2.15.2.7 streamsfuncs.c --- ext/standard/streamsfuncs.c 23 Nov 2007 19:48:56 -0000 1.58.2.6.2.15.2.7 +++ ext/standard/streamsfuncs.c 11 Dec 2007 23:08:53 -0000 @@ -100,6 +100,10 @@ context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); + if (context) { + zend_list_addref(context->rsrc_id); + } + if (flags & PHP_STREAM_CLIENT_PERSISTENT) { spprintf(&hashkey, 0, "stream_socket_client__%s", host); } @@ -155,10 +159,7 @@ } php_stream_to_zval(stream, return_value); - - if (zcontext) { - zend_list_addref(Z_RESVAL_P(zcontext)); - } + } /* }}} */ @@ -182,6 +183,10 @@ } context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); + + if (context) { + zend_list_addref(context->rsrc_id); + } if (zerrno) { zval_dtor(zerrno); @@ -220,10 +225,6 @@ } php_stream_to_zval(stream, return_value); - - if (zcontext) { - zend_list_addref(Z_RESVAL_P(zcontext)); - } } /* }}} */ @@ -1028,7 +1029,7 @@ FG(default_context) = php_stream_context_alloc(); } context = FG(default_context); - + if (params) { parse_context_options(context, params); } @@ -1054,7 +1055,7 @@ parse_context_options(context, params); } - php_stream_context_to_zval(context, return_value); + RETURN_RESOURCE(context->rsrc_id); } /* }}} */ Index: ext/standard/http_fopen_wrapper.c =================================================================== RCS file: /repository/php-src/ext/standard/http_fopen_wrapper.c,v retrieving revision 1.99.2.12.2.9.2.3 diff -u -r1.99.2.12.2.9.2.3 http_fopen_wrapper.c --- ext/standard/http_fopen_wrapper.c 29 Nov 2007 12:28:15 -0000 1.99.2.12.2.9.2.3 +++ ext/standard/http_fopen_wrapper.c 11 Dec 2007 23:08:53 -0000 @@ -587,6 +587,9 @@ if (location[0] != '\0') php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0); + if (context) { /* keep the context for the next try */ + zend_list_addref(context->rsrc_id); + } php_stream_close(stream); stream = NULL; Index: main/streams/streams.c =================================================================== RCS file: /repository/php-src/main/streams/streams.c,v retrieving revision 1.82.2.6.2.18.2.2 diff -u -r1.82.2.6.2.18.2.2 streams.c --- main/streams/streams.c 10 Dec 2007 14:16:57 -0000 1.82.2.6.2.18.2.2 +++ main/streams/streams.c 11 Dec 2007 23:08:53 -0000 @@ -283,6 +283,7 @@ int remove_rsrc = 1; int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; int release_cast = 1; + php_stream_context *context = stream->context; if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { preserve_handle = 1; @@ -423,6 +424,10 @@ #endif } + if (context) { + zend_list_delete(context->rsrc_id); + } + return ret; } /* }}} */ @@ -1792,6 +1797,10 @@ opened_path, context STREAMS_REL_CC TSRMLS_CC); } + if (context) { + zend_list_addref(context->rsrc_id); + } + /* if the caller asked for a persistent stream but the wrapper did not * return one, force an error here */ if (stream && (options & STREAM_OPEN_PERSISTENT) && !stream->is_persistent) { Index: main/streams/userspace.c =================================================================== RCS file: /repository/php-src/main/streams/userspace.c,v retrieving revision 1.31.2.3.2.7.2.1 diff -u -r1.31.2.3.2.7.2.1 userspace.c --- main/streams/userspace.c 7 Oct 2007 05:22:07 -0000 1.31.2.3.2.7.2.1 +++ main/streams/userspace.c 11 Dec 2007 23:08:53 -0000 @@ -215,7 +215,6 @@ zval **args[4]; int call_result; php_stream *stream = NULL; - zval *zcontext = NULL; zend_bool old_in_user_include; /* Try to catch bad usage without preventing flexibility */ @@ -281,12 +280,8 @@ } if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(us->object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(us->object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(us->object, "context"); } @@ -362,7 +357,7 @@ { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; php_userstream_data_t *us; - zval *zfilename, *zoptions, *zretval = NULL, *zfuncname, *zcontext; + zval *zfilename, *zoptions, *zretval = NULL, *zfuncname; zval **args[2]; int call_result; php_stream *stream = NULL; @@ -384,12 +379,8 @@ Z_SET_ISREF_P(us->object); if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(us->object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(us->object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(us->object, "context"); } @@ -952,7 +943,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zfuncname, *zretval, *zcontext; + zval *zfilename, *zfuncname, *zretval; zval **args[1]; int call_result; zval *object; @@ -965,12 +956,8 @@ Z_SET_ISREF_P(object); if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(object, "context"); } @@ -1010,7 +997,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zold_name, *znew_name, *zfuncname, *zretval, *zcontext; + zval *zold_name, *znew_name, *zfuncname, *zretval; zval **args[2]; int call_result; zval *object; @@ -1023,12 +1010,8 @@ Z_SET_ISREF_P(object); if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(object, "context"); } @@ -1073,7 +1056,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval, *zcontext; + zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval; zval **args[3]; int call_result; zval *object; @@ -1086,12 +1069,8 @@ Z_SET_ISREF_P(object); if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(object, "context"); } @@ -1142,7 +1121,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zoptions, *zfuncname, *zretval, *zcontext; + zval *zfilename, *zoptions, *zfuncname, *zretval; zval **args[3]; int call_result; zval *object; @@ -1155,12 +1134,8 @@ Z_SET_ISREF_P(object); if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(object, "context"); } @@ -1206,7 +1181,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zfuncname, *zretval, *zflags, *zcontext; + zval *zfilename, *zfuncname, *zretval, *zflags; zval **args[2]; int call_result; zval *object; @@ -1219,12 +1194,8 @@ Z_SET_ISREF_P(object); if (context) { - MAKE_STD_ZVAL(zcontext); - php_stream_context_to_zval(context, zcontext); - add_property_zval(object, "context", zcontext); - /* The object property should be the only reference, - 'get rid' of our local reference. */ - zval_ptr_dtor(&zcontext); + add_property_resource(object, "context", context->rsrc_id); + zend_list_addref(context->rsrc_id); } else { add_property_null(object, "context"); } Index: main/streams/xp_socket.c =================================================================== RCS file: /repository/php-src/main/streams/xp_socket.c,v retrieving revision 1.33.2.2.2.6 diff -u -r1.33.2.2.2.6 xp_socket.c --- main/streams/xp_socket.c 24 Jul 2007 14:24:44 -0000 1.33.2.2.2.6 +++ main/streams/xp_socket.c 11 Dec 2007 23:08:53 -0000 @@ -712,8 +712,10 @@ xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+"); if (xparam->outputs.client) { - /* TODO: addref ? */ xparam->outputs.client->context = stream->context; + if (stream->context) { + zend_list_addref(stream->context->rsrc_id); + } } } }