[PHP-CVS] svn: /php/php-src/trunk/ UPGRADING.INTERNALS ext/standard/basic_functions.c ext/standard/basic_functions.h main/php_streams.h main/streams/memory.c main/streams/streams.c

2010-11-14 Thread Gustavo André dos Santos Lopes
cataphract   Mon, 15 Nov 2010 03:05:32 +

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

Log:
- Added leak_variable() function.
- Added mechanism to force outer streams to be closed before their inner ones.
- Fixed temp:// streams only handling correctly (through an ad hoc mechanism)  
reverse closing order
  when the  inner stream is of type memory.

Changed paths:
U   php/php-src/trunk/UPGRADING.INTERNALS
U   php/php-src/trunk/ext/standard/basic_functions.c
U   php/php-src/trunk/ext/standard/basic_functions.h
U   php/php-src/trunk/main/php_streams.h
U   php/php-src/trunk/main/streams/memory.c
U   php/php-src/trunk/main/streams/streams.c

Modified: php/php-src/trunk/UPGRADING.INTERNALS
===
--- php/php-src/trunk/UPGRADING.INTERNALS	2010-11-15 01:57:16 UTC (rev 305345)
+++ php/php-src/trunk/UPGRADING.INTERNALS	2010-11-15 03:05:32 UTC (rev 305346)
@@ -8,7 +8,9 @@
   c. readlink support
   d. layout of some core ZE structures (zend_op_array, zend_class_entry, ...)
   e. Zend\zend_fast_cache.h has been removed
-  f. API Signature changes
+  f. streams that enclose private streams
+  g. leak_variable
+  h. API Signature changes

 
 1. Internal API changes
@@ -68,7 +70,55 @@

 Use emalloc, emalloc_rel, efree or efree_rel instead.

-	f. API Signature changes
+	f. Streams that enclose private streams
+Some streams, like the temp:// stream, may enclose private streams. If the
+outer stream leaks due to a programming error or is not exposed through a
+zval (and therefore is not deleted when all the zvals are gone), it will
+be destroyed on shutdown.
+The problem is that the outer usually wants itself to close the inner stream,
+so that it may do any other shutdown action that requires the inner stream to
+be live (e.g. commit data to it). If the outer stream is exposed through a
+zval and the inner one isn't, this is not a problem because the outer stream
+will be freed when the zval is destroyed, which happens before the resources
+are destroyed on shutdown.
+On resource list shutdown, the cleanup happens in reverse order of resource
+creation, so if the inner stream was created in the opener of the outer stream,
+it will be destroyed first.
+The following functions were added to the streams API to force a predictable
+destruction order:
+
+PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);
+#define php_stream_free_enclosed(stream_enclosed, close_options)
+PHPAPI int _php_stream_free_enclosed(php_stream *stream_enclosed, int close_options TSRMLS_DC);
+
+Additionally, the following member was added to php_stream:
+
+	struct _php_stream *enclosing_stream;
+
+and the following macro was added:
+
+#define PHP_STREAM_FREE_IGNORE_ENCLOSING	32
+
+The function php_stream_encloses declares the first stream encloses the second.
+This has the effect that, when the inner stream is closed from a resource
+destructor it will abort and try to free its enclosing stream instead.
+To prevent this from happening when the inner stream is freed from the outer
+stream, the macro php_stream_free_enclosed should be used instead of
+php_stream_free/php_stream_close/php_stream_pclose, or the flag
+PHP_STREAM_FREE_IGNORE_ENCLOSING should be directly passed to php_stream_free.
+The outer stream cannot abstain, in its close callback, from either closing the
+inner stream or clear the enclosing_stream pointer in its enclosed stream by
+calling php_stream_encloses with the 2nd argument NULL. If this is not done,
+there will be problems, so observe this requirement when using
+php_stream_encloses.
+
+	g. leak_variable
+The function leak_variable(variable [, leak_data]) was added. It is only
+available on debug builds. It increments the refcount of a zval or, if the
+second argument is true and the variable is either an object or a resource
+it increments the refcounts of those objects instead.
+
+	h. API Signature changes
 . zend_list_insert
   ZEND_API int zend_list_insert(void *ptr, int type TSRMLS_DC);
   call: zend_list_insert(a, SOMETYPE TSRMLS_CC);

Modified: php/php-src/trunk/ext/standard/basic_functions.c
===
--- php/php-src/trunk/ext/standard/basic_functions.c	2010-11-15 01:57:16 UTC (rev 305345)
+++ php/php-src/trunk/ext/standard/basic_functions.c	2010-11-15 03:05:32 UTC (rev 305346)
@@ -853,6 +853,11 @@
 #if ZEND_DEBUG
 ZEND_BEGIN_ARG_INFO(arginfo_config_get_hash, 0)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_leak_variable, 0, 0, 1)
+	ZEND_ARG_INFO(0, variable)
+	ZEND_ARG_INFO(0, leak_data)
+ZEND_END_ARG_INFO()
 #endif

 #ifdef HAVE_GETLOADAVG
@@ -2997,6 +3002,7 @@
 	PHP_FE(parse_ini_string,arginfo_parse_ini_string)
 #if ZEND_DEBUG
 	PHP_FE(config_get_hash,	arginfo_config_get_hash)
+	PHP_FE(leak_variable,	arginfo_leak_variable)
 

Re: [PHP-CVS] svn: /php/php-src/trunk/ UPGRADING.INTERNALS ext/standard/basic_functions.c ext/standard/basic_functions.h main/php_streams.h main/streams/memory.c main/streams/streams.c

2010-11-14 Thread Kalle Sommer Nielsen
Hi

2010/11/15 Gustavo André dos Santos Lopes cataphr...@php.net:
 cataphract                               Mon, 15 Nov 2010 03:05:32 +

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

 Log:
 - Added leak_variable() function.

Why do we need a leak_variable() function in a regular build unlike
leak() and crash() which are defined in zend_builtin_functions.c in
debug mode only or did I miss something here?

-- 
regards,

Kalle Sommer Nielsen
ka...@php.net

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