PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_execute_API.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 620 736 84.2 %
Date: 2014-07-21 Functions: 39 44 88.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include <stdio.h>
      23             : #include <signal.h>
      24             : 
      25             : #include "zend.h"
      26             : #include "zend_compile.h"
      27             : #include "zend_execute.h"
      28             : #include "zend_API.h"
      29             : #include "zend_ptr_stack.h"
      30             : #include "zend_constants.h"
      31             : #include "zend_extensions.h"
      32             : #include "zend_exceptions.h"
      33             : #include "zend_closures.h"
      34             : #include "zend_generators.h"
      35             : #include "zend_vm.h"
      36             : #include "zend_float.h"
      37             : #ifdef HAVE_SYS_TIME_H
      38             : #include <sys/time.h>
      39             : #endif
      40             : 
      41             : ZEND_API void (*zend_execute_ex)(zend_execute_data *execute_data TSRMLS_DC);
      42             : ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC);
      43             : 
      44             : /* true globals */
      45             : ZEND_API const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 };
      46             : ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL };
      47             : 
      48             : #ifdef ZEND_WIN32
      49             : #include <process.h>
      50             : static WNDCLASS wc;
      51             : static HWND timeout_window;
      52             : static HANDLE timeout_thread_event;
      53             : static HANDLE timeout_thread_handle;
      54             : static DWORD timeout_thread_id;
      55             : static int timeout_thread_initialized=0;
      56             : #endif
      57             : 
      58             : #if 0&&ZEND_DEBUG
      59             : static void (*original_sigsegv_handler)(int);
      60             : static void zend_handle_sigsegv(int dummy) /* {{{ */
      61             : {
      62             :         fflush(stdout);
      63             :         fflush(stderr);
      64             :         if (original_sigsegv_handler == zend_handle_sigsegv) {
      65             :                 signal(SIGSEGV, original_sigsegv_handler);
      66             :         } else {
      67             :                 signal(SIGSEGV, SIG_DFL);
      68             :         }
      69             :         {
      70             :                 TSRMLS_FETCH();
      71             : 
      72             :                 fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
      73             :                                 active_opline->opcode,
      74             :                                 active_opline-EG(active_op_array)->opcodes,
      75             :                                 get_active_function_name(TSRMLS_C),
      76             :                                 zend_get_executed_filename(TSRMLS_C),
      77             :                                 zend_get_executed_lineno(TSRMLS_C));
      78             : /* See http://support.microsoft.com/kb/190351 */
      79             : #ifdef PHP_WIN32
      80             :                 fflush(stderr);
      81             : #endif
      82             :         }
      83             :         if (original_sigsegv_handler!=zend_handle_sigsegv) {
      84             :                 original_sigsegv_handler(dummy);
      85             :         }
      86             : }
      87             : /* }}} */
      88             : #endif
      89             : 
      90       21100 : static void zend_extension_activator(zend_extension *extension TSRMLS_DC) /* {{{ */
      91             : {
      92       21100 :         if (extension->activate) {
      93         368 :                 extension->activate();
      94             :         }
      95       21100 : }
      96             : /* }}} */
      97             : 
      98       21138 : static void zend_extension_deactivator(zend_extension *extension TSRMLS_DC) /* {{{ */
      99             : {
     100       21138 :         if (extension->deactivate) {
     101         368 :                 extension->deactivate();
     102             :         }
     103       21138 : }
     104             : /* }}} */
     105             : 
     106       44418 : static int clean_non_persistent_function(zend_function *function TSRMLS_DC) /* {{{ */
     107             : {
     108       44418 :         return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
     109             : }
     110             : /* }}} */
     111             : 
     112           0 : static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC) /* {{{ */
     113             : {
     114           0 :         return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
     115             : }
     116             : /* }}} */
     117             : 
     118       30421 : static int clean_non_persistent_class(zend_class_entry **ce TSRMLS_DC) /* {{{ */
     119             : {
     120       30421 :         return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
     121             : }
     122             : /* }}} */
     123             : 
     124           0 : static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC) /* {{{ */
     125             : {
     126           0 :         return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
     127             : }
     128             : /* }}} */
     129             : 
     130       21214 : void init_executor(TSRMLS_D) /* {{{ */
     131             : {
     132       21214 :         zend_init_fpu(TSRMLS_C);
     133             : 
     134       21214 :         INIT_ZVAL(EG(uninitialized_zval));
     135             :         /* trick to make uninitialized_zval never be modified, passed by ref, etc. */
     136             :         Z_ADDREF(EG(uninitialized_zval));
     137       21214 :         INIT_ZVAL(EG(error_zval));
     138       21214 :         EG(uninitialized_zval_ptr)=&EG(uninitialized_zval);
     139       21214 :         EG(error_zval_ptr)=&EG(error_zval);
     140             : /* destroys stack frame, therefore makes core dumps worthless */
     141             : #if 0&&ZEND_DEBUG
     142             :         original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
     143             : #endif
     144       21214 :         EG(return_value_ptr_ptr) = NULL;
     145             : 
     146       21214 :         EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
     147       21214 :         EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
     148       21214 :         EG(no_extensions) = 0;
     149             : 
     150       21214 :         EG(function_table) = CG(function_table);
     151       21214 :         EG(class_table) = CG(class_table);
     152             : 
     153       21214 :         EG(in_execution) = 0;
     154       21214 :         EG(in_autoload) = NULL;
     155       21214 :         EG(autoload_func) = NULL;
     156       21214 :         EG(error_handling) = EH_NORMAL;
     157             : 
     158             :         zend_vm_stack_init(TSRMLS_C);
     159             :         zend_vm_stack_push((void *) NULL TSRMLS_CC);
     160             : 
     161       21214 :         zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0);
     162       21214 :         EG(active_symbol_table) = &EG(symbol_table);
     163             : 
     164       21214 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator TSRMLS_CC);
     165       21214 :         EG(opline_ptr) = NULL;
     166             : 
     167       21214 :         zend_hash_init(&EG(included_files), 5, NULL, NULL, 0);
     168             : 
     169       21214 :         EG(ticks_count) = 0;
     170             : 
     171       21214 :         EG(user_error_handler) = NULL;
     172             : 
     173       21214 :         EG(current_execute_data) = NULL;
     174             : 
     175       21214 :         zend_stack_init(&EG(user_error_handlers_error_reporting));
     176       21214 :         zend_ptr_stack_init(&EG(user_error_handlers));
     177       21214 :         zend_ptr_stack_init(&EG(user_exception_handlers));
     178             : 
     179       21214 :         zend_objects_store_init(&EG(objects_store), 1024);
     180             : 
     181       21214 :         EG(full_tables_cleanup) = 0;
     182             : #ifdef ZEND_WIN32
     183             :         EG(timed_out) = 0;
     184             : #endif
     185             : 
     186       21214 :         EG(exception) = NULL;
     187       21214 :         EG(prev_exception) = NULL;
     188             : 
     189       21214 :         EG(scope) = NULL;
     190       21214 :         EG(called_scope) = NULL;
     191             : 
     192       21214 :         EG(This) = NULL;
     193             : 
     194       21214 :         EG(active_op_array) = NULL;
     195             : 
     196       21214 :         EG(active) = 1;
     197       21214 :         EG(start_op) = NULL;
     198       21214 : }
     199             : /* }}} */
     200             : 
     201      278656 : static int zval_call_destructor(zval **zv TSRMLS_DC) /* {{{ */
     202             : {
     203      287957 :         if (Z_TYPE_PP(zv) == IS_OBJECT && Z_REFCOUNT_PP(zv) == 1) {
     204        8628 :                 return ZEND_HASH_APPLY_REMOVE;
     205             :         } else {
     206      270028 :                 return ZEND_HASH_APPLY_KEEP;
     207             :         }
     208             : }
     209             : /* }}} */
     210             : 
     211       21249 : void shutdown_destructors(TSRMLS_D) /* {{{ */
     212             : {
     213       21249 :         zend_try {
     214             :                 int symbols;
     215             :                 do {
     216       26239 :                         symbols = zend_hash_num_elements(&EG(symbol_table));
     217       26239 :                         zend_hash_reverse_apply(&EG(symbol_table), (apply_func_t) zval_call_destructor TSRMLS_CC);
     218       26239 :                 } while (symbols != zend_hash_num_elements(&EG(symbol_table)));
     219       21249 :                 zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC);
     220           0 :         } zend_catch {
     221             :                 /* if we couldn't destruct cleanly, mark all objects as destructed anyway */
     222           0 :                 zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
     223       21249 :         } zend_end_try();
     224       21249 : }
     225             : /* }}} */
     226             : 
     227       21249 : void shutdown_executor(TSRMLS_D) /* {{{ */
     228             : {
     229       21249 :         zend_try {
     230             : 
     231             : /* Removed because this can not be safely done, e.g. in this situation:
     232             :    Object 1 creates object 2
     233             :    Object 3 holds reference to object 2.
     234             :    Now when 1 and 2 are destroyed, 3 can still access 2 in its destructor, with
     235             :    very problematic results */
     236             : /*              zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); */
     237             : 
     238             : /* Moved after symbol table cleaners, because  some of the cleaners can call
     239             :    destructors, which would use EG(symtable_cache_ptr) and thus leave leaks */
     240             : /*              while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     241             :                         zend_hash_destroy(*EG(symtable_cache_ptr));
     242             :                         efree(*EG(symtable_cache_ptr));
     243             :                         EG(symtable_cache_ptr)--;
     244             :                 }
     245             : */
     246       21249 :                 zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC);
     247       21249 :                 zend_hash_graceful_reverse_destroy(&EG(symbol_table));
     248       21249 :         } zend_end_try();
     249             : 
     250       21249 :         zend_try {
     251             :                 zval *zeh;
     252             :                 /* remove error handlers before destroying classes and functions,
     253             :                  * so that if handler used some class, crash would not happen */
     254       21249 :                 if (EG(user_error_handler)) {
     255         256 :                         zeh = EG(user_error_handler);
     256         256 :                         EG(user_error_handler) = NULL;
     257         256 :                         zval_ptr_dtor(&zeh);
     258             :                 }
     259             : 
     260       21249 :                 if (EG(user_exception_handler)) {
     261          11 :                         zeh = EG(user_exception_handler);
     262          11 :                         EG(user_exception_handler) = NULL;
     263          11 :                         zval_ptr_dtor(&zeh);
     264             :                 }
     265             : 
     266       21249 :                 zend_stack_destroy(&EG(user_error_handlers_error_reporting));
     267       21249 :                 zend_stack_init(&EG(user_error_handlers_error_reporting));
     268       21249 :                 zend_ptr_stack_clean(&EG(user_error_handlers), ZVAL_DESTRUCTOR, 1);
     269       21249 :                 zend_ptr_stack_clean(&EG(user_exception_handlers), ZVAL_DESTRUCTOR, 1);
     270       21249 :         } zend_end_try();
     271             : 
     272       21249 :         zend_try {
     273             :                 /* Cleanup static data for functions and arrays.
     274             :                  * We need a separate cleanup stage because of the following problem:
     275             :                  * Suppose we destroy class X, which destroys the class's function table,
     276             :                  * and in the function table we have function foo() that has static $bar.
     277             :                  * Now if an object of class X is assigned to $bar, its destructor will be
     278             :                  * called and will fail since X's function table is in mid-destruction.
     279             :                  * So we want first of all to clean up all data and then move to tables destruction.
     280             :                  * Note that only run-time accessed data need to be cleaned up, pre-defined data can
     281             :                  * not contain objects and thus are not probelmatic */
     282       21249 :                 if (EG(full_tables_cleanup)) {
     283           0 :                         zend_hash_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
     284           0 :                         zend_hash_apply(EG(class_table), (apply_func_t) zend_cleanup_class_data TSRMLS_CC);
     285             :                 } else {
     286       21249 :                         zend_hash_reverse_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data TSRMLS_CC);
     287       21249 :                         zend_hash_reverse_apply(EG(class_table), (apply_func_t) zend_cleanup_user_class_data TSRMLS_CC);
     288       21248 :                         zend_cleanup_internal_classes(TSRMLS_C);
     289             :                 }
     290       21249 :         } zend_end_try();
     291             : 
     292       21249 :         zend_try {
     293       21249 :                 zend_objects_store_free_object_storage(&EG(objects_store) TSRMLS_CC);
     294             : 
     295             :                 zend_vm_stack_destroy(TSRMLS_C);
     296             : 
     297             :                 /* Destroy all op arrays */
     298       21249 :                 if (EG(full_tables_cleanup)) {
     299           0 :                         zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
     300           0 :                         zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
     301             :                 } else {
     302       21249 :                         zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function TSRMLS_CC);
     303       21249 :                         zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class TSRMLS_CC);
     304             :                 }
     305             : 
     306       43312 :                 while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     307         814 :                         zend_hash_destroy(*EG(symtable_cache_ptr));
     308         814 :                         FREE_HASHTABLE(*EG(symtable_cache_ptr));
     309         814 :                         EG(symtable_cache_ptr)--;
     310             :                 }
     311       21249 :         } zend_end_try();
     312             : 
     313       21249 :         zend_try {
     314       21249 :                 clean_non_persistent_constants(TSRMLS_C);
     315       21249 :         } zend_end_try();
     316             : 
     317       21249 :         zend_try {
     318             : #if 0&&ZEND_DEBUG
     319             :         signal(SIGSEGV, original_sigsegv_handler);
     320             : #endif
     321             : 
     322       21249 :                 zend_hash_destroy(&EG(included_files));
     323             : 
     324       21249 :                 zend_stack_destroy(&EG(user_error_handlers_error_reporting));
     325       21249 :                 zend_ptr_stack_destroy(&EG(user_error_handlers));
     326       21249 :                 zend_ptr_stack_destroy(&EG(user_exception_handlers));
     327       21249 :                 zend_objects_store_destroy(&EG(objects_store));
     328       21249 :                 if (EG(in_autoload)) {
     329         168 :                         zend_hash_destroy(EG(in_autoload));
     330         168 :                         FREE_HASHTABLE(EG(in_autoload));
     331             :                 }
     332       21249 :         } zend_end_try();
     333             : 
     334       21249 :         zend_shutdown_fpu(TSRMLS_C);
     335             : 
     336       21249 :         EG(active) = 0;
     337       21249 : }
     338             : /* }}} */
     339             : 
     340             : /* return class name and "::" or "". */
     341      211422 : ZEND_API const char *get_active_class_name(const char **space TSRMLS_DC) /* {{{ */
     342             : {
     343      211422 :         if (!zend_is_executing(TSRMLS_C)) {
     344           0 :                 if (space) {
     345           0 :                         *space = "";
     346             :                 }
     347           0 :                 return "";
     348             :         }
     349      211422 :         switch (EG(current_execute_data)->function_state.function->type) {
     350             :                 case ZEND_USER_FUNCTION:
     351             :                 case ZEND_INTERNAL_FUNCTION:
     352             :                 {
     353      211422 :                         zend_class_entry *ce = EG(current_execute_data)->function_state.function->common.scope;
     354             : 
     355      211422 :                         if (space) {
     356      211422 :                                 *space = ce ? "::" : "";
     357             :                         }
     358      211422 :                         return ce ? ce->name : "";
     359             :                 }
     360             :                 default:
     361           0 :                         if (space) {
     362           0 :                                 *space = "";
     363             :                         }
     364           0 :                         return "";
     365             :         }
     366             : }
     367             : /* }}} */
     368             : 
     369      211516 : ZEND_API const char *get_active_function_name(TSRMLS_D) /* {{{ */
     370             : {
     371      211516 :         if (!zend_is_executing(TSRMLS_C)) {
     372          19 :                 return NULL;
     373             :         }
     374      211497 :         switch (EG(current_execute_data)->function_state.function->type) {
     375             :                 case ZEND_USER_FUNCTION: {
     376         277 :                                 const char *function_name = ((zend_op_array *) EG(current_execute_data)->function_state.function)->function_name;
     377             : 
     378         277 :                                 if (function_name) {
     379         220 :                                         return function_name;
     380             :                                 } else {
     381          57 :                                         return "main";
     382             :                                 }
     383             :                         }
     384             :                         break;
     385             :                 case ZEND_INTERNAL_FUNCTION:
     386      211220 :                         return ((zend_internal_function *) EG(current_execute_data)->function_state.function)->function_name;
     387             :                         break;
     388             :                 default:
     389           0 :                         return NULL;
     390             :         }
     391             : }
     392             : /* }}} */
     393             : 
     394      405741 : ZEND_API const char *zend_get_executed_filename(TSRMLS_D) /* {{{ */
     395             : {
     396      405741 :         if (EG(active_op_array)) {
     397      405736 :                 return EG(active_op_array)->filename;
     398             :         } else {
     399           5 :                 return "[no active file]";
     400             :         }
     401             : }
     402             : /* }}} */
     403             : 
     404      397915 : ZEND_API uint zend_get_executed_lineno(TSRMLS_D) /* {{{ */
     405             : {
     406      398021 :         if(EG(exception) && EG(opline_ptr) && active_opline->opcode == ZEND_HANDLE_EXCEPTION &&
     407         106 :                 active_opline->lineno == 0 && EG(opline_before_exception)) {
     408          53 :                 return EG(opline_before_exception)->lineno;
     409             :         }
     410      397862 :         if (EG(opline_ptr)) {
     411      397857 :                 return active_opline->lineno;
     412             :         } else {
     413           5 :                 return 0;
     414             :         }
     415             : }
     416             : /* }}} */
     417             : 
     418      850814 : ZEND_API zend_bool zend_is_executing(TSRMLS_D) /* {{{ */
     419             : {
     420      850814 :         return EG(in_execution);
     421             : }
     422             : /* }}} */
     423             : 
     424    19426287 : ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     425             : {
     426             :         TSRMLS_FETCH();
     427    19426287 :         i_zval_ptr_dtor(*zval_ptr ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
     428    19426281 : }
     429             : /* }}} */
     430             : 
     431    18926744 : ZEND_API void _zval_internal_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     432             : {
     433             : #if DEBUG_ZEND>=2
     434             :         printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, Z_REFCOUNT_PP(zval_ptr), Z_REFCOUNT_PP(zval_ptr) - 1);
     435             : #endif
     436    18926744 :         Z_DELREF_PP(zval_ptr);
     437    37853488 :         if (Z_REFCOUNT_PP(zval_ptr) == 0) {
     438    13135864 :                 zval_internal_dtor(*zval_ptr);
     439    13135864 :                 free(*zval_ptr);
     440    11581760 :         } else if (Z_REFCOUNT_PP(zval_ptr) == 1) {
     441     1447720 :                 Z_UNSET_ISREF_PP(zval_ptr);
     442             :         }
     443    18926744 : }
     444             : /* }}} */
     445             : 
     446       10435 : ZEND_API int zend_is_true(zval *op TSRMLS_DC) /* {{{ */
     447             : {
     448       10435 :         return i_zend_is_true(op TSRMLS_CC);
     449             : }
     450             : /* }}} */
     451             : 
     452             : #define IS_VISITED_CONSTANT                     0x80
     453             : #define IS_CONSTANT_VISITED(p)          (Z_TYPE_P(p) & IS_VISITED_CONSTANT)
     454             : #define Z_REAL_TYPE_P(p)                        (Z_TYPE_P(p) & ~IS_VISITED_CONSTANT)
     455             : #define MARK_CONSTANT_VISITED(p)        Z_TYPE_P(p) |= IS_VISITED_CONSTANT
     456             : 
     457      135809 : ZEND_API int zval_update_constant_ex(zval **pp, zend_bool inline_change, zend_class_entry *scope TSRMLS_DC) /* {{{ */
     458             : {
     459      135809 :         zval *p = *pp;
     460             :         zval const_value;
     461             :         char *colon;
     462             : 
     463      135809 :         if (IS_CONSTANT_VISITED(p)) {
     464           1 :                 zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
     465      135808 :         } else if ((Z_TYPE_P(p) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
     466             :                 int refcount;
     467             :                 zend_uchar is_ref;
     468             : 
     469         891 :                 SEPARATE_ZVAL_IF_NOT_REF(pp);
     470         319 :                 p = *pp;
     471             : 
     472         319 :                 MARK_CONSTANT_VISITED(p);
     473             : 
     474         319 :                 refcount = Z_REFCOUNT_P(p);
     475         319 :                 is_ref = Z_ISREF_P(p);
     476             : 
     477         319 :                 if (!zend_get_constant_ex(p->value.str.val, p->value.str.len, &const_value, scope, Z_REAL_TYPE_P(p) TSRMLS_CC)) {
     478          20 :                         char *actual = Z_STRVAL_P(p);
     479             : 
     480          20 :                         if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
     481           0 :                                 zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
     482           0 :                                 Z_STRLEN_P(p) -= ((colon - Z_STRVAL_P(p)) + 1);
     483           0 :                                 if (inline_change) {
     484           0 :                                         colon = estrndup(colon, Z_STRLEN_P(p));
     485           0 :                                         str_efree(Z_STRVAL_P(p));
     486           0 :                                         Z_STRVAL_P(p) = colon;
     487             :                                 } else {
     488           0 :                                         Z_STRVAL_P(p) = colon + 1;
     489             :                                 }
     490             :                         } else {
     491          20 :                                 char *save = actual, *slash;
     492          20 :                                 int actual_len = Z_STRLEN_P(p);
     493          20 :                                 if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char *)zend_memrchr(actual, '\\', actual_len))) {
     494           3 :                                         actual = slash + 1;
     495           3 :                                         actual_len -= (actual - Z_STRVAL_P(p));
     496           3 :                                         if (inline_change) {
     497           2 :                                                 actual = estrndup(actual, actual_len);
     498           2 :                                                 Z_STRVAL_P(p) = actual;
     499           2 :                                                 Z_STRLEN_P(p) = actual_len;
     500             :                                         }
     501             :                                 }
     502          20 :                                 if (actual[0] == '\\') {
     503           0 :                                         if (inline_change) {
     504           0 :                                                 memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p));
     505           0 :                                                 --Z_STRLEN_P(p);
     506             :                                         } else {
     507           0 :                                                 ++actual;
     508             :                                         }
     509           0 :                                         --actual_len;
     510             :                                 }
     511          20 :                                 if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
     512          15 :                                         int fix_save = 0;
     513          15 :                                         if (save[0] == '\\') {
     514           0 :                                                 save++;
     515           0 :                                                 fix_save = 1;
     516             :                                         }
     517          15 :                                         zend_error(E_ERROR, "Undefined constant '%s'", save);
     518           0 :                                         if (fix_save) {
     519           0 :                                                 save--;
     520             :                                         }
     521           0 :                                         if (inline_change) {
     522           0 :                                                 str_efree(save);
     523             :                                         }
     524           0 :                                         save = NULL;
     525             :                                 }
     526           5 :                                 if (inline_change && save && save != actual) {
     527           2 :                                         str_efree(save);
     528             :                                 }
     529           5 :                                 zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",  actual,  actual);
     530           5 :                                 p->type = IS_STRING;
     531           5 :                                 if (!inline_change) {
     532           1 :                                         Z_STRVAL_P(p) = actual;
     533           1 :                                         Z_STRLEN_P(p) = actual_len;
     534             :                                         zval_copy_ctor(p);
     535             :                                 }
     536             :                         }
     537             :                 } else {
     538         290 :                         if (inline_change) {
     539         200 :                                 str_efree(Z_STRVAL_P(p));
     540             :                         }
     541         290 :                         *p = const_value;
     542             :                 }
     543             : 
     544         295 :                 Z_SET_REFCOUNT_P(p, refcount);
     545         295 :                 Z_SET_ISREF_TO_P(p, is_ref);
     546      135489 :         } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
     547         290 :                 SEPARATE_ZVAL_IF_NOT_REF(pp);
     548         105 :                 p = *pp;
     549             : 
     550         105 :                 zend_ast_evaluate(&const_value, Z_AST_P(p), scope TSRMLS_CC);
     551          90 :                 if (inline_change) {
     552          72 :                         zend_ast_destroy(Z_AST_P(p));
     553             :                 }
     554          90 :                 ZVAL_COPY_VALUE(p, &const_value);
     555             :         }
     556      135769 :         return 0;
     557             : }
     558             : /* }}} */
     559             : 
     560         185 : ZEND_API int zval_update_constant_inline_change(zval **pp, zend_class_entry *scope TSRMLS_DC) /* {{{ */
     561             : {
     562         185 :         return zval_update_constant_ex(pp, 1, scope TSRMLS_CC);
     563             : }
     564             : /* }}} */
     565             : 
     566           0 : ZEND_API int zval_update_constant_no_inline_change(zval **pp, zend_class_entry *scope TSRMLS_DC) /* {{{ */
     567             : {
     568           0 :         return zval_update_constant_ex(pp, 0, scope TSRMLS_CC);
     569             : }
     570             : /* }}} */
     571             : 
     572      135172 : ZEND_API int zval_update_constant(zval **pp, zend_bool inline_change TSRMLS_DC) /* {{{ */
     573             : {
     574      135172 :         return zval_update_constant_ex(pp, inline_change, NULL TSRMLS_CC);
     575             : }
     576             : /* }}} */
     577             : 
     578        1400 : int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC) /* {{{ */
     579             : {
     580             :         zval ***params_array;
     581             :         zend_uint i;
     582             :         int ex_retval;
     583        1400 :         zval *local_retval_ptr = NULL;
     584             : 
     585        1400 :         if (param_count) {
     586        1086 :                 params_array = (zval ***) emalloc(sizeof(zval **)*param_count);
     587        4017 :                 for (i=0; i<param_count; i++) {
     588        2931 :                         params_array[i] = &params[i];
     589             :                 }
     590             :         } else {
     591         314 :                 params_array = NULL;
     592             :         }
     593        1400 :         ex_retval = call_user_function_ex(function_table, object_pp, function_name, &local_retval_ptr, param_count, params_array, 1, NULL TSRMLS_CC);
     594        1373 :         if (local_retval_ptr) {
     595        4077 :                 COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
     596             :         } else {
     597          14 :                 INIT_ZVAL(*retval_ptr);
     598             :         }
     599        1373 :         if (params_array) {
     600        1067 :                 efree(params_array);
     601             :         }
     602        1373 :         return ex_retval;
     603             : }
     604             : /* }}} */
     605             : 
     606       12202 : 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) /* {{{ */
     607             : {
     608             :         zend_fcall_info fci;
     609             : 
     610       12202 :         fci.size = sizeof(fci);
     611       12202 :         fci.function_table = function_table;
     612       12202 :         fci.object_ptr = object_pp ? *object_pp : NULL;
     613       12202 :         fci.function_name = function_name;
     614       12202 :         fci.retval_ptr_ptr = retval_ptr_ptr;
     615       12202 :         fci.param_count = param_count;
     616       12202 :         fci.params = params;
     617       12202 :         fci.no_separation = (zend_bool) no_separation;
     618       12202 :         fci.symbol_table = symbol_table;
     619             : 
     620       12202 :         return zend_call_function(&fci, NULL TSRMLS_CC);
     621             : }
     622             : /* }}} */
     623             : 
     624      617214 : int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) /* {{{ */
     625             : {
     626             :         zend_uint i;
     627             :         zval **original_return_value;
     628             :         HashTable *calling_symbol_table;
     629             :         zend_op_array *original_op_array;
     630             :         zend_op **original_opline_ptr;
     631             :         zend_class_entry *current_scope;
     632             :         zend_class_entry *current_called_scope;
     633      617214 :         zend_class_entry *calling_scope = NULL;
     634      617214 :         zend_class_entry *called_scope = NULL;
     635             :         zval *current_this;
     636             :         zend_execute_data execute_data;
     637             :         zend_fcall_info_cache fci_cache_local;
     638             : 
     639      617214 :         *fci->retval_ptr_ptr = NULL;
     640             : 
     641      617214 :         if (!EG(active)) {
     642           3 :                 return FAILURE; /* executor is already inactive */
     643             :         }
     644             : 
     645      617211 :         if (EG(exception)) {
     646           7 :                 return FAILURE; /* we would result in an instable executor otherwise */
     647             :         }
     648             : 
     649      617204 :         switch (fci->size) {
     650             :                 case sizeof(zend_fcall_info):
     651      617204 :                         break; /* nothing to do currently */
     652             :                 default:
     653           0 :                         zend_error(E_ERROR, "Corrupted fcall_info provided to zend_call_function()");
     654             :                         break;
     655             :         }
     656             : 
     657             :         /* Initialize execute_data */
     658      617204 :         if (EG(current_execute_data)) {
     659      597734 :                 execute_data = *EG(current_execute_data);
     660      597734 :                 EX(op_array) = NULL;
     661      597734 :                 EX(opline) = NULL;
     662      597734 :                 EX(object) = NULL;
     663             :         } else {
     664             :                 /* This only happens when we're called outside any execute()'s
     665             :                  * It shouldn't be strictly necessary to NULL execute_data out,
     666             :                  * but it may make bugs easier to spot
     667             :                  */
     668       19470 :                 memset(&execute_data, 0, sizeof(zend_execute_data));
     669             :         }
     670             : 
     671      617204 :         if (!fci_cache || !fci_cache->initialized) {
     672             :                 char *callable_name;
     673      260935 :                 char *error = NULL;
     674             : 
     675      260935 :                 if (!fci_cache) {
     676       12614 :                         fci_cache = &fci_cache_local;
     677             :                 }
     678             : 
     679      260935 :                 if (!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC)) {
     680         259 :                         if (error) {
     681           0 :                                 zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
     682           0 :                                 efree(error);
     683             :                         }
     684         259 :                         if (callable_name) {
     685         257 :                                 efree(callable_name);
     686             :                         }
     687         259 :                         return FAILURE;
     688      260676 :                 } else if (error) {
     689             :                         /* Capitalize the first latter of the error message */
     690           3 :                         if (error[0] >= 'a' && error[0] <= 'z') {
     691           3 :                                 error[0] += ('A' - 'a');
     692             :                         }
     693           3 :                         zend_error(E_STRICT, "%s", error);
     694           3 :                         efree(error);
     695             :                 }
     696      260676 :                 efree(callable_name);
     697             :         }
     698             : 
     699      616945 :         EX(function_state).function = fci_cache->function_handler;
     700      616945 :         calling_scope = fci_cache->calling_scope;
     701      616945 :         called_scope = fci_cache->called_scope;
     702      616945 :         fci->object_ptr = fci_cache->object_ptr;
     703      616945 :         EX(object) = fci->object_ptr;
     704     1344649 :         if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
     705      727704 :             (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
     706           0 :                 return FAILURE;
     707             :         }
     708             : 
     709      616945 :         if (EX(function_state).function->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
     710           1 :                 if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
     711           1 :                         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);
     712             :                 }
     713           0 :                 if (EX(function_state).function->common.fn_flags & ZEND_ACC_DEPRECATED) {
     714           0 :                         zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
     715           0 :                                 EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
     716           0 :                                 EX(function_state).function->common.scope ? "::" : "",
     717           0 :                                 EX(function_state).function->common.function_name);
     718             :                 }
     719             :         }
     720             : 
     721      616944 :         ZEND_VM_STACK_GROW_IF_NEEDED(fci->param_count + 1);
     722             : 
     723     1215211 :         for (i=0; i<fci->param_count; i++) {
     724             :                 zval *param;
     725             : 
     726      665126 :                 if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
     727      133992 :                         if (!PZVAL_IS_REF(*fci->params[i]) && Z_REFCOUNT_PP(fci->params[i]) > 1) {
     728             :                                 zval *new_zval;
     729             : 
     730          49 :                                 if (fci->no_separation &&
     731          27 :                                     !ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
     732           8 :                                         if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
     733             :                                                 /* hack to clean up the stack */
     734           1 :                                                 zend_vm_stack_push((void *) (zend_uintptr_t)i TSRMLS_CC);
     735             :                                                 zend_vm_stack_clear_multiple(0 TSRMLS_CC);
     736             :                                         }
     737             : 
     738          26 :                                         zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
     739             :                                                 i+1,
     740          10 :                                                 EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
     741           8 :                                                 EX(function_state).function->common.scope ? "::" : "",
     742           8 :                                                 EX(function_state).function->common.function_name);
     743           8 :                                         return FAILURE;
     744             :                                 }
     745             : 
     746          14 :                                 ALLOC_ZVAL(new_zval);
     747          14 :                                 *new_zval = **fci->params[i];
     748             :                                 zval_copy_ctor(new_zval);
     749             :                                 Z_SET_REFCOUNT_P(new_zval, 1);
     750          14 :                                 Z_DELREF_PP(fci->params[i]);
     751          14 :                                 *fci->params[i] = new_zval;
     752             :                         }
     753       66851 :                         Z_ADDREF_PP(fci->params[i]);
     754       66851 :                         Z_SET_ISREF_PP(fci->params[i]);
     755       66851 :                         param = *fci->params[i];
     756     1063194 :                 } else if (PZVAL_IS_REF(*fci->params[i]) &&
     757             :                            /* don't separate references for __call */
     758         182 :                            (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 ) {
     759         180 :                         ALLOC_ZVAL(param);
     760         180 :                         *param = **(fci->params[i]);
     761         180 :                         INIT_PZVAL(param);
     762             :                         zval_copy_ctor(param);
     763      531236 :                 } else if (*fci->params[i] != &EG(uninitialized_zval)) {
     764      531230 :                         Z_ADDREF_PP(fci->params[i]);
     765      531230 :                         param = *fci->params[i];
     766             :                 } else {
     767           6 :                         ALLOC_ZVAL(param);
     768           6 :                         *param = **(fci->params[i]);
     769           6 :                         INIT_PZVAL(param);
     770             :                 }
     771             :                 zend_vm_stack_push(param TSRMLS_CC);
     772             :         }
     773             : 
     774      616936 :         EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C);
     775      616936 :         zend_vm_stack_push((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
     776             : 
     777      616936 :         current_scope = EG(scope);
     778      616936 :         EG(scope) = calling_scope;
     779             : 
     780      616936 :         current_this = EG(This);
     781             : 
     782      616936 :         current_called_scope = EG(called_scope);
     783      616936 :         if (called_scope) {
     784      364366 :                 EG(called_scope) = called_scope;
     785      252570 :         } else if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
     786      251487 :                 EG(called_scope) = NULL;
     787             :         }
     788             : 
     789      616936 :         if (fci->object_ptr) {
     790      363849 :                 if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
     791          41 :                         EG(This) = NULL;
     792             :                 } else {
     793      363808 :                         EG(This) = fci->object_ptr;
     794             : 
     795      727616 :                         if (!PZVAL_IS_REF(EG(This))) {
     796      350169 :                                 Z_ADDREF_P(EG(This)); /* For $this pointer */
     797             :                         } else {
     798             :                                 zval *this_ptr;
     799             : 
     800       13639 :                                 ALLOC_ZVAL(this_ptr);
     801       13639 :                                 *this_ptr = *EG(This);
     802       13639 :                                 INIT_PZVAL(this_ptr);
     803             :                                 zval_copy_ctor(this_ptr);
     804       13639 :                                 EG(This) = this_ptr;
     805             :                         }
     806             :                 }
     807             :         } else {
     808      253087 :                 EG(This) = NULL;
     809             :         }
     810             : 
     811      616936 :         EX(prev_execute_data) = EG(current_execute_data);
     812      616936 :         EG(current_execute_data) = &execute_data;
     813             : 
     814      616936 :         if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
     815      473037 :                 calling_symbol_table = EG(active_symbol_table);
     816      473037 :                 EG(scope) = EX(function_state).function->common.scope;
     817      473037 :                 if (fci->symbol_table) {
     818           0 :                         EG(active_symbol_table) = fci->symbol_table;
     819             :                 } else {
     820      473037 :                         EG(active_symbol_table) = NULL;
     821             :                 }
     822             : 
     823      473037 :                 original_return_value = EG(return_value_ptr_ptr);
     824      473037 :                 original_op_array = EG(active_op_array);
     825      473037 :                 EG(return_value_ptr_ptr) = fci->retval_ptr_ptr;
     826      473037 :                 EG(active_op_array) = (zend_op_array *) EX(function_state).function;
     827      473037 :                 original_opline_ptr = EG(opline_ptr);
     828             : 
     829      473037 :                 if (EG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) {
     830           3 :                         *fci->retval_ptr_ptr = zend_generator_create_zval(EG(active_op_array) TSRMLS_CC);
     831             :                 } else {
     832      473034 :                         zend_execute(EG(active_op_array) TSRMLS_CC);
     833             :                 }
     834             : 
     835      472991 :                 if (!fci->symbol_table && EG(active_symbol_table)) {
     836         260 :                         zend_clean_and_cache_symbol_table(EG(active_symbol_table) TSRMLS_CC);
     837             :                 }
     838      472991 :                 EG(active_symbol_table) = calling_symbol_table;
     839      472991 :                 EG(active_op_array) = original_op_array;
     840      472991 :                 EG(return_value_ptr_ptr)=original_return_value;
     841      472991 :                 EG(opline_ptr) = original_opline_ptr;
     842      143899 :         } else if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
     843      143899 :                 int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
     844      143899 :                 ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
     845      143899 :                 if (EX(function_state).function->common.scope) {
     846      142816 :                         EG(scope) = EX(function_state).function->common.scope;
     847             :                 }
     848      143899 :                 if (EXPECTED(zend_execute_internal == NULL)) {
     849             :                         /* saves one function call if zend_execute_internal is not used */
     850      143899 :                         EX(function_state).function->internal_function.handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
     851             :                 } else {
     852           0 :                         zend_execute_internal(&execute_data, fci, 1 TSRMLS_CC);
     853             :                 }
     854             :                 /*  We shouldn't fix bad extensions here,
     855             :                         because it can break proper ones (Bug #34045)
     856             :                 if (!EX(function_state).function->common.return_reference)
     857             :                 {
     858             :                         INIT_PZVAL(*fci->retval_ptr_ptr);
     859             :                 }*/
     860      143874 :                 if (EG(exception) && fci->retval_ptr_ptr) {
     861          80 :                         zval_ptr_dtor(fci->retval_ptr_ptr);
     862          80 :                         *fci->retval_ptr_ptr = NULL;
     863             :                 }
     864             : 
     865      143874 :                 if (call_via_handler) {
     866             :                         /* We must re-initialize function again */
     867          41 :                         fci_cache->initialized = 0;
     868             :                 }
     869             :         } else { /* ZEND_OVERLOADED_FUNCTION */
     870           0 :                 ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
     871             : 
     872             :                 /* Not sure what should be done here if it's a static method */
     873           0 :                 if (fci->object_ptr) {
     874           0 :                         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);
     875             :                 } else {
     876           0 :                         zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
     877             :                 }
     878             : 
     879           0 :                 if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
     880           0 :                         efree((char*)EX(function_state).function->common.function_name);
     881             :                 }
     882           0 :                 efree(EX(function_state).function);
     883             : 
     884           0 :                 if (EG(exception) && fci->retval_ptr_ptr) {
     885           0 :                         zval_ptr_dtor(fci->retval_ptr_ptr);
     886           0 :                         *fci->retval_ptr_ptr = NULL;
     887             :                 }
     888             :         }
     889             :         zend_vm_stack_clear_multiple(0 TSRMLS_CC);
     890             : 
     891      616865 :         if (EG(This)) {
     892      363765 :                 zval_ptr_dtor(&EG(This));
     893             :         }
     894      616865 :         EG(called_scope) = current_called_scope;
     895      616865 :         EG(scope) = current_scope;
     896      616865 :         EG(This) = current_this;
     897      616865 :         EG(current_execute_data) = EX(prev_execute_data);
     898             : 
     899      616865 :         if (EG(exception)) {
     900         278 :                 zend_throw_exception_internal(NULL TSRMLS_CC);
     901             :         }
     902      616862 :         return SUCCESS;
     903             : }
     904             : /* }}} */
     905             : 
     906      252967 : ZEND_API int zend_lookup_class_ex(const char *name, int name_length, const zend_literal *key, int use_autoload, zend_class_entry ***ce TSRMLS_DC) /* {{{ */
     907             : {
     908             :         zval **args[1];
     909             :         zval autoload_function;
     910             :         zval *class_name_ptr;
     911      252967 :         zval *retval_ptr = NULL;
     912             :         int retval, lc_length;
     913             :         char *lc_name;
     914             :         char *lc_free;
     915             :         zend_fcall_info fcall_info;
     916             :         zend_fcall_info_cache fcall_cache;
     917      252967 :         char dummy = 1;
     918             :         ulong hash;
     919             :         ALLOCA_FLAG(use_heap)
     920             : 
     921      252967 :         if (key) {
     922       26005 :                 lc_name = Z_STRVAL(key->constant);
     923       26005 :                 lc_length = Z_STRLEN(key->constant) + 1;
     924       26005 :                 hash = key->hash_value;
     925             :         } else {
     926      226962 :                 if (name == NULL || !name_length) {
     927          78 :                         return FAILURE;
     928             :                 }
     929             : 
     930      226884 :                 lc_free = lc_name = do_alloca(name_length + 1, use_heap);
     931      226884 :                 zend_str_tolower_copy(lc_name, name, name_length);
     932      226884 :                 lc_length = name_length + 1;
     933             : 
     934      226884 :                 if (lc_name[0] == '\\') {
     935           9 :                         lc_name += 1;
     936           9 :                         lc_length -= 1;
     937             :                 }
     938             : 
     939      226884 :                 hash = zend_inline_hash_func(lc_name, lc_length);
     940             :         }
     941             : 
     942      252889 :         if (zend_hash_quick_find(EG(class_table), lc_name, lc_length, hash, (void **) ce) == SUCCESS) {
     943      252167 :                 if (!key) {
     944      226240 :                         free_alloca(lc_free, use_heap);
     945             :                 }
     946      252167 :                 return SUCCESS;
     947             :         }
     948             : 
     949             :         /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
     950             :          * (doesn't impact functionality of __autoload()
     951             :         */
     952         722 :         if (!use_autoload || zend_is_compiling(TSRMLS_C)) {
     953         346 :                 if (!key) {
     954         341 :                         free_alloca(lc_free, use_heap);
     955             :                 }
     956         346 :                 return FAILURE;
     957             :         }
     958             : 
     959             :         /* Verify class name before passing it to __autoload() */
     960         376 :         if (strspn(name, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\") != name_length) {
     961          26 :                 if (!key) {
     962          26 :                         free_alloca(lc_free, use_heap);
     963             :                 }
     964          26 :                 return FAILURE;
     965             :         }
     966             :         
     967         350 :         if (EG(in_autoload) == NULL) {
     968         168 :                 ALLOC_HASHTABLE(EG(in_autoload));
     969         168 :                 zend_hash_init(EG(in_autoload), 0, NULL, NULL, 0);
     970             :         }
     971             : 
     972         350 :         if (zend_hash_quick_add(EG(in_autoload), lc_name, lc_length, hash, (void**)&dummy, sizeof(char), NULL) == FAILURE) {
     973           4 :                 if (!key) {
     974           4 :                         free_alloca(lc_free, use_heap);
     975             :                 }
     976           4 :                 return FAILURE;
     977             :         }
     978             : 
     979         346 :         ZVAL_STRINGL(&autoload_function, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1, 0);
     980             : 
     981         346 :         ALLOC_ZVAL(class_name_ptr);
     982         346 :         INIT_PZVAL(class_name_ptr);
     983         346 :         if (name[0] == '\\') {
     984           1 :                 ZVAL_STRINGL(class_name_ptr, name+1, name_length-1, 1);
     985             :         } else {
     986         345 :                 ZVAL_STRINGL(class_name_ptr, name, name_length, 1);
     987             :         }
     988             : 
     989         346 :         args[0] = &class_name_ptr;
     990             : 
     991         346 :         fcall_info.size = sizeof(fcall_info);
     992         346 :         fcall_info.function_table = EG(function_table);
     993         346 :         fcall_info.function_name = &autoload_function;
     994         346 :         fcall_info.symbol_table = NULL;
     995         346 :         fcall_info.retval_ptr_ptr = &retval_ptr;
     996         346 :         fcall_info.param_count = 1;
     997         346 :         fcall_info.params = args;
     998         346 :         fcall_info.object_ptr = NULL;
     999         346 :         fcall_info.no_separation = 1;
    1000             : 
    1001         346 :         fcall_cache.initialized = EG(autoload_func) ? 1 : 0;
    1002         346 :         fcall_cache.function_handler = EG(autoload_func);
    1003         346 :         fcall_cache.calling_scope = NULL;
    1004         346 :         fcall_cache.called_scope = NULL;
    1005         346 :         fcall_cache.object_ptr = NULL;
    1006             : 
    1007         346 :         zend_exception_save(TSRMLS_C);
    1008         346 :         retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC);
    1009         340 :         zend_exception_restore(TSRMLS_C);
    1010             : 
    1011         340 :         EG(autoload_func) = fcall_cache.function_handler;
    1012             : 
    1013         340 :         zval_ptr_dtor(&class_name_ptr);
    1014             : 
    1015         340 :         zend_hash_quick_del(EG(in_autoload), lc_name, lc_length, hash);
    1016             : 
    1017         340 :         if (retval_ptr) {
    1018         178 :                 zval_ptr_dtor(&retval_ptr);
    1019             :         }
    1020             : 
    1021         340 :         if (retval == SUCCESS) {
    1022         201 :                 retval = zend_hash_quick_find(EG(class_table), lc_name, lc_length, hash, (void **) ce);
    1023             :         }
    1024         340 :         if (!key) {
    1025         271 :                 free_alloca(lc_free, use_heap);
    1026             :         }
    1027         340 :         return retval;
    1028             : }
    1029             : /* }}} */
    1030             : 
    1031      135933 : ZEND_API int zend_lookup_class(const char *name, int name_length, zend_class_entry ***ce TSRMLS_DC) /* {{{ */
    1032             : {
    1033      135933 :         return zend_lookup_class_ex(name, name_length, NULL, 1, ce TSRMLS_CC);
    1034             : }
    1035             : /* }}} */
    1036             : 
    1037         164 : ZEND_API int zend_eval_stringl(char *str, int str_len, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
    1038             : {
    1039             :         zval pv;
    1040             :         zend_op_array *new_op_array;
    1041         164 :         zend_op_array *original_active_op_array = EG(active_op_array);
    1042             :         zend_uint original_compiler_options;
    1043             :         int retval;
    1044             : 
    1045         164 :         if (retval_ptr) {
    1046          75 :                 Z_STRLEN(pv) = str_len + sizeof("return ;") - 1;
    1047          75 :                 Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1);
    1048          75 :                 memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
    1049          75 :                 memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
    1050          75 :                 Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
    1051          75 :                 Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
    1052             :         } else {
    1053          89 :                 Z_STRLEN(pv) = str_len;
    1054          89 :                 Z_STRVAL(pv) = str;
    1055             :         }
    1056         164 :         Z_TYPE(pv) = IS_STRING;
    1057             : 
    1058             :         /*printf("Evaluating '%s'\n", pv.value.str.val);*/
    1059             : 
    1060         164 :         original_compiler_options = CG(compiler_options);
    1061         164 :         CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
    1062         164 :         new_op_array = zend_compile_string(&pv, string_name TSRMLS_CC);
    1063         164 :         CG(compiler_options) = original_compiler_options;
    1064             : 
    1065         164 :         if (new_op_array) {
    1066         155 :                 zval *local_retval_ptr=NULL;
    1067         155 :                 zval **original_return_value_ptr_ptr = EG(return_value_ptr_ptr);
    1068         155 :                 zend_op **original_opline_ptr = EG(opline_ptr);
    1069         155 :                 int orig_interactive = CG(interactive);
    1070             : 
    1071         155 :                 EG(return_value_ptr_ptr) = &local_retval_ptr;
    1072         155 :                 EG(active_op_array) = new_op_array;
    1073         155 :                 EG(no_extensions)=1;
    1074         155 :                 if (!EG(active_symbol_table)) {
    1075           2 :                         zend_rebuild_symbol_table(TSRMLS_C);
    1076             :                 }
    1077         155 :                 CG(interactive) = 0;
    1078             : 
    1079         155 :                 zend_try {
    1080         155 :                         zend_execute(new_op_array TSRMLS_CC);
    1081           1 :                 } zend_catch {
    1082           1 :                         destroy_op_array(new_op_array TSRMLS_CC);
    1083           1 :                         efree(new_op_array);
    1084           1 :                         zend_bailout();
    1085         154 :                 } zend_end_try();
    1086             : 
    1087         154 :                 CG(interactive) = orig_interactive;
    1088         154 :                 if (local_retval_ptr) {
    1089         154 :                         if (retval_ptr) {
    1090         204 :                                 COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
    1091             :                         } else {
    1092          86 :                                 zval_ptr_dtor(&local_retval_ptr);
    1093             :                         }
    1094             :                 } else {
    1095           0 :                         if (retval_ptr) {
    1096           0 :                                 INIT_ZVAL(*retval_ptr);
    1097             :                         }
    1098             :                 }
    1099             : 
    1100         154 :                 EG(no_extensions)=0;
    1101         154 :                 EG(opline_ptr) = original_opline_ptr;
    1102         154 :                 EG(active_op_array) = original_active_op_array;
    1103         154 :                 destroy_op_array(new_op_array TSRMLS_CC);
    1104         154 :                 efree(new_op_array);
    1105         154 :                 EG(return_value_ptr_ptr) = original_return_value_ptr_ptr;
    1106         154 :                 retval = SUCCESS;
    1107             :         } else {
    1108           9 :                 retval = FAILURE;
    1109             :         }
    1110         163 :         if (retval_ptr) {
    1111             :                 zval_dtor(&pv);
    1112             :         }
    1113         163 :         return retval;
    1114             : }
    1115             : /* }}} */
    1116             : 
    1117           0 : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
    1118             : {
    1119           0 :         return zend_eval_stringl(str, strlen(str), retval_ptr, string_name TSRMLS_CC);
    1120             : }
    1121             : /* }}} */
    1122             : 
    1123          23 : ZEND_API int zend_eval_stringl_ex(char *str, int str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
    1124             : {
    1125             :         int result;
    1126             : 
    1127          23 :         result = zend_eval_stringl(str, str_len, retval_ptr, string_name TSRMLS_CC);
    1128          22 :         if (handle_exceptions && EG(exception)) {
    1129           0 :                 zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1130           0 :                 result = FAILURE;
    1131             :         }
    1132          22 :         return result;
    1133             : }
    1134             : /* }}} */
    1135             : 
    1136          23 : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
    1137             : {
    1138          23 :         return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions TSRMLS_CC);
    1139             : }
    1140             : /* }}} */
    1141             : 
    1142           0 : void execute_new_code(TSRMLS_D) /* {{{ */
    1143             : {
    1144             :         zend_op *opline, *end;
    1145             :         zend_op *ret_opline;
    1146             :         int orig_interactive;
    1147             : 
    1148           0 :         if (!(CG(active_op_array)->fn_flags & ZEND_ACC_INTERACTIVE)
    1149             :                 || CG(context).backpatch_count>0
    1150           0 :                 || CG(active_op_array)->function_name
    1151           0 :                 || CG(active_op_array)->type!=ZEND_USER_FUNCTION) {
    1152           0 :                 return;
    1153             :         }
    1154             : 
    1155           0 :         ret_opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1156           0 :         ret_opline->opcode = ZEND_RETURN;
    1157           0 :         ret_opline->op1_type = IS_CONST;
    1158           0 :         ret_opline->op1.constant = zend_add_literal(CG(active_op_array), &EG(uninitialized_zval) TSRMLS_CC);
    1159           0 :         SET_UNUSED(ret_opline->op2);
    1160             : 
    1161           0 :         if (!EG(start_op)) {
    1162           0 :                 EG(start_op) = CG(active_op_array)->opcodes;
    1163             :         }
    1164             : 
    1165           0 :         opline=EG(start_op);
    1166           0 :         end=CG(active_op_array)->opcodes+CG(active_op_array)->last;
    1167             : 
    1168           0 :         while (opline<end) {
    1169           0 :                 if (opline->op1_type == IS_CONST) {
    1170           0 :                         opline->op1.zv = &CG(active_op_array)->literals[opline->op1.constant].constant;
    1171             :                 }
    1172           0 :                 if (opline->op2_type == IS_CONST) {
    1173           0 :                         opline->op2.zv = &CG(active_op_array)->literals[opline->op2.constant].constant;
    1174             :                 }
    1175           0 :                 switch (opline->opcode) {
    1176             :                         case ZEND_GOTO:
    1177           0 :                                 if (Z_TYPE_P(opline->op2.zv) != IS_LONG) {
    1178           0 :                                         zend_resolve_goto_label(CG(active_op_array), opline, 1 TSRMLS_CC);
    1179             :                                 }
    1180             :                                 /* break omitted intentionally */
    1181             :                         case ZEND_JMP:
    1182           0 :                                 opline->op1.jmp_addr = &CG(active_op_array)->opcodes[opline->op1.opline_num];
    1183           0 :                                 break;
    1184             :                         case ZEND_JMPZ:
    1185             :                         case ZEND_JMPNZ:
    1186             :                         case ZEND_JMPZ_EX:
    1187             :                         case ZEND_JMPNZ_EX:
    1188             :                         case ZEND_JMP_SET:
    1189             :                         case ZEND_JMP_SET_VAR:
    1190           0 :                                 opline->op2.jmp_addr = &CG(active_op_array)->opcodes[opline->op2.opline_num];
    1191             :                                 break;
    1192             :                 }
    1193           0 :                 ZEND_VM_SET_OPCODE_HANDLER(opline);
    1194           0 :                 opline++;
    1195             :         }
    1196             : 
    1197           0 :         zend_release_labels(1 TSRMLS_CC);
    1198             : 
    1199           0 :         EG(return_value_ptr_ptr) = NULL;
    1200           0 :         EG(active_op_array) = CG(active_op_array);
    1201           0 :         orig_interactive = CG(interactive);
    1202           0 :         CG(interactive) = 0;
    1203           0 :         zend_execute(CG(active_op_array) TSRMLS_CC);
    1204           0 :         CG(interactive) = orig_interactive;
    1205             : 
    1206           0 :         if (EG(exception)) {
    1207           0 :                 zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1208             :         }
    1209             : 
    1210           0 :         CG(active_op_array)->last -= 1;      /* get rid of that ZEND_RETURN */
    1211           0 :         EG(start_op) = CG(active_op_array)->opcodes+CG(active_op_array)->last;
    1212             : }
    1213             : /* }}} */
    1214             : 
    1215           3 : ZEND_API void zend_timeout(int dummy) /* {{{ */
    1216             : {
    1217             :         TSRMLS_FETCH();
    1218             : 
    1219           3 :         if (zend_on_timeout) {
    1220             : #ifdef ZEND_SIGNALS
    1221             :                 /*
    1222             :                    We got here because we got a timeout signal, so we are in a signal handler
    1223             :                    at this point. However, we want to be able to timeout any user-supplied
    1224             :                    shutdown functions, so pretend we are not in a signal handler while we are
    1225             :                    calling these
    1226             :                 */
    1227             :                 SIGG(running) = 0;
    1228             : #endif
    1229           3 :                 zend_on_timeout(EG(timeout_seconds) TSRMLS_CC);
    1230             :         }
    1231             : 
    1232           3 :         zend_error(E_ERROR, "Maximum execution time of %d second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
    1233           0 : }
    1234             : /* }}} */
    1235             : 
    1236             : #ifdef ZEND_WIN32
    1237             : static LRESULT CALLBACK zend_timeout_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) /* {{{ */
    1238             : {
    1239             :         switch (message) {
    1240             :                 case WM_DESTROY:
    1241             :                         PostQuitMessage(0);
    1242             :                         break;
    1243             :                 case WM_REGISTER_ZEND_TIMEOUT:
    1244             :                         /* wParam is the thread id pointer, lParam is the timeout amount in seconds */
    1245             :                         if (lParam == 0) {
    1246             :                                 KillTimer(timeout_window, wParam);
    1247             :                         } else {
    1248             : #ifdef ZTS
    1249             :                                 void ***tsrm_ls;
    1250             : #endif
    1251             :                                 SetTimer(timeout_window, wParam, lParam*1000, NULL);
    1252             : #ifdef ZTS
    1253             :                                 tsrm_ls = ts_resource_ex(0, &wParam);
    1254             :                                 if (!tsrm_ls) {
    1255             :                                         /* shouldn't normally happen */
    1256             :                                         break;
    1257             :                                 }
    1258             : #endif
    1259             :                                 EG(timed_out) = 0;
    1260             :                         }
    1261             :                         break;
    1262             :                 case WM_UNREGISTER_ZEND_TIMEOUT:
    1263             :                         /* wParam is the thread id pointer */
    1264             :                         KillTimer(timeout_window, wParam);
    1265             :                         break;
    1266             :                 case WM_TIMER: {
    1267             : #ifdef ZTS
    1268             :                                 void ***tsrm_ls;
    1269             : 
    1270             :                                 tsrm_ls = ts_resource_ex(0, &wParam);
    1271             :                                 if (!tsrm_ls) {
    1272             :                                         /* Thread died before receiving its timeout? */
    1273             :                                         break;
    1274             :                                 }
    1275             : #endif
    1276             :                                 KillTimer(timeout_window, wParam);
    1277             :                                 EG(timed_out) = 1;
    1278             :                         }
    1279             :                         break;
    1280             :                 default:
    1281             :                         return DefWindowProc(hWnd, message, wParam, lParam);
    1282             :         }
    1283             :         return 0;
    1284             : }
    1285             : /* }}} */
    1286             : 
    1287             : static unsigned __stdcall timeout_thread_proc(void *pArgs) /* {{{ */
    1288             : {
    1289             :         MSG message;
    1290             : 
    1291             :         wc.style=0;
    1292             :         wc.lpfnWndProc = zend_timeout_WndProc;
    1293             :         wc.cbClsExtra=0;
    1294             :         wc.cbWndExtra=0;
    1295             :         wc.hInstance=NULL;
    1296             :         wc.hIcon=NULL;
    1297             :         wc.hCursor=NULL;
    1298             :         wc.hbrBackground=(HBRUSH)(COLOR_BACKGROUND + 5);
    1299             :         wc.lpszMenuName=NULL;
    1300             :         wc.lpszClassName = "Zend Timeout Window";
    1301             :         if (!RegisterClass(&wc)) {
    1302             :                 return -1;
    1303             :         }
    1304             :         timeout_window = CreateWindow(wc.lpszClassName, wc.lpszClassName, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
    1305             :         SetEvent(timeout_thread_event);
    1306             :         while (GetMessage(&message, NULL, 0, 0)) {
    1307             :                 SendMessage(timeout_window, message.message, message.wParam, message.lParam);
    1308             :                 if (message.message == WM_QUIT) {
    1309             :                         break;
    1310             :                 }
    1311             :         }
    1312             :         DestroyWindow(timeout_window);
    1313             :         UnregisterClass(wc.lpszClassName, NULL);
    1314             :         SetEvent(timeout_thread_handle);
    1315             :         return 0;
    1316             : }
    1317             : /* }}} */
    1318             : 
    1319             : void zend_init_timeout_thread(void) /* {{{ */
    1320             : {
    1321             :         timeout_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
    1322             :         timeout_thread_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
    1323             :         _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id);
    1324             :         WaitForSingleObject(timeout_thread_event, INFINITE);
    1325             : }
    1326             : /* }}} */
    1327             : 
    1328             : void zend_shutdown_timeout_thread(void) /* {{{ */
    1329             : {
    1330             :         if (!timeout_thread_initialized) {
    1331             :                 return;
    1332             :         }
    1333             :         PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0);
    1334             : 
    1335             :         /* Wait for thread termination */
    1336             :         WaitForSingleObject(timeout_thread_handle, 5000);
    1337             :         CloseHandle(timeout_thread_handle);
    1338             :         timeout_thread_initialized = 0;
    1339             : }
    1340             : /* }}} */
    1341             : 
    1342             : #endif
    1343             : 
    1344             : /* This one doesn't exists on QNX */
    1345             : #ifndef SIGPROF
    1346             : #define SIGPROF 27
    1347             : #endif
    1348             : 
    1349       21252 : void zend_set_timeout(long seconds, int reset_signals) /* {{{ */
    1350             : {
    1351             :         TSRMLS_FETCH();
    1352             : 
    1353       21252 :         EG(timeout_seconds) = seconds;
    1354             : 
    1355             : #ifdef ZEND_WIN32
    1356             :         if(!seconds) {
    1357             :                 return;
    1358             :         }
    1359             :         if (timeout_thread_initialized == 0 && InterlockedIncrement(&timeout_thread_initialized) == 1) {
    1360             :                 /* We start up this process-wide thread here and not in zend_startup(), because if Zend
    1361             :                  * is initialized inside a DllMain(), you're not supposed to start threads from it.
    1362             :                  */
    1363             :                 zend_init_timeout_thread();
    1364             :         }
    1365             :         PostThreadMessage(timeout_thread_id, WM_REGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) seconds);
    1366             : #else
    1367             : #       ifdef HAVE_SETITIMER
    1368             :         {
    1369             :                 struct itimerval t_r;           /* timeout requested */
    1370             :                 int signo;
    1371             : 
    1372       21252 :                 if(seconds) {
    1373         446 :                         t_r.it_value.tv_sec = seconds;
    1374         446 :                         t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
    1375             : 
    1376             : #       ifdef __CYGWIN__
    1377             :                         setitimer(ITIMER_REAL, &t_r, NULL);
    1378             :                 }
    1379             :                 signo = SIGALRM;
    1380             : #       else
    1381         446 :                         setitimer(ITIMER_PROF, &t_r, NULL);
    1382             :                 }
    1383       21252 :                 signo = SIGPROF;
    1384             : #       endif
    1385             : 
    1386       21252 :                 if (reset_signals) {
    1387             : #       ifdef ZEND_SIGNALS
    1388             :                         zend_signal(signo, zend_timeout TSRMLS_CC);
    1389             : #       else
    1390             :                         sigset_t sigset;
    1391             : 
    1392       21217 :                         signal(signo, zend_timeout);
    1393       21217 :                         sigemptyset(&sigset);
    1394       21217 :                         sigaddset(&sigset, signo);
    1395       21217 :                         sigprocmask(SIG_UNBLOCK, &sigset, NULL);
    1396             : #       endif
    1397             :                 }
    1398             :         }
    1399             : #       endif /* HAVE_SETITIMER */
    1400             : #endif
    1401       21252 : }
    1402             : /* }}} */
    1403             : 
    1404       42533 : void zend_unset_timeout(TSRMLS_D) /* {{{ */
    1405             : {
    1406             : #ifdef ZEND_WIN32
    1407             :         if(timeout_thread_initialized) {
    1408             :                 PostThreadMessage(timeout_thread_id, WM_UNREGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) 0);
    1409             :         }
    1410             : #else
    1411             : #       ifdef HAVE_SETITIMER
    1412       42533 :         if (EG(timeout_seconds)) {
    1413             :                 struct itimerval no_timeout;
    1414             : 
    1415         876 :                 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;
    1416             : 
    1417             : #ifdef __CYGWIN__
    1418             :                 setitimer(ITIMER_REAL, &no_timeout, NULL);
    1419             : #else
    1420         876 :                 setitimer(ITIMER_PROF, &no_timeout, NULL);
    1421             : #endif
    1422             :         }
    1423             : #       endif
    1424             : #endif
    1425       42533 : }
    1426             : /* }}} */
    1427             : 
    1428       93654 : zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len, int fetch_type TSRMLS_DC) /* {{{ */
    1429             : {
    1430             :         zend_class_entry **pce;
    1431       93654 :         int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
    1432       93654 :         int silent       = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
    1433             : 
    1434       93654 :         fetch_type &= ZEND_FETCH_CLASS_MASK;
    1435             : 
    1436             : check_fetch_type:
    1437       93660 :         switch (fetch_type) {
    1438             :                 case ZEND_FETCH_CLASS_SELF:
    1439        1703 :                         if (!EG(scope)) {
    1440           0 :                                 zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
    1441             :                         }
    1442        1703 :                         return EG(scope);
    1443             :                 case ZEND_FETCH_CLASS_PARENT:
    1444        1288 :                         if (!EG(scope)) {
    1445           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
    1446             :                         }
    1447        1288 :                         if (!EG(scope)->parent) {
    1448           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
    1449             :                         }
    1450        1288 :                         return EG(scope)->parent;
    1451             :                 case ZEND_FETCH_CLASS_STATIC:
    1452         111 :                         if (!EG(called_scope)) {
    1453           0 :                                 zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
    1454             :                         }
    1455         111 :                         return EG(called_scope);
    1456             :                 case ZEND_FETCH_CLASS_AUTO: {
    1457       89129 :                                 fetch_type = zend_get_class_fetch_type(class_name, class_name_len);
    1458       89129 :                                 if (fetch_type!=ZEND_FETCH_CLASS_DEFAULT) {
    1459           6 :                                         goto check_fetch_type;
    1460             :                                 }
    1461             :                         }
    1462             :                         break;
    1463             :         }
    1464             : 
    1465       90552 :         if (zend_lookup_class_ex(class_name, class_name_len, NULL, use_autoload, &pce TSRMLS_CC) == FAILURE) {
    1466          21 :                 if (use_autoload) {
    1467          16 :                         if (!silent && !EG(exception)) {
    1468          13 :                                 if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
    1469           0 :                                         zend_error(E_ERROR, "Interface '%s' not found", class_name);
    1470          13 :                                 } else if (fetch_type == ZEND_FETCH_CLASS_TRAIT) {
    1471           0 :                         zend_error(E_ERROR, "Trait '%s' not found", class_name);
    1472             :                 } else {
    1473          13 :                                         zend_error(E_ERROR, "Class '%s' not found", class_name);
    1474             :                                 }
    1475             :                         }
    1476             :                 }
    1477           8 :                 return NULL;
    1478             :         }
    1479       90530 :         return *pce;
    1480             : }
    1481             : /* }}} */
    1482             : 
    1483       26014 : zend_class_entry *zend_fetch_class_by_name(const char *class_name, uint class_name_len, const zend_literal *key, int fetch_type TSRMLS_DC) /* {{{ */
    1484             : {
    1485             :         zend_class_entry **pce;
    1486       26014 :         int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
    1487             : 
    1488       26014 :         if (zend_lookup_class_ex(class_name, class_name_len, key, use_autoload, &pce TSRMLS_CC) == FAILURE) {
    1489          29 :                 if (use_autoload) {
    1490          24 :                         if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) {
    1491          16 :                                 if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
    1492           2 :                                         zend_error(E_ERROR, "Interface '%s' not found", class_name);
    1493          14 :                                 } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
    1494           2 :                                         zend_error(E_ERROR, "Trait '%s' not found", class_name);
    1495             :                                 } else {
    1496          12 :                                         zend_error(E_ERROR, "Class '%s' not found", class_name);
    1497             :                                 }
    1498             :                         }
    1499             :                 }
    1500          13 :                 return NULL;
    1501             :         }
    1502       25981 :         return *pce;
    1503             : }
    1504             : /* }}} */
    1505             : 
    1506             : #define MAX_ABSTRACT_INFO_CNT 3
    1507             : #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
    1508             : #define DISPLAY_ABSTRACT_FN(idx) \
    1509             :         ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
    1510             :         ai.afn[idx] ? "::" : "", \
    1511             :         ai.afn[idx] ? ai.afn[idx]->common.function_name : "", \
    1512             :         ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
    1513             : 
    1514             : typedef struct _zend_abstract_info {
    1515             :         zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
    1516             :         int cnt;
    1517             :         int ctor;
    1518             : } zend_abstract_info;
    1519             : 
    1520          43 : static int zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai TSRMLS_DC) /* {{{ */
    1521             : {
    1522          43 :         if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
    1523          14 :                 if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
    1524          14 :                         ai->afn[ai->cnt] = fn;
    1525             :                 }
    1526          14 :                 if (fn->common.fn_flags & ZEND_ACC_CTOR) {
    1527           1 :                         if (!ai->ctor) {
    1528           1 :                                 ai->cnt++;
    1529           1 :                                 ai->ctor = 1;
    1530             :                         } else {
    1531           0 :                                 ai->afn[ai->cnt] = NULL;
    1532             :                         }
    1533             :                 } else {
    1534          13 :                         ai->cnt++;
    1535             :                 }
    1536             :         }
    1537          43 :         return 0;
    1538             : }
    1539             : /* }}} */
    1540             : 
    1541     1480725 : void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC) /* {{{ */
    1542             : {
    1543             :         zend_abstract_info ai;
    1544             : 
    1545     1480725 :         if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
    1546          23 :                 memset(&ai, 0, sizeof(ai));
    1547             : 
    1548          23 :                 zend_hash_apply_with_argument(&ce->function_table, (apply_func_arg_t) zend_verify_abstract_class_function, &ai TSRMLS_CC);
    1549             : 
    1550          23 :                 if (ai.cnt) {
    1551         249 :                         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 ")",
    1552             :                                 ce->name, ai.cnt,
    1553          13 :                                 ai.cnt > 1 ? "s" : "",
    1554         103 :                                 DISPLAY_ABSTRACT_FN(0),
    1555          68 :                                 DISPLAY_ABSTRACT_FN(1),
    1556          65 :                                 DISPLAY_ABSTRACT_FN(2)
    1557             :                                 );
    1558             :                 }
    1559             :         }
    1560     1480712 : }
    1561             : /* }}} */
    1562             : 
    1563           1 : ZEND_API void zend_reset_all_cv(HashTable *symbol_table TSRMLS_DC) /* {{{ */
    1564             : {
    1565             :         zend_execute_data *ex;
    1566             :         int i;
    1567             : 
    1568           3 :         for (ex = EG(current_execute_data); ex; ex = ex->prev_execute_data) {
    1569           2 :                 if (ex->op_array && ex->symbol_table == symbol_table) {
    1570           1 :                         for (i = 0; i < ex->op_array->last_var; i++) {
    1571           0 :                                 *EX_CV_NUM(ex, i) = NULL;
    1572             :                         }
    1573             :                 }
    1574             :         }
    1575           1 : }
    1576             : /* }}} */
    1577             : 
    1578       23168 : ZEND_API void zend_delete_variable(zend_execute_data *ex, HashTable *ht, const char *name, int name_len, ulong hash_value TSRMLS_DC) /* {{{ */
    1579             : {
    1580       23168 :         if (zend_hash_quick_del(ht, name, name_len, hash_value) == SUCCESS) {
    1581       23101 :                 name_len--;
    1582       46214 :                 while (ex && ex->symbol_table == ht) {
    1583             :                         int i;
    1584             : 
    1585          12 :                         if (ex->op_array) {
    1586          26 :                                 for (i = 0; i < ex->op_array->last_var; i++) {
    1587          26 :                                         if (ex->op_array->vars[i].hash_value == hash_value &&
    1588           4 :                                                 ex->op_array->vars[i].name_len == name_len &&
    1589           4 :                                                 !memcmp(ex->op_array->vars[i].name, name, name_len)) {
    1590           4 :                                                 *EX_CV_NUM(ex, i) = NULL;
    1591           4 :                                                 break;
    1592             :                                         }
    1593             :                                 }
    1594             :                         }
    1595          12 :                         ex = ex->prev_execute_data;
    1596             :                 }
    1597             :         }
    1598       23166 : }
    1599             : /* }}} */
    1600             : 
    1601         363 : ZEND_API int zend_delete_global_variable_ex(const char *name, int name_len, ulong hash_value TSRMLS_DC) /* {{{ */
    1602             : {
    1603             :         zend_execute_data *ex;
    1604             : 
    1605         363 :         if (zend_hash_quick_exists(&EG(symbol_table), name, name_len + 1, hash_value)) {
    1606         370 :                 for (ex = EG(current_execute_data); ex; ex = ex->prev_execute_data) {
    1607         185 :                         if (ex->op_array && ex->symbol_table == &EG(symbol_table)) {
    1608             :                                 int i;
    1609         532 :                                 for (i = 0; i < ex->op_array->last_var; i++) {
    1610         393 :                                         if (ex->op_array->vars[i].hash_value == hash_value &&
    1611          12 :                                                 ex->op_array->vars[i].name_len == name_len &&
    1612          12 :                                                 !memcmp(ex->op_array->vars[i].name, name, name_len)
    1613             :                                         ) {
    1614          12 :                                                 *EX_CV_NUM(ex, i) = NULL;
    1615          12 :                                                 break;
    1616             :                                         }
    1617             :                                 }
    1618             :                         }
    1619             :                 }
    1620         185 :                 return zend_hash_quick_del(&EG(symbol_table), name, name_len + 1, hash_value);
    1621             :         }
    1622         178 :         return FAILURE;
    1623             : }
    1624             : /* }}} */
    1625             : 
    1626         351 : ZEND_API int zend_delete_global_variable(const char *name, int name_len TSRMLS_DC) /* {{{ */
    1627             : {
    1628         351 :         return zend_delete_global_variable_ex(name, name_len, zend_inline_hash_func(name, name_len + 1) TSRMLS_CC);
    1629             : }
    1630             : /* }}} */
    1631             : 
    1632       37119 : ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
    1633             : {
    1634             :         zend_uint i;
    1635             :         zend_execute_data *ex;
    1636             : 
    1637       37119 :         if (!EG(active_symbol_table)) {
    1638             : 
    1639             :                 /* Search for last called user function */
    1640       37119 :                 ex = EG(current_execute_data);
    1641       74247 :                 while (ex && !ex->op_array) {
    1642           9 :                         ex = ex->prev_execute_data;
    1643             :                 }
    1644       37119 :                 if (ex && ex->symbol_table) {
    1645           0 :                         EG(active_symbol_table) = ex->symbol_table;
    1646           0 :                         return;
    1647             :                 }
    1648             : 
    1649       37119 :                 if (ex && ex->op_array) {
    1650       37117 :                         if (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
    1651             :                                 /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
    1652       36292 :                                 EG(active_symbol_table) = *(EG(symtable_cache_ptr)--);
    1653             :                         } else {
    1654         825 :                                 ALLOC_HASHTABLE(EG(active_symbol_table));
    1655         825 :                                 zend_hash_init(EG(active_symbol_table), ex->op_array->last_var, NULL, ZVAL_PTR_DTOR, 0);
    1656             :                                 /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
    1657             :                         }
    1658       37117 :                         ex->symbol_table = EG(active_symbol_table);
    1659             : 
    1660       37178 :                         if (ex->op_array->this_var != -1 &&
    1661          47 :                             !*EX_CV_NUM(ex, ex->op_array->this_var) &&
    1662          14 :                             EG(This)) {
    1663           0 :                             *EX_CV_NUM(ex, ex->op_array->this_var) = (zval**)EX_CV_NUM(ex, ex->op_array->last_var + ex->op_array->this_var);
    1664           0 :                                 **EX_CV_NUM(ex, ex->op_array->this_var) = EG(This);
    1665             :                         }
    1666     1893177 :                         for (i = 0; i < ex->op_array->last_var; i++) {
    1667     1856060 :                                 if (*EX_CV_NUM(ex, i)) {
    1668      761891 :                                         zend_hash_quick_update(EG(active_symbol_table),
    1669             :                                                 ex->op_array->vars[i].name,
    1670             :                                                 ex->op_array->vars[i].name_len + 1,
    1671             :                                                 ex->op_array->vars[i].hash_value,
    1672             :                                                 (void**)*EX_CV_NUM(ex, i),
    1673             :                                                 sizeof(zval*),
    1674             :                                                 (void**)EX_CV_NUM(ex, i));
    1675             :                                 }
    1676             :                         }
    1677             :                 }
    1678             :         }
    1679             : }
    1680             : /* }}} */
    1681             : 
    1682             : /*
    1683             :  * Local variables:
    1684             :  * tab-width: 4
    1685             :  * c-basic-offset: 4
    1686             :  * indent-tabs-mode: t
    1687             :  * End:
    1688             :  */

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:06 +0000 (4 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.