cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_execute.c zend_execute.h zend_execute_API.c

From: Date: Sun, 03 Aug 2003 08:21:08 +0000
Subject: cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_execute.c zend_execute.h zend_execute_API.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1575@lists.php.net to get a copy of this message
zeev Sun Aug 3 04:21:08 2003 EDT Modified files: /ZendEngine2 zend_compile.c zend_compile.h zend_execute.c zend_execute.h zend_execute_API.c Log: Generalize fetch_class

Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.451 ZendEngine2/zend_compile.c:1.452 --- ZendEngine2/zend_compile.c:1.451 Thu Jul 31 05:06:11 2003 +++ ZendEngine2/zend_compile.c Sun Aug 3 04:21:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.451 2003/07/31 09:06:11 zeev Exp $ */ +/* $Id: zend_compile.c,v 1.452 2003/08/03 08:21:08 zeev Exp $ */ #include "zend_language_parser.h" #include "zend.h" @@ -1185,19 +1185,20 @@ opline->extended_value = ZEND_FETCH_CLASS_GLOBAL; CG(catch_begin) = fetch_class_op_number; if (class_name->op_type == IS_CONST) { + int fetch_type; + zend_str_tolower(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); - if ((class_name->u.constant.value.str.len == (sizeof("self") - 1)) && - !memcmp(class_name->u.constant.value.str.val, "self", sizeof("self"))) { - SET_UNUSED(opline->op2); - opline->extended_value = ZEND_FETCH_CLASS_SELF; - zval_dtor(&class_name->u.constant); - } else if ((class_name->u.constant.value.str.len == (sizeof("parent") - 1)) && - !memcmp(class_name->u.constant.value.str.val, "parent", sizeof("parent"))) { - SET_UNUSED(opline->op2); - opline->extended_value = ZEND_FETCH_CLASS_PARENT; - zval_dtor(&class_name->u.constant); - } else { - opline->op2 = *class_name; + fetch_type = zend_get_class_fetch_type(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); + switch (fetch_type) { + case ZEND_FETCH_CLASS_SELF: + case ZEND_FETCH_CLASS_PARENT: + SET_UNUSED(opline->op2); + opline->extended_value = fetch_type; + zval_dtor(&class_name->u.constant); + break; + default: + opline->op2 = *class_name; + break; } } else { opline->op2 = *class_name; @@ -3412,6 +3413,20 @@ ce->parent = NULL; ce->num_interfaces = 0; ce->interfaces = NULL; +} + + +int zend_get_class_fetch_type(char *class_name, uint class_name_len) +{ + if ((class_name_len == sizeof("self")-1) && + !memcmp(class_name, "self", sizeof("self"))) { + return ZEND_FETCH_CLASS_SELF; + } else if ((class_name_len == sizeof("parent")-1) && + !memcmp(class_name, "parent", sizeof("parent"))) { + return ZEND_FETCH_CLASS_PARENT; + } else { + return ZEND_FETCH_CLASS_DEFAULT; + } } /* Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.253 ZendEngine2/zend_compile.h:1.254 --- ZendEngine2/zend_compile.h:1.253 Wed Jul 30 13:49:27 2003 +++ ZendEngine2/zend_compile.h Sun Aug 3 04:21:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.253 2003/07/30 17:49:27 zeev Exp $ */ +/* $Id: zend_compile.h,v 1.254 2003/08/03 08:21:08 zeev Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -465,6 +465,7 @@ ZEND_API zend_bool zend_is_compiling(TSRMLS_D); ZEND_API char *zend_make_compiled_string_description(char *name TSRMLS_DC); void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC); +int zend_get_class_fetch_type(char *class_name, uint class_name_len); typedef zend_bool (*zend_auto_global_callback)(char *name, uint name_len TSRMLS_DC); typedef struct _zend_auto_global { @@ -680,6 +681,7 @@ #define ZEND_FETCH_CLASS_PARENT 2 #define ZEND_FETCH_CLASS_MAIN 3 #define ZEND_FETCH_CLASS_GLOBAL 4 +#define ZEND_FETCH_CLASS_AUTO 5 /* variable parsing type (compile-time) */ Index: ZendEngine2/zend_execute.c diff -u ZendEngine2/zend_execute.c:1.513 ZendEngine2/zend_execute.c:1.514 --- ZendEngine2/zend_execute.c:1.513 Sat Aug 2 07:39:15 2003 +++ ZendEngine2/zend_execute.c Sun Aug 3 04:21:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.513 2003/08/02 11:39:15 helly Exp $ */ +/* $Id: zend_execute.c,v 1.514 2003/08/03 08:21:08 zeev Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -2202,81 +2202,39 @@ NEXT_OPCODE(); } + int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS) { - zend_class_entry **pce; - zend_class_entry *ce = NULL; - zend_bool is_const; char *class_name_strval; - zend_uint class_name_strlen; - zend_bool free_class_name = 0; - zval *class_name; + zval *class_name; + if (EX(opline)->op2.op_type == IS_UNUSED) { - if (EX(opline)->extended_value == ZEND_FETCH_CLASS_SELF) { - if (!EG(scope)) { - zend_error(E_ERROR, "Cannot access self:: when no class scope is active"); - } - EX_T(EX(opline)->result.u.var).EA.class_entry = EG(scope); - NEXT_OPCODE(); - } else if (EX(opline)->extended_value == ZEND_FETCH_CLASS_PARENT) { - if (!EG(scope)) { - zend_error(E_ERROR, "Cannot access parent:: when no class scope is active"); - } - if (!EG(scope)->parent) { - zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent"); - } - EX_T(EX(opline)->result.u.var).EA.class_entry = EG(scope)->parent; - NEXT_OPCODE(); - } + EX_T(EX(opline)->result.u.var).EA.class_entry = zend_fetch_class(NULL, 0, EX(opline)->extended_value TSRMLS_CC); + NEXT_OPCODE(); } - is_const = (EX(opline)->op2.op_type == IS_CONST); - - if (is_const) { - class_name_strval = EX(opline)->op2.u.constant.value.str.val; - class_name_strlen = EX(opline)->op2.u.constant.value.str.len; - } else { - class_name = get_zval_ptr(&EX(opline)->op2, EX(Ts), &EG(free_op2), BP_VAR_R); + class_name = get_zval_ptr(&EX(opline)->op2, EX(Ts), &EG(free_op2), BP_VAR_R); - switch (class_name->type) { - case IS_OBJECT: - ce = Z_OBJCE_P(class_name); - break; - case IS_STRING: - convert_to_string_ex(&class_name); + switch (class_name->type) { + case IS_OBJECT: + EX_T(EX(opline)->result.u.var).EA.class_entry = Z_OBJCE_P(class_name); + break; + case IS_STRING: + if (EX(opline)->op2.op_type != IS_CONST) { class_name_strval = zend_str_tolower_dup(class_name->value.str.val, class_name->value.str.len); - class_name_strlen = class_name->value.str.len; - free_class_name = 1; - break; - default: - zend_error(E_ERROR, "Class name must be a valid object or a string"); - break; - } - } - - if (!ce) { - int retval; - - if (EX(opline)->op1.op_type == IS_UNUSED) { - retval = zend_lookup_class(class_name_strval, class_name_strlen, &pce TSRMLS_CC); - } - if (retval==SUCCESS) { - ce = *pce; - } + EX_T(EX(opline)->result.u.var).EA.class_entry = zend_fetch_class(class_name_strval, Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); + efree(class_name_strval); + } else { + EX_T(EX(opline)->result.u.var).EA.class_entry = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); + } + break; + default: + zend_error(E_ERROR, "Class name must be a valid object or a string"); + break; } - if (!ce) { - zend_error(E_ERROR, "Class '%s' not found", class_name_strval); - } else { - EX_T(EX(opline)->result.u.var).EA.class_entry = ce; - } - if (!is_const) { - if (free_class_name) { - efree(class_name_strval); - } - FREE_OP(EX(Ts), &EX(opline)->op2, EG(free_op2)); - } + FREE_OP(EX(Ts), &EX(opline)->op2, EG(free_op2)); NEXT_OPCODE(); } Index: ZendEngine2/zend_execute.h diff -u ZendEngine2/zend_execute.h:1.56 ZendEngine2/zend_execute.h:1.57 --- ZendEngine2/zend_execute.h:1.56 Tue Jun 10 16:03:24 2003 +++ ZendEngine2/zend_execute.h Sun Aug 3 04:21:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.h,v 1.56 2003/06/10 20:03:24 imajes Exp $ */ +/* $Id: zend_execute.h,v 1.57 2003/08/03 08:21:08 zeev Exp $ */ #ifndef ZEND_EXECUTE_H #define ZEND_EXECUTE_H @@ -147,6 +147,7 @@ ZEND_API void zend_set_timeout(long seconds); ZEND_API void zend_unset_timeout(TSRMLS_D); ZEND_API void zend_timeout(int dummy); +ZEND_API zend_class_entry *zend_fetch_class(char *class_name, uint class_name_len, int fetch_type TSRMLS_DC); #ifdef ZEND_WIN32 void zend_init_timeout_thread(); Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.219 ZendEngine2/zend_execute_API.c:1.220 --- ZendEngine2/zend_execute_API.c:1.219 Sun Jul 27 11:59:37 2003 +++ ZendEngine2/zend_execute_API.c Sun Aug 3 04:21:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.219 2003/07/27 15:59:37 stas Exp $ */ +/* $Id: zend_execute_API.c,v 1.220 2003/08/03 08:21:08 zeev Exp $ */ #include <stdio.h> #include <signal.h> @@ -1047,6 +1047,43 @@ } # endif #endif +} + + +zend_class_entry *zend_fetch_class(char *class_name, uint class_name_len, int fetch_type TSRMLS_DC) +{ + zend_class_entry **pce; + zend_class_entry *ce = NULL; + zend_bool free_class_name = 0; + +check_fetch_type: + switch (fetch_type) { + case ZEND_FETCH_CLASS_SELF: + if (!EG(scope)) { + zend_error(E_ERROR, "Cannot access self:: when no class scope is active"); + } + return EG(scope); + case ZEND_FETCH_CLASS_PARENT: + if (!EG(scope)) { + zend_error(E_ERROR, "Cannot access parent:: when no class scope is active"); + } + if (!EG(scope)->parent) { + zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent"); + } + return EG(scope)->parent; + case ZEND_FETCH_CLASS_AUTO: { + fetch_type = zend_get_class_fetch_type(class_name, class_name_len); + if (fetch_type!=ZEND_FETCH_CLASS_DEFAULT) { + goto check_fetch_type; + } + } + break; + } + + if (zend_lookup_class(class_name, class_name_len, &pce TSRMLS_CC)==FAILURE) { + zend_error(E_ERROR, "Class '%s' not found", class_name); + } + return *pce; } /*
« previous php.zend-engine.cvs (#1575) next »