Re: Howto use zend_register_functions ? possible bug with patch

From: Date: Mon, 02 Dec 2013 13:17:53 +0000
Subject: Re: Howto use zend_register_functions ? possible bug with patch
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-70469@lists.php.net to get a copy of this message
Attached: rewrite of _extension_string and getFunctions. Test 1: php --re standard $diff -u old new + Function [ <internal:standard> function dl ] { + + - Parameters [1] { + Parameter #0 [ <required> $extension_filename ] + } + } + Function [ <internal:standard> function cli_set_process_title ] { + + - Parameters [1] { + Parameter #0 [ <required> $title ] + } + } + Function [ <internal:standard> function cli_get_process_title ] { + + - Parameters [0] { + } + } Test 2: $r=new ReflectionExtension('standard') print_r($r->getFunctions()); + [dl] => ReflectionFunction Object + ( + [name] => dl + ) + + [cli_set_process_title] => ReflectionFunction Object + ( + [name] => cli_set_process_title + ) + + [cli_get_process_title] => ReflectionFunction Object + ( + [name] => cli_get_process_title + ) + Remi.

--- ../ext/reflection/php_reflection.c.old 2013-12-02 13:51:11.363669578 +0100 +++ ../ext/reflection/php_reflection.c 2013-12-02 14:14:55.649633295 +0100 @@ -1105,29 +1105,25 @@ string_free(&str_constants); } - if (module->functions && module->functions->fname) { - zend_function *fptr; - const zend_function_entry *func = module->functions; - - string_printf(str, "\n - Functions {\n"); - - /* Is there a better way of doing this? */ - while (func->fname) { - int fname_len = strlen(func->fname); - char *lc_name = zend_str_tolower_dup(func->fname, fname_len); - - if (zend_hash_find(EG(function_table), lc_name, fname_len + 1, (void**) &fptr) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); - func++; - efree(lc_name); - continue; + { + HashPosition iterator; + zend_internal_function *fptr; + int first = 1; + + zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); + while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + if (fptr->module == module) { + if (first) { + string_printf(str, "\n - Functions {\n"); + first = 0; + } + _function_string(str, (zend_function *)fptr, NULL, " " TSRMLS_CC); } - - _function_string(str, fptr, NULL, " " TSRMLS_CC); - efree(lc_name); - func++; + zend_hash_move_forward_ex(CG(function_table), &iterator); + } + if (!first) { + string_printf(str, "%s }\n", indent); } - string_printf(str, "%s }\n", indent); } { @@ -5264,6 +5260,9 @@ { reflection_object *intern; zend_module_entry *module; + HashPosition iterator; + zval *function; + zend_internal_function *fptr; if (zend_parse_parameters_none() == FAILURE) { return; @@ -5271,29 +5270,14 @@ GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - if (module->functions) { - zval *function; - zend_function *fptr; - const zend_function_entry *func = module->functions; - - /* Is there a better way of doing this? */ - while (func->fname) { - int fname_len = strlen(func->fname); - char *lc_name = zend_str_tolower_dup(func->fname, fname_len); - - if (zend_hash_find(EG(function_table), lc_name, fname_len + 1, (void**) &fptr) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); - func++; - efree(lc_name); - continue; - } - + zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); + while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + if (fptr->module == module) { ALLOC_ZVAL(function); - reflection_function_factory(fptr, NULL, function TSRMLS_CC); - add_assoc_zval_ex(return_value, func->fname, fname_len+1, function); - func++; - efree(lc_name); + reflection_function_factory((zend_function *)fptr, NULL, function TSRMLS_CC); + add_assoc_zval(return_value, fptr->function_name, function); } + zend_hash_move_forward_ex(CG(function_table), &iterator); } } /* }}} */
« previous php.internals (#70469) next »