Skip to content

Commit 2a98715

Browse files
committed
Improve the way we cleanup temporary classes
1 parent 767d7cb commit 2a98715

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

ext/module_class.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,6 @@ static void phpgo_add_method(zend_function_entry *fe, php_export *export)
228228
fe->flags = ZEND_ACC_PUBLIC;
229229
}
230230

231-
void phpgo_module_destroy_class(zend_class_entry *ce)
232-
{
233-
zend_function *f;
234-
for (zend_hash_internal_pointer_reset(&ce->function_table);
235-
zend_hash_get_current_data(&ce->function_table, (void**)&f) == SUCCESS;
236-
zend_hash_move_forward(&ce->function_table)) {
237-
efree((void*)(f->common.arg_info-1));
238-
f->common.arg_info = NULL;
239-
f->common.num_args = 0;
240-
}
241-
}
242-
243231
void phpgo_module_new_instance(zval *ret, phpgo_module *module TSRMLS_DC)
244232
{
245233
zend_class_entry tmpce;
@@ -272,6 +260,7 @@ void phpgo_module_new_instance(zval *ret, phpgo_module *module TSRMLS_DC)
272260
ce = zend_register_internal_class(&tmpce TSRMLS_CC);
273261
ce->create_object = module_new;
274262
ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
263+
zend_llist_add_element(&PHPGO_G(classes), &ce);
275264

276265
object_init_ex(ret, ce);
277266

@@ -289,3 +278,24 @@ void phpgo_module_class_init()
289278
memcpy(&module_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
290279
module_object_handlers.clone_obj = NULL;
291280
}
281+
282+
void destroy_module_class(zend_class_entry *ce)
283+
{
284+
zend_function *f;
285+
for (zend_hash_internal_pointer_reset(&ce->function_table);
286+
zend_hash_get_current_data(&ce->function_table, (void**)&f) == SUCCESS;
287+
zend_hash_move_forward(&ce->function_table)) {
288+
efree((void*)(f->common.arg_info-1));
289+
f->common.arg_info = NULL;
290+
f->common.num_args = 0;
291+
}
292+
}
293+
294+
void phpgo_module_class_list_dtor(void *data TSRMLS_DC) /* {{{ */
295+
{
296+
zend_class_entry *ce = *(zend_class_entry**)data;
297+
if (ce->refcount == 1) {
298+
destroy_module_class(ce);
299+
}
300+
}
301+
/* }}} */

ext/module_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818

1919
void phpgo_module_new_instance(zval *ret, phpgo_module *module TSRMLS_DC);
2020
void phpgo_module_class_init();
21-
void phpgo_module_destroy_class(zend_class_entry *ce);
21+
void phpgo_module_class_list_dtor(void *);
2222

ext/php_phpgo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ PHP_MINFO_FUNCTION(phpgo);
4747
PHP_FUNCTION(phpgo_load);
4848

4949
ZEND_BEGIN_MODULE_GLOBALS(phpgo)
50-
int load_counter;
50+
zend_llist classes;
51+
int load_counter;
5152
ZEND_END_MODULE_GLOBALS(phpgo)
5253

5354
ZEND_EXTERN_MODULE_GLOBALS(phpgo);

ext/phpgo.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ZEND_GET_MODULE(phpgo)
6565

6666
/* {{{ php_phpgo_init_globals
6767
*/
68-
static void php_phpgo_init_globals(zend_phpgo_globals *phpgo_globals)
68+
static void php_phpgo_init_globals(zend_phpgo_globals *phpgo_globals TSRMLS_DC)
6969
{
7070
phpgo_globals->load_counter = 0;
7171
}
@@ -93,27 +93,16 @@ PHP_MSHUTDOWN_FUNCTION(phpgo)
9393
*/
9494
PHP_RINIT_FUNCTION(phpgo)
9595
{
96+
zend_llist_init(&PHPGO_G(classes), sizeof(zend_class_entry*), phpgo_module_class_list_dtor, 0);
9697
return SUCCESS;
9798
}
9899
/* }}} */
99100

100-
static int clean_module_class(void *pDest TSRMLS_DC) /* {{{ */
101-
{
102-
zend_class_entry *ce = *(zend_class_entry**)pDest;
103-
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == phpgo_module_entry.module_number) {
104-
phpgo_module_destroy_class(ce);
105-
return ZEND_HASH_APPLY_REMOVE;
106-
} else {
107-
return ZEND_HASH_APPLY_KEEP;
108-
}
109-
}
110-
/* }}} */
111-
112101
/* {{{ PHP_RSHUTDOWN_FUNCTION
113102
*/
114103
PHP_RSHUTDOWN_FUNCTION(phpgo)
115104
{
116-
zend_hash_apply(EG(class_table), clean_module_class TSRMLS_CC);
105+
zend_llist_destroy(&PHPGO_G(classes));
117106
return SUCCESS;
118107
}
119108
/* }}} */

0 commit comments

Comments
 (0)