On Mon, 15 Nov 2010 07:25:44 -0000, Kalle Sommer Nielsen <ka...@php.net> wrote:

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

Revision: http://svn.php.net/viewvc?view=revision&revision=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?


It's only in the debug builds, not the regular builds. In any case, it makes more sense to have it near leak() and crash. The attached patch does that, but will have to be applied by someone else.

(the previous e-mail doesn't seem to have gone through, apologies if this is the second)

--
Gustavo Lopes
Index: ext/standard/basic_functions.c
===================================================================
--- ext/standard/basic_functions.c      (revision 305370)
+++ ext/standard/basic_functions.c      (working copy)
@@ -853,11 +853,6 @@
 #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
@@ -3002,7 +2997,6 @@
        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)
 #endif
        PHP_FE(is_uploaded_file,                                                
                                                arginfo_is_uploaded_file)
        PHP_FE(move_uploaded_file,                                              
                                                arginfo_move_uploaded_file)
@@ -5923,32 +5917,6 @@
        zend_hash_apply_with_arguments(hash TSRMLS_CC, (apply_func_args_t) 
add_config_entry_cb, 1, return_value);
 }
 /* }}} */
-
-/* {{{ proto leak_variable(variable [, leak_data]) */
-PHP_FUNCTION(leak_variable)
-{
-       zval *zv;
-       zend_bool leak_data = 0;
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zv, 
&leak_data) == FAILURE) {
-               return;
-       }
-
-       if (leak_data && (Z_TYPE_P(zv) != IS_RESOURCE && Z_TYPE_P(zv) != 
IS_OBJECT)) {
-               php_error_docref0(NULL TSRMLS_CC, E_WARNING,
-                       "Leaking non-zval data is only applicable to resources 
and objects");
-               return;
-       }
-
-       if (!leak_data) {
-               zval_add_ref(&zv);
-       } else if (Z_TYPE_P(zv) == IS_RESOURCE) {
-               zend_list_addref(Z_RESVAL_P(zv));
-       } else if (Z_TYPE_P(zv) == IS_OBJECT) {
-               Z_OBJ_HANDLER_P(zv, add_ref)(zv TSRMLS_CC);
-       }
-}
-/* }}} */
 #endif
 
 #ifdef HAVE_GETLOADAVG
Index: ext/standard/basic_functions.h
===================================================================
--- ext/standard/basic_functions.h      (revision 305370)
+++ ext/standard/basic_functions.h      (working copy)
@@ -127,7 +127,6 @@
 PHP_FUNCTION(parse_ini_string);
 #if ZEND_DEBUG
 PHP_FUNCTION(config_get_hash);
-PHP_FUNCTION(leak_variable);
 #endif
 
 PHP_FUNCTION(str_rot13);
Index: Zend/zend_builtin_functions.c
===================================================================
--- Zend/zend_builtin_functions.c       (revision 305370)
+++ Zend/zend_builtin_functions.c       (working copy)
@@ -54,6 +54,7 @@
 static ZEND_FUNCTION(class_alias);
 #if ZEND_DEBUG
 static ZEND_FUNCTION(leak);
+static ZEND_FUNCTION(leak_variable);
 #ifdef ZEND_TEST_EXCEPTIONS
 static ZEND_FUNCTION(crash);
 #endif
@@ -180,6 +181,13 @@
        ZEND_ARG_INFO(0, autoload)
 ZEND_END_ARG_INFO()
 
+#if ZEND_DEBUG
+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
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
        ZEND_ARG_INFO(0, message)
        ZEND_ARG_INFO(0, error_type)
@@ -245,6 +253,7 @@
        ZEND_FE(class_alias,            arginfo_class_alias)
 #if ZEND_DEBUG
        ZEND_FE(leak,                           NULL)
+       ZEND_FE(leak_variable,          arginfo_leak_variable)
 #ifdef ZEND_TEST_EXCEPTIONS
        ZEND_FE(crash,                          NULL)
 #endif
@@ -1367,7 +1376,29 @@
 }
 /* }}} */
 
+/* {{{ proto leak_variable(mixed variable [, bool leak_data]) */
+ZEND_FUNCTION(leak_variable)
+{
+       zval *zv;
+       zend_bool leak_data = 0;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zv, 
&leak_data) == FAILURE) {
+               return;
+       }
+
+       if (!leak_data) {
+               zval_add_ref(&zv);
+       } else if (Z_TYPE_P(zv) == IS_RESOURCE) {
+               zend_list_addref(Z_RESVAL_P(zv));
+       } else if (Z_TYPE_P(zv) == IS_OBJECT) {
+               Z_OBJ_HANDLER_P(zv, add_ref)(zv TSRMLS_CC);
+       } else {
+               zend_error(E_WARNING, "Leaking non-zval data is only applicable 
to resources and objects");
+       }
+}
+/* }}} */
+
+
 #ifdef ZEND_TEST_EXCEPTIONS
 ZEND_FUNCTION(crash)
 {

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

Reply via email to