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: 671 789 85.0 %
Date: 2016-08-28 Functions: 44 49 89.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2016 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             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #include <stdio.h>
      24             : #include <signal.h>
      25             : 
      26             : #include "zend.h"
      27             : #include "zend_compile.h"
      28             : #include "zend_execute.h"
      29             : #include "zend_API.h"
      30             : #include "zend_stack.h"
      31             : #include "zend_constants.h"
      32             : #include "zend_extensions.h"
      33             : #include "zend_exceptions.h"
      34             : #include "zend_closures.h"
      35             : #include "zend_generators.h"
      36             : #include "zend_vm.h"
      37             : #include "zend_float.h"
      38             : #ifdef HAVE_SYS_TIME_H
      39             : #include <sys/time.h>
      40             : #endif
      41             : #ifdef HAVE_UNISTD_H
      42             : #include <unistd.h>
      43             : #endif
      44             : 
      45             : ZEND_API void (*zend_execute_ex)(zend_execute_data *execute_data);
      46             : ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
      47             : 
      48             : /* true globals */
      49             : ZEND_API const zend_fcall_info empty_fcall_info = { 0, {{0}, {{0}}, {0}}, NULL, NULL, NULL, 0, 0 };
      50             : ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL };
      51             : 
      52             : #ifdef ZEND_WIN32
      53             : ZEND_TLS HANDLE tq_timer = NULL;
      54             : #endif
      55             : 
      56             : #if 0&&ZEND_DEBUG
      57             : static void (*original_sigsegv_handler)(int);
      58             : static void zend_handle_sigsegv(int dummy) /* {{{ */
      59             : {
      60             :         fflush(stdout);
      61             :         fflush(stderr);
      62             :         if (original_sigsegv_handler == zend_handle_sigsegv) {
      63             :                 signal(SIGSEGV, original_sigsegv_handler);
      64             :         } else {
      65             :                 signal(SIGSEGV, SIG_DFL);
      66             :         }
      67             :         {
      68             : 
      69             :                 fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
      70             :                                 active_opline->opcode,
      71             :                                 active_opline-EG(active_op_array)->opcodes,
      72             :                                 get_active_function_name(),
      73             :                                 zend_get_executed_filename(),
      74             :                                 zend_get_executed_lineno());
      75             : /* See http://support.microsoft.com/kb/190351 */
      76             : #ifdef ZEND_WIN32
      77             :                 fflush(stderr);
      78             : #endif
      79             :         }
      80             :         if (original_sigsegv_handler!=zend_handle_sigsegv) {
      81             :                 original_sigsegv_handler(dummy);
      82             :         }
      83             : }
      84             : /* }}} */
      85             : #endif
      86             : 
      87       23326 : static void zend_extension_activator(zend_extension *extension) /* {{{ */
      88             : {
      89       23326 :         if (extension->activate) {
      90         380 :                 extension->activate();
      91             :         }
      92       23326 : }
      93             : /* }}} */
      94             : 
      95       23371 : static void zend_extension_deactivator(zend_extension *extension) /* {{{ */
      96             : {
      97       23371 :         if (extension->deactivate) {
      98         380 :                 extension->deactivate();
      99             :         }
     100       23371 : }
     101             : /* }}} */
     102             : 
     103       48008 : static int clean_non_persistent_function(zval *zv) /* {{{ */
     104             : {
     105       48008 :         zend_function *function = Z_PTR_P(zv);
     106       48008 :         return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
     107             : }
     108             : /* }}} */
     109             : 
     110           0 : ZEND_API int clean_non_persistent_function_full(zval *zv) /* {{{ */
     111             : {
     112           0 :         zend_function *function = Z_PTR_P(zv);
     113           0 :         return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
     114             : }
     115             : /* }}} */
     116             : 
     117       33424 : static int clean_non_persistent_class(zval *zv) /* {{{ */
     118             : {
     119       33424 :         zend_class_entry *ce = Z_PTR_P(zv);
     120       33424 :         return (ce->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
     121             : }
     122             : /* }}} */
     123             : 
     124           0 : ZEND_API int clean_non_persistent_class_full(zval *zv) /* {{{ */
     125             : {
     126           0 :         zend_class_entry *ce = Z_PTR_P(zv);
     127           0 :         return (ce->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
     128             : }
     129             : /* }}} */
     130             : 
     131       23458 : void init_executor(void) /* {{{ */
     132             : {
     133       23458 :         zend_init_fpu();
     134             : 
     135       23458 :         ZVAL_NULL(&EG(uninitialized_zval));
     136       23458 :         ZVAL_ERROR(&EG(error_zval));
     137             : /* destroys stack frame, therefore makes core dumps worthless */
     138             : #if 0&&ZEND_DEBUG
     139             :         original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
     140             : #endif
     141             : 
     142       23458 :         EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
     143       23458 :         EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
     144       23458 :         EG(no_extensions) = 0;
     145             : 
     146       23458 :         EG(function_table) = CG(function_table);
     147       23458 :         EG(class_table) = CG(class_table);
     148             : 
     149       23458 :         EG(in_autoload) = NULL;
     150       23458 :         EG(autoload_func) = NULL;
     151       23458 :         EG(error_handling) = EH_NORMAL;
     152             : 
     153       23458 :         zend_vm_stack_init();
     154             : 
     155       23458 :         zend_hash_init(&EG(symbol_table), 64, NULL, ZVAL_PTR_DTOR, 0);
     156       23458 :         EG(valid_symbol_table) = 1;
     157             : 
     158       23458 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator);
     159             : 
     160       23458 :         zend_hash_init(&EG(included_files), 8, NULL, NULL, 0);
     161             : 
     162       23458 :         EG(ticks_count) = 0;
     163             : 
     164       23458 :         ZVAL_UNDEF(&EG(user_error_handler));
     165             : 
     166       23458 :         EG(current_execute_data) = NULL;
     167             : 
     168       23458 :         zend_stack_init(&EG(user_error_handlers_error_reporting), sizeof(int));
     169       23458 :         zend_stack_init(&EG(user_error_handlers), sizeof(zval));
     170       23458 :         zend_stack_init(&EG(user_exception_handlers), sizeof(zval));
     171             : 
     172       23458 :         zend_objects_store_init(&EG(objects_store), 1024);
     173             : 
     174       23458 :         EG(full_tables_cleanup) = 0;
     175       23458 :         EG(vm_interrupt) = 0;
     176       23458 :         EG(timed_out) = 0;
     177             : 
     178       23458 :         EG(exception) = NULL;
     179       23458 :         EG(prev_exception) = NULL;
     180             : 
     181       23458 :         EG(fake_scope) = NULL;
     182             : 
     183       23458 :         EG(ht_iterators_count) = sizeof(EG(ht_iterators_slots)) / sizeof(HashTableIterator);
     184       23458 :         EG(ht_iterators_used) = 0;
     185       23458 :         EG(ht_iterators) = EG(ht_iterators_slots);
     186       23458 :         memset(EG(ht_iterators), 0, sizeof(EG(ht_iterators_slots)));
     187             : 
     188       23458 :         EG(active) = 1;
     189       23458 : }
     190             : /* }}} */
     191             : 
     192      400284 : static int zval_call_destructor(zval *zv) /* {{{ */
     193             : {
     194      400284 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     195        2925 :                 zv = Z_INDIRECT_P(zv);
     196             :         }
     197      410508 :         if (Z_TYPE_P(zv) == IS_OBJECT && Z_REFCOUNT_P(zv) == 1) {
     198        9466 :                 return ZEND_HASH_APPLY_REMOVE;
     199             :         } else {
     200      390818 :                 return ZEND_HASH_APPLY_KEEP;
     201             :         }
     202             : }
     203             : /* }}} */
     204             : 
     205       21146 : static void zend_unclean_zval_ptr_dtor(zval *zv) /* {{{ */
     206             : {
     207       21146 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     208        2557 :                 zv = Z_INDIRECT_P(zv);
     209             :         }
     210             :         i_zval_ptr_dtor(zv ZEND_FILE_LINE_CC);
     211       21146 : }
     212             : /* }}} */
     213             : 
     214          49 : static void zend_throw_or_error(int fetch_type, zend_class_entry *exception_ce, const char *format, ...) /* {{{ */
     215             : {
     216             :         va_list va;
     217          49 :         char *message = NULL;
     218             : 
     219          49 :         va_start(va, format);
     220          49 :         zend_vspprintf(&message, 0, format, va);
     221             : 
     222          49 :         if (fetch_type & ZEND_FETCH_CLASS_EXCEPTION) {
     223          36 :                 zend_throw_error(exception_ce, "%s", message);
     224             :         } else {
     225          13 :                 zend_error(E_ERROR, "%s", message);
     226             :         }
     227             : 
     228          36 :         efree(message);
     229          36 :         va_end(va);
     230          36 : }
     231             : /* }}} */
     232             : 
     233       23500 : void shutdown_destructors(void) /* {{{ */
     234             : {
     235       23500 :         if (CG(unclean_shutdown)) {
     236        2380 :                 EG(symbol_table).pDestructor = zend_unclean_zval_ptr_dtor;
     237             :         }
     238       23500 :         zend_try {
     239             :                 uint32_t symbols;
     240             :                 do {
     241       28931 :                         symbols = zend_hash_num_elements(&EG(symbol_table));
     242       28931 :                         zend_hash_reverse_apply(&EG(symbol_table), (apply_func_t) zval_call_destructor);
     243       28931 :                 } while (symbols != zend_hash_num_elements(&EG(symbol_table)));
     244       23500 :                 zend_objects_store_call_destructors(&EG(objects_store));
     245           1 :         } zend_catch {
     246             :                 /* if we couldn't destruct cleanly, mark all objects as destructed anyway */
     247           1 :                 zend_objects_store_mark_destructed(&EG(objects_store));
     248       23500 :         } zend_end_try();
     249       23500 : }
     250             : /* }}} */
     251             : 
     252       23500 : void shutdown_executor(void) /* {{{ */
     253             : {
     254             :         zend_function *func;
     255             :         zend_class_entry *ce;
     256             : 
     257       23500 :         zend_try {
     258             : 
     259             : /* Removed because this can not be safely done, e.g. in this situation:
     260             :    Object 1 creates object 2
     261             :    Object 3 holds reference to object 2.
     262             :    Now when 1 and 2 are destroyed, 3 can still access 2 in its destructor, with
     263             :    very problematic results */
     264             : /*              zend_objects_store_call_destructors(&EG(objects_store)); */
     265             : 
     266             : /* Moved after symbol table cleaners, because  some of the cleaners can call
     267             :    destructors, which would use EG(symtable_cache_ptr) and thus leave leaks */
     268             : /*              while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     269             :                         zend_hash_destroy(*EG(symtable_cache_ptr));
     270             :                         efree(*EG(symtable_cache_ptr));
     271             :                         EG(symtable_cache_ptr)--;
     272             :                 }
     273             : */
     274       23500 :                 zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator);
     275             : 
     276       23500 :                 if (CG(unclean_shutdown)) {
     277        2386 :                         EG(symbol_table).pDestructor = zend_unclean_zval_ptr_dtor;
     278             :                 }
     279       23500 :                 zend_hash_graceful_reverse_destroy(&EG(symbol_table));
     280       23500 :         } zend_end_try();
     281       23500 :         EG(valid_symbol_table) = 0;
     282             : 
     283       23500 :         zend_try {
     284             :                 zval *zeh;
     285             :                 /* remove error handlers before destroying classes and functions,
     286             :                  * so that if handler used some class, crash would not happen */
     287       23500 :                 if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
     288         247 :                         zeh = &EG(user_error_handler);
     289         247 :                         zval_ptr_dtor(zeh);
     290         247 :                         ZVAL_UNDEF(&EG(user_error_handler));
     291             :                 }
     292             : 
     293       23500 :                 if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
     294          11 :                         zeh = &EG(user_exception_handler);
     295          11 :                         zval_ptr_dtor(zeh);
     296          11 :                         ZVAL_UNDEF(&EG(user_exception_handler));
     297             :                 }
     298             : 
     299       23500 :                 zend_stack_clean(&EG(user_error_handlers_error_reporting), NULL, 1);
     300       23500 :                 zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1);
     301       23500 :                 zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1);
     302       23500 :         } zend_end_try();
     303             : 
     304       23500 :         zend_try {
     305             :                 /* Cleanup static data for functions and arrays.
     306             :                  * We need a separate cleanup stage because of the following problem:
     307             :                  * Suppose we destroy class X, which destroys the class's function table,
     308             :                  * and in the function table we have function foo() that has static $bar.
     309             :                  * Now if an object of class X is assigned to $bar, its destructor will be
     310             :                  * called and will fail since X's function table is in mid-destruction.
     311             :                  * So we want first of all to clean up all data and then move to tables destruction.
     312             :                  * Note that only run-time accessed data need to be cleaned up, pre-defined data can
     313             :                  * not contain objects and thus are not probelmatic */
     314       23500 :                 if (EG(full_tables_cleanup)) {
     315           0 :                         ZEND_HASH_FOREACH_PTR(EG(function_table), func) {
     316           0 :                                 if (func->type == ZEND_USER_FUNCTION) {
     317           0 :                                         zend_cleanup_op_array_data((zend_op_array *) func);
     318             :                                 }
     319             :                         } ZEND_HASH_FOREACH_END();
     320           0 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) {
     321           0 :                                 if (ce->type == ZEND_USER_CLASS) {
     322           0 :                                         zend_cleanup_user_class_data(ce);
     323             :                                 } else {
     324           0 :                                         zend_cleanup_internal_class_data(ce);
     325             :                                 }
     326             :                         } ZEND_HASH_FOREACH_END();
     327             :                 } else {
     328      127072 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(function_table), func) {
     329       48008 :                                 if (func->type != ZEND_USER_FUNCTION) {
     330       23500 :                                         break;
     331             :                                 }
     332       24508 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     333             :                         } ZEND_HASH_FOREACH_END();
     334       79128 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) {
     335       33422 :                                 if (ce->type != ZEND_USER_CLASS) {
     336       23498 :                                         break;
     337             :                                 }
     338        9924 :                                 zend_cleanup_user_class_data(ce);
     339             :                         } ZEND_HASH_FOREACH_END();
     340       23498 :                         zend_cleanup_internal_classes();
     341             :                 }
     342       23500 :         } zend_end_try();
     343             : 
     344       23500 :         zend_try {
     345       23500 :                 zend_llist_destroy(&CG(open_files));
     346       23500 :         } zend_end_try();
     347             : 
     348       23500 :         zend_try {
     349       23500 :                 zend_close_rsrc_list(&EG(regular_list));
     350       23500 :         } zend_end_try();
     351             : 
     352             : #if ZEND_DEBUG
     353             :         if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
     354             :                 gc_collect_cycles();
     355             :         }
     356             : #endif
     357             : 
     358       23500 :         zend_try {
     359       23500 :                 zend_objects_store_free_object_storage(&EG(objects_store));
     360             : 
     361       23500 :                 zend_vm_stack_destroy();
     362             : 
     363             :                 /* Destroy all op arrays */
     364       23500 :                 if (EG(full_tables_cleanup)) {
     365           0 :                         zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function_full);
     366           0 :                         zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class_full);
     367             :                 } else {
     368       23500 :                         zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function);
     369       23500 :                         zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class);
     370             :                 }
     371             : 
     372       47258 :                 while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     373         258 :                         zend_hash_destroy(*EG(symtable_cache_ptr));
     374         258 :                         FREE_HASHTABLE(*EG(symtable_cache_ptr));
     375         258 :                         EG(symtable_cache_ptr)--;
     376             :                 }
     377       23500 :         } zend_end_try();
     378             : 
     379       23500 :         zend_try {
     380       23500 :                 clean_non_persistent_constants();
     381       23500 :         } zend_end_try();
     382             : 
     383       23500 :         zend_try {
     384             : #if 0&&ZEND_DEBUG
     385             :         signal(SIGSEGV, original_sigsegv_handler);
     386             : #endif
     387             : 
     388       23500 :                 zend_hash_destroy(&EG(included_files));
     389             : 
     390       23500 :                 zend_stack_destroy(&EG(user_error_handlers_error_reporting));
     391       23500 :                 zend_stack_destroy(&EG(user_error_handlers));
     392       23500 :                 zend_stack_destroy(&EG(user_exception_handlers));
     393       23500 :                 zend_objects_store_destroy(&EG(objects_store));
     394       23500 :                 if (EG(in_autoload)) {
     395          93 :                         zend_hash_destroy(EG(in_autoload));
     396          93 :                         FREE_HASHTABLE(EG(in_autoload));
     397             :                 }
     398       23500 :         } zend_end_try();
     399             : 
     400       23500 :         zend_shutdown_fpu();
     401             : 
     402             : #if ZEND_DEBUG
     403             :         if (EG(ht_iterators_used) && !CG(unclean_shutdown)) {
     404             :                 zend_error(E_WARNING, "Leaked %" PRIu32 " hashtable iterators", EG(ht_iterators_used));
     405             :         }
     406             : #endif
     407             : 
     408       23500 :         EG(ht_iterators_used) = 0;
     409       23500 :         if (EG(ht_iterators) != EG(ht_iterators_slots)) {
     410           0 :                 efree(EG(ht_iterators));
     411             :         }
     412             : 
     413       23500 :         EG(active) = 0;
     414       23500 : }
     415             : /* }}} */
     416             : 
     417             : /* return class name and "::" or "". */
     418      234826 : ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
     419             : {
     420             :         zend_function *func;
     421             : 
     422      234826 :         if (!zend_is_executing()) {
     423           0 :                 if (space) {
     424           0 :                         *space = "";
     425             :                 }
     426           0 :                 return "";
     427             :         }
     428             : 
     429      234826 :         func = EG(current_execute_data)->func;
     430      234826 :         switch (func->type) {
     431             :                 case ZEND_USER_FUNCTION:
     432             :                 case ZEND_INTERNAL_FUNCTION:
     433             :                 {
     434      234826 :                         zend_class_entry *ce = func->common.scope;
     435             : 
     436      234826 :                         if (space) {
     437      234826 :                                 *space = ce ? "::" : "";
     438             :                         }
     439      234826 :                         return ce ? ZSTR_VAL(ce->name) : "";
     440             :                 }
     441             :                 default:
     442           0 :                         if (space) {
     443           0 :                                 *space = "";
     444             :                         }
     445           0 :                         return "";
     446             :         }
     447             : }
     448             : /* }}} */
     449             : 
     450      234850 : ZEND_API const char *get_active_function_name(void) /* {{{ */
     451             : {
     452             :         zend_function *func;
     453             : 
     454      234850 :         if (!zend_is_executing()) {
     455          16 :                 return NULL;
     456             :         }
     457      234834 :         func = EG(current_execute_data)->func;
     458      234834 :         switch (func->type) {
     459             :                 case ZEND_USER_FUNCTION: {
     460         209 :                                 zend_string *function_name = func->common.function_name;
     461             : 
     462         209 :                                 if (function_name) {
     463         150 :                                         return ZSTR_VAL(function_name);
     464             :                                 } else {
     465          59 :                                         return "main";
     466             :                                 }
     467             :                         }
     468             :                         break;
     469             :                 case ZEND_INTERNAL_FUNCTION:
     470      234625 :                         return ZSTR_VAL(func->common.function_name);
     471             :                         break;
     472             :                 default:
     473           0 :                         return NULL;
     474             :         }
     475             : }
     476             : /* }}} */
     477             : 
     478      445784 : ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
     479             : {
     480      445784 :         zend_execute_data *ex = EG(current_execute_data);
     481             : 
     482     1138805 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     483      247237 :                 ex = ex->prev_execute_data;
     484             :         }
     485      445784 :         if (ex) {
     486      445752 :                 return ZSTR_VAL(ex->func->op_array.filename);
     487             :         } else {
     488          32 :                 return "[no active file]";
     489             :         }
     490             : }
     491             : /* }}} */
     492             : 
     493        6586 : ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
     494             : {
     495        6586 :         zend_execute_data *ex = EG(current_execute_data);
     496             : 
     497       13276 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     498         104 :                 ex = ex->prev_execute_data;
     499             :         }
     500        6586 :         if (ex) {
     501        6586 :                 return ex->func->op_array.filename;
     502             :         } else {
     503           0 :                 return NULL;
     504             :         }
     505             : }
     506             : /* }}} */
     507             : 
     508      444963 : ZEND_API uint zend_get_executed_lineno(void) /* {{{ */
     509             : {
     510      444963 :         zend_execute_data *ex = EG(current_execute_data);
     511             : 
     512     1136746 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     513      246820 :                 ex = ex->prev_execute_data;
     514             :         }
     515      444963 :         if (ex) {
     516      444956 :                 if (EG(exception) && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
     517           8 :                     ex->opline->lineno == 0 && EG(opline_before_exception)) {
     518           4 :                         return EG(opline_before_exception)->lineno;
     519             :                 }
     520      444944 :                 return ex->opline->lineno;
     521             :         } else {
     522          15 :                 return 0;
     523             :         }
     524             : }
     525             : /* }}} */
     526             : 
     527        8895 : ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
     528             : {
     529        8895 :         zend_execute_data *ex = EG(current_execute_data);
     530             : 
     531             :         while (1) {
     532        9786 :                 if (!ex) {
     533           9 :                         return NULL;
     534        9777 :                 } else if (ex->func && (ZEND_USER_CODE(ex->func->type) || ex->func->common.scope)) {
     535        8886 :                         return ex->func->common.scope;
     536             :                 }
     537         891 :                 ex = ex->prev_execute_data;
     538         891 :         }
     539             : }
     540             : /* }}} */
     541             : 
     542      943421 : ZEND_API zend_bool zend_is_executing(void) /* {{{ */
     543             : {
     544      943421 :         return EG(current_execute_data) != 0;
     545             : }
     546             : /* }}} */
     547             : 
     548     7971408 : ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     549             : {
     550             :         i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC);
     551     7971408 : }
     552             : /* }}} */
     553             : 
     554    34491960 : ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     555             : {
     556    34491960 :         if (Z_REFCOUNTED_P(zval_ptr)) {
     557             :                 Z_DELREF_P(zval_ptr);
     558     2354400 :                 if (Z_REFCOUNT_P(zval_ptr) == 0) {
     559     1012392 :                         _zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC);
     560             :                 }
     561             :         }
     562    34491960 : }
     563             : /* }}} */
     564             : 
     565         701 : ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
     566             : {
     567             :         zval *const_value;
     568             :         char *colon;
     569             :         zend_bool inline_change;
     570             : 
     571         701 :         if (Z_TYPE_P(p) == IS_CONSTANT) {
     572         307 :                 if (IS_CONSTANT_VISITED(p)) {
     573           2 :                         zend_throw_error(NULL, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
     574           2 :                         return FAILURE;
     575             :                 }
     576         305 :                 inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
     577         495 :                 SEPARATE_ZVAL_NOREF(p);
     578         305 :                 MARK_CONSTANT_VISITED(p);
     579         305 :                 if (Z_CONST_FLAGS_P(p) & IS_CONSTANT_CLASS) {
     580             :                         ZEND_ASSERT(EG(current_execute_data));
     581           7 :                         if (inline_change) {
     582           7 :                                 zend_string_release(Z_STR_P(p));
     583             :                         }
     584          14 :                         if (scope && scope->name) {
     585           7 :                                 ZVAL_STR_COPY(p, scope->name);
     586             :                         } else {
     587           0 :                                 ZVAL_EMPTY_STRING(p);
     588             :                         }
     589         298 :                 } else if (UNEXPECTED((const_value = zend_get_constant_ex(Z_STR_P(p), scope, Z_CONST_FLAGS_P(p))) == NULL)) {
     590          26 :                         char *actual = Z_STRVAL_P(p);
     591             : 
     592          26 :                         if (UNEXPECTED(EG(exception))) {
     593           6 :                                 RESET_CONSTANT_VISITED(p);
     594           6 :                                 return FAILURE;
     595          40 :                         } else if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
     596           0 :                                 zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(p));
     597           0 :                                 RESET_CONSTANT_VISITED(p);
     598           0 :                                 return FAILURE;
     599             :                         } else {
     600          20 :                                 if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
     601          15 :                                         zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(p));
     602          15 :                                         RESET_CONSTANT_VISITED(p);
     603          15 :                                         return FAILURE;
     604             :                                 } else {
     605           5 :                                         zend_string *save = Z_STR_P(p);
     606           5 :                                         size_t actual_len = Z_STRLEN_P(p);
     607           5 :                                         char *slash = (char *) zend_memrchr(actual, '\\', actual_len);
     608           5 :                                         if (slash) {
     609           3 :                                                 actual = slash + 1;
     610           3 :                                                 actual_len -= (actual - Z_STRVAL_P(p));
     611           3 :                                                 if (inline_change) {
     612           3 :                                                         zend_string *s = zend_string_init(actual, actual_len, 0);
     613           3 :                                                         Z_STR_P(p) = s;
     614           3 :                                                         Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
     615             :                                                 }
     616             :                                         }
     617             : 
     618           5 :                                         zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",  actual,  actual);
     619           5 :                                         if (!inline_change) {
     620           0 :                                                 ZVAL_STRINGL(p, actual, actual_len);
     621             :                                         } else {
     622           5 :                                                 Z_TYPE_INFO_P(p) = Z_REFCOUNTED_P(p) ?
     623             :                                                         IS_STRING_EX : IS_INTERNED_STRING_EX;
     624           5 :                                                 if (save && ZSTR_VAL(save) != actual) {
     625             :                                                         zend_string_release(save);
     626             :                                                 }
     627             :                                         }
     628             :                                 }
     629             :                         }
     630             :                 } else {
     631         266 :                         if (inline_change) {
     632         266 :                                 zend_string_release(Z_STR_P(p));
     633             :                         }
     634         266 :                         ZVAL_COPY_VALUE(p, const_value);
     635             :                         zval_opt_copy_ctor(p);
     636             :                 }
     637         394 :         } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
     638             :                 zval tmp;
     639             : 
     640         128 :                 inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
     641         128 :                 if (UNEXPECTED(zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope) != SUCCESS)) {
     642          17 :                         return FAILURE;
     643             :                 }
     644         109 :                 if (inline_change) {
     645         109 :                         zval_ptr_dtor(p);
     646             :                 }
     647         109 :                 ZVAL_COPY_VALUE(p, &tmp);
     648             :         }
     649         653 :         return SUCCESS;
     650             : }
     651             : /* }}} */
     652             : 
     653           0 : ZEND_API int zval_update_constant(zval *pp) /* {{{ */
     654             : {
     655           0 :         return zval_update_constant_ex(pp, EG(current_execute_data) ? zend_get_executed_scope() : CG(active_class_entry));
     656             : }
     657             : /* }}} */
     658             : 
     659       11641 : int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation) /* {{{ */
     660             : {
     661             :         zend_fcall_info fci;
     662             : 
     663       11641 :         fci.size = sizeof(fci);
     664       11641 :         fci.object = object ? Z_OBJ_P(object) : NULL;
     665       11641 :         ZVAL_COPY_VALUE(&fci.function_name, function_name);
     666       11641 :         fci.retval = retval_ptr;
     667       11641 :         fci.param_count = param_count;
     668       11641 :         fci.params = params;
     669       11641 :         fci.no_separation = (zend_bool) no_separation;
     670             : 
     671       11641 :         return zend_call_function(&fci, NULL);
     672             : }
     673             : /* }}} */
     674             : 
     675      822119 : int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /* {{{ */
     676             : {
     677             :         uint32_t i;
     678             :         zend_execute_data *call, dummy_execute_data;
     679             :         zend_fcall_info_cache fci_cache_local;
     680             :         zend_function *func;
     681             : 
     682      822119 :         ZVAL_UNDEF(fci->retval);
     683             : 
     684      822119 :         if (!EG(active)) {
     685           0 :                 return FAILURE; /* executor is already inactive */
     686             :         }
     687             : 
     688      822119 :         if (EG(exception)) {
     689          16 :                 return FAILURE; /* we would result in an instable executor otherwise */
     690             :         }
     691             : 
     692      822103 :         switch (fci->size) {
     693             :                 case sizeof(zend_fcall_info):
     694      822103 :                         break; /* nothing to do currently */
     695             :                 default:
     696           0 :                         zend_error_noreturn(E_CORE_ERROR, "Corrupted fcall_info provided to zend_call_function()");
     697             :                         break;
     698             :         }
     699             : 
     700             :         /* Initialize execute_data */
     701      822103 :         if (!EG(current_execute_data)) {
     702             :                 /* This only happens when we're called outside any execute()'s
     703             :                  * It shouldn't be strictly necessary to NULL execute_data out,
     704             :                  * but it may make bugs easier to spot
     705             :                  */
     706       20282 :                 memset(&dummy_execute_data, 0, sizeof(zend_execute_data));
     707       20282 :                 EG(current_execute_data) = &dummy_execute_data;
     708     1832337 :         } else if (EG(current_execute_data)->func &&
     709      801808 :                    ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
     710      191392 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL &&
     711       12442 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_ICALL &&
     712       12437 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_UCALL &&
     713       12437 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL_BY_NAME) {
     714             :                 /* Insert fake frame in case of include or magic calls */
     715       12177 :                 dummy_execute_data = *EG(current_execute_data);
     716       12177 :                 dummy_execute_data.prev_execute_data = EG(current_execute_data);
     717       12177 :                 dummy_execute_data.call = NULL;
     718       12177 :                 dummy_execute_data.opline = NULL;
     719       12177 :                 dummy_execute_data.func = NULL;
     720       12177 :                 EG(current_execute_data) = &dummy_execute_data;
     721             :         }
     722             : 
     723      822103 :         if (!fci_cache || !fci_cache->initialized) {
     724             :                 zend_string *callable_name;
     725       12473 :                 char *error = NULL;
     726             : 
     727       12473 :                 if (!fci_cache) {
     728       12448 :                         fci_cache = &fci_cache_local;
     729             :                 }
     730             : 
     731       12473 :                 if (!zend_is_callable_ex(&fci->function_name, fci->object, IS_CALLABLE_CHECK_SILENT, &callable_name, fci_cache, &error)) {
     732          87 :                         if (error) {
     733           0 :                                 zend_error(E_WARNING, "Invalid callback %s, %s", ZSTR_VAL(callable_name), error);
     734           0 :                                 efree(error);
     735             :                         }
     736          87 :                         if (callable_name) {
     737          87 :                                 zend_string_release(callable_name);
     738             :                         }
     739          87 :                         if (EG(current_execute_data) == &dummy_execute_data) {
     740          43 :                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     741             :                         }
     742          87 :                         return FAILURE;
     743       12386 :                 } else if (error) {
     744             :                         /* Capitalize the first latter of the error message */
     745           3 :                         if (error[0] >= 'a' && error[0] <= 'z') {
     746           3 :                                 error[0] += ('A' - 'a');
     747             :                         }
     748           3 :                         zend_error(E_DEPRECATED, "%s", error);
     749           3 :                         efree(error);
     750             :                 }
     751       12386 :                 zend_string_release(callable_name);
     752             :         }
     753             : 
     754      822016 :         func = fci_cache->function_handler;
     755      822016 :         fci->object = (func->common.fn_flags & ZEND_ACC_STATIC) ?
     756             :                 NULL : fci_cache->object;
     757             : 
     758     1644032 :         call = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC,
     759             :                 func, fci->param_count, fci_cache->called_scope, fci->object);
     760     1960002 :         if (fci->object &&
     761      568993 :             (!EG(objects_store).object_buckets ||
     762      568993 :              !IS_OBJ_VALID(EG(objects_store).object_buckets[fci->object->handle]))) {
     763           0 :                 if (EG(current_execute_data) == &dummy_execute_data) {
     764           0 :                         EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     765             :                 }
     766           0 :                 return FAILURE;
     767             :         }
     768             : 
     769      822016 :         if (func->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
     770           0 :                 if (func->common.fn_flags & ZEND_ACC_ABSTRACT) {
     771           0 :                         zend_throw_error(NULL, "Cannot call abstract method %s::%s()", ZSTR_VAL(func->common.scope->name), ZSTR_VAL(func->common.function_name));
     772           0 :                         if (EG(current_execute_data) == &dummy_execute_data) {
     773           0 :                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     774             :                         }
     775           0 :                         return FAILURE;
     776             :                 }
     777           0 :                 if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
     778           0 :                         zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
     779           0 :                                 func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
     780           0 :                                 func->common.scope ? "::" : "",
     781           0 :                                 ZSTR_VAL(func->common.function_name));
     782             :                 }
     783             :         }
     784             : 
     785     1350543 :         for (i=0; i<fci->param_count; i++) {
     786             :                 zval *param;
     787      528532 :                 zval *arg = &fci->params[i];
     788             : 
     789     1057064 :                 if (ARG_SHOULD_BE_SENT_BY_REF(func, i + 1)) {
     790         381 :                         if (UNEXPECTED(!Z_ISREF_P(arg))) {
     791         239 :                                 if (fci->no_separation &&
     792           8 :                                         !ARG_MAY_BE_SENT_BY_REF(func, i + 1)) {
     793           5 :                                         if (i) {
     794             :                                                 /* hack to clean up the stack */
     795           0 :                                                 ZEND_CALL_NUM_ARGS(call) = i;
     796             :                                                 zend_vm_stack_free_args(call);
     797             :                                         }
     798             :                                         zend_vm_stack_free_call_frame(call);
     799             : 
     800          17 :                                         zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
     801             :                                                 i+1,
     802           7 :                                                 func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
     803           5 :                                                 func->common.scope ? "::" : "",
     804           5 :                                                 ZSTR_VAL(func->common.function_name));
     805           5 :                                         if (EG(current_execute_data) == &dummy_execute_data) {
     806           0 :                                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     807             :                                         }
     808           5 :                                         return FAILURE;
     809             :                                 }
     810             : 
     811         226 :                                 ZVAL_NEW_REF(arg, arg);
     812             :                         }
     813             :                         Z_ADDREF_P(arg);
     814             :                 } else {
     815      529101 :                         if (Z_ISREF_P(arg) &&
     816         950 :                             !(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
     817             :                                 /* don't separate references for __call */
     818         950 :                                 arg = Z_REFVAL_P(arg);
     819             :                         }
     820      528151 :                         if (Z_OPT_REFCOUNTED_P(arg)) {
     821             :                                 Z_ADDREF_P(arg);
     822             :                         }
     823             :                 }
     824      528527 :                 param = ZEND_CALL_ARG(call, i+1);
     825      528527 :                 ZVAL_COPY_VALUE(param, arg);
     826             :         }
     827             : 
     828      822011 :         if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
     829             :                 ZEND_ASSERT(GC_TYPE((zend_object*)func->op_array.prototype) == IS_OBJECT);
     830         725 :                 GC_REFCOUNT((zend_object*)func->op_array.prototype)++;
     831         725 :                 ZEND_ADD_CALL_FLAG(call, ZEND_CALL_CLOSURE);
     832             :         }
     833             : 
     834      822011 :         if (func->type == ZEND_USER_FUNCTION) {
     835      573523 :                 int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
     836      573523 :                 zend_init_execute_data(call, &func->op_array, fci->retval);
     837      573523 :                 zend_execute_ex(call);
     838      573488 :                 if (call_via_handler) {
     839             :                         /* We must re-initialize function again */
     840           7 :                         fci_cache->initialized = 0;
     841             :                 }
     842      248488 :         } else if (func->type == ZEND_INTERNAL_FUNCTION) {
     843      248488 :                 int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
     844      248488 :                 ZVAL_NULL(fci->retval);
     845      248488 :                 call->prev_execute_data = EG(current_execute_data);
     846      248488 :                 call->return_value = NULL; /* this is not a constructor call */
     847      248488 :                 EG(current_execute_data) = call;
     848      248488 :                 if (EXPECTED(zend_execute_internal == NULL)) {
     849             :                         /* saves one function call if zend_execute_internal is not used */
     850      248488 :                         func->internal_function.handler(call, fci->retval);
     851             :                 } else {
     852           0 :                         zend_execute_internal(call, fci->retval);
     853             :                 }
     854      248486 :                 EG(current_execute_data) = call->prev_execute_data;
     855             :                 zend_vm_stack_free_args(call);
     856             : 
     857             :                 /*  We shouldn't fix bad extensions here,
     858             :                         because it can break proper ones (Bug #34045)
     859             :                 if (!EX(function_state).function->common.return_reference)
     860             :                 {
     861             :                         INIT_PZVAL(f->retval);
     862             :                 }*/
     863      248486 :                 if (EG(exception)) {
     864          84 :                         zval_ptr_dtor(fci->retval);
     865          84 :                         ZVAL_UNDEF(fci->retval);
     866             :                 }
     867             : 
     868      248486 :                 if (call_via_handler) {
     869             :                         /* We must re-initialize function again */
     870           4 :                         fci_cache->initialized = 0;
     871             :                 }
     872             :         } else { /* ZEND_OVERLOADED_FUNCTION */
     873           0 :                 ZVAL_NULL(fci->retval);
     874             : 
     875             :                 /* Not sure what should be done here if it's a static method */
     876           0 :                 if (fci->object) {
     877           0 :                         call->prev_execute_data = EG(current_execute_data);
     878           0 :                         EG(current_execute_data) = call;
     879           0 :                         fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval);
     880           0 :                         EG(current_execute_data) = call->prev_execute_data;
     881             :                 } else {
     882           0 :                         zend_throw_error(NULL, "Cannot call overloaded function for non-object");
     883             :                 }
     884             : 
     885             :                 zend_vm_stack_free_args(call);
     886             : 
     887           0 :                 if (func->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
     888           0 :                         zend_string_release(func->common.function_name);
     889             :                 }
     890           0 :                 efree(func);
     891             : 
     892           0 :                 if (EG(exception)) {
     893           0 :                         zval_ptr_dtor(fci->retval);
     894           0 :                         ZVAL_UNDEF(fci->retval);
     895             :                 }
     896             :         }
     897             : 
     898             :         zend_vm_stack_free_call_frame(call);
     899             : 
     900      821974 :         if (EG(current_execute_data) == &dummy_execute_data) {
     901       32399 :                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     902             :         }
     903             : 
     904      821974 :         if (EG(exception)) {
     905         376 :                 zend_throw_exception_internal(NULL);
     906             :         }
     907      821968 :         return SUCCESS;
     908             : }
     909             : /* }}} */
     910             : 
     911      169886 : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */
     912             : {
     913      169886 :         zend_class_entry *ce = NULL;
     914             :         zval args[1];
     915             :         zval local_retval;
     916             :         zend_string *lc_name;
     917             :         zend_fcall_info fcall_info;
     918             :         zend_fcall_info_cache fcall_cache;
     919             : 
     920      169886 :         if (key) {
     921       21274 :                 lc_name = Z_STR_P(key);
     922             :         } else {
     923      148612 :                 if (name == NULL || !ZSTR_LEN(name)) {
     924          84 :                         return NULL;
     925             :                 }
     926             : 
     927      148528 :                 if (ZSTR_VAL(name)[0] == '\\') {
     928          28 :                         lc_name = zend_string_alloc(ZSTR_LEN(name) - 1, 0);
     929          14 :                         zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
     930             :                 } else {
     931      148514 :                         lc_name = zend_string_tolower(name);
     932             :                 }
     933             :         }
     934             : 
     935      339604 :         ce = zend_hash_find_ptr(EG(class_table), lc_name);
     936      169802 :         if (ce) {
     937      169035 :                 if (!key) {
     938             :                         zend_string_release(lc_name);
     939             :                 }
     940      169035 :                 return ce;
     941             :         }
     942             : 
     943             :         /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
     944             :          * (doesn't impact functionality of __autoload()
     945             :         */
     946         767 :         if (!use_autoload || zend_is_compiling()) {
     947         376 :                 if (!key) {
     948             :                         zend_string_release(lc_name);
     949             :                 }
     950         376 :                 return NULL;
     951             :         }
     952             : 
     953         391 :         if (!EG(autoload_func)) {
     954         462 :                 zend_function *func = zend_hash_find_ptr(EG(function_table), CG(known_strings)[ZEND_STR_MAGIC_AUTOLOAD]);
     955         231 :                 if (func) {
     956          67 :                         EG(autoload_func) = func;
     957             :                 } else {
     958         164 :                         if (!key) {
     959             :                                 zend_string_release(lc_name);
     960             :                         }
     961         164 :                         return NULL;
     962             :                 }
     963             : 
     964             :         }
     965             : 
     966             :         /* Verify class name before passing it to __autoload() */
     967         227 :         if (strspn(ZSTR_VAL(name), "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\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\\") != ZSTR_LEN(name)) {
     968          11 :                 if (!key) {
     969             :                         zend_string_release(lc_name);
     970             :                 }
     971          11 :                 return NULL;
     972             :         }
     973             : 
     974         216 :         if (EG(in_autoload) == NULL) {
     975          93 :                 ALLOC_HASHTABLE(EG(in_autoload));
     976          93 :                 zend_hash_init(EG(in_autoload), 8, NULL, NULL, 0);
     977             :         }
     978             : 
     979         216 :         if (zend_hash_add_empty_element(EG(in_autoload), lc_name) == NULL) {
     980           4 :                 if (!key) {
     981             :                         zend_string_release(lc_name);
     982             :                 }
     983           4 :                 return NULL;
     984             :         }
     985             : 
     986         212 :         ZVAL_UNDEF(&local_retval);
     987             : 
     988         212 :         if (ZSTR_VAL(name)[0] == '\\') {
     989           2 :                 ZVAL_STRINGL(&args[0], ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
     990             :         } else {
     991         211 :                 ZVAL_STR_COPY(&args[0], name);
     992             :         }
     993             : 
     994         212 :         fcall_info.size = sizeof(fcall_info);
     995         212 :         ZVAL_STR_COPY(&fcall_info.function_name, EG(autoload_func)->common.function_name);
     996         212 :         fcall_info.retval = &local_retval;
     997         212 :         fcall_info.param_count = 1;
     998         212 :         fcall_info.params = args;
     999         212 :         fcall_info.object = NULL;
    1000         212 :         fcall_info.no_separation = 1;
    1001             : 
    1002         212 :         fcall_cache.initialized = 1;
    1003         212 :         fcall_cache.function_handler = EG(autoload_func);
    1004         212 :         fcall_cache.calling_scope = NULL;
    1005         212 :         fcall_cache.called_scope = NULL;
    1006         212 :         fcall_cache.object = NULL;
    1007             : 
    1008         212 :         zend_exception_save();
    1009         212 :         if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) {
    1010         368 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1011             :         }
    1012         209 :         zend_exception_restore();
    1013             : 
    1014         209 :         zval_ptr_dtor(&args[0]);
    1015             :         zval_dtor(&fcall_info.function_name);
    1016             : 
    1017         209 :         zend_hash_del(EG(in_autoload), lc_name);
    1018             : 
    1019         209 :         zval_ptr_dtor(&local_retval);
    1020             : 
    1021         209 :         if (!key) {
    1022             :                 zend_string_release(lc_name);
    1023             :         }
    1024         209 :         return ce;
    1025             : }
    1026             : /* }}} */
    1027             : 
    1028      145058 : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name) /* {{{ */
    1029             : {
    1030      145058 :         return zend_lookup_class_ex(name, NULL, 1);
    1031             : }
    1032             : /* }}} */
    1033             : 
    1034       23564 : ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex) /* {{{ */
    1035             : {
    1036       47458 :         while (ex) {
    1037        1610 :                 if (Z_TYPE(ex->This) == IS_OBJECT) {
    1038          83 :                         return Z_OBJCE(ex->This);
    1039         722 :                 } else if (Z_CE(ex->This)) {
    1040         200 :                         return Z_CE(ex->This);
    1041         522 :                 } else if (ex->func) {
    1042         485 :                         if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) {
    1043         192 :                                 return NULL;
    1044             :                         }
    1045             :                 }
    1046         330 :                 ex = ex->prev_execute_data;
    1047             :         }
    1048       23089 :         return NULL;
    1049             : }
    1050             : /* }}} */
    1051             : 
    1052       23422 : ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex) /* {{{ */
    1053             : {
    1054       47011 :         while (ex) {
    1055        1008 :                 if (Z_TYPE(ex->This) == IS_OBJECT) {
    1056          95 :                         return Z_OBJ(ex->This);
    1057         409 :                 } else if (ex->func) {
    1058         408 :                         if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) {
    1059         242 :                                 return NULL;
    1060             :                         }
    1061             :                 }
    1062         167 :                 ex = ex->prev_execute_data;
    1063             :         }
    1064       23085 :         return NULL;
    1065             : }
    1066             : /* }}} */
    1067             : 
    1068         179 : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{{ */
    1069             : {
    1070             :         zval pv;
    1071             :         zend_op_array *new_op_array;
    1072             :         uint32_t original_compiler_options;
    1073             :         int retval;
    1074             : 
    1075         179 :         if (retval_ptr) {
    1076         160 :                 ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 1));
    1077          80 :                 memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
    1078          80 :                 memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
    1079          80 :                 Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
    1080          80 :                 Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
    1081             :         } else {
    1082         198 :                 ZVAL_STRINGL(&pv, str, str_len);
    1083             :         }
    1084             : 
    1085             :         /*printf("Evaluating '%s'\n", pv.value.str.val);*/
    1086             : 
    1087         179 :         original_compiler_options = CG(compiler_options);
    1088         179 :         CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
    1089         179 :         new_op_array = zend_compile_string(&pv, string_name);
    1090         179 :         CG(compiler_options) = original_compiler_options;
    1091             : 
    1092         179 :         if (new_op_array) {
    1093             :                 zval local_retval;
    1094             : 
    1095         171 :                 EG(no_extensions)=1;
    1096             : 
    1097         171 :                 zend_try {
    1098         171 :                         ZVAL_UNDEF(&local_retval);
    1099         171 :                         zend_execute(new_op_array, &local_retval);
    1100           1 :                 } zend_catch {
    1101           1 :                         destroy_op_array(new_op_array);
    1102           1 :                         efree_size(new_op_array, sizeof(zend_op_array));
    1103           1 :                         zend_bailout();
    1104         170 :                 } zend_end_try();
    1105             : 
    1106         170 :                 if (Z_TYPE(local_retval) != IS_UNDEF) {
    1107         169 :                         if (retval_ptr) {
    1108          73 :                                 ZVAL_COPY_VALUE(retval_ptr, &local_retval);
    1109             :                         } else {
    1110          96 :                                 zval_ptr_dtor(&local_retval);
    1111             :                         }
    1112             :                 } else {
    1113           1 :                         if (retval_ptr) {
    1114           1 :                                 ZVAL_NULL(retval_ptr);
    1115             :                         }
    1116             :                 }
    1117             : 
    1118         170 :                 EG(no_extensions)=0;
    1119         170 :                 destroy_op_array(new_op_array);
    1120         170 :                 efree_size(new_op_array, sizeof(zend_op_array));
    1121         170 :                 retval = SUCCESS;
    1122             :         } else {
    1123           8 :                 retval = FAILURE;
    1124             :         }
    1125             :         zval_dtor(&pv);
    1126         178 :         return retval;
    1127             : }
    1128             : /* }}} */
    1129             : 
    1130           0 : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name) /* {{{ */
    1131             : {
    1132           0 :         return zend_eval_stringl(str, strlen(str), retval_ptr, string_name);
    1133             : }
    1134             : /* }}} */
    1135             : 
    1136          31 : ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */
    1137             : {
    1138             :         int result;
    1139             : 
    1140          31 :         result = zend_eval_stringl(str, str_len, retval_ptr, string_name);
    1141          30 :         if (handle_exceptions && EG(exception)) {
    1142           0 :                 zend_exception_error(EG(exception), E_ERROR);
    1143           0 :                 result = FAILURE;
    1144             :         }
    1145          30 :         return result;
    1146             : }
    1147             : /* }}} */
    1148             : 
    1149          31 : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */
    1150             : {
    1151          31 :         return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions);
    1152             : }
    1153             : /* }}} */
    1154             : 
    1155             : static void zend_set_timeout_ex(zend_long seconds, int reset_signals);
    1156             : 
    1157          13 : ZEND_API ZEND_NORETURN void zend_timeout(int dummy) /* {{{ */
    1158             : {
    1159             : #if defined(PHP_WIN32)
    1160             : # ifndef ZTS
    1161             :         /* No action is needed if we're timed out because zero seconds are
    1162             :            just ignored. Also, the hard timeout needs to be respected. If the
    1163             :            timer is not restarted properly, it could hang in the shutdown
    1164             :            function. */
    1165             :         if (EG(hard_timeout) > 0) {
    1166             :                 EG(timed_out) = 0;
    1167             :                 zend_set_timeout_ex(EG(hard_timeout), 1);
    1168             :                 /* XXX Abused, introduce an additional flag if the value needs to be kept. */
    1169             :                 EG(hard_timeout) = 0;
    1170             :         }
    1171             : # endif
    1172             : #else
    1173          13 :         EG(timed_out) = 0;
    1174          13 :         zend_set_timeout_ex(0, 1);
    1175             : #endif
    1176             : 
    1177          13 :         zend_error_noreturn(E_ERROR, "Maximum execution time of " ZEND_LONG_FMT " second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
    1178             : }
    1179             : /* }}} */
    1180             : 
    1181             : #ifndef ZEND_WIN32
    1182          13 : static void zend_timeout_handler(int dummy) /* {{{ */
    1183             : {
    1184             : #ifndef ZTS
    1185          13 :     if (EG(timed_out)) {
    1186             :                 /* Die on hard timeout */
    1187           0 :                 const char *error_filename = NULL;
    1188           0 :                 uint error_lineno = 0;
    1189             :                 char log_buffer[2048];
    1190           0 :                 int output_len = 0;
    1191             : 
    1192           0 :                 if (zend_is_compiling()) {
    1193           0 :                         error_filename = ZSTR_VAL(zend_get_compiled_filename());
    1194           0 :                         error_lineno = zend_get_compiled_lineno();
    1195           0 :                 } else if (zend_is_executing()) {
    1196           0 :                         error_filename = zend_get_executed_filename();
    1197           0 :                         if (error_filename[0] == '[') { /* [no active file] */
    1198           0 :                                 error_filename = NULL;
    1199           0 :                                 error_lineno = 0;
    1200             :                         } else {
    1201           0 :                                 error_lineno = zend_get_executed_lineno();
    1202             :                         }
    1203             :                 }
    1204           0 :                 if (!error_filename) {
    1205           0 :                         error_filename = "Unknown";
    1206             :                 }
    1207             : 
    1208           0 :                 output_len = snprintf(log_buffer, sizeof(log_buffer), "\nFatal error: Maximum execution time of " ZEND_LONG_FMT "+" ZEND_LONG_FMT " seconds exceeded (terminated) in %s on line %d\n", EG(timeout_seconds), EG(hard_timeout), error_filename, error_lineno);
    1209           0 :                 if (output_len > 0) {
    1210           0 :                         write(2, log_buffer, MIN(output_len, sizeof(log_buffer)));
    1211             :                 }
    1212           0 :                 _exit(1);
    1213             :     }
    1214             : #endif
    1215             : 
    1216          13 :         if (zend_on_timeout) {
    1217             : #ifdef ZEND_SIGNALS
    1218             :                 /*
    1219             :                    We got here because we got a timeout signal, so we are in a signal handler
    1220             :                    at this point. However, we want to be able to timeout any user-supplied
    1221             :                    shutdown functions, so pretend we are not in a signal handler while we are
    1222             :                    calling these
    1223             :                 */
    1224          13 :                 SIGG(running) = 0;
    1225             : #endif
    1226          13 :                 zend_on_timeout(EG(timeout_seconds));
    1227             :         }
    1228             : 
    1229          13 :         EG(timed_out) = 1;
    1230          13 :         EG(vm_interrupt) = 1;
    1231             : 
    1232             : #ifndef ZTS
    1233          13 :         if (EG(hard_timeout) > 0) {
    1234             :                 /* Set hard timeout */
    1235          13 :                 zend_set_timeout_ex(EG(hard_timeout), 1);
    1236             :         }
    1237             : #endif
    1238          13 : }
    1239             : /* }}} */
    1240             : #endif
    1241             : 
    1242             : #ifdef ZEND_WIN32
    1243             : VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
    1244             : {
    1245             :         zend_executor_globals *eg;
    1246             : 
    1247             :         /* The doc states it'll be always true, however it theoretically
    1248             :                 could be FALSE when the thread was signaled. */
    1249             :         if (!timed_out) {
    1250             :                 return;
    1251             :         }
    1252             : 
    1253             :         eg = (zend_executor_globals *)arg;
    1254             :         eg->timed_out = 1;
    1255             :         eg->vm_interrupt = 1;
    1256             : }
    1257             : #endif
    1258             : 
    1259             : /* This one doesn't exists on QNX */
    1260             : #ifndef SIGPROF
    1261             : #define SIGPROF 27
    1262             : #endif
    1263             : 
    1264       23539 : static void zend_set_timeout_ex(zend_long seconds, int reset_signals) /* {{{ */
    1265             : {
    1266             : #ifdef ZEND_WIN32
    1267             :         zend_executor_globals *eg;
    1268             : 
    1269             :         if(!seconds) {
    1270             :                 return;
    1271             :         }
    1272             : 
    1273             :         /* Don't use ChangeTimerQueueTimer() as it will not restart an expired
    1274             :                 timer, so we could end up with just an ignored timeout. Instead
    1275             :                 delete and recreate. */
    1276             :         if (NULL != tq_timer) {
    1277             :                 if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
    1278             :                         tq_timer = NULL;
    1279             :                         zend_error_noreturn(E_ERROR, "Could not delete queued timer");
    1280             :                         return;
    1281             :                 }
    1282             :                 tq_timer = NULL;
    1283             :         }
    1284             : 
    1285             :         /* XXX passing NULL means the default timer queue provided by the system is used */
    1286             :         eg = ZEND_MODULE_GLOBALS_BULK(executor);
    1287             :         if (!CreateTimerQueueTimer(&tq_timer, NULL, (WAITORTIMERCALLBACK)tq_timer_cb, (VOID*)eg, seconds*1000, 0, WT_EXECUTEONLYONCE)) {
    1288             :                 tq_timer = NULL;
    1289             :                 zend_error_noreturn(E_ERROR, "Could not queue new timer");
    1290             :                 return;
    1291             :         }
    1292             : #else
    1293             : #       ifdef HAVE_SETITIMER
    1294             :         {
    1295             :                 struct itimerval t_r;           /* timeout requested */
    1296             :                 int signo;
    1297             : 
    1298       23539 :                 if(seconds) {
    1299         472 :                         t_r.it_value.tv_sec = seconds;
    1300         472 :                         t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
    1301             : 
    1302             : #       ifdef __CYGWIN__
    1303             :                         setitimer(ITIMER_REAL, &t_r, NULL);
    1304             :                 }
    1305             :                 signo = SIGALRM;
    1306             : #       else
    1307         472 :                         setitimer(ITIMER_PROF, &t_r, NULL);
    1308             :                 }
    1309       23539 :                 signo = SIGPROF;
    1310             : #       endif
    1311             : 
    1312       23539 :                 if (reset_signals) {
    1313             : #       ifdef ZEND_SIGNALS
    1314       23484 :                         zend_signal(signo, zend_timeout_handler);
    1315             : #       else
    1316             :                         sigset_t sigset;
    1317             : #   ifdef HAVE_SIGACTION
    1318             :                         struct sigaction act;
    1319             : 
    1320             :                         act.sa_handler = zend_timeout_handler;
    1321             :                         sigemptyset(&act.sa_mask);
    1322             :                         act.sa_flags = SA_RESETHAND | SA_NODEFER;
    1323             :                         sigaction(signo, &act, NULL);
    1324             : #   else
    1325             :                         signal(signo, zend_timeout_handler);
    1326             : #   endif /* HAVE_SIGACTION */
    1327             :                         sigemptyset(&sigset);
    1328             :                         sigaddset(&sigset, signo);
    1329             :                         sigprocmask(SIG_UNBLOCK, &sigset, NULL);
    1330             : #       endif /* ZEND_SIGNALS */
    1331             :                 }
    1332             :         }
    1333             : #       endif /* HAVE_SETITIMER */
    1334             : #endif
    1335       23539 : }
    1336             : /* }}} */
    1337             : 
    1338       23513 : void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
    1339             : {
    1340             : 
    1341       23513 :         EG(timeout_seconds) = seconds;
    1342       23513 :         zend_set_timeout_ex(seconds, reset_signals);
    1343       23513 :         EG(timed_out) = 0;
    1344       23513 : }
    1345             : /* }}} */
    1346             : 
    1347       47055 : void zend_unset_timeout(void) /* {{{ */
    1348             : {
    1349             : #ifdef ZEND_WIN32
    1350             :         if (NULL != tq_timer) {
    1351             :                 if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
    1352             :                         EG(timed_out) = 0;
    1353             :                         tq_timer = NULL;
    1354             :                         zend_error_noreturn(E_ERROR, "Could not delete queued timer");
    1355             :                         return;
    1356             :                 }
    1357             :                 tq_timer = NULL;
    1358             :         }
    1359             :         EG(timed_out) = 0;
    1360             : #else
    1361             : #       ifdef HAVE_SETITIMER
    1362       47055 :         if (EG(timeout_seconds)) {
    1363             :                 struct itimerval no_timeout;
    1364             : 
    1365         910 :                 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;
    1366             : 
    1367             : #ifdef __CYGWIN__
    1368             :                 setitimer(ITIMER_REAL, &no_timeout, NULL);
    1369             : #else
    1370         910 :                 setitimer(ITIMER_PROF, &no_timeout, NULL);
    1371             : #endif
    1372             :         }
    1373             : #       endif
    1374       47055 :         EG(timed_out) = 0;
    1375             : #endif
    1376       47055 : }
    1377             : /* }}} */
    1378             : 
    1379        6195 : zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {{{ */
    1380             : {
    1381             :         zend_class_entry *ce, *scope;
    1382        6195 :         int fetch_sub_type = fetch_type & ZEND_FETCH_CLASS_MASK;
    1383             : 
    1384             : check_fetch_type:
    1385        6206 :         switch (fetch_sub_type) {
    1386             :                 case ZEND_FETCH_CLASS_SELF:
    1387        1700 :                         scope = zend_get_executed_scope();
    1388        1700 :                         if (UNEXPECTED(!scope)) {
    1389           6 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access self:: when no class scope is active");
    1390             :                         }
    1391        1700 :                         return scope;
    1392             :                 case ZEND_FETCH_CLASS_PARENT:
    1393        1382 :                         scope = zend_get_executed_scope();
    1394        1382 :                         if (UNEXPECTED(!scope)) {
    1395           1 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when no class scope is active");
    1396           1 :                                 return NULL;
    1397             :                         }
    1398        1381 :                         if (UNEXPECTED(!scope->parent)) {
    1399           0 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when current class scope has no parent");
    1400             :                         }
    1401        1381 :                         return scope->parent;
    1402             :                 case ZEND_FETCH_CLASS_STATIC:
    1403         122 :                         ce = zend_get_called_scope(EG(current_execute_data));
    1404         122 :                         if (UNEXPECTED(!ce)) {
    1405           4 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access static:: when no class scope is active");
    1406           4 :                                 return NULL;
    1407             :                         }
    1408         118 :                         return ce;
    1409             :                 case ZEND_FETCH_CLASS_AUTO: {
    1410        1492 :                                 fetch_sub_type = zend_get_class_fetch_type(class_name);
    1411        1492 :                                 if (UNEXPECTED(fetch_sub_type != ZEND_FETCH_CLASS_DEFAULT)) {
    1412          11 :                                         goto check_fetch_type;
    1413             :                                 }
    1414             :                         }
    1415             :                         break;
    1416             :         }
    1417             : 
    1418        2991 :         if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) {
    1419        1519 :                 return zend_lookup_class_ex(class_name, NULL, 0);
    1420        1472 :         } else if ((ce = zend_lookup_class_ex(class_name, NULL, 1)) == NULL) {
    1421          16 :                 if (!(fetch_type & ZEND_FETCH_CLASS_SILENT) && !EG(exception)) {
    1422          13 :                         if (fetch_sub_type == ZEND_FETCH_CLASS_INTERFACE) {
    1423           0 :                                 zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name));
    1424          13 :                         } else if (fetch_sub_type == ZEND_FETCH_CLASS_TRAIT) {
    1425           0 :                                 zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name));
    1426             :                         } else {
    1427          13 :                                 zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name));
    1428             :                         }
    1429             :                 }
    1430           8 :                 return NULL;
    1431             :         }
    1432        1455 :         return ce;
    1433             : }
    1434             : /* }}} */
    1435             : 
    1436       19824 : zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type) /* {{{ */
    1437             : {
    1438             :         zend_class_entry *ce;
    1439             : 
    1440       19824 :         if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) {
    1441        1327 :                 return zend_lookup_class_ex(class_name, key, 0);
    1442       18497 :         } else if ((ce = zend_lookup_class_ex(class_name, key, 1)) == NULL) {
    1443          39 :                 if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) {
    1444          25 :                         if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
    1445           2 :                                 zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name));
    1446          23 :                         } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
    1447           2 :                                 zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name));
    1448             :                         } else {
    1449          21 :                                 zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name));
    1450             :                         }
    1451             :                 }
    1452          34 :                 return NULL;
    1453             :         }
    1454       18457 :         return ce;
    1455             : }
    1456             : /* }}} */
    1457             : 
    1458             : #define MAX_ABSTRACT_INFO_CNT 3
    1459             : #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
    1460             : #define DISPLAY_ABSTRACT_FN(idx) \
    1461             :         ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
    1462             :         ai.afn[idx] ? "::" : "", \
    1463             :         ai.afn[idx] ? ZSTR_VAL(ai.afn[idx]->common.function_name) : "", \
    1464             :         ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
    1465             : 
    1466             : typedef struct _zend_abstract_info {
    1467             :         zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
    1468             :         int cnt;
    1469             :         int ctor;
    1470             : } zend_abstract_info;
    1471             : 
    1472          18 : static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai) /* {{{ */
    1473             : {
    1474          18 :         if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
    1475          14 :                 if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
    1476          14 :                         ai->afn[ai->cnt] = fn;
    1477             :                 }
    1478          14 :                 if (fn->common.fn_flags & ZEND_ACC_CTOR) {
    1479           1 :                         if (!ai->ctor) {
    1480           1 :                                 ai->cnt++;
    1481           1 :                                 ai->ctor = 1;
    1482             :                         } else {
    1483           0 :                                 ai->afn[ai->cnt] = NULL;
    1484             :                         }
    1485             :                 } else {
    1486          13 :                         ai->cnt++;
    1487             :                 }
    1488             :         }
    1489          18 : }
    1490             : /* }}} */
    1491             : 
    1492     1773250 : void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
    1493             : {
    1494             :         zend_function *func;
    1495             :         zend_abstract_info ai;
    1496             : 
    1497     1773250 :         if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & (ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) {
    1498          14 :                 memset(&ai, 0, sizeof(ai));
    1499             : 
    1500          50 :                 ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
    1501          18 :                         zend_verify_abstract_class_function(func, &ai);
    1502             :                 } ZEND_HASH_FOREACH_END();
    1503             : 
    1504          14 :                 if (ai.cnt) {
    1505         262 :                         zend_error_noreturn(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 ")",
    1506          13 :                                 ZSTR_VAL(ce->name), ai.cnt,
    1507          13 :                                 ai.cnt > 1 ? "s" : "",
    1508         103 :                                 DISPLAY_ABSTRACT_FN(0),
    1509          68 :                                 DISPLAY_ABSTRACT_FN(1),
    1510          65 :                                 DISPLAY_ABSTRACT_FN(2)
    1511             :                                 );
    1512             :                 }
    1513             :         }
    1514     1773237 : }
    1515             : /* }}} */
    1516             : 
    1517         471 : ZEND_API int zend_delete_global_variable(zend_string *name) /* {{{ */
    1518             : {
    1519         471 :     return zend_hash_del_ind(&EG(symbol_table), name);
    1520             : }
    1521             : /* }}} */
    1522             : 
    1523        3252 : ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
    1524             : {
    1525             :         zend_execute_data *ex;
    1526             :         zend_array *symbol_table;
    1527             : 
    1528             :         /* Search for last called user function */
    1529        3252 :         ex = EG(current_execute_data);
    1530        8689 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) {
    1531        2185 :                 ex = ex->prev_execute_data;
    1532             :         }
    1533        3252 :         if (!ex) {
    1534          35 :                 return NULL;
    1535             :         }
    1536        3217 :         if (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE) {
    1537        2780 :                 return ex->symbol_table;
    1538             :         }
    1539             : 
    1540         437 :         ZEND_ADD_CALL_FLAG(ex, ZEND_CALL_HAS_SYMBOL_TABLE);
    1541         437 :         if (EG(symtable_cache_ptr) >= EG(symtable_cache)) {
    1542             :                 /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
    1543         172 :                 symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--);
    1544         172 :                 if (!ex->func->op_array.last_var) {
    1545           2 :                         return symbol_table;
    1546             :                 }
    1547         170 :                 zend_hash_extend(symbol_table, ex->func->op_array.last_var, 0);
    1548             :         } else {
    1549         265 :                 symbol_table = ex->symbol_table = emalloc(sizeof(zend_array));
    1550         265 :                 zend_hash_init(symbol_table, ex->func->op_array.last_var, NULL, ZVAL_PTR_DTOR, 0);
    1551         265 :                 if (!ex->func->op_array.last_var) {
    1552          17 :                         return symbol_table;
    1553             :                 }
    1554         248 :                 zend_hash_real_init(symbol_table, 0);
    1555             :                 /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
    1556             :         }
    1557         418 :         if (EXPECTED(ex->func->op_array.last_var)) {
    1558         418 :                 zend_string **str = ex->func->op_array.vars;
    1559         418 :                 zend_string **end = str + ex->func->op_array.last_var;
    1560         418 :                 zval *var = ZEND_CALL_VAR_NUM(ex, 0);
    1561             : 
    1562             :                 do {
    1563        2148 :                         _zend_hash_append_ind(symbol_table, *str, var);
    1564        2148 :                         str++;
    1565        2148 :                         var++;
    1566        2148 :                 } while (str != end);
    1567             :         }
    1568         418 :         return symbol_table;
    1569             : }
    1570             : /* }}} */
    1571             : 
    1572       45112 : ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1573             : {
    1574       45112 :         zend_op_array *op_array = &execute_data->func->op_array;
    1575       45112 :         HashTable *ht = execute_data->symbol_table;
    1576             : 
    1577             :         /* copy real values from symbol table into CV slots and create
    1578             :            INDIRECT references to CV in symbol table  */
    1579       45112 :         if (EXPECTED(op_array->last_var)) {
    1580       27196 :                 zend_string **str = op_array->vars;
    1581       27196 :                 zend_string **end = str + op_array->last_var;
    1582       27196 :                 zval *var = EX_VAR_NUM(0);
    1583             : 
    1584             :                 do {
    1585      126344 :                         zval *zv = zend_hash_find(ht, *str);
    1586             : 
    1587      126344 :                         if (zv) {
    1588       50138 :                                 if (Z_TYPE_P(zv) == IS_INDIRECT) {
    1589       36080 :                                         zval *val = Z_INDIRECT_P(zv);
    1590             : 
    1591       36080 :                                         ZVAL_COPY_VALUE(var, val);
    1592             :                                 } else {
    1593       14058 :                                         ZVAL_COPY_VALUE(var, zv);
    1594             :                                 }
    1595             :                         } else {
    1596       76206 :                                 ZVAL_UNDEF(var);
    1597       76206 :                                 zv = zend_hash_add_new(ht, *str, var);
    1598             :                         }
    1599      126344 :                         ZVAL_INDIRECT(zv, var);
    1600      126344 :                         str++;
    1601      126344 :                         var++;
    1602      126344 :                 } while (str != end);
    1603             :         }
    1604       45112 : }
    1605             : /* }}} */
    1606             : 
    1607       32571 : ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1608             : {
    1609       32571 :         zend_op_array *op_array = &execute_data->func->op_array;
    1610       32571 :         HashTable *ht = execute_data->symbol_table;
    1611             : 
    1612             :         /* copy real values from CV slots into symbol table */
    1613       32571 :         if (EXPECTED(op_array->last_var)) {
    1614       19678 :                 zend_string **str = op_array->vars;
    1615       19678 :                 zend_string **end = str + op_array->last_var;
    1616       19678 :                 zval *var = EX_VAR_NUM(0);
    1617             : 
    1618             :                 do {
    1619       88918 :                         if (Z_TYPE_P(var) == IS_UNDEF) {
    1620        9463 :                                 zend_hash_del(ht, *str);
    1621             :                         } else {
    1622       79455 :                                 zend_hash_update(ht, *str, var);
    1623       79455 :                                 ZVAL_UNDEF(var);
    1624             :                         }
    1625       88918 :                         str++;
    1626       88918 :                         var++;
    1627       88918 :                 } while (str != end);
    1628             :         }
    1629       32571 : }
    1630             : /* }}} */
    1631             : 
    1632           0 : ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force) /* {{{ */
    1633             : {
    1634           0 :         zend_execute_data *execute_data = EG(current_execute_data);
    1635             : 
    1636           0 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1637           0 :                 execute_data = execute_data->prev_execute_data;
    1638             :         }
    1639             : 
    1640           0 :         if (execute_data) {
    1641           0 :                 if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
    1642           0 :                         zend_ulong h = zend_string_hash_val(name);
    1643           0 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1644             : 
    1645           0 :                         if (EXPECTED(op_array->last_var)) {
    1646           0 :                                 zend_string **str = op_array->vars;
    1647           0 :                                 zend_string **end = str + op_array->last_var;
    1648             : 
    1649             :                                 do {
    1650           0 :                                         if (ZSTR_H(*str) == h &&
    1651           0 :                                             ZSTR_LEN(*str) == ZSTR_LEN(name) &&
    1652           0 :                                             memcmp(ZSTR_VAL(*str), ZSTR_VAL(name), ZSTR_LEN(name)) == 0) {
    1653           0 :                                                 zval *var = EX_VAR_NUM(str - op_array->vars);
    1654           0 :                                                 ZVAL_COPY_VALUE(var, value);
    1655           0 :                                                 return SUCCESS;
    1656             :                                         }
    1657           0 :                                         str++;
    1658           0 :                                 } while (str != end);
    1659             :                         }
    1660           0 :                         if (force) {
    1661           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table();
    1662           0 :                                 if (symbol_table) {
    1663           0 :                                         return zend_hash_update(symbol_table, name, value) ? SUCCESS : FAILURE;;
    1664             :                                 }
    1665             :                         }
    1666             :                 } else {
    1667           0 :                         return (zend_hash_update_ind(execute_data->symbol_table, name, value) != NULL) ? SUCCESS : FAILURE;
    1668             :                 }
    1669             :         }
    1670           0 :         return FAILURE;
    1671             : }
    1672             : /* }}} */
    1673             : 
    1674       42559 : ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force) /* {{{ */
    1675             : {
    1676       42559 :         zend_execute_data *execute_data = EG(current_execute_data);
    1677             : 
    1678      122162 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1679       37044 :                 execute_data = execute_data->prev_execute_data;
    1680             :         }
    1681             : 
    1682       42559 :         if (execute_data) {
    1683       42557 :                 if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
    1684        5835 :                         zend_ulong h = zend_hash_func(name, len);
    1685        5835 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1686        5835 :                         if (EXPECTED(op_array->last_var)) {
    1687        5761 :                                 zend_string **str = op_array->vars;
    1688        5761 :                                 zend_string **end = str + op_array->last_var;
    1689             : 
    1690             :                                 do {
    1691       46890 :                                         if (ZSTR_H(*str) == h &&
    1692           4 :                                             ZSTR_LEN(*str) == len &&
    1693           4 :                                             memcmp(ZSTR_VAL(*str), name, len) == 0) {
    1694           4 :                                                 zval *var = EX_VAR_NUM(str - op_array->vars);
    1695           4 :                                                 zval_ptr_dtor(var);
    1696           4 :                                                 ZVAL_COPY_VALUE(var, value);
    1697           4 :                                                 return SUCCESS;
    1698             :                                         }
    1699       46878 :                                         str++;
    1700       46878 :                                 } while (str != end);
    1701             :                         }
    1702        5831 :                         if (force) {
    1703           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table();
    1704           0 :                                 if (symbol_table) {
    1705           0 :                                         return zend_hash_str_update(symbol_table, name, len, value) ? SUCCESS : FAILURE;;
    1706             :                                 }
    1707             :                         }
    1708             :                 } else {
    1709       36722 :                         return (zend_hash_str_update_ind(execute_data->symbol_table, name, len, value) != NULL) ? SUCCESS : FAILURE;
    1710             :                 }
    1711             :         }
    1712        5833 :         return FAILURE;
    1713             : }
    1714             : /* }}} */
    1715             : 
    1716         397 : ZEND_API int zend_forbid_dynamic_call(const char *func_name) /* {{{ */
    1717             : {
    1718         397 :         zend_execute_data *ex = EG(current_execute_data);
    1719             :         ZEND_ASSERT(ex != NULL && ex->func != NULL);
    1720             : 
    1721         397 :         if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
    1722          16 :                 zend_error(E_WARNING, "Cannot call %s dynamically", func_name);
    1723          16 :                 return FAILURE;
    1724             :         }
    1725             : 
    1726         381 :         return SUCCESS;
    1727             : }
    1728             : /* }}} */
    1729             : 
    1730             : /*
    1731             :  * Local variables:
    1732             :  * tab-width: 4
    1733             :  * c-basic-offset: 4
    1734             :  * indent-tabs-mode: t
    1735             :  * End:
    1736             :  */

Generated by: LCOV version 1.10

Generated at Sun, 28 Aug 2016 17:09:57 +0000 (5 hours ago)

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