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: 601 707 85.0 %
Date: 2014-12-13 Functions: 41 45 91.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:09 +0000 (5 days ago)

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