Skip to content

Commit 4a9c001

Browse files
authored
Add clean_module_functions() (#8763)
Add clean_module_functions() to clean functions which are registered by zend_register_functions(). The general logic of clean_module_functions() is consistent with clean_module_classes().
1 parent 827754a commit 4a9c001

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Zend/zend_API.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,6 +2968,24 @@ static void clean_module_classes(int module_number) /* {{{ */
29682968
}
29692969
/* }}} */
29702970

2971+
static int clean_module_function(zval *el, void *arg) /* {{{ */
2972+
{
2973+
zend_function *fe = (zend_function *) Z_PTR_P(el);
2974+
zend_module_entry *module = (zend_module_entry *) arg;
2975+
if (fe->common.type == ZEND_INTERNAL_FUNCTION && fe->internal_function.module == module) {
2976+
return ZEND_HASH_APPLY_REMOVE;
2977+
} else {
2978+
return ZEND_HASH_APPLY_KEEP;
2979+
}
2980+
}
2981+
/* }}} */
2982+
2983+
static void clean_module_functions(zend_module_entry *module) /* {{{ */
2984+
{
2985+
zend_hash_apply_with_argument(CG(function_table), clean_module_function, module);
2986+
}
2987+
/* }}} */
2988+
29712989
void module_destructor(zend_module_entry *module) /* {{{ */
29722990
{
29732991
#if ZEND_RC_DEBUG
@@ -3015,6 +3033,8 @@ void module_destructor(zend_module_entry *module) /* {{{ */
30153033
module->module_started=0;
30163034
if (module->type == MODULE_TEMPORARY && module->functions) {
30173035
zend_unregister_functions(module->functions, -1, NULL);
3036+
/* Clean functions registered separately from module->functions */
3037+
clean_module_functions(module);
30183038
}
30193039

30203040
#if HAVE_LIBDL

ext/dl_test/dl_test.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ PHP_FUNCTION(dl_test_test2)
5252
}
5353
/* }}}*/
5454

55+
/* {{{ PHP_DL_TEST_USE_REGISTER_FUNCTIONS_DIRECTLY */
56+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dl_test_use_register_functions_directly, 0, 0, IS_STRING, 0)
57+
ZEND_END_ARG_INFO()
58+
59+
PHP_FUNCTION(dl_test_use_register_functions_directly)
60+
{
61+
ZEND_PARSE_PARAMETERS_NONE();
62+
63+
RETURN_STRING("OK");
64+
}
65+
66+
static const zend_function_entry php_dl_test_use_register_functions_directly_functions[] = {
67+
ZEND_FENTRY(dl_test_use_register_functions_directly, ZEND_FN(dl_test_use_register_functions_directly), arginfo_dl_test_use_register_functions_directly, 0)
68+
ZEND_FE_END
69+
};
70+
/* }}} */
71+
5572
/* {{{ INI */
5673
PHP_INI_BEGIN()
5774
STD_PHP_INI_BOOLEAN("dl_test.long", "0", PHP_INI_ALL, OnUpdateLong, long_value, zend_dl_test_globals, dl_test_globals)
@@ -69,6 +86,10 @@ PHP_MINIT_FUNCTION(dl_test)
6986
REGISTER_INI_ENTRIES();
7087
}
7188

89+
if (getenv("PHP_DL_TEST_USE_REGISTER_FUNCTIONS_DIRECTLY")) {
90+
zend_register_functions(NULL, php_dl_test_use_register_functions_directly_functions, NULL, type);
91+
}
92+
7293
return SUCCESS;
7394
}
7495
/* }}} */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
dl(): use zend_register_functions() directly
3+
--ENV--
4+
PHP_DL_TEST_USE_REGISTER_FUNCTIONS_DIRECTLY=1
5+
--SKIPIF--
6+
<?php require dirname(__DIR__, 3) . "/dl_test/tests/skip.inc"; ?>
7+
--FILE--
8+
<?php
9+
10+
if (extension_loaded('dl_test')) {
11+
exit('Error: dl_test is already loaded');
12+
}
13+
14+
if (PHP_OS_FAMILY === 'Windows') {
15+
$loaded = dl('php_dl_test.dll');
16+
} else {
17+
$loaded = dl('dl_test.so');
18+
}
19+
20+
var_dump($loaded);
21+
var_dump(dl_test_use_register_functions_directly());
22+
?>
23+
--EXPECT--
24+
bool(true)
25+
string(2) "OK"

0 commit comments

Comments
 (0)