tony2001                Fri Jul 11 10:24:29 2008 UTC

  Modified files:              
    /php-src/ext/openssl        xp_ssl.c 
    /php-src/ext/standard       file.c streamsfuncs.c http_fopen_wrapper.c 
    /php-src/main/streams       streams.c userspace.c xp_socket.c 
  Log:
  manage references of stream context properly
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/openssl/xp_ssl.c?r1=1.37&r2=1.38&diff_format=u
Index: php-src/ext/openssl/xp_ssl.c
diff -u php-src/ext/openssl/xp_ssl.c:1.37 php-src/ext/openssl/xp_ssl.c:1.38
--- php-src/ext/openssl/xp_ssl.c:1.37   Mon Apr 14 12:17:38 2008
+++ php-src/ext/openssl/xp_ssl.c        Fri Jul 11 10:24:29 2008
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: xp_ssl.c,v 1.37 2008/04/14 12:17:38 bjori Exp $ */
+/* $Id: xp_ssl.c,v 1.38 2008/07/11 10:24:29 tony2001 Exp $ */
 
 #include "php.h"
 #include "ext/standard/file.h"
@@ -555,7 +555,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);
+                               }
                        }
                }
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.519&r2=1.520&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.519 php-src/ext/standard/file.c:1.520
--- php-src/ext/standard/file.c:1.519   Wed May 28 17:24:47 2008
+++ php-src/ext/standard/file.c Fri Jul 11 10:24:29 2008
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: file.c,v 1.519 2008/05/28 17:24:47 felipe Exp $ */
+/* $Id: file.c,v 1.520 2008/07/11 10:24:29 tony2001 Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1000,10 +1000,6 @@
        }
 
        php_stream_to_zval(stream, return_value);
-
-       if (zcontext) {
-               zend_list_addref(Z_RESVAL_P(zcontext));
-       }
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.116&r2=1.117&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.116 
php-src/ext/standard/streamsfuncs.c:1.117
--- php-src/ext/standard/streamsfuncs.c:1.116   Wed May 28 18:02:52 2008
+++ php-src/ext/standard/streamsfuncs.c Fri Jul 11 10:24:29 2008
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.c,v 1.116 2008/05/28 18:02:52 felipe Exp $ */
+/* $Id: streamsfuncs.c,v 1.117 2008/07/11 10:24:29 tony2001 Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -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);
        }
@@ -156,10 +160,7 @@
        }
        
        php_stream_to_zval(stream, return_value);
-
-       if (zcontext) {
-               zend_list_addref(Z_RESVAL_P(zcontext));
-       }
+       
 }
 /* }}} */
 
@@ -183,6 +184,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);
@@ -222,10 +227,6 @@
        }
        
        php_stream_to_zval(stream, return_value);
-
-       if (zcontext) {
-               zend_list_addref(Z_RESVAL_P(zcontext));
-       }
 }
 /* }}} */
 
@@ -1147,7 +1148,7 @@
                FG(default_context) = php_stream_context_alloc();
        }
        context = FG(default_context);
-       
+
        if (params) {
                parse_context_options(context, params TSRMLS_CC);
        }
@@ -1177,7 +1178,7 @@
                parse_context_params(context, params TSRMLS_CC);
        }
        
-       php_stream_context_to_zval(context, return_value);
+       RETURN_RESOURCE(context->rsrc_id);
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/http_fopen_wrapper.c?r1=1.133&r2=1.134&diff_format=u
Index: php-src/ext/standard/http_fopen_wrapper.c
diff -u php-src/ext/standard/http_fopen_wrapper.c:1.133 
php-src/ext/standard/http_fopen_wrapper.c:1.134
--- php-src/ext/standard/http_fopen_wrapper.c:1.133     Tue Apr 29 08:15:49 2008
+++ php-src/ext/standard/http_fopen_wrapper.c   Fri Jul 11 10:24:29 2008
@@ -19,7 +19,7 @@
    |          Sara Golemon <[EMAIL PROTECTED]>                              |
    +----------------------------------------------------------------------+
  */
-/* $Id: http_fopen_wrapper.c,v 1.133 2008/04/29 08:15:49 dmitry Exp $ */ 
+/* $Id: http_fopen_wrapper.c,v 1.134 2008/07/11 10:24:29 tony2001 Exp $ */ 
 
 #include "php.h"
 #include "php_globals.h"
@@ -659,6 +659,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;
 
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.165&r2=1.166&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.165 
php-src/main/streams/streams.c:1.166
--- php-src/main/streams/streams.c:1.165        Wed Jun 11 09:01:44 2008
+++ php-src/main/streams/streams.c      Fri Jul 11 10:24:29 2008
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.165 2008/06/11 09:01:44 dmitry Exp $ */
+/* $Id: streams.c,v 1.166 2008/07/11 10:24:29 tony2001 Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -288,6 +288,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;
@@ -428,6 +429,10 @@
 #endif
        }
 
+       if (context) {
+               zend_list_delete(context->rsrc_id);
+       }
+
        return ret;
 }
 /* }}} */
@@ -2414,6 +2419,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) {
http://cvs.php.net/viewvc.cgi/php-src/main/streams/userspace.c?r1=1.46&r2=1.47&diff_format=u
Index: php-src/main/streams/userspace.c
diff -u php-src/main/streams/userspace.c:1.46 
php-src/main/streams/userspace.c:1.47
--- php-src/main/streams/userspace.c:1.46       Mon Dec 31 07:12:19 2007
+++ php-src/main/streams/userspace.c    Fri Jul 11 10:24:29 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: userspace.c,v 1.46 2007/12/31 07:12:19 sebastian Exp $ */
+/* $Id: userspace.c,v 1.47 2008/07/11 10:24:29 tony2001 Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -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");
        }
http://cvs.php.net/viewvc.cgi/php-src/main/streams/xp_socket.c?r1=1.45&r2=1.46&diff_format=u
Index: php-src/main/streams/xp_socket.c
diff -u php-src/main/streams/xp_socket.c:1.45 
php-src/main/streams/xp_socket.c:1.46
--- php-src/main/streams/xp_socket.c:1.45       Mon Mar 10 19:55:43 2008
+++ php-src/main/streams/xp_socket.c    Fri Jul 11 10:24:29 2008
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: xp_socket.c,v 1.45 2008/03/10 19:55:43 andrey Exp $ */
+/* $Id: xp_socket.c,v 1.46 2008/07/11 10:24:29 tony2001 Exp $ */
 
 #include "php.h"
 #include "ext/standard/file.h"
@@ -716,8 +716,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);
+                               }
                        }
                }
        }

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

Reply via email to