]> granicus.if.org Git - php/commitdiff
Resolve autoglobals as global-fetch CVs when possible
authorSara Golemon <pollita@php.net>
Sat, 20 Jan 2007 20:36:55 +0000 (20:36 +0000)
committerSara Golemon <pollita@php.net>
Sat, 20 Jan 2007 20:36:55 +0000 (20:36 +0000)
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c

index ff581002751097c698aa807129f7d69caab0cdba..4a6e3d875cf9e8580e2fec77cb4432b66e5597ef 100644 (file)
@@ -267,7 +267,7 @@ static zend_uint get_temporary_variable(zend_op_array *op_array)
        return (op_array->T)++ * sizeof(temp_variable);
 }
 
-static int lookup_cv(zend_op_array *op_array, zend_uchar type, zstr name, int name_len)
+static int lookup_cv(zend_op_array *op_array, zend_uchar type, zstr name, int name_len TSRMLS_DC)
 {
        int i = 0;
        ulong hash_value = zend_u_inline_hash_func(type, name, name_len+1);
@@ -290,6 +290,7 @@ static int lookup_cv(zend_op_array *op_array, zend_uchar type, zstr name, int na
        op_array->vars[i].name = name; /* estrndup(name, name_len); */
        op_array->vars[i].name_len = name_len;
        op_array->vars[i].hash_value = hash_value;
+       op_array->vars[i].fetch_type = zend_u_is_auto_global(type, name, name_len TSRMLS_CC) ? ZEND_FETCH_GLOBAL : ZEND_FETCH_LOCAL;
        return i;
 }
 
@@ -380,13 +381,12 @@ void fetch_simple_variable_ex(znode *result, znode *varname, int bp, zend_uchar
        if (varname->op_type == IS_CONST &&
            (Z_TYPE(varname->u.constant) == IS_STRING ||
             Z_TYPE(varname->u.constant) == IS_UNICODE) &&
-           !zend_u_is_auto_global(Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant) TSRMLS_CC) &&
            !(Z_UNILEN(varname->u.constant) == (sizeof("this")-1) &&
              ZEND_U_EQUAL(Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant), "this", sizeof("this")-1)) &&
            (CG(active_op_array)->last == 0 ||
             CG(active_op_array)->opcodes[CG(active_op_array)->last-1].opcode != ZEND_BEGIN_SILENCE)) {
                result->op_type = IS_CV;
-               result->u.var = lookup_cv(CG(active_op_array), Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant));
+               result->u.var = lookup_cv(CG(active_op_array), Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant) TSRMLS_CC);
                result->u.EA.type = 0;
                return;
        }
index 6e272afdec8de425d5bc4e58c519d26376e39be7..18c17ed7ca6593447dfbf4daa79677299ffaa195 100644 (file)
@@ -174,6 +174,7 @@ typedef struct _zend_compiled_variable {
        zstr name;
        int name_len;
        ulong hash_value;
+       zend_uint fetch_type;
 } zend_compiled_variable;
 
 struct _zend_op_array {
index e92bf2b606ebd45c326fe0b325eaf292eb4414c0..da3cf32520b0f462e31f06ec100599ec9dadc406 100644 (file)
@@ -226,8 +226,9 @@ static inline zval *_get_zval_ptr_cv(znode *node, temp_variable *Ts, int type TS
        if (!*ptr) {
                zend_compiled_variable *cv = &CV_DEF_OF(node->u.var);
                zend_uchar utype = UG(unicode)?IS_UNICODE:IS_STRING;
+               HashTable *symbol_table = (cv->fetch_type == ZEND_FETCH_GLOBAL) ? &EG(symbol_table) : EG(active_symbol_table);
 
-               if (zend_u_hash_quick_find(EG(active_symbol_table), utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
+               if (zend_u_hash_quick_find(symbol_table, utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
                        switch (type) {
                                case BP_VAR_R:
                                case BP_VAR_UNSET:
@@ -296,8 +297,9 @@ static inline zval **_get_zval_ptr_ptr_cv(znode *node, temp_variable *Ts, int ty
        if (!*ptr) {
                zend_compiled_variable *cv = &CV_DEF_OF(node->u.var);
                zend_uchar utype = UG(unicode)?IS_UNICODE:IS_STRING;
+               HashTable *symbol_table = (cv->fetch_type == ZEND_FETCH_GLOBAL) ? &EG(symbol_table) : EG(active_symbol_table);
 
-               if (zend_u_hash_quick_find(EG(active_symbol_table), utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
+               if (zend_u_hash_quick_find(symbol_table, utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) {
                        switch (type) {
                                case BP_VAR_R:
                                case BP_VAR_UNSET: