From 0165ab6251aca20a28b1befa3b0e4749bd05a5da Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Tue, 30 Aug 2005 18:27:17 +0000 Subject: [PATCH] - Adds module registering a function to struct zend_internal_function. (Johannes) # This information is by reflection API and error messages. --- Zend/zend_API.c | 6 +++- Zend/zend_compile.c | 4 +++ Zend/zend_compile.h | 1 + Zend/zend_object_handlers.c | 1 + Zend/zend_reflection_api.c | 60 +++++++++++++++++++++++++++++++-- ext/reflection/php_reflection.c | 60 +++++++++++++++++++++++++++++++-- 6 files changed, 127 insertions(+), 5 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 1eb64bc3d2..0b54bae3d1 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1914,12 +1914,15 @@ ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TS } efree(lcname); module = module_ptr; + EG(current_module) = module; if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type TSRMLS_CC)==FAILURE) { + EG(current_module) = NULL; zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name); return NULL; } + EG(current_module) = NULL; return module; } @@ -1996,7 +1999,8 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr target_function_table = CG(function_table); } internal_function->type = ZEND_INTERNAL_FUNCTION; - + internal_function->module = EG(current_module); + if (scope) { class_name_len = scope->name_length; lc_class_name = zend_str_tolower_dup(scope->name, class_name_len); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 3927f36094..0549b51ef5 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2277,6 +2277,10 @@ ZEND_API int do_bind_function(zend_op *opline, HashTable *function_table, zend_b Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), ((zend_op_array *) function)->filename, ((zend_op_array *) function)->opcodes[0].lineno); + } else if (((zend_internal_function *)function)->module) { + zend_error(error_level, "Cannot redeclare %R() (internal function exists in module %s)", + Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), + ((zend_internal_function *)function)->module->name); } else { zend_error(error_level, "Cannot redeclare %R()", Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant)); } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index a75a76c8f8..c0ae3181b3 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -238,6 +238,7 @@ typedef struct _zend_internal_function { /* END of common elements */ void (*handler)(INTERNAL_FUNCTION_PARAMETERS); + struct _zend_module_entry *module; } zend_internal_function; #define ZEND_FN_SCOPE_NAME(function) ((function) && (function)->common.scope ? (function)->common.scope->name : EMPTY_STR) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 9a0604228f..6a14c72fc5 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -716,6 +716,7 @@ static union _zend_function *zend_std_get_method(zval **object_ptr, char *method if (zobj->ce->__call) { zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function)); call_user_call->type = ZEND_INTERNAL_FUNCTION; + call_user_call->module = zobj->ce->module; call_user_call->handler = zend_std_call_user_call; call_user_call->arg_info = NULL; call_user_call->num_args = 0; diff --git a/Zend/zend_reflection_api.c b/Zend/zend_reflection_api.c index 19ed0f0439..faa9fcbf6a 100644 --- a/Zend/zend_reflection_api.c +++ b/Zend/zend_reflection_api.c @@ -648,7 +648,13 @@ static void _function_string(string *str, zend_function *fptr, char* indent TSRM } string_printf(str, fptr->common.scope ? "%sMethod [ " : "%sFunction [ ", indent); - string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? " " : " "); + string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "type == ZEND_INTERNAL_FUNCTION && ((zend_internal_function*)fptr)->module) { + string_printf(str, ":%s", ((zend_internal_function*)fptr)->module->name); + } + string_printf(str, "> "); + + if (fptr->common.fn_flags & ZEND_ACC_CTOR) { string_printf(str, " "); } @@ -1552,7 +1558,7 @@ ZEND_METHOD(reflection_function, getNumberOfRequiredParameters) } /* }}} */ -/* {{{ proto public ReflectionParameter[] Reflection_Function::getParameters() +/* {{{ proto public ReflectionParameter[] ReflectionFunction::getParameters() Returns an array of parameter objects for this function */ ZEND_METHOD(reflection_function, getParameters) { @@ -1579,6 +1585,54 @@ ZEND_METHOD(reflection_function, getParameters) } /* }}} */ +/* {{{ proto public ReflectionExtension|NULL ReflectionFunction::getExtension() + Returns NULL or the extension the function belongs to */ +ZEND_METHOD(reflection_function, getExtension) +{ + reflection_object *intern; + zend_function *fptr; + zend_internal_function *internal; + + METHOD_NOTSTATIC; + GET_REFLECTION_OBJECT_PTR(fptr); + + if (fptr->type != ZEND_INTERNAL_FUNCTION) { + RETURN_NULL(); + } + + internal = (zend_internal_function *)fptr; + if (internal->module) { + reflection_extension_factory(return_value, internal->module->name TSRMLS_CC); + } else { + RETURN_NULL(); + } +} +/* }}} */ + +/* {{{ proto public string|false ReflectionFunction::getExtensionName() + Returns false or the name of the extension the function belongs to */ +ZEND_METHOD(reflection_function, getExtensionName) +{ + reflection_object *intern; + zend_function *fptr; + zend_internal_function *internal; + + METHOD_NOTSTATIC; + GET_REFLECTION_OBJECT_PTR(fptr); + + if (fptr->type != ZEND_INTERNAL_FUNCTION) { + RETURN_FALSE; + } + + internal = (zend_internal_function *)fptr; + if (internal->module) { + RETURN_STRING(internal->module->name, 1); + } else { + RETURN_FALSE; + } +} +/* }}} */ + /* {{{ proto public static mixed ReflectionParameter::export(mixed function, mixed parameter [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_parameter, export) @@ -3850,6 +3904,8 @@ static zend_function_entry reflection_function_functions[] = { ZEND_ME(reflection_function, getParameters, NULL, 0) ZEND_ME(reflection_function, getNumberOfParameters, NULL, 0) ZEND_ME(reflection_function, getNumberOfRequiredParameters, NULL, 0) + ZEND_ME(reflection_function, getExtension, NULL, 0) + ZEND_ME(reflection_function, getExtensionName, NULL, 0) {NULL, NULL, NULL} }; diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 19ed0f0439..faa9fcbf6a 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -648,7 +648,13 @@ static void _function_string(string *str, zend_function *fptr, char* indent TSRM } string_printf(str, fptr->common.scope ? "%sMethod [ " : "%sFunction [ ", indent); - string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? " " : " "); + string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "type == ZEND_INTERNAL_FUNCTION && ((zend_internal_function*)fptr)->module) { + string_printf(str, ":%s", ((zend_internal_function*)fptr)->module->name); + } + string_printf(str, "> "); + + if (fptr->common.fn_flags & ZEND_ACC_CTOR) { string_printf(str, " "); } @@ -1552,7 +1558,7 @@ ZEND_METHOD(reflection_function, getNumberOfRequiredParameters) } /* }}} */ -/* {{{ proto public ReflectionParameter[] Reflection_Function::getParameters() +/* {{{ proto public ReflectionParameter[] ReflectionFunction::getParameters() Returns an array of parameter objects for this function */ ZEND_METHOD(reflection_function, getParameters) { @@ -1579,6 +1585,54 @@ ZEND_METHOD(reflection_function, getParameters) } /* }}} */ +/* {{{ proto public ReflectionExtension|NULL ReflectionFunction::getExtension() + Returns NULL or the extension the function belongs to */ +ZEND_METHOD(reflection_function, getExtension) +{ + reflection_object *intern; + zend_function *fptr; + zend_internal_function *internal; + + METHOD_NOTSTATIC; + GET_REFLECTION_OBJECT_PTR(fptr); + + if (fptr->type != ZEND_INTERNAL_FUNCTION) { + RETURN_NULL(); + } + + internal = (zend_internal_function *)fptr; + if (internal->module) { + reflection_extension_factory(return_value, internal->module->name TSRMLS_CC); + } else { + RETURN_NULL(); + } +} +/* }}} */ + +/* {{{ proto public string|false ReflectionFunction::getExtensionName() + Returns false or the name of the extension the function belongs to */ +ZEND_METHOD(reflection_function, getExtensionName) +{ + reflection_object *intern; + zend_function *fptr; + zend_internal_function *internal; + + METHOD_NOTSTATIC; + GET_REFLECTION_OBJECT_PTR(fptr); + + if (fptr->type != ZEND_INTERNAL_FUNCTION) { + RETURN_FALSE; + } + + internal = (zend_internal_function *)fptr; + if (internal->module) { + RETURN_STRING(internal->module->name, 1); + } else { + RETURN_FALSE; + } +} +/* }}} */ + /* {{{ proto public static mixed ReflectionParameter::export(mixed function, mixed parameter [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_parameter, export) @@ -3850,6 +3904,8 @@ static zend_function_entry reflection_function_functions[] = { ZEND_ME(reflection_function, getParameters, NULL, 0) ZEND_ME(reflection_function, getNumberOfParameters, NULL, 0) ZEND_ME(reflection_function, getNumberOfRequiredParameters, NULL, 0) + ZEND_ME(reflection_function, getExtension, NULL, 0) + ZEND_ME(reflection_function, getExtensionName, NULL, 0) {NULL, NULL, NULL} }; -- 2.40.0