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-07-19 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       23231 : static void zend_extension_activator(zend_extension *extension) /* {{{ */
      88             : {
      89       23231 :         if (extension->activate) {
      90         380 :                 extension->activate();
      91             :         }
      92       23231 : }
      93             : /* }}} */
      94             : 
      95       23272 : static void zend_extension_deactivator(zend_extension *extension) /* {{{ */
      96             : {
      97       23272 :         if (extension->deactivate) {
      98         380 :                 extension->deactivate();
      99             :         }
     100       23272 : }
     101             : /* }}} */
     102             : 
     103       47697 : static int clean_non_persistent_function(zval *zv) /* {{{ */
     104             : {
     105       47697 :         zend_function *function = Z_PTR_P(zv);
     106       47697 :         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       33311 : static int clean_non_persistent_class(zval *zv) /* {{{ */
     118             : {
     119       33311 :         zend_class_entry *ce = Z_PTR_P(zv);
     120       33311 :         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       23363 : void init_executor(void) /* {{{ */
     132             : {
     133       23363 :         zend_init_fpu();
     134             : 
     135       23363 :         ZVAL_NULL(&EG(uninitialized_zval));
     136       23363 :         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       23363 :         EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
     143       23363 :         EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
     144       23363 :         EG(no_extensions) = 0;
     145             : 
     146       23363 :         EG(function_table) = CG(function_table);
     147       23363 :         EG(class_table) = CG(class_table);
     148             : 
     149       23363 :         EG(in_autoload) = NULL;
     150       23363 :         EG(autoload_func) = NULL;
     151       23363 :         EG(error_handling) = EH_NORMAL;
     152             : 
     153       23363 :         zend_vm_stack_init();
     154             : 
     155       23363 :         zend_hash_init(&EG(symbol_table), 64, NULL, ZVAL_PTR_DTOR, 0);
     156       23363 :         EG(valid_symbol_table) = 1;
     157             : 
     158       23363 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator);
     159             : 
     160       23363 :         zend_hash_init(&EG(included_files), 8, NULL, NULL, 0);
     161             : 
     162       23363 :         EG(ticks_count) = 0;
     163             : 
     164       23363 :         ZVAL_UNDEF(&EG(user_error_handler));
     165             : 
     166       23363 :         EG(current_execute_data) = NULL;
     167             : 
     168       23363 :         zend_stack_init(&EG(user_error_handlers_error_reporting), sizeof(int));
     169       23363 :         zend_stack_init(&EG(user_error_handlers), sizeof(zval));
     170       23363 :         zend_stack_init(&EG(user_exception_handlers), sizeof(zval));
     171             : 
     172       23363 :         zend_objects_store_init(&EG(objects_store), 1024);
     173             : 
     174       23363 :         EG(full_tables_cleanup) = 0;
     175       23363 :         EG(vm_interrupt) = 0;
     176       23363 :         EG(timed_out) = 0;
     177             : 
     178       23363 :         EG(exception) = NULL;
     179       23363 :         EG(prev_exception) = NULL;
     180             : 
     181       23363 :         EG(fake_scope) = NULL;
     182             : 
     183       23363 :         EG(ht_iterators_count) = sizeof(EG(ht_iterators_slots)) / sizeof(HashTableIterator);
     184       23363 :         EG(ht_iterators_used) = 0;
     185       23363 :         EG(ht_iterators) = EG(ht_iterators_slots);
     186       23363 :         memset(EG(ht_iterators), 0, sizeof(EG(ht_iterators_slots)));
     187             : 
     188       23363 :         EG(active) = 1;
     189       23363 : }
     190             : /* }}} */
     191             : 
     192      398966 : static int zval_call_destructor(zval *zv) /* {{{ */
     193             : {
     194      398966 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     195        2693 :                 zv = Z_INDIRECT_P(zv);
     196             :         }
     197      409171 :         if (Z_TYPE_P(zv) == IS_OBJECT && Z_REFCOUNT_P(zv) == 1) {
     198        9447 :                 return ZEND_HASH_APPLY_REMOVE;
     199             :         } else {
     200      389519 :                 return ZEND_HASH_APPLY_KEEP;
     201             :         }
     202             : }
     203             : /* }}} */
     204             : 
     205       20912 : static void zend_unclean_zval_ptr_dtor(zval *zv) /* {{{ */
     206             : {
     207       20912 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     208        2331 :                 zv = Z_INDIRECT_P(zv);
     209             :         }
     210             :         i_zval_ptr_dtor(zv ZEND_FILE_LINE_CC);
     211       20912 : }
     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       23401 : void shutdown_destructors(void) /* {{{ */
     234             : {
     235       23401 :         if (CG(unclean_shutdown)) {
     236        2374 :                 EG(symbol_table).pDestructor = zend_unclean_zval_ptr_dtor;
     237             :         }
     238       23401 :         zend_try {
     239             :                 uint32_t symbols;
     240             :                 do {
     241       28823 :                         symbols = zend_hash_num_elements(&EG(symbol_table));
     242       28823 :                         zend_hash_reverse_apply(&EG(symbol_table), (apply_func_t) zval_call_destructor);
     243       28823 :                 } while (symbols != zend_hash_num_elements(&EG(symbol_table)));
     244       23401 :                 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       23401 :         } zend_end_try();
     249       23401 : }
     250             : /* }}} */
     251             : 
     252       23401 : void shutdown_executor(void) /* {{{ */
     253             : {
     254             :         zend_function *func;
     255             :         zend_class_entry *ce;
     256             : 
     257       23401 :         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       23401 :                 zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator);
     275             : 
     276       23401 :                 if (CG(unclean_shutdown)) {
     277        2380 :                         EG(symbol_table).pDestructor = zend_unclean_zval_ptr_dtor;
     278             :                 }
     279       23401 :                 zend_hash_graceful_reverse_destroy(&EG(symbol_table));
     280       23401 :         } zend_end_try();
     281       23401 :         EG(valid_symbol_table) = 0;
     282             : 
     283       23401 :         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       23401 :                 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       23401 :                 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       23401 :                 zend_stack_clean(&EG(user_error_handlers_error_reporting), NULL, 1);
     300       23401 :                 zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1);
     301       23401 :                 zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1);
     302       23401 :         } zend_end_try();
     303             : 
     304       23401 :         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       23401 :                 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      126206 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(function_table), func) {
     329       47697 :                                 if (func->type != ZEND_USER_FUNCTION) {
     330       23401 :                                         break;
     331             :                                 }
     332       24296 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     333             :                         } ZEND_HASH_FOREACH_END();
     334       78894 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) {
     335       33309 :                                 if (ce->type != ZEND_USER_CLASS) {
     336       23399 :                                         break;
     337             :                                 }
     338        9910 :                                 zend_cleanup_user_class_data(ce);
     339             :                         } ZEND_HASH_FOREACH_END();
     340       23399 :                         zend_cleanup_internal_classes();
     341             :                 }
     342       23401 :         } zend_end_try();
     343             : 
     344       23401 :         zend_try {
     345       23401 :                 zend_llist_destroy(&CG(open_files));
     346       23401 :         } zend_end_try();
     347             : 
     348       23401 :         zend_try {
     349       23401 :                 zend_close_rsrc_list(&EG(regular_list));
     350       23401 :         } 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       23401 :         zend_try {
     359       23401 :                 zend_objects_store_free_object_storage(&EG(objects_store));
     360             : 
     361       23401 :                 zend_vm_stack_destroy();
     362             : 
     363             :                 /* Destroy all op arrays */
     364       23401 :                 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       23401 :                         zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function);
     369       23401 :                         zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class);
     370             :                 }
     371             : 
     372       47059 :                 while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     373         257 :                         zend_hash_destroy(*EG(symtable_cache_ptr));
     374         257 :                         FREE_HASHTABLE(*EG(symtable_cache_ptr));
     375         257 :                         EG(symtable_cache_ptr)--;
     376             :                 }
     377       23401 :         } zend_end_try();
     378             : 
     379       23401 :         zend_try {
     380       23401 :                 clean_non_persistent_constants();
     381       23401 :         } zend_end_try();
     382             : 
     383       23401 :         zend_try {
     384             : #if 0&&ZEND_DEBUG
     385             :         signal(SIGSEGV, original_sigsegv_handler);
     386             : #endif
     387             : 
     388       23401 :                 zend_hash_destroy(&EG(included_files));
     389             : 
     390       23401 :                 zend_stack_destroy(&EG(user_error_handlers_error_reporting));
     391       23401 :                 zend_stack_destroy(&EG(user_error_handlers));
     392       23401 :                 zend_stack_destroy(&EG(user_exception_handlers));
     393       23401 :                 zend_objects_store_destroy(&EG(objects_store));
     394       23401 :                 if (EG(in_autoload)) {
     395          93 :                         zend_hash_destroy(EG(in_autoload));
     396          93 :                         FREE_HASHTABLE(EG(in_autoload));
     397             :                 }
     398       23401 :         } zend_end_try();
     399             : 
     400       23401 :         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       23401 :         EG(ht_iterators_used) = 0;
     409       23401 :         if (EG(ht_iterators) != EG(ht_iterators_slots)) {
     410           0 :                 efree(EG(ht_iterators));
     411             :         }
     412             : 
     413       23401 :         EG(active) = 0;
     414       23401 : }
     415             : /* }}} */
     416             : 
     417             : /* return class name and "::" or "". */
     418      234084 : ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
     419             : {
     420             :         zend_function *func;
     421             : 
     422      234084 :         if (!zend_is_executing()) {
     423           0 :                 if (space) {
     424           0 :                         *space = "";
     425             :                 }
     426           0 :                 return "";
     427             :         }
     428             : 
     429      234084 :         func = EG(current_execute_data)->func;
     430      234084 :         switch (func->type) {
     431             :                 case ZEND_USER_FUNCTION:
     432             :                 case ZEND_INTERNAL_FUNCTION:
     433             :                 {
     434      234084 :                         zend_class_entry *ce = func->common.scope;
     435             : 
     436      234084 :                         if (space) {
     437      234084 :                                 *space = ce ? "::" : "";
     438             :                         }
     439      234084 :                         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      234108 : ZEND_API const char *get_active_function_name(void) /* {{{ */
     451             : {
     452             :         zend_function *func;
     453             : 
     454      234108 :         if (!zend_is_executing()) {
     455          16 :                 return NULL;
     456             :         }
     457      234092 :         func = EG(current_execute_data)->func;
     458      234092 :         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      233883 :                         return ZSTR_VAL(func->common.function_name);
     471             :                         break;
     472             :                 default:
     473           0 :                         return NULL;
     474             :         }
     475             : }
     476             : /* }}} */
     477             : 
     478      444342 : ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
     479             : {
     480      444342 :         zend_execute_data *ex = EG(current_execute_data);
     481             : 
     482     1135140 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     483      246456 :                 ex = ex->prev_execute_data;
     484             :         }
     485      444342 :         if (ex) {
     486      444311 :                 return ZSTR_VAL(ex->func->op_array.filename);
     487             :         } else {
     488          31 :                 return "[no active file]";
     489             :         }
     490             : }
     491             : /* }}} */
     492             : 
     493        6564 : ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
     494             : {
     495        6564 :         zend_execute_data *ex = EG(current_execute_data);
     496             : 
     497       13232 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     498         104 :                 ex = ex->prev_execute_data;
     499             :         }
     500        6564 :         if (ex) {
     501        6564 :                 return ex->func->op_array.filename;
     502             :         } else {
     503           0 :                 return NULL;
     504             :         }
     505             : }
     506             : /* }}} */
     507             : 
     508      443517 : ZEND_API uint zend_get_executed_lineno(void) /* {{{ */
     509             : {
     510      443517 :         zend_execute_data *ex = EG(current_execute_data);
     511             : 
     512     1133073 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     513      246039 :                 ex = ex->prev_execute_data;
     514             :         }
     515      443517 :         if (ex) {
     516      443510 :                 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      443498 :                 return ex->opline->lineno;
     521             :         } else {
     522          15 :                 return 0;
     523             :         }
     524             : }
     525             : /* }}} */
     526             : 
     527        8891 : ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
     528             : {
     529        8891 :         zend_execute_data *ex = EG(current_execute_data);
     530             : 
     531             :         while (1) {
     532        9782 :                 if (!ex) {
     533           9 :                         return NULL;
     534        9773 :                 } else if (ex->func && (ZEND_USER_CODE(ex->func->type) || ex->func->common.scope)) {
     535        8882 :                         return ex->func->common.scope;
     536             :                 }
     537         891 :                 ex = ex->prev_execute_data;
     538         891 :         }
     539             : }
     540             : /* }}} */
     541             : 
     542      940386 : ZEND_API zend_bool zend_is_executing(void) /* {{{ */
     543             : {
     544      940386 :         return EG(current_execute_data) != 0;
     545             : }
     546             : /* }}} */
     547             : 
     548     7953410 : 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     7953410 : }
     552             : /* }}} */
     553             : 
     554    34346925 : ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     555             : {
     556    34346925 :         if (Z_REFCOUNTED_P(zval_ptr)) {
     557             :                 Z_DELREF_P(zval_ptr);
     558     2344500 :                 if (Z_REFCOUNT_P(zval_ptr) == 0) {
     559     1008135 :                         _zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC);
     560             :                 }
     561             :         }
     562    34346925 : }
     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          22 :                         char *actual = Z_STRVAL_P(p);
     591             : 
     592          22 :                         if (UNEXPECTED(EG(exception))) {
     593           2 :                                 RESET_CONSTANT_VISITED(p);
     594           2 :                                 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 :                                 zend_string *save = Z_STR_P(p);
     601             :                                 char *slash;
     602          20 :                                 size_t actual_len = Z_STRLEN_P(p);
     603          25 :                                 if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char *)zend_memrchr(actual, '\\', actual_len))) {
     604           3 :                                         actual = slash + 1;
     605           3 :                                         actual_len -= (actual - Z_STRVAL_P(p));
     606           3 :                                         if (inline_change) {
     607           3 :                                                 zend_string *s = zend_string_init(actual, actual_len, 0);
     608           3 :                                                 Z_STR_P(p) = s;
     609           3 :                                                 Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
     610             :                                         }
     611             :                                 }
     612          20 :                                 if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
     613          15 :                                         zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(save));
     614          15 :                                         if (inline_change) {
     615             :                                                 zend_string_release(save);
     616             :                                         }
     617          15 :                                         RESET_CONSTANT_VISITED(p);
     618          15 :                                         return FAILURE;
     619             :                                 } else {
     620           5 :                                         zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",  actual,  actual);
     621           5 :                                         if (!inline_change) {
     622           0 :                                                 ZVAL_STRINGL(p, actual, actual_len);
     623             :                                         } else {
     624           5 :                                                 Z_TYPE_INFO_P(p) = Z_REFCOUNTED_P(p) ?
     625             :                                                         IS_STRING_EX : IS_INTERNED_STRING_EX;
     626           5 :                                                 if (save && ZSTR_VAL(save) != actual) {
     627             :                                                         zend_string_release(save);
     628             :                                                 }
     629             :                                         }
     630             :                                 }
     631             :                         }
     632             :                 } else {
     633         270 :                         if (inline_change) {
     634         270 :                                 zend_string_release(Z_STR_P(p));
     635             :                         }
     636         270 :                         ZVAL_COPY_VALUE(p, const_value);
     637             :                         zval_opt_copy_ctor(p);
     638             :                 }
     639         394 :         } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
     640             :                 zval tmp;
     641             : 
     642         128 :                 inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
     643         128 :                 if (UNEXPECTED(zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope) != SUCCESS)) {
     644          15 :                         return FAILURE;
     645             :                 }
     646         111 :                 if (inline_change) {
     647         111 :                         zval_ptr_dtor(p);
     648             :                 }
     649         111 :                 ZVAL_COPY_VALUE(p, &tmp);
     650             :         }
     651         659 :         return SUCCESS;
     652             : }
     653             : /* }}} */
     654             : 
     655           0 : ZEND_API int zval_update_constant(zval *pp) /* {{{ */
     656             : {
     657           0 :         return zval_update_constant_ex(pp, EG(current_execute_data) ? zend_get_executed_scope() : CG(active_class_entry));
     658             : }
     659             : /* }}} */
     660             : 
     661       11638 : int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation) /* {{{ */
     662             : {
     663             :         zend_fcall_info fci;
     664             : 
     665       11638 :         fci.size = sizeof(fci);
     666       11638 :         fci.object = object ? Z_OBJ_P(object) : NULL;
     667       11638 :         ZVAL_COPY_VALUE(&fci.function_name, function_name);
     668       11638 :         fci.retval = retval_ptr;
     669       11638 :         fci.param_count = param_count;
     670       11638 :         fci.params = params;
     671       11638 :         fci.no_separation = (zend_bool) no_separation;
     672             : 
     673       11638 :         return zend_call_function(&fci, NULL);
     674             : }
     675             : /* }}} */
     676             : 
     677      820650 : int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /* {{{ */
     678             : {
     679             :         uint32_t i;
     680             :         zend_execute_data *call, dummy_execute_data;
     681             :         zend_fcall_info_cache fci_cache_local;
     682             :         zend_function *func;
     683             : 
     684      820650 :         ZVAL_UNDEF(fci->retval);
     685             : 
     686      820650 :         if (!EG(active)) {
     687           0 :                 return FAILURE; /* executor is already inactive */
     688             :         }
     689             : 
     690      820650 :         if (EG(exception)) {
     691          16 :                 return FAILURE; /* we would result in an instable executor otherwise */
     692             :         }
     693             : 
     694      820634 :         switch (fci->size) {
     695             :                 case sizeof(zend_fcall_info):
     696      820634 :                         break; /* nothing to do currently */
     697             :                 default:
     698           0 :                         zend_error_noreturn(E_CORE_ERROR, "Corrupted fcall_info provided to zend_call_function()");
     699             :                         break;
     700             :         }
     701             : 
     702             :         /* Initialize execute_data */
     703      820634 :         if (!EG(current_execute_data)) {
     704             :                 /* This only happens when we're called outside any execute()'s
     705             :                  * It shouldn't be strictly necessary to NULL execute_data out,
     706             :                  * but it may make bugs easier to spot
     707             :                  */
     708       20283 :                 memset(&dummy_execute_data, 0, sizeof(zend_execute_data));
     709       20283 :                 EG(current_execute_data) = &dummy_execute_data;
     710     1829377 :         } else if (EG(current_execute_data)->func &&
     711      800338 :                    ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
     712      191387 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL &&
     713       12437 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_ICALL &&
     714       12432 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_UCALL &&
     715       12432 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL_BY_NAME) {
     716             :                 /* Insert fake frame in case of include or magic calls */
     717       12172 :                 dummy_execute_data = *EG(current_execute_data);
     718       12172 :                 dummy_execute_data.prev_execute_data = EG(current_execute_data);
     719       12172 :                 dummy_execute_data.call = NULL;
     720       12172 :                 dummy_execute_data.opline = NULL;
     721       12172 :                 dummy_execute_data.func = NULL;
     722       12172 :                 EG(current_execute_data) = &dummy_execute_data;
     723             :         }
     724             : 
     725      820634 :         if (!fci_cache || !fci_cache->initialized) {
     726             :                 zend_string *callable_name;
     727       12469 :                 char *error = NULL;
     728             : 
     729       12469 :                 if (!fci_cache) {
     730       12445 :                         fci_cache = &fci_cache_local;
     731             :                 }
     732             : 
     733       12469 :                 if (!zend_is_callable_ex(&fci->function_name, fci->object, IS_CALLABLE_CHECK_SILENT, &callable_name, fci_cache, &error)) {
     734          87 :                         if (error) {
     735           0 :                                 zend_error(E_WARNING, "Invalid callback %s, %s", ZSTR_VAL(callable_name), error);
     736           0 :                                 efree(error);
     737             :                         }
     738          87 :                         if (callable_name) {
     739          87 :                                 zend_string_release(callable_name);
     740             :                         }
     741          87 :                         if (EG(current_execute_data) == &dummy_execute_data) {
     742          43 :                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     743             :                         }
     744          87 :                         return FAILURE;
     745       12382 :                 } else if (error) {
     746             :                         /* Capitalize the first latter of the error message */
     747           3 :                         if (error[0] >= 'a' && error[0] <= 'z') {
     748           3 :                                 error[0] += ('A' - 'a');
     749             :                         }
     750           3 :                         zend_error(E_DEPRECATED, "%s", error);
     751           3 :                         efree(error);
     752             :                 }
     753       12382 :                 zend_string_release(callable_name);
     754             :         }
     755             : 
     756      820547 :         func = fci_cache->function_handler;
     757      820547 :         fci->object = (func->common.fn_flags & ZEND_ACC_STATIC) ?
     758             :                 NULL : fci_cache->object;
     759             : 
     760     1641094 :         call = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC,
     761             :                 func, fci->param_count, fci_cache->called_scope, fci->object);
     762     1958465 :         if (fci->object &&
     763      568959 :             (!EG(objects_store).object_buckets ||
     764      568959 :              !IS_OBJ_VALID(EG(objects_store).object_buckets[fci->object->handle]))) {
     765           0 :                 if (EG(current_execute_data) == &dummy_execute_data) {
     766           0 :                         EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     767             :                 }
     768           0 :                 return FAILURE;
     769             :         }
     770             : 
     771      820547 :         if (func->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
     772           0 :                 if (func->common.fn_flags & ZEND_ACC_ABSTRACT) {
     773           0 :                         zend_throw_error(NULL, "Cannot call abstract method %s::%s()", ZSTR_VAL(func->common.scope->name), ZSTR_VAL(func->common.function_name));
     774           0 :                         if (EG(current_execute_data) == &dummy_execute_data) {
     775           0 :                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     776             :                         }
     777           0 :                         return FAILURE;
     778             :                 }
     779           0 :                 if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
     780           0 :                         zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
     781           0 :                                 func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
     782           0 :                                 func->common.scope ? "::" : "",
     783           0 :                                 ZSTR_VAL(func->common.function_name));
     784             :                 }
     785             :         }
     786             : 
     787     1346189 :         for (i=0; i<fci->param_count; i++) {
     788             :                 zval *param;
     789      525647 :                 zval *arg = &fci->params[i];
     790             : 
     791     1051294 :                 if (ARG_SHOULD_BE_SENT_BY_REF(func, i + 1)) {
     792         369 :                         if (UNEXPECTED(!Z_ISREF_P(arg))) {
     793         259 :                                 if (fci->no_separation &&
     794           8 :                                         !ARG_MAY_BE_SENT_BY_REF(func, i + 1)) {
     795           5 :                                         if (i) {
     796             :                                                 /* hack to clean up the stack */
     797           0 :                                                 ZEND_CALL_NUM_ARGS(call) = i;
     798             :                                                 zend_vm_stack_free_args(call);
     799             :                                         }
     800             :                                         zend_vm_stack_free_call_frame(call);
     801             : 
     802          17 :                                         zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
     803             :                                                 i+1,
     804           7 :                                                 func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
     805           5 :                                                 func->common.scope ? "::" : "",
     806           5 :                                                 ZSTR_VAL(func->common.function_name));
     807           5 :                                         if (EG(current_execute_data) == &dummy_execute_data) {
     808           0 :                                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     809             :                                         }
     810           5 :                                         return FAILURE;
     811             :                                 }
     812             : 
     813         246 :                                 ZVAL_NEW_REF(arg, arg);
     814             :                         }
     815             :                         Z_ADDREF_P(arg);
     816             :                 } else {
     817      525360 :                         if (Z_ISREF_P(arg) &&
     818          82 :                             !(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
     819             :                                 /* don't separate references for __call */
     820          82 :                                 arg = Z_REFVAL_P(arg);
     821             :                         }
     822      525278 :                         if (Z_OPT_REFCOUNTED_P(arg)) {
     823             :                                 Z_ADDREF_P(arg);
     824             :                         }
     825             :                 }
     826      525642 :                 param = ZEND_CALL_ARG(call, i+1);
     827      525642 :                 ZVAL_COPY_VALUE(param, arg);
     828             :         }
     829             : 
     830      820542 :         if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
     831             :                 ZEND_ASSERT(GC_TYPE((zend_object*)func->op_array.prototype) == IS_OBJECT);
     832         708 :                 GC_REFCOUNT((zend_object*)func->op_array.prototype)++;
     833         708 :                 ZEND_ADD_CALL_FLAG(call, ZEND_CALL_CLOSURE);
     834             :         }
     835             : 
     836      820542 :         if (func->type == ZEND_USER_FUNCTION) {
     837      572080 :                 int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
     838      572080 :                 zend_init_execute_data(call, &func->op_array, fci->retval);
     839      572080 :                 zend_execute_ex(call);
     840      572045 :                 if (call_via_handler) {
     841             :                         /* We must re-initialize function again */
     842           7 :                         fci_cache->initialized = 0;
     843             :                 }
     844      248462 :         } else if (func->type == ZEND_INTERNAL_FUNCTION) {
     845      248462 :                 int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
     846      248462 :                 ZVAL_NULL(fci->retval);
     847      248462 :                 call->prev_execute_data = EG(current_execute_data);
     848      248462 :                 call->return_value = NULL; /* this is not a constructor call */
     849      248462 :                 EG(current_execute_data) = call;
     850      248462 :                 if (EXPECTED(zend_execute_internal == NULL)) {
     851             :                         /* saves one function call if zend_execute_internal is not used */
     852      248462 :                         func->internal_function.handler(call, fci->retval);
     853             :                 } else {
     854           0 :                         zend_execute_internal(call, fci->retval);
     855             :                 }
     856      248460 :                 EG(current_execute_data) = call->prev_execute_data;
     857             :                 zend_vm_stack_free_args(call);
     858             : 
     859             :                 /*  We shouldn't fix bad extensions here,
     860             :                         because it can break proper ones (Bug #34045)
     861             :                 if (!EX(function_state).function->common.return_reference)
     862             :                 {
     863             :                         INIT_PZVAL(f->retval);
     864             :                 }*/
     865      248460 :                 if (EG(exception)) {
     866          83 :                         zval_ptr_dtor(fci->retval);
     867          83 :                         ZVAL_UNDEF(fci->retval);
     868             :                 }
     869             : 
     870      248460 :                 if (call_via_handler) {
     871             :                         /* We must re-initialize function again */
     872           4 :                         fci_cache->initialized = 0;
     873             :                 }
     874             :         } else { /* ZEND_OVERLOADED_FUNCTION */
     875           0 :                 ZVAL_NULL(fci->retval);
     876             : 
     877             :                 /* Not sure what should be done here if it's a static method */
     878           0 :                 if (fci->object) {
     879           0 :                         call->prev_execute_data = EG(current_execute_data);
     880           0 :                         EG(current_execute_data) = call;
     881           0 :                         fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval);
     882           0 :                         EG(current_execute_data) = call->prev_execute_data;
     883             :                 } else {
     884           0 :                         zend_throw_error(NULL, "Cannot call overloaded function for non-object");
     885             :                 }
     886             : 
     887             :                 zend_vm_stack_free_args(call);
     888             : 
     889           0 :                 if (func->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
     890           0 :                         zend_string_release(func->common.function_name);
     891             :                 }
     892           0 :                 efree(func);
     893             : 
     894           0 :                 if (EG(exception)) {
     895           0 :                         zval_ptr_dtor(fci->retval);
     896           0 :                         ZVAL_UNDEF(fci->retval);
     897             :                 }
     898             :         }
     899             : 
     900             :         zend_vm_stack_free_call_frame(call);
     901             : 
     902      820505 :         if (EG(current_execute_data) == &dummy_execute_data) {
     903       32395 :                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     904             :         }
     905             : 
     906      820505 :         if (EG(exception)) {
     907         372 :                 zend_throw_exception_internal(NULL);
     908             :         }
     909      820499 :         return SUCCESS;
     910             : }
     911             : /* }}} */
     912             : 
     913      169851 : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */
     914             : {
     915      169851 :         zend_class_entry *ce = NULL;
     916             :         zval args[1];
     917             :         zval local_retval;
     918             :         zend_string *lc_name;
     919             :         zend_fcall_info fcall_info;
     920             :         zend_fcall_info_cache fcall_cache;
     921             : 
     922      169851 :         if (key) {
     923       21246 :                 lc_name = Z_STR_P(key);
     924             :         } else {
     925      148605 :                 if (name == NULL || !ZSTR_LEN(name)) {
     926          84 :                         return NULL;
     927             :                 }
     928             : 
     929      148521 :                 if (ZSTR_VAL(name)[0] == '\\') {
     930          28 :                         lc_name = zend_string_alloc(ZSTR_LEN(name) - 1, 0);
     931          14 :                         zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
     932             :                 } else {
     933      148507 :                         lc_name = zend_string_tolower(name);
     934             :                 }
     935             :         }
     936             : 
     937      339534 :         ce = zend_hash_find_ptr(EG(class_table), lc_name);
     938      169767 :         if (ce) {
     939      169000 :                 if (!key) {
     940             :                         zend_string_release(lc_name);
     941             :                 }
     942      169000 :                 return ce;
     943             :         }
     944             : 
     945             :         /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
     946             :          * (doesn't impact functionality of __autoload()
     947             :         */
     948         767 :         if (!use_autoload || zend_is_compiling()) {
     949         376 :                 if (!key) {
     950             :                         zend_string_release(lc_name);
     951             :                 }
     952         376 :                 return NULL;
     953             :         }
     954             : 
     955         391 :         if (!EG(autoload_func)) {
     956         462 :                 zend_function *func = zend_hash_find_ptr(EG(function_table), CG(known_strings)[ZEND_STR_MAGIC_AUTOLOAD]);
     957         231 :                 if (func) {
     958          67 :                         EG(autoload_func) = func;
     959             :                 } else {
     960         164 :                         if (!key) {
     961             :                                 zend_string_release(lc_name);
     962             :                         }
     963         164 :                         return NULL;
     964             :                 }
     965             : 
     966             :         }
     967             : 
     968             :         /* Verify class name before passing it to __autoload() */
     969         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)) {
     970          11 :                 if (!key) {
     971             :                         zend_string_release(lc_name);
     972             :                 }
     973          11 :                 return NULL;
     974             :         }
     975             : 
     976         216 :         if (EG(in_autoload) == NULL) {
     977          93 :                 ALLOC_HASHTABLE(EG(in_autoload));
     978          93 :                 zend_hash_init(EG(in_autoload), 8, NULL, NULL, 0);
     979             :         }
     980             : 
     981         216 :         if (zend_hash_add_empty_element(EG(in_autoload), lc_name) == NULL) {
     982           4 :                 if (!key) {
     983             :                         zend_string_release(lc_name);
     984             :                 }
     985           4 :                 return NULL;
     986             :         }
     987             : 
     988         212 :         ZVAL_UNDEF(&local_retval);
     989             : 
     990         212 :         if (ZSTR_VAL(name)[0] == '\\') {
     991           2 :                 ZVAL_STRINGL(&args[0], ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1);
     992             :         } else {
     993         211 :                 ZVAL_STR_COPY(&args[0], name);
     994             :         }
     995             : 
     996         212 :         fcall_info.size = sizeof(fcall_info);
     997         212 :         ZVAL_STR_COPY(&fcall_info.function_name, EG(autoload_func)->common.function_name);
     998         212 :         fcall_info.retval = &local_retval;
     999         212 :         fcall_info.param_count = 1;
    1000         212 :         fcall_info.params = args;
    1001         212 :         fcall_info.object = NULL;
    1002         212 :         fcall_info.no_separation = 1;
    1003             : 
    1004         212 :         fcall_cache.initialized = 1;
    1005         212 :         fcall_cache.function_handler = EG(autoload_func);
    1006         212 :         fcall_cache.calling_scope = NULL;
    1007         212 :         fcall_cache.called_scope = NULL;
    1008         212 :         fcall_cache.object = NULL;
    1009             : 
    1010         212 :         zend_exception_save();
    1011         212 :         if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) {
    1012         368 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1013             :         }
    1014         209 :         zend_exception_restore();
    1015             : 
    1016         209 :         zval_ptr_dtor(&args[0]);
    1017             :         zval_dtor(&fcall_info.function_name);
    1018             : 
    1019         209 :         zend_hash_del(EG(in_autoload), lc_name);
    1020             : 
    1021         209 :         zval_ptr_dtor(&local_retval);
    1022             : 
    1023         209 :         if (!key) {
    1024             :                 zend_string_release(lc_name);
    1025             :         }
    1026         209 :         return ce;
    1027             : }
    1028             : /* }}} */
    1029             : 
    1030      145056 : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name) /* {{{ */
    1031             : {
    1032      145056 :         return zend_lookup_class_ex(name, NULL, 1);
    1033             : }
    1034             : /* }}} */
    1035             : 
    1036       23470 : ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex) /* {{{ */
    1037             : {
    1038       47270 :         while (ex) {
    1039        1610 :                 if (Z_TYPE(ex->This) == IS_OBJECT) {
    1040          83 :                         return Z_OBJCE(ex->This);
    1041         722 :                 } else if (Z_CE(ex->This)) {
    1042         200 :                         return Z_CE(ex->This);
    1043         522 :                 } else if (ex->func) {
    1044         485 :                         if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) {
    1045         192 :                                 return NULL;
    1046             :                         }
    1047             :                 }
    1048         330 :                 ex = ex->prev_execute_data;
    1049             :         }
    1050       22995 :         return NULL;
    1051             : }
    1052             : /* }}} */
    1053             : 
    1054       23328 : ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex) /* {{{ */
    1055             : {
    1056       46823 :         while (ex) {
    1057        1008 :                 if (Z_TYPE(ex->This) == IS_OBJECT) {
    1058          95 :                         return Z_OBJ(ex->This);
    1059         409 :                 } else if (ex->func) {
    1060         408 :                         if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) {
    1061         242 :                                 return NULL;
    1062             :                         }
    1063             :                 }
    1064         167 :                 ex = ex->prev_execute_data;
    1065             :         }
    1066       22991 :         return NULL;
    1067             : }
    1068             : /* }}} */
    1069             : 
    1070         179 : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{{ */
    1071             : {
    1072             :         zval pv;
    1073             :         zend_op_array *new_op_array;
    1074             :         uint32_t original_compiler_options;
    1075             :         int retval;
    1076             : 
    1077         179 :         if (retval_ptr) {
    1078         160 :                 ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 1));
    1079          80 :                 memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
    1080          80 :                 memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
    1081          80 :                 Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
    1082          80 :                 Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
    1083             :         } else {
    1084         198 :                 ZVAL_STRINGL(&pv, str, str_len);
    1085             :         }
    1086             : 
    1087             :         /*printf("Evaluating '%s'\n", pv.value.str.val);*/
    1088             : 
    1089         179 :         original_compiler_options = CG(compiler_options);
    1090         179 :         CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
    1091         179 :         new_op_array = zend_compile_string(&pv, string_name);
    1092         179 :         CG(compiler_options) = original_compiler_options;
    1093             : 
    1094         179 :         if (new_op_array) {
    1095             :                 zval local_retval;
    1096             : 
    1097         171 :                 EG(no_extensions)=1;
    1098             : 
    1099         171 :                 zend_try {
    1100         171 :                         ZVAL_UNDEF(&local_retval);
    1101         171 :                         zend_execute(new_op_array, &local_retval);
    1102           1 :                 } zend_catch {
    1103           1 :                         destroy_op_array(new_op_array);
    1104           1 :                         efree_size(new_op_array, sizeof(zend_op_array));
    1105           1 :                         zend_bailout();
    1106         170 :                 } zend_end_try();
    1107             : 
    1108         170 :                 if (Z_TYPE(local_retval) != IS_UNDEF) {
    1109         169 :                         if (retval_ptr) {
    1110          73 :                                 ZVAL_COPY_VALUE(retval_ptr, &local_retval);
    1111             :                         } else {
    1112          96 :                                 zval_ptr_dtor(&local_retval);
    1113             :                         }
    1114             :                 } else {
    1115           1 :                         if (retval_ptr) {
    1116           1 :                                 ZVAL_NULL(retval_ptr);
    1117             :                         }
    1118             :                 }
    1119             : 
    1120         170 :                 EG(no_extensions)=0;
    1121         170 :                 destroy_op_array(new_op_array);
    1122         170 :                 efree_size(new_op_array, sizeof(zend_op_array));
    1123         170 :                 retval = SUCCESS;
    1124             :         } else {
    1125           8 :                 retval = FAILURE;
    1126             :         }
    1127             :         zval_dtor(&pv);
    1128         178 :         return retval;
    1129             : }
    1130             : /* }}} */
    1131             : 
    1132           0 : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name) /* {{{ */
    1133             : {
    1134           0 :         return zend_eval_stringl(str, strlen(str), retval_ptr, string_name);
    1135             : }
    1136             : /* }}} */
    1137             : 
    1138          31 : ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */
    1139             : {
    1140             :         int result;
    1141             : 
    1142          31 :         result = zend_eval_stringl(str, str_len, retval_ptr, string_name);
    1143          30 :         if (handle_exceptions && EG(exception)) {
    1144           0 :                 zend_exception_error(EG(exception), E_ERROR);
    1145           0 :                 result = FAILURE;
    1146             :         }
    1147          30 :         return result;
    1148             : }
    1149             : /* }}} */
    1150             : 
    1151          31 : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */
    1152             : {
    1153          31 :         return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions);
    1154             : }
    1155             : /* }}} */
    1156             : 
    1157             : static void zend_set_timeout_ex(zend_long seconds, int reset_signals);
    1158             : 
    1159          13 : ZEND_API ZEND_NORETURN void zend_timeout(int dummy) /* {{{ */
    1160             : {
    1161             : #if defined(PHP_WIN32)
    1162             : # ifndef ZTS
    1163             :         /* No action is needed if we're timed out because zero seconds are
    1164             :            just ignored. Also, the hard timeout needs to be respected. If the
    1165             :            timer is not restarted properly, it could hang in the shutdown
    1166             :            function. */
    1167             :         if (EG(hard_timeout) > 0) {
    1168             :                 EG(timed_out) = 0;
    1169             :                 zend_set_timeout_ex(EG(hard_timeout), 1);
    1170             :                 /* XXX Abused, introduce an additional flag if the value needs to be kept. */
    1171             :                 EG(hard_timeout) = 0;
    1172             :         }
    1173             : # endif
    1174             : #else
    1175          13 :         EG(timed_out) = 0;
    1176          13 :         zend_set_timeout_ex(0, 1);
    1177             : #endif
    1178             : 
    1179          13 :         zend_error_noreturn(E_ERROR, "Maximum execution time of " ZEND_LONG_FMT " second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
    1180             : }
    1181             : /* }}} */
    1182             : 
    1183             : #ifndef ZEND_WIN32
    1184          13 : static void zend_timeout_handler(int dummy) /* {{{ */
    1185             : {
    1186             : #ifndef ZTS
    1187          13 :     if (EG(timed_out)) {
    1188             :                 /* Die on hard timeout */
    1189           0 :                 const char *error_filename = NULL;
    1190           0 :                 uint error_lineno = 0;
    1191             :                 char log_buffer[2048];
    1192           0 :                 int output_len = 0;
    1193             : 
    1194           0 :                 if (zend_is_compiling()) {
    1195           0 :                         error_filename = ZSTR_VAL(zend_get_compiled_filename());
    1196           0 :                         error_lineno = zend_get_compiled_lineno();
    1197           0 :                 } else if (zend_is_executing()) {
    1198           0 :                         error_filename = zend_get_executed_filename();
    1199           0 :                         if (error_filename[0] == '[') { /* [no active file] */
    1200           0 :                                 error_filename = NULL;
    1201           0 :                                 error_lineno = 0;
    1202             :                         } else {
    1203           0 :                                 error_lineno = zend_get_executed_lineno();
    1204             :                         }
    1205             :                 }
    1206           0 :                 if (!error_filename) {
    1207           0 :                         error_filename = "Unknown";
    1208             :                 }
    1209             : 
    1210           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);
    1211           0 :                 if (output_len > 0) {
    1212           0 :                         write(2, log_buffer, MIN(output_len, sizeof(log_buffer)));
    1213             :                 }
    1214           0 :                 _exit(1);
    1215             :     }
    1216             : #endif
    1217             : 
    1218          13 :         if (zend_on_timeout) {
    1219             : #ifdef ZEND_SIGNALS
    1220             :                 /*
    1221             :                    We got here because we got a timeout signal, so we are in a signal handler
    1222             :                    at this point. However, we want to be able to timeout any user-supplied
    1223             :                    shutdown functions, so pretend we are not in a signal handler while we are
    1224             :                    calling these
    1225             :                 */
    1226          13 :                 SIGG(running) = 0;
    1227             : #endif
    1228          13 :                 zend_on_timeout(EG(timeout_seconds));
    1229             :         }
    1230             : 
    1231          13 :         EG(timed_out) = 1;
    1232          13 :         EG(vm_interrupt) = 1;
    1233             : 
    1234             : #ifndef ZTS
    1235          13 :         if (EG(hard_timeout) > 0) {
    1236             :                 /* Set hard timeout */
    1237          13 :                 zend_set_timeout_ex(EG(hard_timeout), 1);
    1238             :         }
    1239             : #endif
    1240          13 : }
    1241             : /* }}} */
    1242             : #endif
    1243             : 
    1244             : #ifdef ZEND_WIN32
    1245             : VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
    1246             : {
    1247             :         zend_executor_globals *eg;
    1248             : 
    1249             :         /* The doc states it'll be always true, however it theoretically
    1250             :                 could be FALSE when the thread was signaled. */
    1251             :         if (!timed_out) {
    1252             :                 return;
    1253             :         }
    1254             : 
    1255             :         eg = (zend_executor_globals *)arg;
    1256             :         eg->timed_out = 1;
    1257             :         eg->vm_interrupt = 1;
    1258             : }
    1259             : #endif
    1260             : 
    1261             : /* This one doesn't exists on QNX */
    1262             : #ifndef SIGPROF
    1263             : #define SIGPROF 27
    1264             : #endif
    1265             : 
    1266       23444 : static void zend_set_timeout_ex(zend_long seconds, int reset_signals) /* {{{ */
    1267             : {
    1268             : #ifdef ZEND_WIN32
    1269             :         zend_executor_globals *eg;
    1270             : 
    1271             :         if(!seconds) {
    1272             :                 return;
    1273             :         }
    1274             : 
    1275             :         /* Don't use ChangeTimerQueueTimer() as it will not restart an expired
    1276             :                 timer, so we could end up with just an ignored timeout. Instead
    1277             :                 delete and recreate. */
    1278             :         if (NULL != tq_timer) {
    1279             :                 if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
    1280             :                         tq_timer = NULL;
    1281             :                         zend_error_noreturn(E_ERROR, "Could not delete queued timer");
    1282             :                         return;
    1283             :                 }
    1284             :                 tq_timer = NULL;
    1285             :         }
    1286             : 
    1287             :         /* XXX passing NULL means the default timer queue provided by the system is used */
    1288             :         eg = ZEND_MODULE_GLOBALS_BULK(executor);
    1289             :         if (!CreateTimerQueueTimer(&tq_timer, NULL, (WAITORTIMERCALLBACK)tq_timer_cb, (VOID*)eg, seconds*1000, 0, WT_EXECUTEONLYONCE)) {
    1290             :                 tq_timer = NULL;
    1291             :                 zend_error_noreturn(E_ERROR, "Could not queue new timer");
    1292             :                 return;
    1293             :         }
    1294             : #else
    1295             : #       ifdef HAVE_SETITIMER
    1296             :         {
    1297             :                 struct itimerval t_r;           /* timeout requested */
    1298             :                 int signo;
    1299             : 
    1300       23444 :                 if(seconds) {
    1301         472 :                         t_r.it_value.tv_sec = seconds;
    1302         472 :                         t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
    1303             : 
    1304             : #       ifdef __CYGWIN__
    1305             :                         setitimer(ITIMER_REAL, &t_r, NULL);
    1306             :                 }
    1307             :                 signo = SIGALRM;
    1308             : #       else
    1309         472 :                         setitimer(ITIMER_PROF, &t_r, NULL);
    1310             :                 }
    1311       23444 :                 signo = SIGPROF;
    1312             : #       endif
    1313             : 
    1314       23444 :                 if (reset_signals) {
    1315             : #       ifdef ZEND_SIGNALS
    1316       23389 :                         zend_signal(signo, zend_timeout_handler);
    1317             : #       else
    1318             :                         sigset_t sigset;
    1319             : #   ifdef HAVE_SIGACTION
    1320             :                         struct sigaction act;
    1321             : 
    1322             :                         act.sa_handler = zend_timeout_handler;
    1323             :                         sigemptyset(&act.sa_mask);
    1324             :                         act.sa_flags = SA_RESETHAND | SA_NODEFER;
    1325             :                         sigaction(signo, &act, NULL);
    1326             : #   else
    1327             :                         signal(signo, zend_timeout_handler);
    1328             : #   endif /* HAVE_SIGACTION */
    1329             :                         sigemptyset(&sigset);
    1330             :                         sigaddset(&sigset, signo);
    1331             :                         sigprocmask(SIG_UNBLOCK, &sigset, NULL);
    1332             : #       endif /* ZEND_SIGNALS */
    1333             :                 }
    1334             :         }
    1335             : #       endif /* HAVE_SETITIMER */
    1336             : #endif
    1337       23444 : }
    1338             : /* }}} */
    1339             : 
    1340       23418 : void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
    1341             : {
    1342             : 
    1343       23418 :         EG(timeout_seconds) = seconds;
    1344       23418 :         zend_set_timeout_ex(seconds, reset_signals);
    1345       23418 :         EG(timed_out) = 0;
    1346       23418 : }
    1347             : /* }}} */
    1348             : 
    1349       46857 : void zend_unset_timeout(void) /* {{{ */
    1350             : {
    1351             : #ifdef ZEND_WIN32
    1352             :         if (NULL != tq_timer) {
    1353             :                 if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
    1354             :                         EG(timed_out) = 0;
    1355             :                         tq_timer = NULL;
    1356             :                         zend_error_noreturn(E_ERROR, "Could not delete queued timer");
    1357             :                         return;
    1358             :                 }
    1359             :                 tq_timer = NULL;
    1360             :         }
    1361             :         EG(timed_out) = 0;
    1362             : #else
    1363             : #       ifdef HAVE_SETITIMER
    1364       46857 :         if (EG(timeout_seconds)) {
    1365             :                 struct itimerval no_timeout;
    1366             : 
    1367         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;
    1368             : 
    1369             : #ifdef __CYGWIN__
    1370             :                 setitimer(ITIMER_REAL, &no_timeout, NULL);
    1371             : #else
    1372         910 :                 setitimer(ITIMER_PROF, &no_timeout, NULL);
    1373             : #endif
    1374             :         }
    1375             : #       endif
    1376       46857 :         EG(timed_out) = 0;
    1377             : #endif
    1378       46857 : }
    1379             : /* }}} */
    1380             : 
    1381        6188 : zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {{{ */
    1382             : {
    1383             :         zend_class_entry *ce, *scope;
    1384        6188 :         int fetch_sub_type = fetch_type & ZEND_FETCH_CLASS_MASK;
    1385             : 
    1386             : check_fetch_type:
    1387        6199 :         switch (fetch_sub_type) {
    1388             :                 case ZEND_FETCH_CLASS_SELF:
    1389        1698 :                         scope = zend_get_executed_scope();
    1390        1698 :                         if (UNEXPECTED(!scope)) {
    1391           6 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access self:: when no class scope is active");
    1392             :                         }
    1393        1698 :                         return scope;
    1394             :                 case ZEND_FETCH_CLASS_PARENT:
    1395        1382 :                         scope = zend_get_executed_scope();
    1396        1382 :                         if (UNEXPECTED(!scope)) {
    1397           1 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when no class scope is active");
    1398           1 :                                 return NULL;
    1399             :                         }
    1400        1381 :                         if (UNEXPECTED(!scope->parent)) {
    1401           0 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when current class scope has no parent");
    1402             :                         }
    1403        1381 :                         return scope->parent;
    1404             :                 case ZEND_FETCH_CLASS_STATIC:
    1405         122 :                         ce = zend_get_called_scope(EG(current_execute_data));
    1406         122 :                         if (UNEXPECTED(!ce)) {
    1407           4 :                                 zend_throw_or_error(fetch_type, NULL, "Cannot access static:: when no class scope is active");
    1408           4 :                                 return NULL;
    1409             :                         }
    1410         118 :                         return ce;
    1411             :                 case ZEND_FETCH_CLASS_AUTO: {
    1412        1489 :                                 fetch_sub_type = zend_get_class_fetch_type(class_name);
    1413        1489 :                                 if (UNEXPECTED(fetch_sub_type != ZEND_FETCH_CLASS_DEFAULT)) {
    1414          11 :                                         goto check_fetch_type;
    1415             :                                 }
    1416             :                         }
    1417             :                         break;
    1418             :         }
    1419             : 
    1420        2986 :         if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) {
    1421        1516 :                 return zend_lookup_class_ex(class_name, NULL, 0);
    1422        1470 :         } else if ((ce = zend_lookup_class_ex(class_name, NULL, 1)) == NULL) {
    1423          16 :                 if (!(fetch_type & ZEND_FETCH_CLASS_SILENT) && !EG(exception)) {
    1424          13 :                         if (fetch_sub_type == ZEND_FETCH_CLASS_INTERFACE) {
    1425           0 :                                 zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name));
    1426          13 :                         } else if (fetch_sub_type == ZEND_FETCH_CLASS_TRAIT) {
    1427           0 :                                 zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name));
    1428             :                         } else {
    1429          13 :                                 zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name));
    1430             :                         }
    1431             :                 }
    1432           8 :                 return NULL;
    1433             :         }
    1434        1453 :         return ce;
    1435             : }
    1436             : /* }}} */
    1437             : 
    1438       19797 : zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type) /* {{{ */
    1439             : {
    1440             :         zend_class_entry *ce;
    1441             : 
    1442       19797 :         if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) {
    1443        1323 :                 return zend_lookup_class_ex(class_name, key, 0);
    1444       18474 :         } else if ((ce = zend_lookup_class_ex(class_name, key, 1)) == NULL) {
    1445          39 :                 if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) {
    1446          25 :                         if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
    1447           2 :                                 zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name));
    1448          23 :                         } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
    1449           2 :                                 zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name));
    1450             :                         } else {
    1451          21 :                                 zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name));
    1452             :                         }
    1453             :                 }
    1454          34 :                 return NULL;
    1455             :         }
    1456       18434 :         return ce;
    1457             : }
    1458             : /* }}} */
    1459             : 
    1460             : #define MAX_ABSTRACT_INFO_CNT 3
    1461             : #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
    1462             : #define DISPLAY_ABSTRACT_FN(idx) \
    1463             :         ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
    1464             :         ai.afn[idx] ? "::" : "", \
    1465             :         ai.afn[idx] ? ZSTR_VAL(ai.afn[idx]->common.function_name) : "", \
    1466             :         ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
    1467             : 
    1468             : typedef struct _zend_abstract_info {
    1469             :         zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
    1470             :         int cnt;
    1471             :         int ctor;
    1472             : } zend_abstract_info;
    1473             : 
    1474          18 : static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai) /* {{{ */
    1475             : {
    1476          18 :         if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
    1477          14 :                 if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
    1478          14 :                         ai->afn[ai->cnt] = fn;
    1479             :                 }
    1480          14 :                 if (fn->common.fn_flags & ZEND_ACC_CTOR) {
    1481           1 :                         if (!ai->ctor) {
    1482           1 :                                 ai->cnt++;
    1483           1 :                                 ai->ctor = 1;
    1484             :                         } else {
    1485           0 :                                 ai->afn[ai->cnt] = NULL;
    1486             :                         }
    1487             :                 } else {
    1488          13 :                         ai->cnt++;
    1489             :                 }
    1490             :         }
    1491          18 : }
    1492             : /* }}} */
    1493             : 
    1494     1766110 : void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
    1495             : {
    1496             :         zend_function *func;
    1497             :         zend_abstract_info ai;
    1498             : 
    1499     1766110 :         if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & (ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) {
    1500          14 :                 memset(&ai, 0, sizeof(ai));
    1501             : 
    1502          50 :                 ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
    1503          18 :                         zend_verify_abstract_class_function(func, &ai);
    1504             :                 } ZEND_HASH_FOREACH_END();
    1505             : 
    1506          14 :                 if (ai.cnt) {
    1507         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 ")",
    1508          13 :                                 ZSTR_VAL(ce->name), ai.cnt,
    1509          13 :                                 ai.cnt > 1 ? "s" : "",
    1510         103 :                                 DISPLAY_ABSTRACT_FN(0),
    1511          68 :                                 DISPLAY_ABSTRACT_FN(1),
    1512          65 :                                 DISPLAY_ABSTRACT_FN(2)
    1513             :                                 );
    1514             :                 }
    1515             :         }
    1516     1766097 : }
    1517             : /* }}} */
    1518             : 
    1519         469 : ZEND_API int zend_delete_global_variable(zend_string *name) /* {{{ */
    1520             : {
    1521         469 :     return zend_hash_del_ind(&EG(symbol_table), name);
    1522             : }
    1523             : /* }}} */
    1524             : 
    1525        3249 : ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
    1526             : {
    1527             :         zend_execute_data *ex;
    1528             :         zend_array *symbol_table;
    1529             : 
    1530             :         /* Search for last called user function */
    1531        3249 :         ex = EG(current_execute_data);
    1532        8684 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) {
    1533        2186 :                 ex = ex->prev_execute_data;
    1534             :         }
    1535        3249 :         if (!ex) {
    1536          34 :                 return NULL;
    1537             :         }
    1538        3215 :         if (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE) {
    1539        2779 :                 return ex->symbol_table;
    1540             :         }
    1541             : 
    1542         436 :         ZEND_ADD_CALL_FLAG(ex, ZEND_CALL_HAS_SYMBOL_TABLE);
    1543         436 :         if (EG(symtable_cache_ptr) >= EG(symtable_cache)) {
    1544             :                 /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
    1545         172 :                 symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--);
    1546         172 :                 if (!ex->func->op_array.last_var) {
    1547           2 :                         return symbol_table;
    1548             :                 }
    1549         170 :                 zend_hash_extend(symbol_table, ex->func->op_array.last_var, 0);
    1550             :         } else {
    1551         264 :                 symbol_table = ex->symbol_table = emalloc(sizeof(zend_array));
    1552         264 :                 zend_hash_init(symbol_table, ex->func->op_array.last_var, NULL, ZVAL_PTR_DTOR, 0);
    1553         264 :                 if (!ex->func->op_array.last_var) {
    1554          17 :                         return symbol_table;
    1555             :                 }
    1556         247 :                 zend_hash_real_init(symbol_table, 0);
    1557             :                 /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
    1558             :         }
    1559         417 :         if (EXPECTED(ex->func->op_array.last_var)) {
    1560         417 :                 zend_string **str = ex->func->op_array.vars;
    1561         417 :                 zend_string **end = str + ex->func->op_array.last_var;
    1562         417 :                 zval *var = ZEND_CALL_VAR_NUM(ex, 0);
    1563             : 
    1564             :                 do {
    1565        2145 :                         _zend_hash_append_ind(symbol_table, *str, var);
    1566        2145 :                         str++;
    1567        2145 :                         var++;
    1568        2145 :                 } while (str != end);
    1569             :         }
    1570         417 :         return symbol_table;
    1571             : }
    1572             : /* }}} */
    1573             : 
    1574       44959 : ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1575             : {
    1576       44959 :         zend_op_array *op_array = &execute_data->func->op_array;
    1577       44959 :         HashTable *ht = execute_data->symbol_table;
    1578             : 
    1579             :         /* copy real values from symbol table into CV slots and create
    1580             :            INDIRECT references to CV in symbol table  */
    1581       44959 :         if (EXPECTED(op_array->last_var)) {
    1582       27107 :                 zend_string **str = op_array->vars;
    1583       27107 :                 zend_string **end = str + op_array->last_var;
    1584       27107 :                 zval *var = EX_VAR_NUM(0);
    1585             : 
    1586             :                 do {
    1587      125761 :                         zval *zv = zend_hash_find(ht, *str);
    1588             : 
    1589      125761 :                         if (zv) {
    1590       49997 :                                 if (Z_TYPE_P(zv) == IS_INDIRECT) {
    1591       35991 :                                         zval *val = Z_INDIRECT_P(zv);
    1592             : 
    1593       35991 :                                         ZVAL_COPY_VALUE(var, val);
    1594             :                                 } else {
    1595       14006 :                                         ZVAL_COPY_VALUE(var, zv);
    1596             :                                 }
    1597             :                         } else {
    1598       75764 :                                 ZVAL_UNDEF(var);
    1599       75764 :                                 zv = zend_hash_add_new(ht, *str, var);
    1600             :                         }
    1601      125761 :                         ZVAL_INDIRECT(zv, var);
    1602      125761 :                         str++;
    1603      125761 :                         var++;
    1604      125761 :                 } while (str != end);
    1605             :         }
    1606       44959 : }
    1607             : /* }}} */
    1608             : 
    1609       32450 : ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1610             : {
    1611       32450 :         zend_op_array *op_array = &execute_data->func->op_array;
    1612       32450 :         HashTable *ht = execute_data->symbol_table;
    1613             : 
    1614             :         /* copy real values from CV slots into symbol table */
    1615       32450 :         if (EXPECTED(op_array->last_var)) {
    1616       19611 :                 zend_string **str = op_array->vars;
    1617       19611 :                 zend_string **end = str + op_array->last_var;
    1618       19611 :                 zval *var = EX_VAR_NUM(0);
    1619             : 
    1620             :                 do {
    1621       88427 :                         if (Z_TYPE_P(var) == IS_UNDEF) {
    1622        9272 :                                 zend_hash_del(ht, *str);
    1623             :                         } else {
    1624       79155 :                                 zend_hash_update(ht, *str, var);
    1625       79155 :                                 ZVAL_UNDEF(var);
    1626             :                         }
    1627       88427 :                         str++;
    1628       88427 :                         var++;
    1629       88427 :                 } while (str != end);
    1630             :         }
    1631       32450 : }
    1632             : /* }}} */
    1633             : 
    1634           0 : ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force) /* {{{ */
    1635             : {
    1636           0 :         zend_execute_data *execute_data = EG(current_execute_data);
    1637             : 
    1638           0 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1639           0 :                 execute_data = execute_data->prev_execute_data;
    1640             :         }
    1641             : 
    1642           0 :         if (execute_data) {
    1643           0 :                 if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
    1644           0 :                         zend_ulong h = zend_string_hash_val(name);
    1645           0 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1646             : 
    1647           0 :                         if (EXPECTED(op_array->last_var)) {
    1648           0 :                                 zend_string **str = op_array->vars;
    1649           0 :                                 zend_string **end = str + op_array->last_var;
    1650             : 
    1651             :                                 do {
    1652           0 :                                         if (ZSTR_H(*str) == h &&
    1653           0 :                                             ZSTR_LEN(*str) == ZSTR_LEN(name) &&
    1654           0 :                                             memcmp(ZSTR_VAL(*str), ZSTR_VAL(name), ZSTR_LEN(name)) == 0) {
    1655           0 :                                                 zval *var = EX_VAR_NUM(str - op_array->vars);
    1656           0 :                                                 ZVAL_COPY_VALUE(var, value);
    1657           0 :                                                 return SUCCESS;
    1658             :                                         }
    1659           0 :                                         str++;
    1660           0 :                                 } while (str != end);
    1661             :                         }
    1662           0 :                         if (force) {
    1663           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table();
    1664           0 :                                 if (symbol_table) {
    1665           0 :                                         return zend_hash_update(symbol_table, name, value) ? SUCCESS : FAILURE;;
    1666             :                                 }
    1667             :                         }
    1668             :                 } else {
    1669           0 :                         return (zend_hash_update_ind(execute_data->symbol_table, name, value) != NULL) ? SUCCESS : FAILURE;
    1670             :                 }
    1671             :         }
    1672           0 :         return FAILURE;
    1673             : }
    1674             : /* }}} */
    1675             : 
    1676       42530 : ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force) /* {{{ */
    1677             : {
    1678       42530 :         zend_execute_data *execute_data = EG(current_execute_data);
    1679             : 
    1680      122074 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1681       37014 :                 execute_data = execute_data->prev_execute_data;
    1682             :         }
    1683             : 
    1684       42530 :         if (execute_data) {
    1685       42528 :                 if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
    1686        5838 :                         zend_ulong h = zend_hash_func(name, len);
    1687        5838 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1688        5838 :                         if (EXPECTED(op_array->last_var)) {
    1689        5764 :                                 zend_string **str = op_array->vars;
    1690        5764 :                                 zend_string **end = str + op_array->last_var;
    1691             : 
    1692             :                                 do {
    1693       46887 :                                         if (ZSTR_H(*str) == h &&
    1694           4 :                                             ZSTR_LEN(*str) == len &&
    1695           4 :                                             memcmp(ZSTR_VAL(*str), name, len) == 0) {
    1696           4 :                                                 zval *var = EX_VAR_NUM(str - op_array->vars);
    1697           4 :                                                 zval_ptr_dtor(var);
    1698           4 :                                                 ZVAL_COPY_VALUE(var, value);
    1699           4 :                                                 return SUCCESS;
    1700             :                                         }
    1701       46875 :                                         str++;
    1702       46875 :                                 } while (str != end);
    1703             :                         }
    1704        5834 :                         if (force) {
    1705           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table();
    1706           0 :                                 if (symbol_table) {
    1707           0 :                                         return zend_hash_str_update(symbol_table, name, len, value) ? SUCCESS : FAILURE;;
    1708             :                                 }
    1709             :                         }
    1710             :                 } else {
    1711       36690 :                         return (zend_hash_str_update_ind(execute_data->symbol_table, name, len, value) != NULL) ? SUCCESS : FAILURE;
    1712             :                 }
    1713             :         }
    1714        5836 :         return FAILURE;
    1715             : }
    1716             : /* }}} */
    1717             : 
    1718         397 : ZEND_API int zend_forbid_dynamic_call(const char *func_name) /* {{{ */
    1719             : {
    1720         397 :         zend_execute_data *ex = EG(current_execute_data);
    1721             :         ZEND_ASSERT(ex != NULL && ex->func != NULL);
    1722             : 
    1723         397 :         if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
    1724          16 :                 zend_error(E_WARNING, "Cannot call %s dynamically", func_name);
    1725          16 :                 return FAILURE;
    1726             :         }
    1727             : 
    1728         381 :         return SUCCESS;
    1729             : }
    1730             : /* }}} */
    1731             : 
    1732             : /*
    1733             :  * Local variables:
    1734             :  * tab-width: 4
    1735             :  * c-basic-offset: 4
    1736             :  * indent-tabs-mode: t
    1737             :  * End:
    1738             :  */

Generated by: LCOV version 1.10

Generated at Wed, 20 Jul 2016 02:56:14 +0000 (5 days ago)

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