]> granicus.if.org Git - php/commitdiff
Split ZEND_NAMESPACE into user and internal namespaces. Hope this is
authorAndrei Zmievski <andrei@php.net>
Tue, 1 Apr 2003 19:37:04 +0000 (19:37 +0000)
committerAndrei Zmievski <andrei@php.net>
Tue, 1 Apr 2003 19:37:04 +0000 (19:37 +0000)
okay with engine folks.

Zend/zend_builtin_functions.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_object_handlers.c
Zend/zend_opcode.c

index 351f04fd85b2d14f31ad3505ca0513731e449ba3..d8f016459e19741f15c7f30555005b6c6c553f7c 100644 (file)
@@ -1051,7 +1051,7 @@ static int copy_class_name(zend_class_entry **pce, int num_args, va_list args, z
        zend_class_entry *ce  = *pce;
 
        if (hash_key->nKeyLength==0 || hash_key->arKey[0]!=0) {
-               if (ce->type == ZEND_NAMESPACE) {
+               if (ce->type == ZEND_USER_NAMESPACE || ce->type == ZEND_INTERNAL_NAMESPACE) {
                        zval *subarray;
 
                        MAKE_STD_ZVAL(subarray);
index 38f0ead9bfcd256c2d8283be2d491472894fde1c..8e0e229607c75247606c58ba81bbce318e38d49a 100644 (file)
@@ -3330,6 +3330,8 @@ void zend_destroy_property_info(zend_property_info *property_info)
 
 void zend_init_namespace(zend_namespace *ns TSRMLS_DC)
 {
+       zend_bool persistent_hashes = (ns->type == ZEND_INTERNAL_NAMESPACE) ? 1 : 0;
+
        ns->refcount = 1;
        ns->constants_updated = 0;
        ns->ce_flags = 0;
@@ -3338,11 +3340,15 @@ void zend_init_namespace(zend_namespace *ns TSRMLS_DC)
        ns->doc_comment = NULL;
        ns->doc_comment_len = 0;
 
-       zend_hash_init(&ns->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
-       zend_hash_init(&ns->class_table, 10, NULL, ZEND_CLASS_DTOR, 0);
-       zend_hash_init(&ns->constants_table, 10, NULL, ZVAL_PTR_DTOR, 0);
-       ALLOC_HASHTABLE(ns->static_members);
-       zend_hash_init(ns->static_members, 0, NULL, ZVAL_PTR_DTOR, 0);
+       if (persistent_hashes) {
+               ns->static_members = (HashTable *) malloc(sizeof(HashTable));
+       } else {
+               ALLOC_HASHTABLE(ns->static_members);
+       }
+       zend_hash_init_ex(ns->static_members, 0, NULL, ZVAL_PTR_DTOR, persistent_hashes, 0);
+       zend_hash_init_ex(&ns->function_table, 10, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
+       zend_hash_init_ex(&ns->class_table, 10, NULL, ZEND_CLASS_DTOR, persistent_hashes, 0);
+       zend_hash_init_ex(&ns->constants_table, 10, NULL, ZVAL_PTR_DTOR, persistent_hashes, 0);
 
        ns->parent = NULL;
        ns->ns = NULL;
@@ -3353,8 +3359,6 @@ void zend_init_namespace(zend_namespace *ns TSRMLS_DC)
        ns->__set = NULL;
        ns->__call = NULL;
        ns->create_object = NULL;
-
-       ns->type = ZEND_NAMESPACE;
 }
 
 void zend_do_begin_namespace(znode *ns_token, znode *ns_name TSRMLS_DC)
@@ -3366,7 +3370,7 @@ void zend_do_begin_namespace(znode *ns_token, znode *ns_name TSRMLS_DC)
 
        if(zend_hash_find(&CG(global_namespace).class_table, ns_name->u.constant.value.str.val, ns_name->u.constant.value.str.len+1, (void **)&pns) == SUCCESS) {
                ns = *pns;
-               if(ns->type != ZEND_NAMESPACE || ns == CG(active_namespace)) {
+               if(ns->type != ZEND_USER_NAMESPACE || ns == CG(active_namespace)) {
                        zend_error(E_COMPILE_ERROR, "Cannot redefine namespace '%s' - class or namespace with this name already defined", ns->name);
                }
                FREE_PNODE(ns_name);
@@ -3374,6 +3378,7 @@ void zend_do_begin_namespace(znode *ns_token, znode *ns_name TSRMLS_DC)
                ns = emalloc(sizeof(zend_namespace));
                ns->name = ns_name->u.constant.value.str.val;
                ns->name_length = ns_name->u.constant.value.str.len;
+               ns->type = ZEND_USER_NAMESPACE;
                zend_hash_add(&CG(global_namespace).class_table, ns->name, ns->name_length+1, (void **)&ns, sizeof(zend_namespace *), NULL);
                zend_init_namespace(ns TSRMLS_CC);
                ns->line_start = zend_get_compiled_lineno(TSRMLS_C);
index f2b7b8b27ae750e4b66d0f317c944592a4d346aa..0522c86cb78be8640b149378ba6cae92023372d2 100644 (file)
@@ -720,9 +720,10 @@ int zendlex(znode *zendlval TSRMLS_DC);
 #define ZEND_OVERLOADED_FUNCTION       3
 #define        ZEND_EVAL_CODE                          4
 
-#define ZEND_INTERNAL_CLASS            1
-#define ZEND_USER_CLASS                        2
-#define ZEND_NAMESPACE          3
+#define ZEND_INTERNAL_CLASS         1
+#define ZEND_USER_CLASS             2
+#define ZEND_INTERNAL_NAMESPACE     3
+#define ZEND_USER_NAMESPACE         4
 
 #define ZEND_EVAL                              (1<<0)
 #define ZEND_INCLUDE                   (1<<1)
index ad704279151568e95dd8dbb067a4f16c7c9a0ff2..88274c8e176187ce09479f23b135f187059b4986 100644 (file)
@@ -2371,7 +2371,7 @@ int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS)
 
                        if(retval == FAILURE) {
                                /* try namespace */
-                               if(zend_hash_find(&EG(global_namespace_ptr)->class_table, class_name_strval, class_name_strlen+1, (void **)&pce) == SUCCESS && (*pce)->type != ZEND_NAMESPACE) {
+                               if(zend_hash_find(&EG(global_namespace_ptr)->class_table, class_name_strval, class_name_strlen+1, (void **)&pce) == SUCCESS && (*pce)->type != ZEND_USER_NAMESPACE && (*pce)->type != ZEND_INTERNAL_NAMESPACE) {
                                        retval = SUCCESS;
                                }
                        }
@@ -2382,7 +2382,7 @@ int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS)
                        if(EX(opline)->extended_value == ZEND_FETCH_CLASS_GLOBAL) {
                                ns = EG(global_namespace_ptr);
                        } else {
-                               if (zend_hash_find(&EG(global_namespace_ptr)->class_table, EX(opline)->op1.u.constant.value.str.val, EX(opline)->op1.u.constant.value.str.len+1, (void **)&pce) == FAILURE || (*pce)->type != ZEND_NAMESPACE) {
+                               if (zend_hash_find(&EG(global_namespace_ptr)->class_table, EX(opline)->op1.u.constant.value.str.val, EX(opline)->op1.u.constant.value.str.len+1, (void **)&pce) == FAILURE || ((*pce)->type != ZEND_USER_NAMESPACE && (*pce)->type != ZEND_INTERNAL_NAMESPACE)) {
                                        zend_error(E_ERROR, "Namespace '%s' not found", EX(opline)->op1.u.constant.value.str.val);
                                }
                                ns = *pce;
@@ -3976,7 +3976,7 @@ int zend_start_namespace_handler(ZEND_OPCODE_HANDLER_ARGS)
                        zend_error(E_ERROR, "Internal error: Invalid type in namespace definition - %d", Z_TYPE_P(namespace_name));
                }
 
-               if(zend_hash_find(&EG(global_namespace_ptr)->class_table, Z_STRVAL_P(namespace_name), Z_STRLEN_P(namespace_name)+1, (void **)&pns) != SUCCESS || (*pns)->type != ZEND_NAMESPACE) {
+               if(zend_hash_find(&EG(global_namespace_ptr)->class_table, Z_STRVAL_P(namespace_name), Z_STRLEN_P(namespace_name)+1, (void **)&pns) != SUCCESS || (*pns)->type != ZEND_USER_NAMESPACE) {
                        zend_error(E_ERROR, "Internal error: Cannot locate namespace '%s'", Z_STRVAL_P(namespace_name));
                }
        } else {
index 89a39f632e4b91a553e296a77c6a890de49d8f58..44e2405048b148ebb0cf6c64663007a3731360c4 100644 (file)
@@ -652,7 +652,7 @@ zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, i
        zend_property_info *property_info;
        zend_property_info std_property_info;
 
-       if (ce->type == ZEND_NAMESPACE) {
+       if (ce->type == ZEND_USER_NAMESPACE || ce->type == ZEND_INTERNAL_NAMESPACE) {
                zend_hash_find(ce->static_members, property_name, property_name_len+1, (void **) &retval);
        } else {
                if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE) {
index 31ddb4557ef6beb61acbfa7af638f6a8d398e980..302a715ff2180be3a92e1bdd505aacb837db71c4 100644 (file)
@@ -175,7 +175,8 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce)
                        zend_hash_destroy(&ce->class_table);
                        free(ce);
                        break;
-               case ZEND_NAMESPACE:
+               case ZEND_USER_NAMESPACE:
+               case ZEND_INTERNAL_NAMESPACE:
                        destroy_zend_namespace(pce);
                        break;
        }
@@ -184,16 +185,30 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce)
 ZEND_API void destroy_zend_namespace(zend_namespace **pns)
 {
        zend_namespace *ns = *pns;
-       zend_hash_destroy(&ns->function_table);
-       zend_hash_destroy(&ns->class_table);
-       zend_hash_destroy(&ns->constants_table);
-       zend_hash_destroy(ns->static_members);
-       FREE_HASHTABLE(ns->static_members);
-       if (ns->doc_comment) {
-               efree(ns->doc_comment);
+       switch (ns->type) {
+               case ZEND_USER_NAMESPACE:
+                       zend_hash_destroy(&ns->function_table);
+                       zend_hash_destroy(&ns->class_table);
+                       zend_hash_destroy(&ns->constants_table);
+                       zend_hash_destroy(ns->static_members);
+                       FREE_HASHTABLE(ns->static_members);
+                       if (ns->doc_comment) {
+                               efree(ns->doc_comment);
+                       }
+                       efree(ns->name);
+                       efree(ns);
+                       break;
+
+               case ZEND_INTERNAL_NAMESPACE:
+                       zend_hash_destroy(&ns->function_table);
+                       zend_hash_destroy(&ns->class_table);
+                       zend_hash_destroy(&ns->constants_table);
+                       zend_hash_destroy(ns->static_members);
+                       free(ns->static_members);
+                       free(ns->name);
+                       free(ns);
+                       break;
        }
-       efree(ns->name);
-       efree(ns);
 }
 
 void zend_class_add_ref(zend_class_entry **ce)