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: 595 701 84.9 %
Date: 2015-01-18 Functions: 40 44 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include <stdio.h>
      23             : #include <signal.h>
      24             : 
      25             : #include "zend.h"
      26             : #include "zend_compile.h"
      27             : #include "zend_execute.h"
      28             : #include "zend_API.h"
      29             : #include "zend_stack.h"
      30             : #include "zend_constants.h"
      31             : #include "zend_extensions.h"
      32             : #include "zend_exceptions.h"
      33             : #include "zend_closures.h"
      34             : #include "zend_generators.h"
      35             : #include "zend_vm.h"
      36             : #include "zend_float.h"
      37             : #ifdef HAVE_SYS_TIME_H
      38             : #include <sys/time.h>
      39             : #endif
      40             : 
      41             : ZEND_API void (*zend_execute_ex)(zend_execute_data *execute_data);
      42             : ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
      43             : 
      44             : /* true globals */
      45             : ZEND_API const zend_fcall_info empty_fcall_info = { 0, NULL, {{0}, {{0}}, {0}}, NULL, NULL, NULL, NULL, 0, 0 };
      46             : ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL };
      47             : 
      48             : #ifdef ZEND_WIN32
      49             : #ifdef ZTS
      50             : __declspec(thread)
      51             : #endif
      52             : HANDLE tq_timer = NULL;
      53             : #endif
      54             : 
      55             : #if 0&&ZEND_DEBUG
      56             : static void (*original_sigsegv_handler)(int);
      57             : static void zend_handle_sigsegv(int dummy) /* {{{ */
      58             : {
      59             :         fflush(stdout);
      60             :         fflush(stderr);
      61             :         if (original_sigsegv_handler == zend_handle_sigsegv) {
      62             :                 signal(SIGSEGV, original_sigsegv_handler);
      63             :         } else {
      64             :                 signal(SIGSEGV, SIG_DFL);
      65             :         }
      66             :         {
      67             : 
      68             :                 fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
      69             :                                 active_opline->opcode,
      70             :                                 active_opline-EG(active_op_array)->opcodes,
      71             :                                 get_active_function_name(),
      72             :                                 zend_get_executed_filename(),
      73             :                                 zend_get_executed_lineno());
      74             : /* See http://support.microsoft.com/kb/190351 */
      75             : #ifdef PHP_WIN32
      76             :                 fflush(stderr);
      77             : #endif
      78             :         }
      79             :         if (original_sigsegv_handler!=zend_handle_sigsegv) {
      80             :                 original_sigsegv_handler(dummy);
      81             :         }
      82             : }
      83             : /* }}} */
      84             : #endif
      85             : 
      86       20527 : static void zend_extension_activator(zend_extension *extension) /* {{{ */
      87             : {
      88       20527 :         if (extension->activate) {
      89         368 :                 extension->activate();
      90             :         }
      91       20527 : }
      92             : /* }}} */
      93             : 
      94       20566 : static void zend_extension_deactivator(zend_extension *extension) /* {{{ */
      95             : {
      96       20566 :         if (extension->deactivate) {
      97         368 :                 extension->deactivate();
      98             :         }
      99       20566 : }
     100             : /* }}} */
     101             : 
     102       42131 : static int clean_non_persistent_function(zval *zv) /* {{{ */
     103             : {
     104       42131 :         zend_function *function = Z_PTR_P(zv);
     105       42131 :         return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
     106             : }
     107             : /* }}} */
     108             : 
     109           0 : ZEND_API int clean_non_persistent_function_full(zval *zv) /* {{{ */
     110             : {
     111           0 :         zend_function *function = Z_PTR_P(zv);
     112           0 :         return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
     113             : }
     114             : /* }}} */
     115             : 
     116       29680 : static int clean_non_persistent_class(zval *zv) /* {{{ */
     117             : {
     118       29680 :         zend_class_entry *ce = Z_PTR_P(zv);
     119       29680 :         return (ce->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
     120             : }
     121             : /* }}} */
     122             : 
     123           0 : ZEND_API int clean_non_persistent_class_full(zval *zv) /* {{{ */
     124             : {
     125           0 :         zend_class_entry *ce = Z_PTR_P(zv);
     126           0 :         return (ce->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
     127             : }
     128             : /* }}} */
     129             : 
     130       20645 : void init_executor(void) /* {{{ */
     131             : {
     132       20645 :         zend_init_fpu();
     133             : 
     134       20645 :         ZVAL_NULL(&EG(uninitialized_zval));
     135             :         /* trick to make uninitialized_zval never be modified, passed by ref, etc. */
     136       20645 :         ZVAL_NULL(&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       20645 :         EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
     143       20645 :         EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
     144       20645 :         EG(no_extensions) = 0;
     145             : 
     146       20645 :         EG(function_table) = CG(function_table);
     147       20645 :         EG(class_table) = CG(class_table);
     148             : 
     149       20645 :         EG(in_autoload) = NULL;
     150       20645 :         EG(autoload_func) = NULL;
     151       20645 :         EG(error_handling) = EH_NORMAL;
     152             : 
     153       20645 :         zend_vm_stack_init();
     154             : 
     155       20645 :         zend_hash_init(&EG(symbol_table).ht, 64, NULL, ZVAL_PTR_DTOR, 0);
     156       20645 :         GC_REFCOUNT(&EG(symbol_table)) = 1;
     157       20645 :         GC_TYPE_INFO(&EG(symbol_table)) = IS_ARRAY;
     158       20645 :         EG(valid_symbol_table) = 1;
     159             : 
     160       20645 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator);
     161             : 
     162       20645 :         zend_hash_init(&EG(included_files), 8, NULL, NULL, 0);
     163             : 
     164       20645 :         EG(ticks_count) = 0;
     165             : 
     166       20645 :         ZVAL_UNDEF(&EG(user_error_handler));
     167             : 
     168       20645 :         EG(current_execute_data) = NULL;
     169             : 
     170       20645 :         zend_stack_init(&EG(user_error_handlers_error_reporting), sizeof(int));
     171       20645 :         zend_stack_init(&EG(user_error_handlers), sizeof(zval));
     172       20645 :         zend_stack_init(&EG(user_exception_handlers), sizeof(zval));
     173             : 
     174       20645 :         zend_objects_store_init(&EG(objects_store), 1024);
     175             : 
     176       20645 :         EG(full_tables_cleanup) = 0;
     177             : #ifdef ZEND_WIN32
     178             :         EG(timed_out) = 0;
     179             : #endif
     180             : 
     181       20645 :         EG(exception) = NULL;
     182       20645 :         EG(prev_exception) = NULL;
     183             : 
     184       20645 :         EG(scope) = NULL;
     185             : 
     186       20645 :         EG(active) = 1;
     187       20645 : }
     188             : /* }}} */
     189             : 
     190      264122 : static int zval_call_destructor(zval *zv) /* {{{ */
     191             : {
     192      264122 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     193        3228 :                 zv = Z_INDIRECT_P(zv);
     194             :         }
     195      273091 :         if (Z_TYPE_P(zv) == IS_OBJECT && Z_REFCOUNT_P(zv) == 1) {
     196        8244 :                 return ZEND_HASH_APPLY_REMOVE;
     197             :         } else {
     198      255878 :                 return ZEND_HASH_APPLY_KEEP;
     199             :         }
     200             : }
     201             : /* }}} */
     202             : 
     203       17942 : static void zend_unclean_zval_ptr_dtor(zval *zv) /* {{{ */
     204             : {
     205             : 
     206       17942 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     207        2821 :                 zv = Z_INDIRECT_P(zv);
     208             :         }
     209             :         i_zval_ptr_dtor(zv ZEND_FILE_LINE_CC);
     210       17942 : }
     211             : /* }}} */
     212             : 
     213       20681 : void shutdown_destructors(void) /* {{{ */
     214             : {
     215       20681 :         if (CG(unclean_shutdown)) {
     216        1950 :                 EG(symbol_table).ht.pDestructor = zend_unclean_zval_ptr_dtor;
     217             :         }
     218       20681 :         zend_try {
     219             :                 uint32_t symbols;
     220             :                 do {
     221       25431 :                         symbols = zend_hash_num_elements(&EG(symbol_table).ht);
     222       25431 :                         zend_hash_reverse_apply(&EG(symbol_table).ht, (apply_func_t) zval_call_destructor);
     223       25431 :                 } while (symbols != zend_hash_num_elements(&EG(symbol_table).ht));
     224       20681 :                 zend_objects_store_call_destructors(&EG(objects_store));
     225           0 :         } zend_catch {
     226             :                 /* if we couldn't destruct cleanly, mark all objects as destructed anyway */
     227           0 :                 zend_objects_store_mark_destructed(&EG(objects_store));
     228       20681 :         } zend_end_try();
     229       20681 : }
     230             : /* }}} */
     231             : 
     232       20681 : void shutdown_executor(void) /* {{{ */
     233             : {
     234             :         zend_function *func;
     235             :         zend_class_entry *ce;
     236             : 
     237       20681 :         zend_try {
     238             : 
     239             : /* Removed because this can not be safely done, e.g. in this situation:
     240             :    Object 1 creates object 2
     241             :    Object 3 holds reference to object 2.
     242             :    Now when 1 and 2 are destroyed, 3 can still access 2 in its destructor, with
     243             :    very problematic results */
     244             : /*              zend_objects_store_call_destructors(&EG(objects_store)); */
     245             : 
     246             : /* Moved after symbol table cleaners, because  some of the cleaners can call
     247             :    destructors, which would use EG(symtable_cache_ptr) and thus leave leaks */
     248             : /*              while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     249             :                         zend_hash_destroy(*EG(symtable_cache_ptr));
     250             :                         efree(*EG(symtable_cache_ptr));
     251             :                         EG(symtable_cache_ptr)--;
     252             :                 }
     253             : */
     254       20681 :                 zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator);
     255             : 
     256       20681 :                 if (CG(unclean_shutdown)) {
     257        1955 :                         EG(symbol_table).ht.pDestructor = zend_unclean_zval_ptr_dtor;
     258             :                 }
     259       20681 :                 zend_hash_graceful_reverse_destroy(&EG(symbol_table).ht);
     260       20681 :         } zend_end_try();
     261       20681 :         EG(valid_symbol_table) = 0;
     262             : 
     263       20681 :         zend_try {
     264             :                 zval *zeh;
     265             :                 /* remove error handlers before destroying classes and functions,
     266             :                  * so that if handler used some class, crash would not happen */
     267       20681 :                 if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
     268         273 :                         zeh = &EG(user_error_handler);
     269         273 :                         zval_ptr_dtor(zeh);
     270         273 :                         ZVAL_UNDEF(&EG(user_error_handler));
     271             :                 }
     272             : 
     273       20681 :                 if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
     274          11 :                         zeh = &EG(user_exception_handler);
     275          11 :                         zval_ptr_dtor(zeh);
     276          11 :                         ZVAL_UNDEF(&EG(user_exception_handler));
     277             :                 }
     278             : 
     279       20681 :                 zend_stack_clean(&EG(user_error_handlers_error_reporting), NULL, 1);
     280       20681 :                 zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_DESTRUCTOR, 1);
     281       20681 :                 zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_DESTRUCTOR, 1);
     282       20681 :         } zend_end_try();
     283             : 
     284       20681 :         zend_try {
     285             :                 /* Cleanup static data for functions and arrays.
     286             :                  * We need a separate cleanup stage because of the following problem:
     287             :                  * Suppose we destroy class X, which destroys the class's function table,
     288             :                  * and in the function table we have function foo() that has static $bar.
     289             :                  * Now if an object of class X is assigned to $bar, its destructor will be
     290             :                  * called and will fail since X's function table is in mid-destruction.
     291             :                  * So we want first of all to clean up all data and then move to tables destruction.
     292             :                  * Note that only run-time accessed data need to be cleaned up, pre-defined data can
     293             :                  * not contain objects and thus are not probelmatic */
     294       20681 :                 if (EG(full_tables_cleanup)) {
     295           0 :                         ZEND_HASH_FOREACH_PTR(EG(function_table), func) {
     296           0 :                                 if (func->type == ZEND_USER_FUNCTION) {
     297           0 :                                         zend_cleanup_op_array_data((zend_op_array *) func);
     298             :                                 }
     299             :                         } ZEND_HASH_FOREACH_END();
     300           0 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) {
     301           0 :                                 if (ce->type == ZEND_USER_CLASS) {
     302           0 :                                         zend_cleanup_user_class_data(ce);
     303             :                                 } else {
     304           0 :                                         zend_cleanup_internal_class_data(ce);
     305             :                                 }
     306             :                         } ZEND_HASH_FOREACH_END();
     307             :                 } else {
     308      111042 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(function_table), func) {
     309       42131 :                                 if (func->type != ZEND_USER_FUNCTION) {
     310       20681 :                                         break;
     311             :                                 }
     312       21450 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     313             :                         } ZEND_HASH_FOREACH_END();
     314       70274 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) {
     315       29679 :                                 if (ce->type != ZEND_USER_CLASS) {
     316       20680 :                                         break;
     317             :                                 }
     318        8999 :                                 zend_cleanup_user_class_data(ce);
     319             :                         } ZEND_HASH_FOREACH_END();
     320       20680 :                         zend_cleanup_internal_classes();
     321             :                 }
     322       20681 :         } zend_end_try();
     323             : 
     324       20681 :         zend_try {
     325       20681 :                 zend_llist_destroy(&CG(open_files));
     326       20681 :         } zend_end_try();
     327             : 
     328       20681 :         zend_try {
     329       20681 :                 zend_close_rsrc_list(&EG(regular_list));
     330       20681 :         } zend_end_try();
     331             : 
     332       20681 :         zend_try {
     333       20681 :                 zend_objects_store_free_object_storage(&EG(objects_store));
     334             : 
     335       20681 :                 zend_vm_stack_destroy();
     336             : 
     337             :                 /* Destroy all op arrays */
     338       20681 :                 if (EG(full_tables_cleanup)) {
     339           0 :                         zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function_full);
     340           0 :                         zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class_full);
     341             :                 } else {
     342       20681 :                         zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function);
     343       20681 :                         zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class);
     344             :                 }
     345             : 
     346       41623 :                 while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
     347         261 :                         zend_hash_destroy(&(*EG(symtable_cache_ptr))->ht);
     348         261 :                         FREE_HASHTABLE(*EG(symtable_cache_ptr));
     349         261 :                         EG(symtable_cache_ptr)--;
     350             :                 }
     351       20681 :         } zend_end_try();
     352             : 
     353       20681 :         zend_try {
     354       20681 :                 clean_non_persistent_constants();
     355       20681 :         } zend_end_try();
     356             : 
     357       20681 :         zend_try {
     358             : #if 0&&ZEND_DEBUG
     359             :         signal(SIGSEGV, original_sigsegv_handler);
     360             : #endif
     361             : 
     362       20681 :                 zend_hash_destroy(&EG(included_files));
     363             : 
     364       20681 :                 zend_stack_destroy(&EG(user_error_handlers_error_reporting));
     365       20681 :                 zend_stack_destroy(&EG(user_error_handlers));
     366       20681 :                 zend_stack_destroy(&EG(user_exception_handlers));
     367       20681 :                 zend_objects_store_destroy(&EG(objects_store));
     368       20681 :                 if (EG(in_autoload)) {
     369          89 :                         zend_hash_destroy(EG(in_autoload));
     370          89 :                         FREE_HASHTABLE(EG(in_autoload));
     371             :                 }
     372       20681 :         } zend_end_try();
     373             : 
     374       20681 :         zend_shutdown_fpu();
     375             : 
     376       20681 :         EG(active) = 0;
     377       20681 : }
     378             : /* }}} */
     379             : 
     380             : /* return class name and "::" or "". */
     381      208674 : ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
     382             : {
     383             :         zend_function *func;
     384             : 
     385      208674 :         if (!zend_is_executing()) {
     386           0 :                 if (space) {
     387           0 :                         *space = "";
     388             :                 }
     389           0 :                 return "";
     390             :         }
     391             : 
     392      208674 :         func = EG(current_execute_data)->func;
     393      208674 :         switch (func->type) {
     394             :                 case ZEND_USER_FUNCTION:
     395             :                 case ZEND_INTERNAL_FUNCTION:
     396             :                 {
     397      208674 :                         zend_class_entry *ce = func->common.scope;
     398             : 
     399      208674 :                         if (space) {
     400      208674 :                                 *space = ce ? "::" : "";
     401             :                         }
     402      208674 :                         return ce ? ce->name->val : "";
     403             :                 }
     404             :                 default:
     405           0 :                         if (space) {
     406           0 :                                 *space = "";
     407             :                         }
     408           0 :                         return "";
     409             :         }
     410             : }
     411             : /* }}} */
     412             : 
     413      208747 : ZEND_API const char *get_active_function_name(void) /* {{{ */
     414             : {
     415             :         zend_function *func;
     416             : 
     417      208747 :         if (!zend_is_executing()) {
     418          68 :                 return NULL;
     419             :         }
     420      208679 :         func = EG(current_execute_data)->func;
     421      208679 :         switch (func->type) {
     422             :                 case ZEND_USER_FUNCTION: {
     423         208 :                                 zend_string *function_name = func->common.function_name;
     424             : 
     425         208 :                                 if (function_name) {
     426         150 :                                         return function_name->val;
     427             :                                 } else {
     428          58 :                                         return "main";
     429             :                                 }
     430             :                         }
     431             :                         break;
     432             :                 case ZEND_INTERNAL_FUNCTION:
     433      208471 :                         return func->common.function_name->val;
     434             :                         break;
     435             :                 default:
     436           0 :                         return NULL;
     437             :         }
     438             : }
     439             : /* }}} */
     440             : 
     441      399848 : ZEND_API const char *zend_get_executed_filename(void) /* {{{ */
     442             : {
     443      399848 :         zend_execute_data *ex = EG(current_execute_data);
     444             : 
     445     1019765 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     446      220069 :                 ex = ex->prev_execute_data;
     447             :         }
     448      399848 :         if (ex) {
     449      399827 :                 return ex->func->op_array.filename->val;
     450             :         } else {
     451          21 :                 return "[no active file]";
     452             :         }
     453             : }
     454             : /* }}} */
     455             : 
     456      392556 : ZEND_API uint zend_get_executed_lineno(void) /* {{{ */
     457             : {
     458      392556 :         zend_execute_data *ex = EG(current_execute_data);
     459             : 
     460     1004659 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     461      219547 :                 ex = ex->prev_execute_data;
     462             :         }
     463      392556 :         if (ex) {
     464      392541 :                 if (EG(exception) && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
     465           0 :                     ex->opline->lineno == 0 && EG(opline_before_exception)) {
     466           0 :                         return EG(opline_before_exception)->lineno;
     467             :                 }
     468      392541 :                 return ex->opline->lineno;
     469             :         } else {
     470          15 :                 return 0;
     471             :         }
     472             : }
     473             : /* }}} */
     474             : 
     475      837393 : ZEND_API zend_bool zend_is_executing(void) /* {{{ */
     476             : {
     477      837393 :         return EG(current_execute_data) != 0;
     478             : }
     479             : /* }}} */
     480             : 
     481     6509376 : ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     482             : {
     483             :         i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC);
     484     6509374 : }
     485             : /* }}} */
     486             : 
     487    19670231 : ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     488             : {
     489    19670231 :         if (Z_REFCOUNTED_P(zval_ptr)) {
     490             :                 Z_DELREF_P(zval_ptr);
     491     5372119 :                 if (Z_REFCOUNT_P(zval_ptr) == 0) {
     492     1994433 :                         _zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC);
     493             :                 }
     494             :         }
     495    19670231 : }
     496             : /* }}} */
     497             : 
     498             : #define IS_VISITED_CONSTANT                     0x80
     499             : #define IS_CONSTANT_VISITED(p)          (Z_TYPE_P(p) & IS_VISITED_CONSTANT)
     500             : #define MARK_CONSTANT_VISITED(p)        Z_TYPE_INFO_P(p) |= IS_VISITED_CONSTANT
     501             : 
     502         829 : ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_class_entry *scope) /* {{{ */
     503             : {
     504             :         zval *const_value;
     505             :         char *colon;
     506             : 
     507         829 :         if (IS_CONSTANT_VISITED(p)) {
     508           2 :                 zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
     509         827 :         } else if (Z_TYPE_P(p) == IS_CONSTANT) {
     510             :                 int refcount;
     511             : 
     512         574 :                 SEPARATE_ZVAL_NOREF(p);
     513         333 :                 MARK_CONSTANT_VISITED(p);
     514         569 :                 refcount =  Z_REFCOUNTED_P(p) ? Z_REFCOUNT_P(p) : 1;
     515         333 :                 const_value = zend_get_constant_ex(Z_STR_P(p), scope, Z_CONST_FLAGS_P(p));
     516         321 :                 if (!const_value) {
     517          20 :                         char *actual = Z_STRVAL_P(p);
     518             : 
     519          40 :                         if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
     520             :                                 size_t len;
     521             : 
     522           0 :                                 zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
     523           0 :                                 len = Z_STRLEN_P(p) - ((colon - Z_STRVAL_P(p)) + 1);
     524           0 :                                 if (inline_change) {
     525           0 :                                         zend_string *tmp = zend_string_init(colon + 1, len, 0);
     526           0 :                                         zend_string_release(Z_STR_P(p));
     527           0 :                                         Z_STR_P(p) = tmp;
     528             :                                 } else {
     529           0 :                                         Z_STR_P(p) = zend_string_init(colon + 1, len, 0);
     530             :                                 }
     531           0 :                                 Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
     532             :                         } else {
     533          20 :                                 zend_string *save = Z_STR_P(p);
     534             :                                 char *slash;
     535          20 :                                 size_t actual_len = Z_STRLEN_P(p);
     536          25 :                                 if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char *)zend_memrchr(actual, '\\', actual_len))) {
     537           3 :                                         actual = slash + 1;
     538           3 :                                         actual_len -= (actual - Z_STRVAL_P(p));
     539           3 :                                         if (inline_change) {
     540           2 :                                                 zend_string *s = zend_string_init(actual, actual_len, 0);
     541           2 :                                                 Z_STR_P(p) = s;
     542           2 :                                                 Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
     543             :                                         }
     544             :                                 }
     545          20 :                                 if (actual[0] == '\\') {
     546           0 :                                         if (inline_change) {
     547           0 :                                                 memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p));
     548           0 :                                                 --Z_STRLEN_P(p);
     549             :                                         } else {
     550           0 :                                                 ++actual;
     551             :                                         }
     552           0 :                                         --actual_len;
     553             :                                 }
     554          20 :                                 if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
     555          15 :                                         if (save->val[0] == '\\') {
     556           0 :                                                 zend_error(E_ERROR, "Undefined constant '%s'", save->val + 1);
     557             :                                         } else {
     558          15 :                                                 zend_error(E_ERROR, "Undefined constant '%s'", save->val);
     559             :                                         }
     560           0 :                                         if (inline_change) {
     561             :                                                 zend_string_release(save);
     562             :                                         }
     563           0 :                                         save = NULL;
     564             :                                 }
     565           5 :                                 zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",  actual,  actual);
     566           5 :                                 if (!inline_change) {
     567           2 :                                         ZVAL_STRINGL(p, actual, actual_len);
     568             :                                 } else {
     569           4 :                                         Z_TYPE_INFO_P(p) = Z_REFCOUNTED_P(p) ?
     570             :                                                 IS_STRING_EX : IS_INTERNED_STRING_EX;
     571           4 :                                         if (save && save->val != actual) {
     572             :                                                 zend_string_release(save);
     573             :                                         }
     574             :                                 }
     575             :                         }
     576             :                 } else {
     577         301 :                         if (inline_change) {
     578         216 :                                 zend_string_release(Z_STR_P(p));
     579             :                         }
     580         301 :                         ZVAL_COPY_VALUE(p, const_value);
     581         301 :                         if (Z_OPT_CONSTANT_P(p)) {
     582           0 :                                 zval_update_constant_ex(p, 1, NULL);
     583             :                         }
     584             :                         zval_opt_copy_ctor(p);
     585             :                 }
     586             : 
     587         306 :                 if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount);
     588         494 :         } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
     589             :                 zval tmp;
     590         274 :                 SEPARATE_ZVAL_NOREF(p);
     591             : 
     592         136 :                 zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope);
     593         116 :                 if (inline_change) {
     594          73 :                         zend_ast_destroy_and_free(Z_ASTVAL_P(p));
     595          73 :                         efree_size(Z_AST_P(p), sizeof(zend_ast_ref));
     596             :                 }
     597         116 :                 ZVAL_COPY_VALUE(p, &tmp);
     598             :         }
     599         780 :         return 0;
     600             : }
     601             : /* }}} */
     602             : 
     603         186 : ZEND_API int zval_update_constant_inline_change(zval *pp, zend_class_entry *scope) /* {{{ */
     604             : {
     605         186 :         return zval_update_constant_ex(pp, 1, scope);
     606             : }
     607             : /* }}} */
     608             : 
     609           0 : ZEND_API int zval_update_constant_no_inline_change(zval *pp, zend_class_entry *scope) /* {{{ */
     610             : {
     611           0 :         return zval_update_constant_ex(pp, 0, scope);
     612             : }
     613             : /* }}} */
     614             : 
     615         412 : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change) /* {{{ */
     616             : {
     617         412 :         return zval_update_constant_ex(pp, inline_change, NULL);
     618             : }
     619             : /* }}} */
     620             : 
     621        1380 : int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[]) /* {{{ */
     622             : {
     623        1380 :         return call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, 1, NULL);
     624             : }
     625             : /* }}} */
     626             : 
     627       12233 : int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation, zend_array *symbol_table) /* {{{ */
     628             : {
     629             :         zend_fcall_info fci;
     630             : 
     631       12233 :         fci.size = sizeof(fci);
     632       12233 :         fci.function_table = function_table;
     633       12233 :         fci.object = object ? Z_OBJ_P(object) : NULL;
     634       12233 :         ZVAL_COPY_VALUE(&fci.function_name, function_name);
     635       12233 :         fci.retval = retval_ptr;
     636       12233 :         fci.param_count = param_count;
     637       12233 :         fci.params = params;
     638       12233 :         fci.no_separation = (zend_bool) no_separation;
     639       12233 :         fci.symbol_table = symbol_table;
     640             : 
     641       12233 :         return zend_call_function(&fci, NULL);
     642             : }
     643             : /* }}} */
     644             : 
     645      681946 : int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /* {{{ */
     646             : {
     647             :         uint32_t i;
     648      681946 :         zend_class_entry *calling_scope = NULL;
     649             :         zend_execute_data *call, dummy_execute_data;
     650             :         zend_fcall_info_cache fci_cache_local;
     651             :         zend_function *func;
     652             :         zend_class_entry *orig_scope;
     653             :         zval tmp;
     654             : 
     655      681946 :         ZVAL_UNDEF(fci->retval);
     656             : 
     657      681946 :         if (!EG(active)) {
     658           0 :                 return FAILURE; /* executor is already inactive */
     659             :         }
     660             : 
     661      681946 :         if (EG(exception)) {
     662           7 :                 return FAILURE; /* we would result in an instable executor otherwise */
     663             :         }
     664             : 
     665      681939 :         switch (fci->size) {
     666             :                 case sizeof(zend_fcall_info):
     667      681939 :                         break; /* nothing to do currently */
     668             :                 default:
     669           0 :                         zend_error(E_ERROR, "Corrupted fcall_info provided to zend_call_function()");
     670             :                         break;
     671             :         }
     672             : 
     673      681939 :         orig_scope = EG(scope);
     674             : 
     675             :         /* Initialize execute_data */
     676      681939 :         if (!EG(current_execute_data)) {
     677             :                 /* This only happens when we're called outside any execute()'s
     678             :                  * It shouldn't be strictly necessary to NULL execute_data out,
     679             :                  * but it may make bugs easier to spot
     680             :                  */
     681       93382 :                 memset(&dummy_execute_data, 0, sizeof(zend_execute_data));
     682       93382 :                 EG(current_execute_data) = &dummy_execute_data;
     683     1192759 :         } else if (EG(current_execute_data)->func &&
     684      588544 :                    ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
     685       15658 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL) {
     686             :                 /* Insert fake frame in case of include or magic calls */
     687       14603 :                 dummy_execute_data = *EG(current_execute_data);
     688       14603 :                 dummy_execute_data.prev_execute_data = EG(current_execute_data);
     689       14603 :                 dummy_execute_data.call = NULL;
     690       14603 :                 dummy_execute_data.opline = NULL;
     691       14603 :                 dummy_execute_data.func = NULL;
     692       14603 :                 EG(current_execute_data) = &dummy_execute_data;
     693             :         }
     694             : 
     695      681939 :         if (!fci_cache || !fci_cache->initialized) {
     696             :                 zend_string *callable_name;
     697      225934 :                 char *error = NULL;
     698             : 
     699      225934 :                 if (!fci_cache) {
     700       12663 :                         fci_cache = &fci_cache_local;
     701             :                 }
     702             : 
     703      225934 :                 if (!zend_is_callable_ex(&fci->function_name, fci->object, IS_CALLABLE_CHECK_SILENT, &callable_name, fci_cache, &error)) {
     704         123 :                         if (error) {
     705           0 :                                 zend_error(E_WARNING, "Invalid callback %s, %s", callable_name->val, error);
     706           0 :                                 efree(error);
     707             :                         }
     708         123 :                         if (callable_name) {
     709         123 :                                 zend_string_release(callable_name);
     710             :                         }
     711         123 :                         if (EG(current_execute_data) == &dummy_execute_data) {
     712          75 :                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     713             :                         }
     714         123 :                         return FAILURE;
     715      225811 :                 } else if (error) {
     716             :                         /* Capitalize the first latter of the error message */
     717           3 :                         if (error[0] >= 'a' && error[0] <= 'z') {
     718           3 :                                 error[0] += ('A' - 'a');
     719             :                         }
     720           3 :                         zend_error(E_STRICT, "%s", error);
     721           3 :                         efree(error);
     722             :                 }
     723      225811 :                 zend_string_release(callable_name);
     724             :         }
     725             : 
     726      681816 :         func = fci_cache->function_handler;
     727     1363632 :         call = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_FUNCTION,
     728             :                 func, fci->param_count, fci_cache->called_scope, fci_cache->object, NULL);
     729      681816 :         calling_scope = fci_cache->calling_scope;
     730      681816 :         fci->object = fci_cache->object;
     731     1608824 :         if (fci->object &&
     732      463504 :             (!EG(objects_store).object_buckets ||
     733      463504 :              !IS_OBJ_VALID(EG(objects_store).object_buckets[fci->object->handle]))) {
     734           0 :                 if (EG(current_execute_data) == &dummy_execute_data) {
     735           0 :                         EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     736             :                 }
     737           0 :                 return FAILURE;
     738             :         }
     739             : 
     740      681816 :         if (func->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
     741           0 :                 if (func->common.fn_flags & ZEND_ACC_ABSTRACT) {
     742           0 :                         zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", func->common.scope->name->val, func->common.function_name->val);
     743             :                 }
     744           0 :                 if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
     745           0 :                         zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
     746           0 :                                 func->common.scope ? func->common.scope->name->val : "",
     747           0 :                                 func->common.scope ? "::" : "",
     748           0 :                                 func->common.function_name->val);
     749             :                 }
     750             :         }
     751             : 
     752     1145232 :         for (i=0; i<fci->param_count; i++) {
     753             :                 zval *param;
     754             : 
     755      926840 :                 if (ARG_SHOULD_BE_SENT_BY_REF(func, i + 1)) {
     756             :                         // TODO: Scalar values don't have reference counters anymore.
     757             :                         // They are assumed to be 1, and they may be easily passed by
     758             :                         // reference now. However, previously scalars with refcount==1
     759             :                         // might be passed and with refcount>1 might not. We can support
     760             :                         // only single behavior ???
     761             : #if 0
     762             :                         if (Z_REFCOUNTED(fci->params[i]) &&
     763             :                                 // This solution breaks the following test (omit warning message) ???
     764             :                                 // Zend/tests/bug61273.phpt
     765             :                                 // ext/reflection/tests/bug42976.phpt
     766             :                                 // ext/standard/tests/general_functions/call_user_func_array_variation_001.phpt
     767             : #else
     768         819 :                         if (!Z_REFCOUNTED(fci->params[i]) ||
     769             :                                 // This solution breaks the following test (emit warning message) ???
     770             :                                 // ext/pdo_sqlite/tests/pdo_005.phpt
     771             : #endif
     772         258 :                             (!Z_ISREF(fci->params[i]) && Z_REFCOUNT(fci->params[i]) > 1)) {
     773             : 
     774         241 :                                 if (fci->no_separation &&
     775           4 :                                         !ARG_MAY_BE_SENT_BY_REF(func, i + 1)) {
     776           4 :                                         if (i) {
     777             :                                                 /* hack to clean up the stack */
     778           0 :                                                 ZEND_CALL_NUM_ARGS(call) = i;
     779             :                                                 zend_vm_stack_free_args(call);
     780             :                                         }
     781             :                                         zend_vm_stack_free_call_frame(call);
     782             : 
     783          14 :                                         zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
     784             :                                                 i+1,
     785           6 :                                                 func->common.scope ? func->common.scope->name->val : "",
     786           4 :                                                 func->common.scope ? "::" : "",
     787           4 :                                                 func->common.function_name->val);
     788           4 :                                         if (EG(current_execute_data) == &dummy_execute_data) {
     789           0 :                                                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     790             :                                         }
     791           4 :                                         return FAILURE;
     792             :                                 }
     793             : 
     794         233 :                                 if (Z_REFCOUNTED(fci->params[i])) {
     795          73 :                                         Z_DELREF(fci->params[i]);
     796             :                                 }
     797         233 :                                 ZVAL_DUP(&tmp, &fci->params[i]);
     798         233 :                                 ZVAL_NEW_REF(&fci->params[i], &tmp);
     799         233 :                                 Z_ADDREF(fci->params[i]);
     800         182 :                         } else if (!Z_ISREF(fci->params[i])) {
     801          17 :                                 ZVAL_NEW_REF(&fci->params[i], &fci->params[i]);
     802          17 :                                 Z_ADDREF(fci->params[i]);
     803          74 :                         } else if (Z_REFCOUNTED(fci->params[i])) {
     804          74 :                                 Z_ADDREF(fci->params[i]);
     805             :                         }
     806         324 :                         param = ZEND_CALL_ARG(call, i+1);
     807         324 :                         ZVAL_COPY_VALUE(param, &fci->params[i]);
     808      926334 :                 } else if (Z_ISREF(fci->params[i]) &&
     809             :                            /* don't separate references for __call */
     810          75 :                            (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0 ) {
     811          75 :                         param = ZEND_CALL_ARG(call, i+1);
     812          75 :                         ZVAL_DUP(param, Z_REFVAL(fci->params[i]));
     813             :                 } else {
     814      463017 :                         param = ZEND_CALL_ARG(call, i+1);
     815      463017 :                         ZVAL_COPY(param, &fci->params[i]);
     816             :                 }
     817             :         }
     818             : 
     819      681812 :         EG(scope) = calling_scope;
     820      681812 :         if (func->common.fn_flags & ZEND_ACC_STATIC) {
     821         433 :                 fci->object = NULL;
     822             :         }
     823      681812 :         if (!fci->object) {
     824      218338 :                 Z_OBJ(call->This) = NULL;
     825             :         } else {
     826      463474 :                 Z_OBJ(call->This) = fci->object;
     827      463474 :                 GC_REFCOUNT(fci->object)++;
     828             :         }
     829             : 
     830      681812 :         if (func->type == ZEND_USER_FUNCTION) {
     831      438247 :                 EG(scope) = func->common.scope;
     832      438247 :                 call->symbol_table = fci->symbol_table;
     833      438247 :                 if (EXPECTED((func->op_array.fn_flags & ZEND_ACC_GENERATOR) == 0)) {
     834      438245 :                         zend_init_execute_data(call, &func->op_array, fci->retval);
     835      438245 :                         zend_execute_ex(call);
     836             :                 } else {
     837           2 :                         zend_generator_create_zval(call, &func->op_array, fci->retval);
     838             :                 }
     839      243565 :         } else if (func->type == ZEND_INTERNAL_FUNCTION) {
     840      243565 :                 int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
     841      243565 :                 ZVAL_NULL(fci->retval);
     842      243565 :                 if (func->common.scope) {
     843      242554 :                         EG(scope) = func->common.scope;
     844             :                 }
     845      243565 :                 call->prev_execute_data = EG(current_execute_data);
     846      243565 :                 call->return_value = NULL; /* this is not a constructor call */
     847      243565 :                 EG(current_execute_data) = call;
     848      243565 :                 if (EXPECTED(zend_execute_internal == NULL)) {
     849             :                         /* saves one function call if zend_execute_internal is not used */
     850      243565 :                         func->internal_function.handler(call, fci->retval);
     851             :                 } else {
     852           0 :                         zend_execute_internal(call, fci->retval);
     853             :                 }
     854      243543 :                 EG(current_execute_data) = call->prev_execute_data;
     855             :                 zend_vm_stack_free_args(call);
     856             :                 zend_vm_stack_free_call_frame(call);
     857             : 
     858             :                 /*  We shouldn't fix bad extensions here,
     859             :                         because it can break proper ones (Bug #34045)
     860             :                 if (!EX(function_state).function->common.return_reference)
     861             :                 {
     862             :                         INIT_PZVAL(f->retval);
     863             :                 }*/
     864      243543 :                 if (EG(exception)) {
     865          78 :                         zval_ptr_dtor(fci->retval);
     866          78 :                         ZVAL_UNDEF(fci->retval);
     867             :                 }
     868             : 
     869      243543 :                 if (call_via_handler) {
     870             :                         /* We must re-initialize function again */
     871           9 :                         fci_cache->initialized = 0;
     872             :                 }
     873             :         } else { /* ZEND_OVERLOADED_FUNCTION */
     874           0 :                 ZVAL_NULL(fci->retval);
     875             : 
     876             :                 /* Not sure what should be done here if it's a static method */
     877           0 :                 if (fci->object) {
     878           0 :                         call->prev_execute_data = EG(current_execute_data);
     879           0 :                         EG(current_execute_data) = call;
     880           0 :                         fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval);
     881           0 :                         EG(current_execute_data) = call->prev_execute_data;
     882             :                 } else {
     883           0 :                         zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
     884             :                 }
     885             : 
     886             :                 zend_vm_stack_free_args(call);
     887             :                 zend_vm_stack_free_call_frame(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      681745 :         if (fci->object) {
     901      463434 :                 OBJ_RELEASE(fci->object);
     902             :         }
     903             : 
     904      681745 :         EG(scope) = orig_scope;
     905      681745 :         if (EG(current_execute_data) == &dummy_execute_data) {
     906      107889 :                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     907             :         }
     908             : 
     909      681745 :         if (EG(exception)) {
     910         268 :                 zend_throw_exception_internal(NULL);
     911             :         }
     912      681742 :         return SUCCESS;
     913             : }
     914             : /* }}} */
     915             : 
     916      251723 : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */
     917             : {
     918      251723 :         zend_class_entry *ce = NULL;
     919             :         zval args[1];
     920             :         zval local_retval;
     921             :         int retval;
     922             :         zend_string *lc_name;
     923             :         zend_fcall_info fcall_info;
     924             :         zend_fcall_info_cache fcall_cache;
     925             : 
     926      251723 :         if (key) {
     927       24800 :                 lc_name = Z_STR_P(key);
     928             :         } else {
     929      226923 :                 if (name == NULL || !name->len) {
     930          80 :                         return NULL;
     931             :                 }
     932             : 
     933      226843 :                 if (name->val[0] == '\\') {
     934          18 :                         lc_name = zend_string_alloc(name->len - 1, 0);
     935           9 :                         zend_str_tolower_copy(lc_name->val, name->val + 1, name->len - 1);
     936             :                 } else {
     937      226834 :                         lc_name = zend_string_tolower(name);
     938             :                 }
     939             :         }
     940             : 
     941      503286 :         ce = zend_hash_find_ptr(EG(class_table), lc_name);
     942      251643 :         if (ce) {
     943      250918 :                 if (!key) {
     944             :                         zend_string_release(lc_name);
     945             :                 }
     946      250918 :                 return ce;
     947             :         }
     948             : 
     949             :         /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
     950             :          * (doesn't impact functionality of __autoload()
     951             :         */
     952         725 :         if (!use_autoload || zend_is_compiling()) {
     953         352 :                 if (!key) {
     954             :                         zend_string_release(lc_name);
     955             :                 }
     956         352 :                 return NULL;
     957             :         }
     958             : 
     959         373 :         if (!EG(autoload_func)) {
     960         434 :                 zend_function *func = zend_hash_str_find_ptr(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1);
     961         217 :                 if (func) {
     962          66 :                         EG(autoload_func) = func;
     963             :                 } else {
     964         151 :                         if (!key) {
     965             :                                 zend_string_release(lc_name);
     966             :                         }
     967         151 :                         return NULL;
     968             :                 }
     969             : 
     970             :         }
     971             : 
     972             :         /* Verify class name before passing it to __autoload() */
     973         222 :         if (strspn(name->val, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\") != name->len) {
     974          11 :                 if (!key) {
     975             :                         zend_string_release(lc_name);
     976             :                 }
     977          11 :                 return NULL;
     978             :         }
     979             : 
     980         211 :         if (EG(in_autoload) == NULL) {
     981          89 :                 ALLOC_HASHTABLE(EG(in_autoload));
     982          89 :                 zend_hash_init(EG(in_autoload), 8, NULL, NULL, 0);
     983             :         }
     984             : 
     985         211 :         if (zend_hash_add_empty_element(EG(in_autoload), lc_name) == NULL) {
     986           4 :                 if (!key) {
     987             :                         zend_string_release(lc_name);
     988             :                 }
     989           4 :                 return NULL;
     990             :         }
     991             : 
     992         207 :         ZVAL_UNDEF(&local_retval);
     993             : 
     994         207 :         if (name->val[0] == '\\') {
     995           2 :                 ZVAL_STRINGL(&args[0], name->val + 1, name->len - 1);
     996             :         } else {
     997         206 :                 ZVAL_STR_COPY(&args[0], name);
     998             :         }
     999             : 
    1000         207 :         fcall_info.size = sizeof(fcall_info);
    1001         207 :         fcall_info.function_table = EG(function_table);
    1002         207 :         ZVAL_STR_COPY(&fcall_info.function_name, EG(autoload_func)->common.function_name);
    1003         207 :         fcall_info.symbol_table = NULL;
    1004         207 :         fcall_info.retval = &local_retval;
    1005         207 :         fcall_info.param_count = 1;
    1006         207 :         fcall_info.params = args;
    1007         207 :         fcall_info.object = NULL;
    1008         207 :         fcall_info.no_separation = 1;
    1009             : 
    1010         207 :         fcall_cache.initialized = 1;
    1011         207 :         fcall_cache.function_handler = EG(autoload_func);
    1012         207 :         fcall_cache.calling_scope = NULL;
    1013         207 :         fcall_cache.called_scope = NULL;
    1014         207 :         fcall_cache.object = NULL;
    1015             : 
    1016         207 :         zend_exception_save();
    1017         207 :         retval = zend_call_function(&fcall_info, &fcall_cache);
    1018         201 :         zend_exception_restore();
    1019             : 
    1020         201 :         zval_ptr_dtor(&args[0]);
    1021             :         zval_dtor(&fcall_info.function_name);
    1022             : 
    1023         201 :         zend_hash_del(EG(in_autoload), lc_name);
    1024             : 
    1025         201 :         zval_ptr_dtor(&local_retval);
    1026             : 
    1027         201 :         if (retval == SUCCESS) {
    1028         402 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1029             :         }
    1030         201 :         if (!key) {
    1031             :                 zend_string_release(lc_name);
    1032             :         }
    1033         201 :         return ce;
    1034             : }
    1035             : /* }}} */
    1036             : 
    1037      135996 : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name) /* {{{ */
    1038             : {
    1039      135996 :         return zend_lookup_class_ex(name, NULL, 1);
    1040             : }
    1041             : /* }}} */
    1042             : 
    1043         162 : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{{ */
    1044             : {
    1045             :         zval pv;
    1046             :         zend_op_array *new_op_array;
    1047             :         uint32_t original_compiler_options;
    1048             :         int retval;
    1049             : 
    1050         162 :         if (retval_ptr) {
    1051         150 :                 ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 1));
    1052          75 :                 memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
    1053          75 :                 memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
    1054          75 :                 Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
    1055          75 :                 Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
    1056             :         } else {
    1057         174 :                 ZVAL_STRINGL(&pv, str, str_len);
    1058             :         }
    1059             : 
    1060             :         /*printf("Evaluating '%s'\n", pv.value.str.val);*/
    1061             : 
    1062         162 :         original_compiler_options = CG(compiler_options);
    1063         162 :         CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
    1064         162 :         new_op_array = zend_compile_string(&pv, string_name);
    1065         162 :         CG(compiler_options) = original_compiler_options;
    1066             : 
    1067         162 :         if (new_op_array) {
    1068             :                 zval local_retval;
    1069             : 
    1070         153 :                 EG(no_extensions)=1;
    1071             : 
    1072         153 :                 zend_try {
    1073         153 :                         ZVAL_UNDEF(&local_retval);
    1074         153 :                         zend_execute(new_op_array, &local_retval);
    1075           1 :                 } zend_catch {
    1076           1 :                         destroy_op_array(new_op_array);
    1077           1 :                         efree_size(new_op_array, sizeof(zend_op_array));
    1078           1 :                         zend_bailout();
    1079         152 :                 } zend_end_try();
    1080             : 
    1081         152 :                 if (Z_TYPE(local_retval) != IS_UNDEF) {
    1082         152 :                         if (retval_ptr) {
    1083          68 :                                 ZVAL_COPY_VALUE(retval_ptr, &local_retval);
    1084             :                         } else {
    1085          84 :                                 zval_ptr_dtor(&local_retval);
    1086             :                         }
    1087             :                 } else {
    1088           0 :                         if (retval_ptr) {
    1089           0 :                                 ZVAL_NULL(retval_ptr);
    1090             :                         }
    1091             :                 }
    1092             : 
    1093         152 :                 EG(no_extensions)=0;
    1094         152 :                 destroy_op_array(new_op_array);
    1095         152 :                 efree_size(new_op_array, sizeof(zend_op_array));
    1096         152 :                 retval = SUCCESS;
    1097             :         } else {
    1098           9 :                 retval = FAILURE;
    1099             :         }
    1100             :         zval_dtor(&pv);
    1101         161 :         return retval;
    1102             : }
    1103             : /* }}} */
    1104             : 
    1105           0 : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name) /* {{{ */
    1106             : {
    1107           0 :         return zend_eval_stringl(str, strlen(str), retval_ptr, string_name);
    1108             : }
    1109             : /* }}} */
    1110             : 
    1111          25 : ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */
    1112             : {
    1113             :         int result;
    1114             : 
    1115          25 :         result = zend_eval_stringl(str, str_len, retval_ptr, string_name);
    1116          24 :         if (handle_exceptions && EG(exception)) {
    1117           0 :                 zend_exception_error(EG(exception), E_ERROR);
    1118           0 :                 result = FAILURE;
    1119             :         }
    1120          24 :         return result;
    1121             : }
    1122             : /* }}} */
    1123             : 
    1124          25 : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */
    1125             : {
    1126          25 :         return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions);
    1127             : }
    1128             : /* }}} */
    1129             : 
    1130           3 : ZEND_API void zend_timeout(int dummy) /* {{{ */
    1131             : {
    1132             : 
    1133           3 :         if (zend_on_timeout) {
    1134             : #ifdef ZEND_SIGNALS
    1135             :                 /*
    1136             :                    We got here because we got a timeout signal, so we are in a signal handler
    1137             :                    at this point. However, we want to be able to timeout any user-supplied
    1138             :                    shutdown functions, so pretend we are not in a signal handler while we are
    1139             :                    calling these
    1140             :                 */
    1141             :                 SIGG(running) = 0;
    1142             : #endif
    1143           3 :                 zend_on_timeout(EG(timeout_seconds));
    1144             :         }
    1145             : 
    1146           3 :         zend_error(E_ERROR, "Maximum execution time of %pd second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
    1147           0 : }
    1148             : /* }}} */
    1149             : 
    1150             : #ifdef ZEND_WIN32
    1151             : VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
    1152             : {
    1153             :         zend_bool *php_timed_out;
    1154             : 
    1155             :         /* The doc states it'll be always true, however it theoretically
    1156             :                 could be FALSE when the thread was signaled. */
    1157             :         if (!timed_out) {
    1158             :                 return;
    1159             :         }
    1160             : 
    1161             :         php_timed_out = (zend_bool *)arg;
    1162             :         *php_timed_out = 1;
    1163             : }
    1164             : #endif
    1165             : 
    1166             : /* This one doesn't exists on QNX */
    1167             : #ifndef SIGPROF
    1168             : #define SIGPROF 27
    1169             : #endif
    1170             : 
    1171       20683 : void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
    1172             : {
    1173             : 
    1174       20683 :         EG(timeout_seconds) = seconds;
    1175             : 
    1176             : #ifdef ZEND_WIN32
    1177             :         if(!seconds) {
    1178             :                 return;
    1179             :         }
    1180             : 
    1181             :         /* Don't use ChangeTimerQueueTimer() as it will not restart an expired
    1182             :                 timer, so we could end up with just an ignored timeout. Instead
    1183             :                 delete and recreate. */
    1184             :         if (NULL != tq_timer) {
    1185             :                 if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
    1186             :                         EG(timed_out) = 0;
    1187             :                         tq_timer = NULL;
    1188             :                         zend_error(E_ERROR, "Could not delete queued timer");
    1189             :                         return;
    1190             :                 }
    1191             :                 tq_timer = NULL;
    1192             :         }
    1193             : 
    1194             :         /* XXX passing NULL means the default timer queue provided by the system is used */
    1195             :         if (!CreateTimerQueueTimer(&tq_timer, NULL, (WAITORTIMERCALLBACK)tq_timer_cb, (VOID*)&EG(timed_out), seconds*1000, 0, WT_EXECUTEONLYONCE)) {
    1196             :                 EG(timed_out) = 0;
    1197             :                 tq_timer = NULL;
    1198             :                 zend_error(E_ERROR, "Could not queue new timer");
    1199             :                 return;
    1200             :         }
    1201             :         EG(timed_out) = 0;
    1202             : #else
    1203             : #       ifdef HAVE_SETITIMER
    1204             :         {
    1205             :                 struct itimerval t_r;           /* timeout requested */
    1206             :                 int signo;
    1207             : 
    1208       20683 :                 if(seconds) {
    1209         446 :                         t_r.it_value.tv_sec = seconds;
    1210         446 :                         t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
    1211             : 
    1212             : #       ifdef __CYGWIN__
    1213             :                         setitimer(ITIMER_REAL, &t_r, NULL);
    1214             :                 }
    1215             :                 signo = SIGALRM;
    1216             : #       else
    1217         446 :                         setitimer(ITIMER_PROF, &t_r, NULL);
    1218             :                 }
    1219       20683 :                 signo = SIGPROF;
    1220             : #       endif
    1221             : 
    1222       20683 :                 if (reset_signals) {
    1223             : #       ifdef ZEND_SIGNALS
    1224             :                         zend_signal(signo, zend_timeout);
    1225             : #       else
    1226             :                         sigset_t sigset;
    1227             : 
    1228       20648 :                         signal(signo, zend_timeout);
    1229       20648 :                         sigemptyset(&sigset);
    1230       20648 :                         sigaddset(&sigset, signo);
    1231       20648 :                         sigprocmask(SIG_UNBLOCK, &sigset, NULL);
    1232             : #       endif
    1233             :                 }
    1234             :         }
    1235             : #       endif /* HAVE_SETITIMER */
    1236             : #endif
    1237       20683 : }
    1238             : /* }}} */
    1239             : 
    1240       41397 : void zend_unset_timeout(void) /* {{{ */
    1241             : {
    1242             : #ifdef ZEND_WIN32
    1243             :         if (NULL != tq_timer) {
    1244             :                 if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
    1245             :                         EG(timed_out) = 0;
    1246             :                         tq_timer = NULL;
    1247             :                         zend_error(E_ERROR, "Could not delete queued timer");
    1248             :                         return;
    1249             :                 }
    1250             :                 tq_timer = NULL;
    1251             :         }
    1252             :         EG(timed_out) = 0;
    1253             : #else
    1254             : #       ifdef HAVE_SETITIMER
    1255       41397 :         if (EG(timeout_seconds)) {
    1256             :                 struct itimerval no_timeout;
    1257             : 
    1258         876 :                 no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0;
    1259             : 
    1260             : #ifdef __CYGWIN__
    1261             :                 setitimer(ITIMER_REAL, &no_timeout, NULL);
    1262             : #else
    1263         876 :                 setitimer(ITIMER_PROF, &no_timeout, NULL);
    1264             : #endif
    1265             :         }
    1266             : #       endif
    1267             : #endif
    1268       41397 : }
    1269             : /* }}} */
    1270             : 
    1271       93538 : zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {{{ */
    1272             : {
    1273             :         zend_class_entry *ce;
    1274       93538 :         int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
    1275       93538 :         int silent       = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
    1276             : 
    1277       93538 :         fetch_type &= ZEND_FETCH_CLASS_MASK;
    1278             : 
    1279             : check_fetch_type:
    1280       93544 :         switch (fetch_type) {
    1281             :                 case ZEND_FETCH_CLASS_SELF:
    1282        1698 :                         if (!EG(scope)) {
    1283           0 :                                 zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
    1284             :                         }
    1285        1698 :                         return EG(scope);
    1286             :                 case ZEND_FETCH_CLASS_PARENT:
    1287        1282 :                         if (!EG(scope)) {
    1288           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
    1289             :                         }
    1290        1282 :                         if (!EG(scope)->parent) {
    1291           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
    1292             :                         }
    1293        1282 :                         return EG(scope)->parent;
    1294             :                 case ZEND_FETCH_CLASS_STATIC:
    1295         111 :                         if (!EG(current_execute_data) || !EG(current_execute_data)->called_scope) {
    1296           0 :                                 zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
    1297             :                         }
    1298         111 :                         return EG(current_execute_data)->called_scope;
    1299             :                 case ZEND_FETCH_CLASS_AUTO: {
    1300       89156 :                                 fetch_type = zend_get_class_fetch_type(class_name);
    1301       89156 :                                 if (fetch_type!=ZEND_FETCH_CLASS_DEFAULT) {
    1302           6 :                                         goto check_fetch_type;
    1303             :                                 }
    1304             :                         }
    1305             :                         break;
    1306             :         }
    1307             : 
    1308       90447 :         if ((ce = zend_lookup_class_ex(class_name, NULL, use_autoload)) == NULL) {
    1309          21 :                 if (use_autoload) {
    1310          16 :                         if (!silent && !EG(exception)) {
    1311          13 :                                 if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
    1312           0 :                                         zend_error(E_ERROR, "Interface '%s' not found", class_name->val);
    1313          13 :                                 } else if (fetch_type == ZEND_FETCH_CLASS_TRAIT) {
    1314           0 :                         zend_error(E_ERROR, "Trait '%s' not found", class_name->val);
    1315             :                 } else {
    1316          13 :                                         zend_error(E_ERROR, "Class '%s' not found", class_name->val);
    1317             :                                 }
    1318             :                         }
    1319             :                 }
    1320           8 :                 return NULL;
    1321             :         }
    1322       90425 :         return ce;
    1323             : }
    1324             : /* }}} */
    1325             : 
    1326       24813 : zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type) /* {{{ */
    1327             : {
    1328             :         zend_class_entry *ce;
    1329       24813 :         int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
    1330             : 
    1331       24813 :         if ((ce = zend_lookup_class_ex(class_name, key, use_autoload)) == NULL) {
    1332          30 :                 if (use_autoload) {
    1333          24 :                         if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) {
    1334          16 :                                 if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
    1335           2 :                                         zend_error(E_ERROR, "Interface '%s' not found", class_name->val);
    1336          14 :                                 } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
    1337           2 :                                         zend_error(E_ERROR, "Trait '%s' not found", class_name->val);
    1338             :                                 } else {
    1339          12 :                                         zend_error(E_ERROR, "Class '%s' not found", class_name->val);
    1340             :                                 }
    1341             :                         }
    1342             :                 }
    1343          14 :                 return NULL;
    1344             :         }
    1345       24779 :         return ce;
    1346             : }
    1347             : /* }}} */
    1348             : 
    1349             : #define MAX_ABSTRACT_INFO_CNT 3
    1350             : #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
    1351             : #define DISPLAY_ABSTRACT_FN(idx) \
    1352             :         ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
    1353             :         ai.afn[idx] ? "::" : "", \
    1354             :         ai.afn[idx] ? ai.afn[idx]->common.function_name->val : "", \
    1355             :         ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
    1356             : 
    1357             : typedef struct _zend_abstract_info {
    1358             :         zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
    1359             :         int cnt;
    1360             :         int ctor;
    1361             : } zend_abstract_info;
    1362             : 
    1363          43 : static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai) /* {{{ */
    1364             : {
    1365          43 :         if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
    1366          14 :                 if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
    1367          14 :                         ai->afn[ai->cnt] = fn;
    1368             :                 }
    1369          14 :                 if (fn->common.fn_flags & ZEND_ACC_CTOR) {
    1370           1 :                         if (!ai->ctor) {
    1371           1 :                                 ai->cnt++;
    1372           1 :                                 ai->ctor = 1;
    1373             :                         } else {
    1374           0 :                                 ai->afn[ai->cnt] = NULL;
    1375             :                         }
    1376             :                 } else {
    1377          13 :                         ai->cnt++;
    1378             :                 }
    1379             :         }
    1380          43 : }
    1381             : /* }}} */
    1382             : 
    1383     1436933 : void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
    1384             : {
    1385             :         zend_function *func;
    1386             :         zend_abstract_info ai;
    1387             : 
    1388     1436933 :         if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
    1389          23 :                 memset(&ai, 0, sizeof(ai));
    1390             : 
    1391         109 :                 ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
    1392          43 :                         zend_verify_abstract_class_function(func, &ai);
    1393             :                 } ZEND_HASH_FOREACH_END();
    1394             : 
    1395          23 :                 if (ai.cnt) {
    1396         262 :                         zend_error(E_ERROR, "Class %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining methods (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
    1397          13 :                                 ce->name->val, ai.cnt,
    1398          13 :                                 ai.cnt > 1 ? "s" : "",
    1399         103 :                                 DISPLAY_ABSTRACT_FN(0),
    1400          68 :                                 DISPLAY_ABSTRACT_FN(1),
    1401          65 :                                 DISPLAY_ABSTRACT_FN(2)
    1402             :                                 );
    1403             :                 }
    1404             :         }
    1405     1436920 : }
    1406             : /* }}} */
    1407             : 
    1408         372 : ZEND_API int zend_delete_global_variable(zend_string *name) /* {{{ */
    1409             : {
    1410         372 :     return zend_hash_del_ind(&EG(symbol_table).ht, name);
    1411             : }
    1412             : /* }}} */
    1413             : 
    1414       91918 : ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
    1415             : {
    1416             :         int i;
    1417             :         zend_execute_data *ex;
    1418             :         zend_array *symbol_table;
    1419             : 
    1420             :         /* Search for last called user function */
    1421       91918 :         ex = EG(current_execute_data);
    1422      186584 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) {
    1423        2748 :                 ex = ex->prev_execute_data;
    1424             :         }
    1425       91918 :         if (!ex) {
    1426           0 :                 return NULL;
    1427             :         }
    1428       91918 :         if (ex->symbol_table) {
    1429        4086 :                 return ex->symbol_table;
    1430             :         }
    1431             : 
    1432       87832 :         if (EG(symtable_cache_ptr) >= EG(symtable_cache)) {
    1433             :                 /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
    1434       87570 :                 symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--);
    1435             :         } else {
    1436         262 :                 symbol_table = ex->symbol_table = emalloc(sizeof(zend_array));
    1437         262 :                 GC_REFCOUNT(symbol_table) = 0;
    1438         262 :                 GC_TYPE_INFO(symbol_table) = IS_ARRAY;
    1439         262 :                 zend_hash_init(&symbol_table->ht, ex->func->op_array.last_var, NULL, ZVAL_PTR_DTOR, 0);
    1440             :                 /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
    1441             :         }
    1442      264925 :         for (i = 0; i < ex->func->op_array.last_var; i++) {
    1443             :                 zval zv;
    1444             : 
    1445      177093 :                 ZVAL_INDIRECT(&zv, ZEND_CALL_VAR_NUM(ex, i));
    1446      177093 :                 zend_hash_add_new(&symbol_table->ht,
    1447             :                         ex->func->op_array.vars[i], &zv);
    1448             :         }
    1449       87832 :         return symbol_table;
    1450             : }
    1451             : /* }}} */
    1452             : 
    1453       38781 : ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1454             : {
    1455             :         int i;
    1456       38781 :         zend_op_array *op_array = &execute_data->func->op_array;
    1457       38781 :         HashTable *ht = &execute_data->symbol_table->ht;
    1458             : 
    1459             :         /* copy real values from symbol table into CV slots and create
    1460             :            INDIRECT references to CV in symbol table  */
    1461      144330 :         for (i = 0; i < op_array->last_var; i++) {
    1462      105549 :                 zval *zv = zend_hash_find(ht, op_array->vars[i]);
    1463             : 
    1464      105549 :                 if (zv) {
    1465       40028 :                         if (Z_TYPE_P(zv) == IS_INDIRECT) {
    1466       28283 :                                 zval *val = Z_INDIRECT_P(zv);
    1467             : 
    1468       28283 :                                 ZVAL_COPY_VALUE(EX_VAR_NUM(i), val);
    1469             :                         } else {
    1470       11745 :                                 ZVAL_COPY_VALUE(EX_VAR_NUM(i), zv);
    1471             :                         }
    1472             :                 } else {
    1473       65521 :                         ZVAL_UNDEF(EX_VAR_NUM(i));
    1474       65521 :                         zv = zend_hash_add_new(ht, op_array->vars[i], EX_VAR_NUM(i));
    1475             :                 }
    1476      105549 :                 ZVAL_INDIRECT(zv, EX_VAR_NUM(i));
    1477             :         }
    1478       38781 : }
    1479             : /* }}} */
    1480             : 
    1481       27944 : ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1482             : {
    1483             :         int i;
    1484       27944 :         zend_op_array *op_array = &execute_data->func->op_array;
    1485       27944 :         HashTable *ht = &execute_data->symbol_table->ht;
    1486             : 
    1487             :         /* copy real values from CV slots into symbol table */
    1488      103383 :         for (i = 0; i < op_array->last_var; i++) {
    1489      150878 :                 if (Z_TYPE_P(EX_VAR_NUM(i)) == IS_UNDEF) {
    1490        7730 :                         zend_hash_del(ht, op_array->vars[i]);
    1491             :                 } else {
    1492       67709 :                         zend_hash_update(ht, op_array->vars[i], EX_VAR_NUM(i));
    1493       67709 :                         ZVAL_UNDEF(EX_VAR_NUM(i));
    1494             :                 }
    1495             :         }
    1496       27944 : }
    1497             : /* }}} */
    1498             : 
    1499         286 : ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force) /* {{{ */
    1500             : {
    1501         286 :         zend_execute_data *execute_data = EG(current_execute_data);
    1502             : 
    1503         858 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1504         286 :                 execute_data = execute_data->prev_execute_data;
    1505             :         }
    1506             : 
    1507         286 :         if (execute_data) {
    1508         286 :                 if (!execute_data->symbol_table) {
    1509           0 :                         zend_ulong h = zend_string_hash_val(name);
    1510           0 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1511             :                         int i;
    1512             : 
    1513           0 :                         for (i = 0; i < op_array->last_var; i++) {
    1514           0 :                                 if (op_array->vars[i]->h == h &&
    1515           0 :                                     op_array->vars[i]->len == name->len &&
    1516           0 :                                     memcmp(op_array->vars[i]->val, name->val, name->len) == 0) {
    1517           0 :                                         ZVAL_COPY_VALUE(EX_VAR_NUM(i), value);
    1518           0 :                                         return SUCCESS;
    1519             :                                 }
    1520             :                         }
    1521           0 :                         if (force) {
    1522           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table();
    1523           0 :                                 if (symbol_table) {
    1524           0 :                                         return zend_hash_update(&symbol_table->ht, name, value) ? SUCCESS : FAILURE;;
    1525             :                                 }
    1526             :                         }
    1527             :                 } else {
    1528         286 :                         return (zend_hash_update_ind(&execute_data->symbol_table->ht, name, value) != NULL) ? SUCCESS : FAILURE;
    1529             :                 }
    1530             :         }
    1531           0 :         return FAILURE;
    1532             : }
    1533             : /* }}} */
    1534             : 
    1535       39727 : ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force) /* {{{ */
    1536             : {
    1537       39727 :         zend_execute_data *execute_data = EG(current_execute_data);
    1538             : 
    1539      115015 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1540       35561 :                 execute_data = execute_data->prev_execute_data;
    1541             :         }
    1542             : 
    1543       39727 :         if (execute_data) {
    1544       39719 :                 if (!execute_data->symbol_table) {
    1545        5736 :                         zend_ulong h = zend_hash_func(name, len);
    1546        5736 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1547             :                         int i;
    1548             : 
    1549       48366 :                         for (i = 0; i < op_array->last_var; i++) {
    1550       42636 :                                 if (op_array->vars[i]->h == h &&
    1551           2 :                                     op_array->vars[i]->len == len &&
    1552           2 :                                     memcmp(op_array->vars[i]->val, name, len) == 0) {
    1553           2 :                                         zval_ptr_dtor(EX_VAR_NUM(i));
    1554           2 :                                         ZVAL_COPY_VALUE(EX_VAR_NUM(i), value);
    1555           2 :                                         return SUCCESS;
    1556             :                                 }
    1557             :                         }
    1558             : 
    1559        5734 :                         if (force) {
    1560           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table();
    1561           0 :                                 if (symbol_table) {
    1562           0 :                                         return zend_hash_str_update(&symbol_table->ht, name, len, value) ? SUCCESS : FAILURE;;
    1563             :                                 }
    1564             :                         }
    1565             :                 } else {
    1566       33983 :                         return (zend_hash_str_update_ind(&execute_data->symbol_table->ht, name, len, value) != NULL) ? SUCCESS : FAILURE;
    1567             :                 }
    1568             :         }
    1569        5742 :         return FAILURE;
    1570             : }
    1571             : /* }}} */
    1572             : 
    1573             : /*
    1574             :  * Local variables:
    1575             :  * tab-width: 4
    1576             :  * c-basic-offset: 4
    1577             :  * indent-tabs-mode: t
    1578             :  * End:
    1579             :  */

Generated by: LCOV version 1.10

Generated at Sun, 18 Jan 2015 09:00:36 +0000 (8 days ago)

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