Skip to content

Commit 565c484

Browse files
committed
- Moved leak_variable() to zend_builtin_functions.c (Gustavo)
1 parent c3727cc commit 565c484

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

Zend/zend_builtin_functions.c

+31
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static ZEND_FUNCTION(function_exists);
5454
static ZEND_FUNCTION(class_alias);
5555
#if ZEND_DEBUG
5656
static ZEND_FUNCTION(leak);
57+
static ZEND_FUNCTION(leak_variable);
5758
#ifdef ZEND_TEST_EXCEPTIONS
5859
static ZEND_FUNCTION(crash);
5960
#endif
@@ -180,6 +181,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2)
180181
ZEND_ARG_INFO(0, autoload)
181182
ZEND_END_ARG_INFO()
182183

184+
#if ZEND_DEBUG
185+
ZEND_BEGIN_ARG_INFO_EX(arginfo_leak_variable, 0, 0, 1)
186+
ZEND_ARG_INFO(0, variable)
187+
ZEND_ARG_INFO(0, leak_data)
188+
ZEND_END_ARG_INFO()
189+
#endif
190+
183191
ZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
184192
ZEND_ARG_INFO(0, message)
185193
ZEND_ARG_INFO(0, error_type)
@@ -245,6 +253,7 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
245253
ZEND_FE(class_alias, arginfo_class_alias)
246254
#if ZEND_DEBUG
247255
ZEND_FE(leak, NULL)
256+
ZEND_FE(leak_variable, arginfo_leak_variable)
248257
#ifdef ZEND_TEST_EXCEPTIONS
249258
ZEND_FE(crash, NULL)
250259
#endif
@@ -1367,6 +1376,28 @@ ZEND_FUNCTION(leak)
13671376
}
13681377
/* }}} */
13691378

1379+
/* {{{ proto leak_variable(mixed variable [, bool leak_data]) */
1380+
ZEND_FUNCTION(leak_variable)
1381+
{
1382+
zval *zv;
1383+
zend_bool leak_data = 0;
1384+
1385+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zv, &leak_data) == FAILURE) {
1386+
return;
1387+
}
1388+
1389+
if (!leak_data) {
1390+
zval_add_ref(&zv);
1391+
} else if (Z_TYPE_P(zv) == IS_RESOURCE) {
1392+
zend_list_addref(Z_RESVAL_P(zv));
1393+
} else if (Z_TYPE_P(zv) == IS_OBJECT) {
1394+
Z_OBJ_HANDLER_P(zv, add_ref)(zv TSRMLS_CC);
1395+
} else {
1396+
zend_error(E_WARNING, "Leaking non-zval data is only applicable to resources and objects");
1397+
}
1398+
}
1399+
/* }}} */
1400+
13701401

13711402
#ifdef ZEND_TEST_EXCEPTIONS
13721403
ZEND_FUNCTION(crash)

ext/standard/basic_functions.c

-32
Original file line numberDiff line numberDiff line change
@@ -853,11 +853,6 @@ ZEND_END_ARG_INFO()
853853
#if ZEND_DEBUG
854854
ZEND_BEGIN_ARG_INFO(arginfo_config_get_hash, 0)
855855
ZEND_END_ARG_INFO()
856-
857-
ZEND_BEGIN_ARG_INFO_EX(arginfo_leak_variable, 0, 0, 1)
858-
ZEND_ARG_INFO(0, variable)
859-
ZEND_ARG_INFO(0, leak_data)
860-
ZEND_END_ARG_INFO()
861856
#endif
862857

863858
#ifdef HAVE_GETLOADAVG
@@ -3002,7 +2997,6 @@ const zend_function_entry basic_functions[] = { /* {{{ */
30022997
PHP_FE(parse_ini_string, arginfo_parse_ini_string)
30032998
#if ZEND_DEBUG
30042999
PHP_FE(config_get_hash, arginfo_config_get_hash)
3005-
PHP_FE(leak_variable, arginfo_leak_variable)
30063000
#endif
30073001
PHP_FE(is_uploaded_file, arginfo_is_uploaded_file)
30083002
PHP_FE(move_uploaded_file, arginfo_move_uploaded_file)
@@ -5923,32 +5917,6 @@ PHP_FUNCTION(config_get_hash) /* {{{ */
59235917
zend_hash_apply_with_arguments(hash TSRMLS_CC, (apply_func_args_t) add_config_entry_cb, 1, return_value);
59245918
}
59255919
/* }}} */
5926-
5927-
/* {{{ proto leak_variable(variable [, leak_data]) */
5928-
PHP_FUNCTION(leak_variable)
5929-
{
5930-
zval *zv;
5931-
zend_bool leak_data = 0;
5932-
5933-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zv, &leak_data) == FAILURE) {
5934-
return;
5935-
}
5936-
5937-
if (leak_data && (Z_TYPE_P(zv) != IS_RESOURCE && Z_TYPE_P(zv) != IS_OBJECT)) {
5938-
php_error_docref0(NULL TSRMLS_CC, E_WARNING,
5939-
"Leaking non-zval data is only applicable to resources and objects");
5940-
return;
5941-
}
5942-
5943-
if (!leak_data) {
5944-
zval_add_ref(&zv);
5945-
} else if (Z_TYPE_P(zv) == IS_RESOURCE) {
5946-
zend_list_addref(Z_RESVAL_P(zv));
5947-
} else if (Z_TYPE_P(zv) == IS_OBJECT) {
5948-
Z_OBJ_HANDLER_P(zv, add_ref)(zv TSRMLS_CC);
5949-
}
5950-
}
5951-
/* }}} */
59525920
#endif
59535921

59545922
#ifdef HAVE_GETLOADAVG

ext/standard/basic_functions.h

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ PHP_FUNCTION(parse_ini_file);
127127
PHP_FUNCTION(parse_ini_string);
128128
#if ZEND_DEBUG
129129
PHP_FUNCTION(config_get_hash);
130-
PHP_FUNCTION(leak_variable);
131130
#endif
132131

133132
PHP_FUNCTION(str_rot13);

0 commit comments

Comments
 (0)