Split ZEND_NAMESPACE into user and internal namespaces. Hope this is

okay with engine folks.
This commit is contained in:
Andrei Zmievski 2003-04-01 19:37:04 +00:00
parent e2333fd1df
commit 62f9eb8006
6 changed files with 47 additions and 26 deletions

View 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);

View 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);

View 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)

View 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 {

View 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) {

View 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)