Back to index

php5  5.3.10
zend_execute_API.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | Zend Engine                                                          |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 2.00 of the Zend license,     |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.zend.com/license/2_00.txt.                                |
00011    | If you did not receive a copy of the Zend license and are unable to  |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@zend.com so we can mail you a copy immediately.              |
00014    +----------------------------------------------------------------------+
00015    | Authors: Andi Gutmans <andi@zend.com>                                |
00016    |          Zeev Suraski <zeev@zend.com>                                |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: zend_execute_API.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #include <stdio.h>
00023 #include <signal.h>
00024 
00025 #include "zend.h"
00026 #include "zend_compile.h"
00027 #include "zend_execute.h"
00028 #include "zend_API.h"
00029 #include "zend_ptr_stack.h"
00030 #include "zend_constants.h"
00031 #include "zend_extensions.h"
00032 #include "zend_exceptions.h"
00033 #include "zend_closures.h"
00034 #include "zend_vm.h"
00035 #include "zend_float.h"
00036 #ifdef HAVE_SYS_TIME_H
00037 #include <sys/time.h>
00038 #endif
00039 
00040 ZEND_API void (*zend_execute)(zend_op_array *op_array TSRMLS_DC);
00041 ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
00042 
00043 /* true globals */
00044 ZEND_API const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 };
00045 ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL };
00046 
00047 #ifdef ZEND_WIN32
00048 #include <process.h>
00049 static WNDCLASS wc;
00050 static HWND timeout_window;
00051 static HANDLE timeout_thread_event;
00052 static HANDLE timeout_thread_handle;
00053 static DWORD timeout_thread_id;
00054 static int timeout_thread_initialized=0;
00055 #endif
00056 
00057 #if 0&&ZEND_DEBUG
00058 static void (*original_sigsegv_handler)(int);
00059 static void zend_handle_sigsegv(int dummy) /* {{{ */
00060 {
00061        fflush(stdout);
00062        fflush(stderr);
00063        if (original_sigsegv_handler == zend_handle_sigsegv) {
00064               signal(SIGSEGV, original_sigsegv_handler);
00065        } else {
00066               signal(SIGSEGV, SIG_DFL);
00067        }
00068        {
00069               TSRMLS_FETCH();
00070 
00071               fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
00072                             active_opline->opcode,
00073                             active_opline-EG(active_op_array)->opcodes,
00074                             get_active_function_name(TSRMLS_C),
00075                             zend_get_executed_filename(TSRMLS_C),
00076                             zend_get_executed_lineno(TSRMLS_C));
00077 /* See http://support.microsoft.com/kb/190351 */
00078 #ifdef PHP_WIN32
00079               fflush(stderr);
00080 #endif
00081        }
00082        if (original_sigsegv_handler!=zend_handle_sigsegv) {
00083               original_sigsegv_handler(dummy);
00084        }
00085 }
00086 /* }}} */
00087 #endif
00088 
00089 static void zend_extension_activator(zend_extension *extension TSRMLS_DC) /* {{{ */
00090 {
00091        if (extension->activate) {
00092               extension->activate();
00093        }
00094 }
00095 /* }}} */
00096 
00097 static void zend_extension_deactivator(zend_extension *extension TSRMLS_DC) /* {{{ */
00098 {
00099        if (extension->deactivate) {
00100               extension->deactivate();
00101        }
00102 }
00103 /* }}} */
00104 
00105 static int clean_non_persistent_function(zend_function *function TSRMLS_DC) /* {{{ */
00106 {
00107        return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
00108 }
00109 /* }}} */
00110 
00111 static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC) /* {{{ */
00112 {
00113        return (function->type != ZEND_INTERNAL_FUNCTION);
00114 }
00115 /* }}} */
00116 
00117 static int clean_non_persistent_class(zend_class_entry **ce TSRMLS_DC) /* {{{ */
00118 {
00119        return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
00120 }
00121 /* }}} */
00122 
00123 static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC) /* {{{ */
00124 {
00125        return ((*ce)->type != ZEND_INTERNAL_CLASS);
00126 }
00127 /* }}} */
00128 
00129 void init_executor(TSRMLS_D) /* {{{ */
00130 {
00131        zend_init_fpu(TSRMLS_C);
00132 
00133        INIT_ZVAL(EG(uninitialized_zval));
00134        /* trick to make uninitialized_zval never be modified, passed by ref, etc. */
00135        Z_ADDREF(EG(uninitialized_zval));
00136        INIT_ZVAL(EG(error_zval));
00137        EG(uninitialized_zval_ptr)=&EG(uninitialized_zval);
00138        EG(error_zval_ptr)=&EG(error_zval);
00139        zend_ptr_stack_init(&EG(arg_types_stack));
00140 /* destroys stack frame, therefore makes core dumps worthless */
00141 #if 0&&ZEND_DEBUG
00142        original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
00143 #endif
00144        EG(return_value_ptr_ptr) = NULL;
00145 
00146        EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
00147        EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
00148        EG(no_extensions) = 0;
00149 
00150        EG(function_table) = CG(function_table);
00151        EG(class_table) = CG(class_table);
00152 
00153        EG(in_execution) = 0;
00154        EG(in_autoload) = NULL;
00155        EG(autoload_func) = NULL;
00156        EG(error_handling) = EH_NORMAL;
00157 
00158        zend_vm_stack_init(TSRMLS_C);
00159        zend_vm_stack_push((void *) NULL TSRMLS_CC);
00160 
00161        zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0);
00162        {
00163               zval *globals;
00164 
00165               ALLOC_ZVAL(globals);
00166               Z_SET_REFCOUNT_P(globals, 1);
00167               Z_SET_ISREF_P(globals);
00168               Z_TYPE_P(globals) = IS_ARRAY;
00169               Z_ARRVAL_P(globals) = &EG(symbol_table);
00170               zend_hash_update(&EG(symbol_table), "GLOBALS", sizeof("GLOBALS"), &globals, sizeof(zval *), NULL);
00171        }
00172        EG(active_symbol_table) = &EG(symbol_table);
00173 
00174        zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator TSRMLS_CC);
00175        EG(opline_ptr) = NULL;
00176 
00177        zend_hash_init(&EG(included_files), 5, NULL, NULL, 0);
00178 
00179        EG(ticks_count) = 0;
00180 
00181        EG(user_error_handler) = NULL;
00182 
00183        EG(current_execute_data) = NULL;
00184 
00185        zend_stack_init(&EG(user_error_handlers_error_reporting));
00186        zend_ptr_stack_init(&EG(user_error_handlers));
00187        zend_ptr_stack_init(&EG(user_exception_handlers));
00188 
00189        zend_objects_store_init(&EG(objects_store), 1024);
00190 
00191        EG(full_tables_cleanup) = 0;
00192 #ifdef ZEND_WIN32
00193        EG(timed_out) = 0;
00194 #endif
00195 
00196        EG(exception) = NULL;
00197        EG(prev_exception) = NULL;
00198 
00199        EG(scope) = NULL;
00200        EG(called_scope) = NULL;
00201 
00202        EG(This) = NULL;
00203 
00204        EG(active_op_array) = NULL;
00205 
00206        EG(active) = 1;
00207 }
00208 /* }}} */
00209 
00210 static int zval_call_destructor(zval **zv TSRMLS_DC) /* {{{ */
00211 {
00212        if (Z_TYPE_PP(zv) == IS_OBJECT && Z_REFCOUNT_PP(zv) == 1) {
00213               return ZEND_HASH_APPLY_REMOVE;
00214        } else {
00215               return ZEND_HASH_APPLY_KEEP;
00216        }
00217 }
00218 /* }}} */
00219 
00220 void shutdown_destructors(TSRMLS_D) /* {{{ */
00221 {
00222        zend_try {
00223               int symbols;
00224               do {
00225                      symbols = zend_hash_num_elements(&EG(symbol_table));
00226                      zend_hash_reverse_apply(&EG(symbol_table), (apply_func_t) zval_call_destructor TSRMLS_CC);
00227               } while (symbols != zend_hash_num_elements(&EG(symbol_table)));
00228               zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC);
00229        } zend_catch {
00230               /* if we couldn't destruct cleanly, mark all objects as destructed anyway */
00231               zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
00232        } zend_end_try();
00233 }
00234 /* }}} */
00235 
00236 void shutdown_executor(TSRMLS_D) /* {{{ */
00237 {
00238        zend_try {
00239 
00240 /* Removed because this can not be safely done, e.g. in this situation:
00241    Object 1 creates object 2
00242    Object 3 holds reference to object 2.
00243    Now when 1 and 2 are destroyed, 3 can still access 2 in its destructor, with
00244    very problematic results */
00245 /*            zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); */
00246 
00247 /* Moved after symbol table cleaners, because  some of the cleaners can call
00248    destructors, which would use EG(symtable_cache_ptr) and thus leave leaks */
00249 /*            while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
00250                      zend_hash_destroy(*EG(symtable_cache_ptr));
00251                      efree(*EG(symtable_cache_ptr));
00252                      EG(symtable_cache_ptr)--;
00253               }
00254 */
00255               zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC);
00256               zend_hash_graceful_reverse_destroy(&EG(symbol_table));
00257        } zend_end_try();
00258 
00259        zend_try {
00260               zval *zeh;
00261               /* remove error handlers before destroying classes and functions,
00262                * so that if handler used some class, crash would not happen */
00263               if (EG(user_error_handler)) {
00264                      zeh = EG(user_error_handler);
00265                      EG(user_error_handler) = NULL;
00266                      zval_dtor(zeh);
00267                      FREE_ZVAL(zeh);
00268               }
00269 
00270               if (EG(user_exception_handler)) {
00271                      zeh = EG(user_exception_handler);
00272                      EG(user_exception_handler) = NULL;
00273                      zval_dtor(zeh);
00274                      FREE_ZVAL(zeh);
00275               }
00276 
00277               zend_stack_destroy(&EG(user_error_handlers_error_reporting));
00278               zend_stack_init(&EG(user_error_handlers_error_reporting));
00279               zend_ptr_stack_clean(&EG(user_error_handlers), ZVAL_DESTRUCTOR, 1);
00280               zend_ptr_stack_clean(&EG(user_exception_handlers), ZVAL_DESTRUCTOR, 1);
00281        } zend_end_try();
00282 
00283        zend_try {
00284               /* Cleanup static data for functions and arrays.
00285                * We need a separate cleanup stage because of the following problem:
00286                * Suppose we destroy class X, which destroys the class's function table,
00287                * and in the function table we have function foo() that has static $bar.
00288                * Now if an object of class X is assigned to $bar, its destructor will be
00289                * called and will fail since X's function table is in mid-destruction.
00290                * So we want first of all to clean up all data and then move to tables destruction.
00291                * Note that only run-time accessed data need to be cleaned up, pre-defined data can
00292                * not contain objects and thus are not probelmatic */
00293               if (EG(full_tables_cleanup)) {
00294                      zend_hash_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
00295               } else {
00296                      zend_hash_reverse_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data TSRMLS_CC);
00297               }
00298               zend_hash_apply(EG(class_table), (apply_func_t) zend_cleanup_class_data TSRMLS_CC);
00299        } zend_end_try();
00300 
00301        zend_try {
00302               zend_vm_stack_destroy(TSRMLS_C);
00303 
00304               zend_objects_store_free_object_storage(&EG(objects_store) TSRMLS_CC);
00305 
00306               /* Destroy all op arrays */
00307               if (EG(full_tables_cleanup)) {
00308                      zend_hash_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
00309                      zend_hash_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
00310               } else {
00311                      zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function TSRMLS_CC);
00312                      zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class TSRMLS_CC);
00313               }
00314 
00315               while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
00316                      zend_hash_destroy(*EG(symtable_cache_ptr));
00317                      FREE_HASHTABLE(*EG(symtable_cache_ptr));
00318                      EG(symtable_cache_ptr)--;
00319               }
00320        } zend_end_try();
00321 
00322        zend_try {
00323               clean_non_persistent_constants(TSRMLS_C);
00324        } zend_end_try();
00325 
00326        zend_try {
00327 #if 0&&ZEND_DEBUG
00328        signal(SIGSEGV, original_sigsegv_handler);
00329 #endif
00330 
00331               zend_hash_destroy(&EG(included_files));
00332 
00333               zend_ptr_stack_destroy(&EG(arg_types_stack));
00334               zend_stack_destroy(&EG(user_error_handlers_error_reporting));
00335               zend_ptr_stack_destroy(&EG(user_error_handlers));
00336               zend_ptr_stack_destroy(&EG(user_exception_handlers));
00337               zend_objects_store_destroy(&EG(objects_store));
00338               if (EG(in_autoload)) {
00339                      zend_hash_destroy(EG(in_autoload));
00340                      FREE_HASHTABLE(EG(in_autoload));
00341               }
00342        } zend_end_try();
00343 
00344        zend_shutdown_fpu(TSRMLS_C);
00345 
00346        EG(active) = 0;
00347 }
00348 /* }}} */
00349 
00350 /* return class name and "::" or "". */
00351 ZEND_API char *get_active_class_name(char **space TSRMLS_DC) /* {{{ */
00352 {
00353        if (!zend_is_executing(TSRMLS_C)) {
00354               if (space) {
00355                      *space = "";
00356               }
00357               return "";
00358        }
00359        switch (EG(current_execute_data)->function_state.function->type) {
00360               case ZEND_USER_FUNCTION:
00361               case ZEND_INTERNAL_FUNCTION:
00362               {
00363                      zend_class_entry *ce = EG(current_execute_data)->function_state.function->common.scope;
00364 
00365                      if (space) {
00366                             *space = ce ? "::" : "";
00367                      }
00368                      return ce ? ce->name : "";
00369               }
00370               default:
00371                      if (space) {
00372                             *space = "";
00373                      }
00374                      return "";
00375        }
00376 }
00377 /* }}} */
00378 
00379 ZEND_API char *get_active_function_name(TSRMLS_D) /* {{{ */
00380 {
00381        if (!zend_is_executing(TSRMLS_C)) {
00382               return NULL;
00383        }
00384        switch (EG(current_execute_data)->function_state.function->type) {
00385               case ZEND_USER_FUNCTION: {
00386                             char *function_name = ((zend_op_array *) EG(current_execute_data)->function_state.function)->function_name;
00387 
00388                             if (function_name) {
00389                                    return function_name;
00390                             } else {
00391                                    return "main";
00392                             }
00393                      }
00394                      break;
00395               case ZEND_INTERNAL_FUNCTION:
00396                      return ((zend_internal_function *) EG(current_execute_data)->function_state.function)->function_name;
00397                      break;
00398               default:
00399                      return NULL;
00400        }
00401 }
00402 /* }}} */
00403 
00404 ZEND_API char *zend_get_executed_filename(TSRMLS_D) /* {{{ */
00405 {
00406        if (EG(active_op_array)) {
00407               return EG(active_op_array)->filename;
00408        } else {
00409               return "[no active file]";
00410        }
00411 }
00412 /* }}} */
00413 
00414 ZEND_API uint zend_get_executed_lineno(TSRMLS_D) /* {{{ */
00415 {
00416        if(EG(exception) && EG(opline_ptr) && active_opline->opcode == ZEND_HANDLE_EXCEPTION && 
00417               active_opline->lineno == 0 && EG(opline_before_exception)) {
00418               return EG(opline_before_exception)->lineno;
00419        }
00420        if (EG(opline_ptr)) {
00421               return active_opline->lineno;
00422        } else {
00423               return 0;
00424        }
00425 }
00426 /* }}} */
00427 
00428 ZEND_API zend_bool zend_is_executing(TSRMLS_D) /* {{{ */
00429 {
00430        return EG(in_execution);
00431 }
00432 /* }}} */
00433 
00434 ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
00435 {
00436        zval *zv = *zval_ptr;
00437 
00438 #if DEBUG_ZEND>=2
00439        printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, Z_REFCOUNT_PP(zval_ptr), Z_REFCOUNT_PP(zval_ptr) - 1);
00440 #endif
00441        Z_DELREF_P(zv);
00442        if (Z_REFCOUNT_P(zv) == 0) {
00443               TSRMLS_FETCH();
00444 
00445               if (zv != &EG(uninitialized_zval)) {
00446                      GC_REMOVE_ZVAL_FROM_BUFFER(zv);
00447                      zval_dtor(zv);
00448                      efree_rel(zv);
00449               }
00450        } else {
00451               TSRMLS_FETCH();
00452 
00453               if (Z_REFCOUNT_P(zv) == 1) {
00454                      Z_UNSET_ISREF_P(zv);
00455               }
00456 
00457               GC_ZVAL_CHECK_POSSIBLE_ROOT(zv);
00458        }
00459 }
00460 /* }}} */
00461 
00462 ZEND_API void _zval_internal_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
00463 {
00464 #if DEBUG_ZEND>=2
00465        printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, Z_REFCOUNT_PP(zval_ptr), Z_REFCOUNT_PP(zval_ptr) - 1);
00466 #endif
00467        Z_DELREF_PP(zval_ptr);
00468        if (Z_REFCOUNT_PP(zval_ptr) == 0) {
00469               zval_internal_dtor(*zval_ptr);
00470               free(*zval_ptr);
00471        } else if (Z_REFCOUNT_PP(zval_ptr) == 1) {
00472               Z_UNSET_ISREF_PP(zval_ptr);
00473        }
00474 }
00475 /* }}} */
00476 
00477 ZEND_API int zend_is_true(zval *op) /* {{{ */
00478 {
00479        return i_zend_is_true(op);
00480 }
00481 /* }}} */
00482 
00483 #include "../TSRM/tsrm_strtok_r.h"
00484 
00485 #define IS_VISITED_CONSTANT               IS_CONSTANT_INDEX
00486 #define IS_CONSTANT_VISITED(p)            (Z_TYPE_P(p) & IS_VISITED_CONSTANT)
00487 #define Z_REAL_TYPE_P(p)                  (Z_TYPE_P(p) & ~IS_VISITED_CONSTANT)
00488 #define MARK_CONSTANT_VISITED(p)   Z_TYPE_P(p) |= IS_VISITED_CONSTANT
00489 
00490 static void zval_deep_copy(zval **p)
00491 {
00492        zval *value;
00493 
00494        ALLOC_ZVAL(value);
00495        *value = **p;
00496        Z_TYPE_P(value) &= ~IS_CONSTANT_INDEX;
00497        zval_copy_ctor(value);
00498        Z_TYPE_P(value) = Z_TYPE_PP(p);
00499        INIT_PZVAL(value);
00500        *p = value;
00501 }
00502 
00503 ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *scope TSRMLS_DC) /* {{{ */
00504 {
00505        zval *p = *pp;
00506        zend_bool inline_change = (zend_bool) (zend_uintptr_t) arg;
00507        zval const_value;
00508        char *colon;
00509 
00510        if (IS_CONSTANT_VISITED(p)) {
00511               zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
00512        } else if ((Z_TYPE_P(p) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
00513               int refcount;
00514               zend_uchar is_ref;
00515 
00516               SEPARATE_ZVAL_IF_NOT_REF(pp);
00517               p = *pp;
00518 
00519               MARK_CONSTANT_VISITED(p);
00520 
00521               refcount = Z_REFCOUNT_P(p);
00522               is_ref = Z_ISREF_P(p);
00523 
00524               if (!zend_get_constant_ex(p->value.str.val, p->value.str.len, &const_value, scope, Z_REAL_TYPE_P(p) TSRMLS_CC)) {
00525                      char *actual = Z_STRVAL_P(p);
00526 
00527                      if ((colon = zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
00528                             zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
00529                             Z_STRLEN_P(p) -= ((colon - Z_STRVAL_P(p)) + 1);
00530                             if (inline_change) {
00531                                    colon = estrndup(colon, Z_STRLEN_P(p));
00532                                    efree(Z_STRVAL_P(p));
00533                                    Z_STRVAL_P(p) = colon;
00534                             } else {
00535                                    Z_STRVAL_P(p) = colon + 1;
00536                             }
00537                      } else {
00538                             char *save = actual, *slash;
00539                             int actual_len = Z_STRLEN_P(p);
00540                             if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char *)zend_memrchr(actual, '\\', actual_len))) {
00541                                    actual = slash + 1;
00542                                    actual_len -= (actual - Z_STRVAL_P(p));
00543                                    if (inline_change) {
00544                                           actual = estrndup(actual, actual_len);
00545                                           Z_STRVAL_P(p) = actual;
00546                                           Z_STRLEN_P(p) = actual_len;
00547                                    }
00548                             }
00549                             if (actual[0] == '\\') {
00550                                    if (inline_change) {
00551                                           memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p));
00552                                           --Z_STRLEN_P(p);
00553                                    } else {
00554                                           ++actual;
00555                                    }
00556                                    --actual_len;
00557                             }
00558                             if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
00559                                    int fix_save = 0;
00560                                    if (save[0] == '\\') {
00561                                           save++;
00562                                           fix_save = 1;
00563                                    }
00564                                    zend_error(E_ERROR, "Undefined constant '%s'", save);
00565                                    if (fix_save) {
00566                                           save--;
00567                                    }
00568                                    if (inline_change) {
00569                                           efree(save);
00570                                    }
00571                                    save = NULL;
00572                             }
00573                             if (inline_change && save && save != actual) {
00574                                    efree(save);
00575                             }
00576                             zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",  actual,  actual);
00577                             p->type = IS_STRING;
00578                             if (!inline_change) {
00579                                    Z_STRVAL_P(p) = actual;
00580                                    Z_STRLEN_P(p) = actual_len;
00581                                    zval_copy_ctor(p);
00582                             }
00583                      }
00584               } else {
00585                      if (inline_change) {
00586                             STR_FREE(Z_STRVAL_P(p));
00587                      }
00588                      *p = const_value;
00589               }
00590 
00591               Z_SET_REFCOUNT_P(p, refcount);
00592               Z_SET_ISREF_TO_P(p, is_ref);
00593        } else if (Z_TYPE_P(p) == IS_CONSTANT_ARRAY) {
00594               zval **element, *new_val;
00595               char *str_index;
00596               uint str_index_len;
00597               ulong num_index;
00598               int ret;
00599 
00600               SEPARATE_ZVAL_IF_NOT_REF(pp);
00601               p = *pp;
00602               Z_TYPE_P(p) = IS_ARRAY;
00603 
00604               if (!inline_change) {
00605                      zval *tmp;
00606                      HashTable *tmp_ht = NULL;
00607 
00608                      ALLOC_HASHTABLE(tmp_ht);
00609                      zend_hash_init(tmp_ht, zend_hash_num_elements(Z_ARRVAL_P(p)), NULL, ZVAL_PTR_DTOR, 0);
00610                      zend_hash_copy(tmp_ht, Z_ARRVAL_P(p), (copy_ctor_func_t) zval_deep_copy, (void *) &tmp, sizeof(zval *));
00611                      Z_ARRVAL_P(p) = tmp_ht;
00612               } 
00613 
00614               /* First go over the array and see if there are any constant indices */
00615               zend_hash_internal_pointer_reset(Z_ARRVAL_P(p));
00616               while (zend_hash_get_current_data(Z_ARRVAL_P(p), (void **) &element) == SUCCESS) {
00617                      if (!(Z_TYPE_PP(element) & IS_CONSTANT_INDEX)) {
00618                             zend_hash_move_forward(Z_ARRVAL_P(p));
00619                             continue;
00620                      }
00621                      Z_TYPE_PP(element) &= ~IS_CONSTANT_INDEX;
00622                      if (zend_hash_get_current_key_ex(Z_ARRVAL_P(p), &str_index, &str_index_len, &num_index, 0, NULL) != HASH_KEY_IS_STRING) {
00623                             zend_hash_move_forward(Z_ARRVAL_P(p));
00624                             continue;
00625                      }
00626                      if (!zend_get_constant_ex(str_index, str_index_len - 3, &const_value, scope, str_index[str_index_len - 2] TSRMLS_CC)) {
00627                             char *actual, *save = str_index;
00628                             if ((colon = zend_memrchr(str_index, ':', str_index_len - 3))) {
00629                                    zend_error(E_ERROR, "Undefined class constant '%s'", str_index);
00630                                    str_index_len -= ((colon - str_index) + 1);
00631                                    str_index = colon;
00632                             } else {
00633                                    if (str_index[str_index_len - 2] & IS_CONSTANT_UNQUALIFIED) {
00634                                           if ((actual = (char *)zend_memrchr(str_index, '\\', str_index_len - 3))) {
00635                                                  actual++;
00636                                                  str_index_len -= (actual - str_index);
00637                                                  str_index = actual;
00638                                           }
00639                                    }
00640                                    if (str_index[0] == '\\') {
00641                                           ++str_index;
00642                                           --str_index_len;
00643                                    }
00644                                    if (save[0] == '\\') {
00645                                           ++save;
00646                                    }
00647                                    if ((str_index[str_index_len - 2] & IS_CONSTANT_UNQUALIFIED) == 0) {
00648                                           zend_error(E_ERROR, "Undefined constant '%s'", save);
00649                                    }
00650                                    zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",   str_index, str_index);
00651                             }
00652                             ZVAL_STRINGL(&const_value, str_index, str_index_len-3, 1);
00653                      }
00654 
00655                      if (Z_REFCOUNT_PP(element) > 1) {
00656                             ALLOC_ZVAL(new_val);
00657                             *new_val = **element;
00658                             zval_copy_ctor(new_val);
00659                             Z_SET_REFCOUNT_P(new_val, 1);
00660                             Z_UNSET_ISREF_P(new_val);
00661 
00662                             /* preserve this bit for inheritance */
00663                             Z_TYPE_PP(element) |= IS_CONSTANT_INDEX;
00664                             zval_ptr_dtor(element);
00665                             *element = new_val;
00666                      }
00667 
00668                      switch (Z_TYPE(const_value)) {
00669                             case IS_STRING:
00670                                    ret = zend_symtable_update_current_key(Z_ARRVAL_P(p), Z_STRVAL(const_value), Z_STRLEN(const_value) + 1, HASH_UPDATE_KEY_IF_BEFORE);
00671                                    break;
00672                             case IS_BOOL:
00673                             case IS_LONG:
00674                                    ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, Z_LVAL(const_value), HASH_UPDATE_KEY_IF_BEFORE, NULL);
00675                                    break;
00676                             case IS_DOUBLE:
00677                                    ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, zend_dval_to_lval(Z_DVAL(const_value)), HASH_UPDATE_KEY_IF_BEFORE, NULL);
00678                                    break;
00679                             case IS_NULL:
00680                                    ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_STRING, "", 1, 0, HASH_UPDATE_KEY_IF_BEFORE, NULL);
00681                                    break;
00682                             default:
00683                                    ret = SUCCESS;
00684                                    break;
00685                      }
00686                      if (ret == SUCCESS) {
00687                             zend_hash_move_forward(Z_ARRVAL_P(p));
00688                      }
00689                      zval_dtor(&const_value);
00690               }
00691               zend_hash_apply_with_argument(Z_ARRVAL_P(p), (apply_func_arg_t) zval_update_constant_inline_change, (void *) scope TSRMLS_CC);
00692               zend_hash_internal_pointer_reset(Z_ARRVAL_P(p));
00693        }
00694        return 0;
00695 }
00696 /* }}} */
00697 
00698 ZEND_API int zval_update_constant_inline_change(zval **pp, void *scope TSRMLS_DC) /* {{{ */
00699 {
00700        return zval_update_constant_ex(pp, (void*)1, scope TSRMLS_CC);
00701 }
00702 /* }}} */
00703 
00704 ZEND_API int zval_update_constant_no_inline_change(zval **pp, void *scope TSRMLS_DC) /* {{{ */
00705 {
00706        return zval_update_constant_ex(pp, (void*)0, scope TSRMLS_CC);
00707 }
00708 /* }}} */
00709 
00710 ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC) /* {{{ */
00711 {
00712        return zval_update_constant_ex(pp, arg, NULL TSRMLS_CC);
00713 }
00714 /* }}} */
00715 
00716 int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC) /* {{{ */
00717 {
00718        zval ***params_array;
00719        zend_uint i;
00720        int ex_retval;
00721        zval *local_retval_ptr = NULL;
00722 
00723        if (param_count) {
00724               params_array = (zval ***) emalloc(sizeof(zval **)*param_count);
00725               for (i=0; i<param_count; i++) {
00726                      params_array[i] = &params[i];
00727               }
00728        } else {
00729               params_array = NULL;
00730        }
00731        ex_retval = call_user_function_ex(function_table, object_pp, function_name, &local_retval_ptr, param_count, params_array, 1, NULL TSRMLS_CC);
00732        if (local_retval_ptr) {
00733               COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
00734        } else {
00735               INIT_ZVAL(*retval_ptr);
00736        }
00737        if (params_array) {
00738               efree(params_array);
00739        }
00740        return ex_retval;
00741 }
00742 /* }}} */
00743 
00744 int call_user_function_ex(HashTable *function_table, zval **object_pp, zval *function_name, zval **retval_ptr_ptr, zend_uint param_count, zval **params[], int no_separation, HashTable *symbol_table TSRMLS_DC) /* {{{ */
00745 {
00746        zend_fcall_info fci;
00747 
00748        fci.size = sizeof(fci);
00749        fci.function_table = function_table;
00750        fci.object_ptr = object_pp ? *object_pp : NULL;
00751        fci.function_name = function_name;
00752        fci.retval_ptr_ptr = retval_ptr_ptr;
00753        fci.param_count = param_count;
00754        fci.params = params;
00755        fci.no_separation = (zend_bool) no_separation;
00756        fci.symbol_table = symbol_table;
00757 
00758        return zend_call_function(&fci, NULL TSRMLS_CC);
00759 }
00760 /* }}} */
00761 
00762 int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) /* {{{ */
00763 {
00764        zend_uint i;
00765        zval **original_return_value;
00766        HashTable *calling_symbol_table;
00767        zend_op_array *original_op_array;
00768        zend_op **original_opline_ptr;
00769        zend_class_entry *current_scope;
00770        zend_class_entry *current_called_scope;
00771        zend_class_entry *calling_scope = NULL;
00772        zend_class_entry *called_scope = NULL;
00773        zval *current_this;
00774        zend_execute_data execute_data;
00775 
00776        *fci->retval_ptr_ptr = NULL;
00777 
00778        if (!EG(active)) {
00779               return FAILURE; /* executor is already inactive */
00780        }
00781 
00782        if (EG(exception)) {
00783               return FAILURE; /* we would result in an instable executor otherwise */
00784        }
00785 
00786        switch (fci->size) {
00787               case sizeof(zend_fcall_info):
00788                      break; /* nothing to do currently */
00789               default:
00790                      zend_error(E_ERROR, "Corrupted fcall_info provided to zend_call_function()");
00791                      break;
00792        }
00793 
00794        /* Initialize execute_data */
00795        if (EG(current_execute_data)) {
00796               execute_data = *EG(current_execute_data);
00797               EX(op_array) = NULL;
00798               EX(opline) = NULL;
00799               EX(object) = NULL;
00800        } else {
00801               /* This only happens when we're called outside any execute()'s
00802                * It shouldn't be strictly necessary to NULL execute_data out,
00803                * but it may make bugs easier to spot
00804                */
00805               memset(&execute_data, 0, sizeof(zend_execute_data));
00806        }
00807 
00808        if (!fci_cache || !fci_cache->initialized) {
00809               zend_fcall_info_cache fci_cache_local;
00810               char *callable_name;
00811               char *error = NULL;
00812 
00813               if (!fci_cache) {
00814                      fci_cache = &fci_cache_local;
00815               }
00816 
00817               if (!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC)) {
00818                      if (error) {
00819                             zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
00820                             efree(error);
00821                      }
00822                      if (callable_name) {
00823                             efree(callable_name);
00824                      }
00825                      return FAILURE;
00826               } else if (error) {
00827                      /* Capitalize the first latter of the error message */
00828                      if (error[0] >= 'a' && error[0] <= 'z') {
00829                             error[0] += ('A' - 'a');
00830                      }
00831                      zend_error(E_STRICT, "%s", error);
00832                      efree(error);
00833               }
00834               efree(callable_name);
00835        }
00836 
00837        EX(function_state).function = fci_cache->function_handler;
00838        calling_scope = fci_cache->calling_scope;
00839        called_scope = fci_cache->called_scope;
00840        fci->object_ptr = fci_cache->object_ptr;
00841        EX(object) = fci->object_ptr;
00842        if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
00843            (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
00844               return FAILURE;
00845        }
00846 
00847        if (EX(function_state).function->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
00848               if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
00849                      zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", EX(function_state).function->common.scope->name, EX(function_state).function->common.function_name);
00850               }
00851               if (EX(function_state).function->common.fn_flags & ZEND_ACC_DEPRECATED) {
00852                      zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
00853                             EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
00854                             EX(function_state).function->common.scope ? "::" : "",
00855                             EX(function_state).function->common.function_name);
00856               }
00857        }
00858 
00859        ZEND_VM_STACK_GROW_IF_NEEDED(fci->param_count + 1);
00860 
00861        for (i=0; i<fci->param_count; i++) {
00862               zval *param;
00863 
00864               if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION 
00865                      && (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 
00866                      && !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
00867                      && PZVAL_IS_REF(*fci->params[i])) {
00868                      ALLOC_ZVAL(param);
00869                      *param = **(fci->params[i]);
00870                      INIT_PZVAL(param);
00871                      zval_copy_ctor(param);
00872               } else if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
00873                      && !PZVAL_IS_REF(*fci->params[i])) {
00874 
00875                      if (Z_REFCOUNT_PP(fci->params[i]) > 1) {
00876                             zval *new_zval;
00877 
00878                             if (fci->no_separation &&
00879                                 !ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
00880                                    if(i) {
00881                                           /* hack to clean up the stack */
00882                                           zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
00883                                           zend_vm_stack_clear_multiple(TSRMLS_C);
00884                                    }
00885 
00886                                    zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
00887                                           i+1,
00888                                           EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
00889                                           EX(function_state).function->common.scope ? "::" : "",
00890                                           EX(function_state).function->common.function_name);
00891                                    return FAILURE;
00892                             }
00893 
00894                             ALLOC_ZVAL(new_zval);
00895                             *new_zval = **fci->params[i];
00896                             zval_copy_ctor(new_zval);
00897                             Z_SET_REFCOUNT_P(new_zval, 1);
00898                             Z_DELREF_PP(fci->params[i]);
00899                             *fci->params[i] = new_zval;
00900                      }
00901                      Z_ADDREF_PP(fci->params[i]);
00902                      Z_SET_ISREF_PP(fci->params[i]);
00903                      param = *fci->params[i];
00904               } else if (*fci->params[i] != &EG(uninitialized_zval)) {
00905                      Z_ADDREF_PP(fci->params[i]);
00906                      param = *fci->params[i];
00907               } else {
00908                      ALLOC_ZVAL(param);
00909                      *param = **(fci->params[i]);
00910                      INIT_PZVAL(param);
00911               }
00912               zend_vm_stack_push_nocheck(param TSRMLS_CC);
00913        }
00914 
00915        EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C);
00916        zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
00917 
00918        current_scope = EG(scope);
00919        EG(scope) = calling_scope;
00920 
00921        current_this = EG(This);
00922 
00923        current_called_scope = EG(called_scope);
00924        if (called_scope) {
00925               EG(called_scope) = called_scope;
00926        } else if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
00927               EG(called_scope) = NULL;
00928        }
00929 
00930        if (fci->object_ptr) {
00931               if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
00932                      EG(This) = NULL;
00933               } else {
00934                      EG(This) = fci->object_ptr;
00935 
00936                      if (!PZVAL_IS_REF(EG(This))) {
00937                             Z_ADDREF_P(EG(This)); /* For $this pointer */
00938                      } else {
00939                             zval *this_ptr;
00940 
00941                             ALLOC_ZVAL(this_ptr);
00942                             *this_ptr = *EG(This);
00943                             INIT_PZVAL(this_ptr);
00944                             zval_copy_ctor(this_ptr);
00945                             EG(This) = this_ptr;
00946                      }
00947               }
00948        } else {
00949               EG(This) = NULL;
00950        }
00951 
00952        EX(prev_execute_data) = EG(current_execute_data);
00953        EG(current_execute_data) = &execute_data;
00954 
00955        if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
00956               calling_symbol_table = EG(active_symbol_table);
00957               EG(scope) = EX(function_state).function->common.scope;
00958               if (fci->symbol_table) {
00959                      EG(active_symbol_table) = fci->symbol_table;
00960               } else {
00961                      EG(active_symbol_table) = NULL;
00962               }
00963 
00964               original_return_value = EG(return_value_ptr_ptr);
00965               original_op_array = EG(active_op_array);
00966               EG(return_value_ptr_ptr) = fci->retval_ptr_ptr;
00967               EG(active_op_array) = (zend_op_array *) EX(function_state).function;
00968               original_opline_ptr = EG(opline_ptr);
00969               zend_execute(EG(active_op_array) TSRMLS_CC);
00970               if (!fci->symbol_table && EG(active_symbol_table)) {
00971                      if (EG(symtable_cache_ptr)>=EG(symtable_cache_limit)) {
00972                             zend_hash_destroy(EG(active_symbol_table));
00973                             FREE_HASHTABLE(EG(active_symbol_table));
00974                      } else {
00975                             /* clean before putting into the cache, since clean
00976                                could call dtors, which could use cached hash */
00977                             zend_hash_clean(EG(active_symbol_table));
00978                             *(++EG(symtable_cache_ptr)) = EG(active_symbol_table);
00979                      }
00980               }
00981               EG(active_symbol_table) = calling_symbol_table;
00982               EG(active_op_array) = original_op_array;
00983               EG(return_value_ptr_ptr)=original_return_value;
00984               EG(opline_ptr) = original_opline_ptr;
00985        } else if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
00986               int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
00987               ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
00988               if (EX(function_state).function->common.scope) {
00989                      EG(scope) = EX(function_state).function->common.scope;
00990               }
00991               ((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
00992               /*  We shouldn't fix bad extensions here,
00993                      because it can break proper ones (Bug #34045)
00994               if (!EX(function_state).function->common.return_reference)
00995               {
00996                      INIT_PZVAL(*fci->retval_ptr_ptr);
00997               }*/
00998               if (EG(exception) && fci->retval_ptr_ptr) {
00999                      zval_ptr_dtor(fci->retval_ptr_ptr);
01000                      *fci->retval_ptr_ptr = NULL;
01001               }
01002 
01003               if (call_via_handler) {
01004                      /* We must re-initialize function again */
01005                      fci_cache->initialized = 0;
01006               }
01007        } else { /* ZEND_OVERLOADED_FUNCTION */
01008               ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
01009 
01010               /* Not sure what should be done here if it's a static method */
01011               if (fci->object_ptr) {
01012                      Z_OBJ_HT_P(fci->object_ptr)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
01013               } else {
01014                      zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
01015               }
01016 
01017               if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
01018                      efree(EX(function_state).function->common.function_name);
01019               }
01020               efree(EX(function_state).function);
01021 
01022               if (EG(exception) && fci->retval_ptr_ptr) {
01023                      zval_ptr_dtor(fci->retval_ptr_ptr);
01024                      *fci->retval_ptr_ptr = NULL;
01025               }
01026        }
01027        zend_vm_stack_clear_multiple(TSRMLS_C);
01028 
01029        if (EG(This)) {
01030               zval_ptr_dtor(&EG(This));
01031        }
01032        EG(called_scope) = current_called_scope;
01033        EG(scope) = current_scope;
01034        EG(This) = current_this;
01035        EG(current_execute_data) = EX(prev_execute_data);
01036 
01037        if (EG(exception)) {
01038               zend_throw_exception_internal(NULL TSRMLS_CC);
01039        }
01040        return SUCCESS;
01041 }
01042 /* }}} */
01043 
01044 ZEND_API int zend_lookup_class_ex(const char *name, int name_length, int use_autoload, zend_class_entry ***ce TSRMLS_DC) /* {{{ */
01045 {
01046        zval **args[1];
01047        zval autoload_function;
01048        zval *class_name_ptr;
01049        zval *retval_ptr = NULL;
01050        int retval, lc_length;
01051        char *lc_name;
01052        char *lc_free;
01053        zend_fcall_info fcall_info;
01054        zend_fcall_info_cache fcall_cache;
01055        char dummy = 1;
01056        ulong hash;
01057        ALLOCA_FLAG(use_heap)
01058 
01059        if (name == NULL || !name_length) {
01060               return FAILURE;
01061        }
01062 
01063        lc_free = lc_name = do_alloca(name_length + 1, use_heap);
01064        zend_str_tolower_copy(lc_name, name, name_length);
01065        lc_length = name_length + 1;
01066 
01067        if (lc_name[0] == '\\') {
01068               lc_name += 1;
01069               lc_length -= 1;
01070        }
01071 
01072        hash = zend_inline_hash_func(lc_name, lc_length);
01073 
01074        if (zend_hash_quick_find(EG(class_table), lc_name, lc_length, hash, (void **) ce) == SUCCESS) {
01075               free_alloca(lc_free, use_heap);
01076               return SUCCESS;
01077        }
01078 
01079        /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
01080         * (doesn't impact fuctionality of __autoload()
01081        */
01082        if (!use_autoload || zend_is_compiling(TSRMLS_C)) {
01083               free_alloca(lc_free, use_heap);
01084               return FAILURE;
01085        }
01086 
01087        if (EG(in_autoload) == NULL) {
01088               ALLOC_HASHTABLE(EG(in_autoload));
01089               zend_hash_init(EG(in_autoload), 0, NULL, NULL, 0);
01090        }
01091 
01092        if (zend_hash_quick_add(EG(in_autoload), lc_name, lc_length, hash, (void**)&dummy, sizeof(char), NULL) == FAILURE) {
01093               free_alloca(lc_free, use_heap);
01094               return FAILURE;
01095        }
01096 
01097        ZVAL_STRINGL(&autoload_function, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1, 0);
01098 
01099        ALLOC_ZVAL(class_name_ptr);
01100        INIT_PZVAL(class_name_ptr);
01101        if (name[0] == '\\') {
01102               ZVAL_STRINGL(class_name_ptr, name+1, name_length-1, 1);
01103        } else {
01104               ZVAL_STRINGL(class_name_ptr, name, name_length, 1);
01105        }
01106 
01107        args[0] = &class_name_ptr;
01108 
01109        fcall_info.size = sizeof(fcall_info);
01110        fcall_info.function_table = EG(function_table);
01111        fcall_info.function_name = &autoload_function;
01112        fcall_info.symbol_table = NULL;
01113        fcall_info.retval_ptr_ptr = &retval_ptr;
01114        fcall_info.param_count = 1;
01115        fcall_info.params = args;
01116        fcall_info.object_ptr = NULL;
01117        fcall_info.no_separation = 1;
01118 
01119        fcall_cache.initialized = EG(autoload_func) ? 1 : 0;
01120        fcall_cache.function_handler = EG(autoload_func);
01121        fcall_cache.calling_scope = NULL;
01122        fcall_cache.called_scope = NULL;
01123        fcall_cache.object_ptr = NULL;
01124 
01125        zend_exception_save(TSRMLS_C);
01126        retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC);
01127        zend_exception_restore(TSRMLS_C);
01128 
01129        EG(autoload_func) = fcall_cache.function_handler;
01130 
01131        zval_ptr_dtor(&class_name_ptr);
01132 
01133        zend_hash_quick_del(EG(in_autoload), lc_name, lc_length, hash);
01134 
01135        if (retval_ptr) {
01136               zval_ptr_dtor(&retval_ptr);
01137        }
01138 
01139        if (retval == FAILURE) {
01140               free_alloca(lc_free, use_heap);
01141               return FAILURE;
01142        }
01143 
01144        retval = zend_hash_quick_find(EG(class_table), lc_name, lc_length, hash, (void **) ce);
01145        free_alloca(lc_free, use_heap);
01146        return retval;
01147 }
01148 /* }}} */
01149 
01150 ZEND_API int zend_lookup_class(const char *name, int name_length, zend_class_entry ***ce TSRMLS_DC) /* {{{ */
01151 {
01152        return zend_lookup_class_ex(name, name_length, 1, ce TSRMLS_CC);
01153 }
01154 /* }}} */
01155 
01156 ZEND_API int zend_eval_stringl(char *str, int str_len, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
01157 {
01158        zval pv;
01159        zend_op_array *new_op_array;
01160        zend_op_array *original_active_op_array = EG(active_op_array);
01161        zend_uint original_compiler_options;
01162        int retval;
01163 
01164        if (retval_ptr) {
01165               Z_STRLEN(pv) = str_len + sizeof("return ;") - 1;
01166               Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1);
01167               memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
01168               memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
01169               Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
01170               Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
01171        } else {
01172               Z_STRLEN(pv) = str_len;
01173               Z_STRVAL(pv) = str;
01174        }
01175        Z_TYPE(pv) = IS_STRING;
01176 
01177        /*printf("Evaluating '%s'\n", pv.value.str.val);*/
01178 
01179        original_compiler_options = CG(compiler_options);
01180        CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
01181        new_op_array = zend_compile_string(&pv, string_name TSRMLS_CC);
01182        CG(compiler_options) = original_compiler_options;
01183 
01184        if (new_op_array) {
01185               zval *local_retval_ptr=NULL;
01186               zval **original_return_value_ptr_ptr = EG(return_value_ptr_ptr);
01187               zend_op **original_opline_ptr = EG(opline_ptr);
01188               int orig_interactive = CG(interactive);
01189 
01190               EG(return_value_ptr_ptr) = &local_retval_ptr;
01191               EG(active_op_array) = new_op_array;
01192               EG(no_extensions)=1;
01193               if (!EG(active_symbol_table)) {
01194                      zend_rebuild_symbol_table(TSRMLS_C);
01195               }
01196               CG(interactive) = 0;
01197 
01198               zend_execute(new_op_array TSRMLS_CC);
01199 
01200               CG(interactive) = orig_interactive;
01201               if (local_retval_ptr) {
01202                      if (retval_ptr) {
01203                             COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
01204                      } else {
01205                             zval_ptr_dtor(&local_retval_ptr);
01206                      }
01207               } else {
01208                      if (retval_ptr) {
01209                             INIT_ZVAL(*retval_ptr);
01210                      }
01211               }
01212 
01213               EG(no_extensions)=0;
01214               EG(opline_ptr) = original_opline_ptr;
01215               EG(active_op_array) = original_active_op_array;
01216               destroy_op_array(new_op_array TSRMLS_CC);
01217               efree(new_op_array);
01218               EG(return_value_ptr_ptr) = original_return_value_ptr_ptr;
01219               retval = SUCCESS;
01220        } else {
01221               retval = FAILURE;
01222        }
01223        if (retval_ptr) {
01224               zval_dtor(&pv);
01225        }
01226        return retval;
01227 }
01228 /* }}} */
01229 
01230 ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
01231 {
01232        return zend_eval_stringl(str, strlen(str), retval_ptr, string_name TSRMLS_CC);
01233 }
01234 /* }}} */
01235 
01236 ZEND_API int zend_eval_stringl_ex(char *str, int str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
01237 {
01238        int result;
01239 
01240        result = zend_eval_stringl(str, str_len, retval_ptr, string_name TSRMLS_CC);
01241        if (handle_exceptions && EG(exception)) {
01242               zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
01243               result = FAILURE;
01244        }
01245        return result;
01246 }
01247 /* }}} */
01248 
01249 ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
01250 {
01251        return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions TSRMLS_CC);
01252 }
01253 /* }}} */
01254 
01255 void execute_new_code(TSRMLS_D) /* {{{ */
01256 {
01257        zend_op *opline, *end;
01258        zend_op *ret_opline;
01259        int orig_interactive;
01260 
01261        if (!(CG(active_op_array)->fn_flags & ZEND_ACC_INTERACTIVE)
01262               || CG(active_op_array)->backpatch_count>0
01263               || CG(active_op_array)->function_name
01264               || CG(active_op_array)->type!=ZEND_USER_FUNCTION) {
01265               return;
01266        }
01267 
01268        ret_opline = get_next_op(CG(active_op_array) TSRMLS_CC);
01269        ret_opline->opcode = ZEND_RETURN;
01270        ret_opline->op1.op_type = IS_CONST;
01271        INIT_ZVAL(ret_opline->op1.u.constant);
01272        SET_UNUSED(ret_opline->op2);
01273 
01274        if (!CG(active_op_array)->start_op) {
01275               CG(active_op_array)->start_op = CG(active_op_array)->opcodes;
01276        }
01277 
01278        opline=CG(active_op_array)->start_op;
01279        end=CG(active_op_array)->opcodes+CG(active_op_array)->last;
01280 
01281        while (opline<end) {
01282               if (opline->op1.op_type == IS_CONST) {
01283                      Z_SET_ISREF(opline->op1.u.constant);
01284                      Z_SET_REFCOUNT(opline->op1.u.constant, 2); /* Make sure is_ref won't be reset */
01285               }
01286               if (opline->op2.op_type == IS_CONST) {
01287                      Z_SET_ISREF(opline->op2.u.constant);
01288                      Z_SET_REFCOUNT(opline->op2.u.constant, 2);
01289               }
01290               switch (opline->opcode) {
01291                      case ZEND_GOTO:
01292                             if (Z_TYPE(opline->op2.u.constant) != IS_LONG) {
01293                                    zend_resolve_goto_label(CG(active_op_array), opline, 1 TSRMLS_CC);
01294                             }
01295                             /* break omitted intentionally */
01296                      case ZEND_JMP:
01297                             opline->op1.u.jmp_addr = &CG(active_op_array)->opcodes[opline->op1.u.opline_num];
01298                             break;
01299                      case ZEND_JMPZ:
01300                      case ZEND_JMPNZ:
01301                      case ZEND_JMPZ_EX:
01302                      case ZEND_JMPNZ_EX:
01303                      case ZEND_JMP_SET:
01304                             opline->op2.u.jmp_addr = &CG(active_op_array)->opcodes[opline->op2.u.opline_num];
01305                             break;
01306               }
01307               ZEND_VM_SET_OPCODE_HANDLER(opline);
01308               opline++;
01309        }
01310        
01311        zend_release_labels(TSRMLS_C);
01312        
01313        EG(return_value_ptr_ptr) = NULL;
01314        EG(active_op_array) = CG(active_op_array);
01315        orig_interactive = CG(interactive);
01316        CG(interactive) = 0;
01317        zend_execute(CG(active_op_array) TSRMLS_CC);
01318        CG(interactive) = orig_interactive;
01319 
01320        if (EG(exception)) {
01321               zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
01322        }
01323 
01324        CG(active_op_array)->last -= 1;    /* get rid of that ZEND_RETURN */
01325        CG(active_op_array)->start_op = CG(active_op_array)->opcodes+CG(active_op_array)->last;
01326 }
01327 /* }}} */
01328 
01329 ZEND_API void zend_timeout(int dummy) /* {{{ */
01330 {
01331        TSRMLS_FETCH();
01332 
01333        if (zend_on_timeout) {
01334               zend_on_timeout(EG(timeout_seconds) TSRMLS_CC);
01335        }
01336 
01337        zend_error(E_ERROR, "Maximum execution time of %d second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
01338 }
01339 /* }}} */
01340 
01341 #ifdef ZEND_WIN32
01342 static LRESULT CALLBACK zend_timeout_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) /* {{{ */
01343 {
01344        switch (message) {
01345               case WM_DESTROY:
01346                      PostQuitMessage(0);
01347                      break;
01348               case WM_REGISTER_ZEND_TIMEOUT:
01349                      /* wParam is the thread id pointer, lParam is the timeout amount in seconds */
01350                      if (lParam == 0) {
01351                             KillTimer(timeout_window, wParam);
01352                      } else {
01353 #ifdef ZTS
01354                             void ***tsrm_ls;
01355 #endif
01356                             SetTimer(timeout_window, wParam, lParam*1000, NULL);
01357 #ifdef ZTS
01358                             tsrm_ls = ts_resource_ex(0, &wParam);
01359                             if (!tsrm_ls) {
01360                                    /* shouldn't normally happen */
01361                                    break;
01362                             }
01363 #endif
01364                             EG(timed_out) = 0;
01365                      }
01366                      break;
01367               case WM_UNREGISTER_ZEND_TIMEOUT:
01368                      /* wParam is the thread id pointer */
01369                      KillTimer(timeout_window, wParam);
01370                      break;
01371               case WM_TIMER: {
01372 #ifdef ZTS
01373                             void ***tsrm_ls;
01374 
01375                             tsrm_ls = ts_resource_ex(0, &wParam);
01376                             if (!tsrm_ls) {
01377                                    /* Thread died before receiving its timeout? */
01378                                    break;
01379                             }
01380 #endif
01381                             KillTimer(timeout_window, wParam);
01382                             EG(timed_out) = 1;
01383                      }
01384                      break;
01385               default:
01386                      return DefWindowProc(hWnd, message, wParam, lParam);
01387        }
01388        return 0;
01389 }
01390 /* }}} */
01391 
01392 static unsigned __stdcall timeout_thread_proc(void *pArgs) /* {{{ */
01393 {
01394        MSG message;
01395 
01396        wc.style=0;
01397        wc.lpfnWndProc = zend_timeout_WndProc;
01398        wc.cbClsExtra=0;
01399        wc.cbWndExtra=0;
01400        wc.hInstance=NULL;
01401        wc.hIcon=NULL;
01402        wc.hCursor=NULL;
01403        wc.hbrBackground=(HBRUSH)(COLOR_BACKGROUND + 5);
01404        wc.lpszMenuName=NULL;
01405        wc.lpszClassName = "Zend Timeout Window";
01406        if (!RegisterClass(&wc)) {
01407               return -1;
01408        }
01409        timeout_window = CreateWindow(wc.lpszClassName, wc.lpszClassName, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
01410        SetEvent(timeout_thread_event);
01411        while (GetMessage(&message, NULL, 0, 0)) {
01412               SendMessage(timeout_window, message.message, message.wParam, message.lParam);
01413               if (message.message == WM_QUIT) {
01414                      break;
01415               }
01416        }
01417        DestroyWindow(timeout_window);
01418        UnregisterClass(wc.lpszClassName, NULL);
01419        SetEvent(timeout_thread_handle);
01420        return 0;
01421 }
01422 /* }}} */
01423 
01424 void zend_init_timeout_thread(void) /* {{{ */
01425 {
01426        timeout_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
01427        timeout_thread_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
01428        _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id);
01429        WaitForSingleObject(timeout_thread_event, INFINITE);
01430 }
01431 /* }}} */
01432 
01433 void zend_shutdown_timeout_thread(void) /* {{{ */
01434 {
01435        if (!timeout_thread_initialized) {
01436               return;
01437        }
01438        PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0);
01439 
01440        /* Wait for thread termination */
01441        WaitForSingleObject(timeout_thread_handle, 5000);
01442        CloseHandle(timeout_thread_handle);
01443        timeout_thread_initialized = 0;
01444 }
01445 /* }}} */
01446 
01447 #endif
01448 
01449 /* This one doesn't exists on QNX */
01450 #ifndef SIGPROF
01451 #define SIGPROF 27
01452 #endif
01453 
01454 void zend_set_timeout(long seconds, int reset_signals) /* {{{ */
01455 {
01456        TSRMLS_FETCH();
01457 
01458        EG(timeout_seconds) = seconds;
01459 
01460 #ifdef ZEND_WIN32
01461        if(!seconds) {
01462               return;
01463        }
01464        if (timeout_thread_initialized == 0 && InterlockedIncrement(&timeout_thread_initialized) == 1) {
01465               /* We start up this process-wide thread here and not in zend_startup(), because if Zend
01466                * is initialized inside a DllMain(), you're not supposed to start threads from it.
01467                */
01468               zend_init_timeout_thread();
01469        }
01470        PostThreadMessage(timeout_thread_id, WM_REGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) seconds);
01471 #else
01472 #      ifdef HAVE_SETITIMER
01473        {
01474               struct itimerval t_r;              /* timeout requested */
01475               sigset_t sigset;
01476 
01477               if(seconds) {
01478                      t_r.it_value.tv_sec = seconds;
01479                      t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
01480 
01481 #      ifdef __CYGWIN__
01482                      setitimer(ITIMER_REAL, &t_r, NULL);
01483               }
01484               if(reset_signals) {
01485                      signal(SIGALRM, zend_timeout);
01486                      sigemptyset(&sigset);
01487                      sigaddset(&sigset, SIGALRM);
01488               }
01489 #      else
01490                      setitimer(ITIMER_PROF, &t_r, NULL);
01491               }
01492               if(reset_signals) {
01493                      signal(SIGPROF, zend_timeout);
01494                      sigemptyset(&sigset);
01495                      sigaddset(&sigset, SIGPROF);
01496               }
01497 #      endif
01498               if(reset_signals) {
01499                      sigprocmask(SIG_UNBLOCK, &sigset, NULL);
01500               }
01501        }
01502 #      endif
01503 #endif
01504 }
01505 /* }}} */
01506 
01507 void zend_unset_timeout(TSRMLS_D) /* {{{ */
01508 {
01509 #ifdef ZEND_WIN32
01510        if(timeout_thread_initialized) {
01511               PostThreadMessage(timeout_thread_id, WM_UNREGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) 0);
01512        }
01513 #else
01514 #      ifdef HAVE_SETITIMER
01515        if (EG(timeout_seconds)) {
01516               struct itimerval no_timeout;
01517 
01518               no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0;
01519 
01520 #ifdef __CYGWIN__
01521               setitimer(ITIMER_REAL, &no_timeout, NULL);
01522 #else
01523               setitimer(ITIMER_PROF, &no_timeout, NULL);
01524 #endif
01525        }
01526 #      endif
01527 #endif
01528 }
01529 /* }}} */
01530 
01531 zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len, int fetch_type TSRMLS_DC) /* {{{ */
01532 {
01533        zend_class_entry **pce;
01534        int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
01535        int silent       = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
01536 
01537        fetch_type &= ZEND_FETCH_CLASS_MASK;
01538 
01539 check_fetch_type:
01540        switch (fetch_type) {
01541               case ZEND_FETCH_CLASS_SELF:
01542                      if (!EG(scope)) {
01543                             zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
01544                      }
01545                      return EG(scope);
01546               case ZEND_FETCH_CLASS_PARENT:
01547                      if (!EG(scope)) {
01548                             zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
01549                      }
01550                      if (!EG(scope)->parent) {
01551                             zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
01552                      }
01553                      return EG(scope)->parent;
01554               case ZEND_FETCH_CLASS_STATIC:
01555                      if (!EG(called_scope)) {
01556                             zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
01557                      }
01558                      return EG(called_scope);
01559               case ZEND_FETCH_CLASS_AUTO: {
01560                             fetch_type = zend_get_class_fetch_type(class_name, class_name_len);
01561                             if (fetch_type!=ZEND_FETCH_CLASS_DEFAULT) {
01562                                    goto check_fetch_type;
01563                             }
01564                      }
01565                      break;
01566        }
01567 
01568        if (zend_lookup_class_ex(class_name, class_name_len, use_autoload, &pce TSRMLS_CC) == FAILURE) {
01569               if (use_autoload) {
01570                      if (!silent && !EG(exception)) {
01571                             if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
01572                                    zend_error(E_ERROR, "Interface '%s' not found", class_name);
01573                             } else {
01574                                    zend_error(E_ERROR, "Class '%s' not found", class_name);
01575                             }      
01576                      }
01577               }
01578               return NULL;
01579        }
01580        return *pce;
01581 }
01582 /* }}} */
01583 
01584 #define MAX_ABSTRACT_INFO_CNT 3
01585 #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
01586 #define DISPLAY_ABSTRACT_FN(idx) \
01587        ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
01588        ai.afn[idx] ? "::" : "", \
01589        ai.afn[idx] ? ai.afn[idx]->common.function_name : "", \
01590        ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
01591 
01592 typedef struct _zend_abstract_info {
01593        zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
01594        int cnt;
01595        int ctor;
01596 } zend_abstract_info;
01597 
01598 static int zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai TSRMLS_DC) /* {{{ */
01599 {
01600        if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
01601               if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
01602                      ai->afn[ai->cnt] = fn;
01603               }
01604               if (fn->common.fn_flags & ZEND_ACC_CTOR) {
01605                      if (!ai->ctor) {
01606                             ai->cnt++;
01607                             ai->ctor = 1;
01608                      } else {
01609                             ai->afn[ai->cnt] = NULL;
01610                      }
01611               } else {
01612                      ai->cnt++;
01613               }
01614        }
01615        return 0;
01616 }
01617 /* }}} */
01618 
01619 void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC) /* {{{ */
01620 {
01621        zend_abstract_info ai;
01622 
01623        if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
01624               memset(&ai, 0, sizeof(ai));
01625 
01626               zend_hash_apply_with_argument(&ce->function_table, (apply_func_arg_t) zend_verify_abstract_class_function, &ai TSRMLS_CC);
01627 
01628               if (ai.cnt) {
01629                      zend_error(E_ERROR, "Class %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining methods (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
01630                             ce->name, ai.cnt,
01631                             ai.cnt > 1 ? "s" : "",
01632                             DISPLAY_ABSTRACT_FN(0),
01633                             DISPLAY_ABSTRACT_FN(1),
01634                             DISPLAY_ABSTRACT_FN(2)
01635                             );
01636               }
01637        }
01638 }
01639 /* }}} */
01640 
01641 ZEND_API void zend_reset_all_cv(HashTable *symbol_table TSRMLS_DC) /* {{{ */
01642 {
01643        zend_execute_data *ex;
01644        int i;
01645 
01646        for (ex = EG(current_execute_data); ex; ex = ex->prev_execute_data) {
01647               if (ex->op_array && ex->symbol_table == symbol_table) {
01648                      for (i = 0; i < ex->op_array->last_var; i++) {
01649                             ex->CVs[i] = NULL;
01650                      }
01651               }
01652        }
01653 }
01654 /* }}} */
01655 
01656 ZEND_API int zend_delete_global_variable(char *name, int name_len TSRMLS_DC) /* {{{ */
01657 {
01658        zend_execute_data *ex;
01659        ulong hash_value = zend_inline_hash_func(name, name_len + 1);
01660 
01661        if (zend_hash_quick_exists(&EG(symbol_table), name, name_len + 1, hash_value)) {
01662               for (ex = EG(current_execute_data); ex; ex = ex->prev_execute_data) {
01663                      if (ex->op_array && ex->symbol_table == &EG(symbol_table)) {
01664                             int i;
01665                             for (i = 0; i < ex->op_array->last_var; i++) {
01666                                    if (ex->op_array->vars[i].hash_value == hash_value &&
01667                                           ex->op_array->vars[i].name_len == name_len &&
01668                                           !memcmp(ex->op_array->vars[i].name, name, name_len)
01669                                    ) {
01670                                           ex->CVs[i] = NULL;
01671                                           break;
01672                                    }
01673                             }
01674                      }
01675               }
01676               return zend_hash_quick_del(&EG(symbol_table), name, name_len + 1, hash_value);
01677        }
01678        return FAILURE;
01679 }
01680 /* }}} */
01681 
01682 ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
01683 {
01684        zend_uint i;
01685        zend_execute_data *ex;
01686 
01687        if (!EG(active_symbol_table)) {
01688               
01689               /* Search for last called user function */
01690               ex = EG(current_execute_data);
01691               while (ex && !ex->op_array) {
01692                      ex = ex->prev_execute_data;
01693               }
01694               if (ex && ex->symbol_table) {
01695                      EG(active_symbol_table) = ex->symbol_table;
01696                      return;
01697               }
01698 
01699               if (ex && ex->op_array) {
01700                      if (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
01701                             /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
01702                             EG(active_symbol_table) = *(EG(symtable_cache_ptr)--);
01703                      } else {
01704                             ALLOC_HASHTABLE(EG(active_symbol_table));
01705                             zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
01706                             /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
01707                      }
01708                      ex->symbol_table = EG(active_symbol_table);
01709 
01710                      if (ex->op_array->this_var != -1 &&
01711                          !ex->CVs[ex->op_array->this_var] &&
01712                          EG(This)) {
01713                             ex->CVs[ex->op_array->this_var] = (zval**)ex->CVs + ex->op_array->last_var + ex->op_array->this_var;
01714                             *ex->CVs[ex->op_array->this_var] = EG(This);
01715                      }
01716                      for (i = 0; i < ex->op_array->last_var; i++) {
01717                             if (ex->CVs[i]) {
01718                                    zend_hash_quick_update(EG(active_symbol_table),
01719                                           ex->op_array->vars[i].name,
01720                                           ex->op_array->vars[i].name_len + 1,
01721                                           ex->op_array->vars[i].hash_value,
01722                                           (void**)ex->CVs[i],
01723                                           sizeof(zval*),
01724                                           (void**)&ex->CVs[i]);
01725                             }
01726                      }
01727               }
01728        }
01729 }
01730 /* }}} */
01731 
01732 /*
01733  * Local variables:
01734  * tab-width: 4
01735  * c-basic-offset: 4
01736  * indent-tabs-mode: t
01737  * End:
01738  */