]> granicus.if.org Git - php/commitdiff
- Adds module registering a function to struct zend_internal_function.
authorMarcus Boerger <helly@php.net>
Tue, 30 Aug 2005 18:27:17 +0000 (18:27 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 30 Aug 2005 18:27:17 +0000 (18:27 +0000)
  (Johannes)
# This information is by reflection API and error messages.

Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_object_handlers.c
Zend/zend_reflection_api.c
ext/reflection/php_reflection.c

index 1eb64bc3d273af3c03030fbb82c5634262e5af95..0b54bae3d133e478eebb322d32a08e2ff8895946 100644 (file)
@@ -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);
index 3927f36094961900527ee8ab9e8429933c92fda1..0549b51ef53993fbdb9363de22dfa91fd5bed801 100644 (file)
@@ -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));
                }
index a75a76c8f8757bd55df95a1f971b32da8cdaae01..c0ae3181b3a93150329119a19d205a86b4a24d86 100644 (file)
@@ -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)
index 9a0604228f184ccb10766c8b7f196ef71caee933..6a14c72fc56e21f0048db5349ed2c1b2ab6a8fb5 100644 (file)
@@ -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;
index 19ed0f04391f4a8278c7cbd69319fba52152aedf..faa9fcbf6a06b3978f47eeff8c2cac38f11504ba 100644 (file)
@@ -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) ? "<user> " : "<internal> ");
+       string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal");
+       if (fptr->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, "<ctor> ");
        }
@@ -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}
 };
 
index 19ed0f04391f4a8278c7cbd69319fba52152aedf..faa9fcbf6a06b3978f47eeff8c2cac38f11504ba 100644 (file)
@@ -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) ? "<user> " : "<internal> ");
+       string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal");
+       if (fptr->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, "<ctor> ");
        }
@@ -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}
 };