cvs: ZendEngine2 / zend_builtin_functions.c zend_compile.c zend_compile.h zend_execute.c zend_object_handlers.c zend_opcode.c

From: Date: Tue, 01 Apr 2003 19:37:04 +0000
Subject: cvs: ZendEngine2 / zend_builtin_functions.c zend_compile.c zend_compile.h zend_execute.c zend_object_handlers.c zend_opcode.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1092@lists.php.net to get a copy of this message
andrei Tue Apr 1 14:37:04 2003 EDT Modified files: /ZendEngine2 zend_builtin_functions.c zend_compile.c zend_compile.h zend_execute.c zend_object_handlers.c zend_opcode.c Log: Split ZEND_NAMESPACE into user and internal namespaces. Hope this is okay with engine folks.

Index: ZendEngine2/zend_builtin_functions.c diff -u ZendEngine2/zend_builtin_functions.c:1.179 ZendEngine2/zend_builtin_functions.c:1.180 --- ZendEngine2/zend_builtin_functions.c:1.179 Tue Apr 1 04:43:30 2003 +++ ZendEngine2/zend_builtin_functions.c Tue Apr 1 14:37:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_builtin_functions.c,v 1.179 2003/04/01 09:43:30 stas Exp $ */ +/* $Id: zend_builtin_functions.c,v 1.180 2003/04/01 19:37:04 andrei Exp $ */ #include "zend.h" #include "zend_API.h" @@ -1051,7 +1051,7 @@ 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: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.404 ZendEngine2/zend_compile.c:1.405 --- ZendEngine2/zend_compile.c:1.404 Mon Mar 31 15:42:00 2003 +++ ZendEngine2/zend_compile.c Tue Apr 1 14:37:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.404 2003/03/31 20:42:00 andrei Exp $ */ +/* $Id: zend_compile.c,v 1.405 2003/04/01 19:37:04 andrei Exp $ */ #include "zend_language_parser.h" #include "zend.h" @@ -3330,6 +3330,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.229 ZendEngine2/zend_compile.h:1.230 --- ZendEngine2/zend_compile.h:1.229 Mon Mar 31 15:42:00 2003 +++ ZendEngine2/zend_compile.h Tue Apr 1 14:37:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.229 2003/03/31 20:42:00 andrei Exp $ */ +/* $Id: zend_compile.h,v 1.230 2003/04/01 19:37:04 andrei Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -720,9 +720,10 @@ #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: ZendEngine2/zend_execute.c diff -u ZendEngine2/zend_execute.c:1.451 ZendEngine2/zend_execute.c:1.452 --- ZendEngine2/zend_execute.c:1.451 Sun Mar 30 08:40:40 2003 +++ ZendEngine2/zend_execute.c Tue Apr 1 14:37:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.451 2003/03/30 13:40:40 sebastian Exp $ */ +/* $Id: zend_execute.c,v 1.452 2003/04/01 19:37:04 andrei Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -2371,7 +2371,7 @@ 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 @@ 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 @@ 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: ZendEngine2/zend_object_handlers.c diff -u ZendEngine2/zend_object_handlers.c:1.45 ZendEngine2/zend_object_handlers.c:1.46 --- ZendEngine2/zend_object_handlers.c:1.45 Wed Mar 26 01:32:53 2003 +++ ZendEngine2/zend_object_handlers.c Tue Apr 1 14:37:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_object_handlers.c,v 1.45 2003/03/26 06:32:53 sebastian Exp $ */ +/* $Id: zend_object_handlers.c,v 1.46 2003/04/01 19:37:04 andrei Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -652,7 +652,7 @@ 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: ZendEngine2/zend_opcode.c diff -u ZendEngine2/zend_opcode.c:1.87 ZendEngine2/zend_opcode.c:1.88 --- ZendEngine2/zend_opcode.c:1.87 Mon Mar 31 15:42:01 2003 +++ ZendEngine2/zend_opcode.c Tue Apr 1 14:37:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_opcode.c,v 1.87 2003/03/31 20:42:01 andrei Exp $ */ +/* $Id: zend_opcode.c,v 1.88 2003/04/01 19:37:04 andrei Exp $ */ #include <stdio.h> @@ -175,7 +175,8 @@ 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_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)
« previous php.zend-engine.cvs (#1092) next »