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: 602 708 85.0 %
Date: 2014-11-22 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       20346 : static void zend_extension_activator(zend_extension *extension TSRMLS_DC) /* {{{ */
      91             : {
      92       20346 :         if (extension->activate) {
      93         368 :                 extension->activate();
      94             :         }
      95       20346 : }
      96             : /* }}} */
      97             : 
      98       20385 : static void zend_extension_deactivator(zend_extension *extension TSRMLS_DC) /* {{{ */
      99             : {
     100       20385 :         if (extension->deactivate) {
     101         368 :                 extension->deactivate();
     102             :         }
     103       20385 : }
     104             : /* }}} */
     105             : 
     106       41906 : static int clean_non_persistent_function(zval *zv TSRMLS_DC) /* {{{ */
     107             : {
     108       41906 :         zend_function *function = Z_PTR_P(zv);
     109       41906 :         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       29482 : static int clean_non_persistent_class(zval *zv TSRMLS_DC) /* {{{ */
     121             : {
     122       29482 :         zend_class_entry *ce = Z_PTR_P(zv);
     123       29482 :         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       20464 : void init_executor(TSRMLS_D) /* {{{ */
     135             : {
     136       20464 :         zend_init_fpu(TSRMLS_C);
     137             : 
     138       20464 :         ZVAL_NULL(&EG(uninitialized_zval));
     139             :         /* trick to make uninitialized_zval never be modified, passed by ref, etc. */
     140       20464 :         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       20464 :         EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
     147       20464 :         EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
     148       20464 :         EG(no_extensions) = 0;
     149             : 
     150       20464 :         EG(function_table) = CG(function_table);
     151       20464 :         EG(class_table) = CG(class_table);
     152             : 
     153       20464 :         EG(in_autoload) = NULL;
     154       20464 :         EG(autoload_func) = NULL;
     155       20464 :         EG(error_handling) = EH_NORMAL;
     156             : 
     157       20464 :         zend_vm_stack_init(TSRMLS_C);
     158             : 
     159       20464 :         zend_hash_init(&EG(symbol_table).ht, 64, NULL, ZVAL_PTR_DTOR, 0);
     160       20464 :         GC_REFCOUNT(&EG(symbol_table)) = 1;
     161       20464 :         GC_TYPE_INFO(&EG(symbol_table)) = IS_ARRAY;
     162       20464 :         EG(valid_symbol_table) = 1;
     163             : 
     164       20464 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator TSRMLS_CC);
     165             : 
     166       20464 :         zend_hash_init(&EG(included_files), 8, NULL, NULL, 0);
     167             : 
     168       20464 :         EG(ticks_count) = 0;
     169             : 
     170       20464 :         ZVAL_UNDEF(&EG(user_error_handler));
     171             : 
     172       20464 :         EG(current_execute_data) = NULL;
     173             : 
     174       20464 :         zend_stack_init(&EG(user_error_handlers_error_reporting), sizeof(int));
     175       20464 :         zend_stack_init(&EG(user_error_handlers), sizeof(zval));
     176       20464 :         zend_stack_init(&EG(user_exception_handlers), sizeof(zval));
     177             : 
     178       20464 :         zend_objects_store_init(&EG(objects_store), 1024);
     179             : 
     180       20464 :         EG(full_tables_cleanup) = 0;
     181             : #ifdef ZEND_WIN32
     182             :         EG(timed_out) = 0;
     183             : #endif
     184             : 
     185       20464 :         EG(exception) = NULL;
     186       20464 :         EG(prev_exception) = NULL;
     187             : 
     188       20464 :         EG(scope) = NULL;
     189             : 
     190       20464 :         EG(active) = 1;
     191       20464 : }
     192             : /* }}} */
     193             : 
     194      262236 : static int zval_call_destructor(zval *zv TSRMLS_DC) /* {{{ */
     195             : {
     196      262236 :         if (Z_TYPE_P(zv) == IS_INDIRECT) {
     197        3247 :                 zv = Z_INDIRECT_P(zv);
     198             :         }
     199      271120 :         if (Z_TYPE_P(zv) == IS_OBJECT && Z_REFCOUNT_P(zv) == 1) {
     200        8156 :                 return ZEND_HASH_APPLY_REMOVE;
     201             :         } else {
     202      254080 :                 return ZEND_HASH_APPLY_KEEP;
     203             :         }
     204             : }
     205             : /* }}} */
     206             : 
     207       17730 : static void zend_unclean_zval_ptr_dtor(zval *zv) /* {{{ */
     208             : {
     209             :         TSRMLS_FETCH();
     210             : 
     211       17730 :         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       17730 : }
     216             : /* }}} */
     217             : 
     218       20500 : void shutdown_destructors(TSRMLS_D) /* {{{ */
     219             : {
     220       20500 :         if (CG(unclean_shutdown)) {
     221        1916 :                 EG(symbol_table).ht.pDestructor = zend_unclean_zval_ptr_dtor;
     222             :         }
     223       20500 :         zend_try {
     224             :                 int symbols;
     225             :                 do {
     226       25206 :                         symbols = zend_hash_num_elements(&EG(symbol_table).ht);
     227       25206 :                         zend_hash_reverse_apply(&EG(symbol_table).ht, (apply_func_t) zval_call_destructor TSRMLS_CC);
     228       25206 :                 } while (symbols != zend_hash_num_elements(&EG(symbol_table).ht));
     229       20500 :                 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       20500 :         } zend_end_try();
     234       20500 : }
     235             : /* }}} */
     236             : 
     237       20500 : void shutdown_executor(TSRMLS_D) /* {{{ */
     238             : {
     239             :         zend_function *func;
     240             :         zend_class_entry *ce;
     241             : 
     242       20500 :         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       20500 :                 zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC);
     260             : 
     261       20500 :                 if (CG(unclean_shutdown)) {
     262        1921 :                         EG(symbol_table).ht.pDestructor = zend_unclean_zval_ptr_dtor;
     263             :                 }
     264       20500 :                 zend_hash_graceful_reverse_destroy(&EG(symbol_table).ht);
     265       20500 :         } zend_end_try();
     266       20500 :         EG(valid_symbol_table) = 0;
     267             : 
     268       20500 :         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       20500 :                 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       20500 :                 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       20500 :                 zend_stack_clean(&EG(user_error_handlers_error_reporting), NULL, 1);
     285       20500 :                 zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_DESTRUCTOR, 1);
     286       20500 :                 zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_DESTRUCTOR, 1);
     287       20500 :         } zend_end_try();
     288             : 
     289       20500 :         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       20500 :                 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      110530 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(function_table), func) {
     314       41906 :                                 if (func->type != ZEND_USER_FUNCTION) {
     315       20500 :                                         break;
     316             :                                 }
     317       21406 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     318             :                         } ZEND_HASH_FOREACH_END();
     319       69882 :                         ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) {
     320       29481 :                                 if (ce->type != ZEND_USER_CLASS) {
     321       20499 :                                         break;
     322             :                                 }
     323        8982 :                                 zend_cleanup_user_class_data(ce TSRMLS_CC);
     324             :                         } ZEND_HASH_FOREACH_END();
     325       20499 :                         zend_cleanup_internal_classes(TSRMLS_C);
     326             :                 }
     327       20500 :         } zend_end_try();
     328             : 
     329       20500 :         zend_try {
     330       20500 :                 zend_llist_destroy(&CG(open_files));
     331       20500 :         } zend_end_try();
     332             : 
     333       20500 :         zend_try {
     334       20500 :                 zend_close_rsrc_list(&EG(regular_list) TSRMLS_CC);
     335       20500 :         } zend_end_try();
     336             : 
     337       20500 :         zend_try {
     338       20500 :                 zend_objects_store_free_object_storage(&EG(objects_store) TSRMLS_CC);
     339             : 
     340       20500 :                 zend_vm_stack_destroy(TSRMLS_C);
     341             : 
     342             :                 /* Destroy all op arrays */
     343       20500 :                 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       20500 :                         zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function TSRMLS_CC);
     348       20500 :                         zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class TSRMLS_CC);
     349             :                 }
     350             : 
     351       41259 :                 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       20500 :         } zend_end_try();
     357             : 
     358       20500 :         zend_try {
     359       20500 :                 clean_non_persistent_constants(TSRMLS_C);
     360       20500 :         } zend_end_try();
     361             : 
     362       20500 :         zend_try {
     363             : #if 0&&ZEND_DEBUG
     364             :         signal(SIGSEGV, original_sigsegv_handler);
     365             : #endif
     366             : 
     367       20500 :                 zend_hash_destroy(&EG(included_files));
     368             : 
     369       20500 :                 zend_stack_destroy(&EG(user_error_handlers_error_reporting));
     370       20500 :                 zend_stack_destroy(&EG(user_error_handlers));
     371       20500 :                 zend_stack_destroy(&EG(user_exception_handlers));
     372       20500 :                 zend_objects_store_destroy(&EG(objects_store));
     373       20500 :                 if (EG(in_autoload)) {
     374          89 :                         zend_hash_destroy(EG(in_autoload));
     375          89 :                         FREE_HASHTABLE(EG(in_autoload));
     376             :                 }
     377       20500 :         } zend_end_try();
     378             : 
     379       20500 :         zend_shutdown_fpu(TSRMLS_C);
     380             : 
     381       20500 :         EG(active) = 0;
     382       20500 : }
     383             : /* }}} */
     384             : 
     385             : /* return class name and "::" or "". */
     386      207239 : ZEND_API const char *get_active_class_name(const char **space TSRMLS_DC) /* {{{ */
     387             : {
     388             :         zend_function *func;
     389             : 
     390      207239 :         if (!zend_is_executing(TSRMLS_C)) {
     391           0 :                 if (space) {
     392           0 :                         *space = "";
     393             :                 }
     394           0 :                 return "";
     395             :         }
     396             : 
     397      207239 :         func = EG(current_execute_data)->func;
     398      207239 :         switch (func->type) {
     399             :                 case ZEND_USER_FUNCTION:
     400             :                 case ZEND_INTERNAL_FUNCTION:
     401             :                 {
     402      207239 :                         zend_class_entry *ce = func->common.scope;
     403             : 
     404      207239 :                         if (space) {
     405      207239 :                                 *space = ce ? "::" : "";
     406             :                         }
     407      207239 :                         return ce ? ce->name->val : "";
     408             :                 }
     409             :                 default:
     410           0 :                         if (space) {
     411           0 :                                 *space = "";
     412             :                         }
     413           0 :                         return "";
     414             :         }
     415             : }
     416             : /* }}} */
     417             : 
     418      207312 : ZEND_API const char *get_active_function_name(TSRMLS_D) /* {{{ */
     419             : {
     420             :         zend_function *func;
     421             : 
     422      207312 :         if (!zend_is_executing(TSRMLS_C)) {
     423          68 :                 return NULL;
     424             :         }
     425      207244 :         func = EG(current_execute_data)->func;
     426      207244 :         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      207036 :                         return func->common.function_name->val;
     439             :                         break;
     440             :                 default:
     441           0 :                         return NULL;
     442             :         }
     443             : }
     444             : /* }}} */
     445             : 
     446      397090 : ZEND_API const char *zend_get_executed_filename(TSRMLS_D) /* {{{ */
     447             : {
     448      397090 :         zend_execute_data *ex = EG(current_execute_data);
     449             : 
     450     1012740 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     451      218560 :                 ex = ex->prev_execute_data;
     452             :         }
     453      397090 :         if (ex) {
     454      397069 :                 return ex->func->op_array.filename->val;
     455             :         } else {
     456          21 :                 return "[no active file]";
     457             :         }
     458             : }
     459             : /* }}} */
     460             : 
     461      389805 : ZEND_API uint zend_get_executed_lineno(TSRMLS_D) /* {{{ */
     462             : {
     463      389805 :         zend_execute_data *ex = EG(current_execute_data);
     464             : 
     465      997648 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     466      218038 :                 ex = ex->prev_execute_data;
     467             :         }
     468      389805 :         if (ex) {
     469      389790 :                 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      389790 :                 return ex->opline->lineno;
     474             :         } else {
     475          15 :                 return 0;
     476             :         }
     477             : }
     478             : /* }}} */
     479             : 
     480      831648 : ZEND_API zend_bool zend_is_executing(TSRMLS_D) /* {{{ */
     481             : {
     482      831648 :         return EG(current_execute_data) != 0;
     483             : }
     484             : /* }}} */
     485             : 
     486    16976583 : 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    16976579 : }
     491             : /* }}} */
     492             : 
     493    19477880 : ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
     494             : {
     495    19477880 :         if (Z_REFCOUNTED_P(zval_ptr)) {
     496             :                 Z_DELREF_P(zval_ptr);
     497     5325199 :                 if (Z_REFCOUNT_P(zval_ptr) == 0) {
     498     1977016 :                         _zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC);
     499             :                 }
     500             :         }
     501    19477880 : }
     502             : /* }}} */
     503             : 
     504       10736 : ZEND_API int zend_is_true(zval *op TSRMLS_DC) /* {{{ */
     505             : {
     506       10735 :         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         823 : 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         823 :         if (IS_CONSTANT_VISITED(p)) {
     520           2 :                 zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
     521         821 :         } else if (Z_TYPE_P(p) == IS_CONSTANT) {
     522             :                 int refcount;
     523             : 
     524         569 :                 SEPARATE_ZVAL_NOREF(p);
     525         328 :                 MARK_CONSTANT_VISITED(p);
     526         564 :                 refcount =  Z_REFCOUNTED_P(p) ? Z_REFCOUNT_P(p) : 1;
     527         328 :                 const_value = zend_get_constant_ex(Z_STR_P(p), scope, Z_CONST_FLAGS_P(p) TSRMLS_CC);
     528         316 :                 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         296 :                         if (inline_change) {
     590         216 :                                 zend_string_release(Z_STR_P(p));
     591             :                         }
     592         296 :                         ZVAL_COPY_VALUE(p, const_value);
     593         296 :                         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         301 :                 if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount);
     600         493 :         } 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         774 :         return 0;
     612             : }
     613             : /* }}} */
     614             : 
     615         185 : ZEND_API int zval_update_constant_inline_change(zval *pp, zend_class_entry *scope TSRMLS_DC) /* {{{ */
     616             : {
     617         185 :         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         407 : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change TSRMLS_DC) /* {{{ */
     628             : {
     629         407 :         return zval_update_constant_ex(pp, inline_change, NULL TSRMLS_CC);
     630             : }
     631             : /* }}} */
     632             : 
     633        1380 : 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        1380 :         return call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, 1, NULL TSRMLS_CC);
     636             : }
     637             : /* }}} */
     638             : 
     639       12249 : 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       12249 :         fci.size = sizeof(fci);
     644       12249 :         fci.function_table = function_table;
     645       12249 :         fci.object = object ? Z_OBJ_P(object) : NULL;
     646       12249 :         ZVAL_COPY_VALUE(&fci.function_name, function_name);
     647       12249 :         fci.retval = retval_ptr;
     648       12249 :         fci.param_count = param_count;
     649       12249 :         fci.params = params;
     650       12249 :         fci.no_separation = (zend_bool) no_separation;
     651       12249 :         fci.symbol_table = symbol_table;
     652             : 
     653       12249 :         return zend_call_function(&fci, NULL TSRMLS_CC);
     654             : }
     655             : /* }}} */
     656             : 
     657      716431 : int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) /* {{{ */
     658             : {
     659             :         uint32_t i;
     660      716431 :         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      716431 :         ZVAL_UNDEF(fci->retval);
     668             : 
     669      716431 :         if (!EG(active)) {
     670           0 :                 return FAILURE; /* executor is already inactive */
     671             :         }
     672             : 
     673      716431 :         if (EG(exception)) {
     674           7 :                 return FAILURE; /* we would result in an instable executor otherwise */
     675             :         }
     676             : 
     677      716424 :         switch (fci->size) {
     678             :                 case sizeof(zend_fcall_info):
     679      716424 :                         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      716424 :         orig_scope = EG(scope);
     686             : 
     687             :         /* Initialize execute_data */
     688      716424 :         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     1261710 :         } else if (EG(current_execute_data)->func &&
     696      623030 :                    ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
     697       15637 :                    EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL) {
     698             :                 /* Insert fake frame in case of include or magic calls */
     699       14582 :                 dummy_execute_data = *EG(current_execute_data);
     700       14582 :                 dummy_execute_data.prev_execute_data = EG(current_execute_data);
     701       14582 :                 dummy_execute_data.call = NULL;
     702       14582 :                 dummy_execute_data.opline = NULL;
     703       14582 :                 dummy_execute_data.func = NULL;
     704       14582 :                 EG(current_execute_data) = &dummy_execute_data;
     705             :         }
     706             : 
     707      716424 :         if (!fci_cache || !fci_cache->initialized) {
     708             :                 zend_string *callable_name;
     709      260459 :                 char *error = NULL;
     710             : 
     711      260459 :                 if (!fci_cache) {
     712       12676 :                         fci_cache = &fci_cache_local;
     713             :                 }
     714             : 
     715      260459 :                 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      260336 :                 } 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      260336 :                 zend_string_release(callable_name);
     736             :         }
     737             : 
     738      716301 :         func = fci_cache->function_handler;
     739     1432602 :         call = zend_vm_stack_push_call_frame(VM_FRAME_TOP_FUNCTION,
     740             :                 func, fci->param_count, fci_cache->called_scope, fci_cache->object, NULL TSRMLS_CC);
     741      716301 :         calling_scope = fci_cache->calling_scope;
     742      716301 :         fci->object = fci_cache->object;
     743     1643163 :         if (fci->object &&
     744      463431 :             (!EG(objects_store).object_buckets ||
     745      463431 :              !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      716301 :         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     1248886 :         for (i=0; i<fci->param_count; i++) {
     765             :                 zval *param;
     766             : 
     767     1065178 :                 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 :                                                 call->num_args = 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     1064688 :                 } 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      532190 :                         param = ZEND_CALL_ARG(call, i+1);
     827      532190 :                         ZVAL_COPY(param, &fci->params[i]);
     828             :                 }
     829             :         }
     830      716297 :         call->num_args = fci->param_count;
     831             : 
     832      716297 :         EG(scope) = calling_scope;
     833      716297 :         if (func->common.fn_flags & ZEND_ACC_STATIC) {
     834         467 :                 fci->object = NULL;
     835             :         }
     836      716297 :         if (!fci->object) {
     837      252896 :                 Z_OBJ(call->This) = NULL;
     838      252896 :                 Z_TYPE_INFO(call->This) = IS_UNDEF;
     839             :         } else {
     840      463401 :                 ZVAL_OBJ(&call->This, fci->object);
     841      463401 :                 GC_REFCOUNT(fci->object)++;
     842             :         }
     843             : 
     844      716297 :         if (func->type == ZEND_USER_FUNCTION) {
     845      472783 :                 EG(scope) = func->common.scope;
     846      472783 :                 call->symbol_table = fci->symbol_table;
     847      472783 :                 if (EXPECTED((func->op_array.fn_flags & ZEND_ACC_GENERATOR) == 0)) {
     848      472781 :                         zend_init_execute_data(call, &func->op_array, fci->retval TSRMLS_CC);
     849      472781 :                         zend_execute_ex(call TSRMLS_CC);
     850             :                 } else {
     851           2 :                         zend_generator_create_zval(call, &func->op_array, fci->retval TSRMLS_CC);
     852             :                 }
     853      243514 :         } else if (func->type == ZEND_INTERNAL_FUNCTION) {
     854      243514 :                 int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
     855      243514 :                 ZVAL_NULL(fci->retval);
     856      243514 :                 if (func->common.scope) {
     857      242478 :                         EG(scope) = func->common.scope;
     858             :                 }
     859      243514 :                 call->prev_execute_data = EG(current_execute_data);
     860      243514 :                 call->return_value = NULL; /* this is not a constructor call */
     861      243514 :                 EG(current_execute_data) = call;
     862      243514 :                 if (EXPECTED(zend_execute_internal == NULL)) {
     863             :                         /* saves one function call if zend_execute_internal is not used */
     864      243514 :                         func->internal_function.handler(call, fci->retval TSRMLS_CC);
     865             :                 } else {
     866           0 :                         zend_execute_internal(call, fci->retval TSRMLS_CC);
     867             :                 }
     868      243492 :                 EG(current_execute_data) = call->prev_execute_data;
     869             :                 zend_vm_stack_free_args(call TSRMLS_CC);
     870             :                 zend_vm_stack_free_call_frame(call TSRMLS_CC);
     871             : 
     872             :                 /*  We shouldn't fix bad extensions here,
     873             :                         because it can break proper ones (Bug #34045)
     874             :                 if (!EX(function_state).function->common.return_reference)
     875             :                 {
     876             :                         INIT_PZVAL(f->retval);
     877             :                 }*/
     878      243492 :                 if (EG(exception)) {
     879          78 :                         zval_ptr_dtor(fci->retval);
     880          78 :                         ZVAL_UNDEF(fci->retval);
     881             :                 }
     882             : 
     883      243492 :                 if (call_via_handler) {
     884             :                         /* We must re-initialize function again */
     885           9 :                         fci_cache->initialized = 0;
     886             :                 }
     887             :         } else { /* ZEND_OVERLOADED_FUNCTION */
     888           0 :                 ZVAL_NULL(fci->retval);
     889             : 
     890             :                 /* Not sure what should be done here if it's a static method */
     891           0 :                 if (fci->object) {
     892           0 :                         call->prev_execute_data = EG(current_execute_data);
     893           0 :                         EG(current_execute_data) = call;
     894           0 :                         fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval TSRMLS_CC);
     895           0 :                         EG(current_execute_data) = call->prev_execute_data;
     896             :                 } else {
     897           0 :                         zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
     898             :                 }
     899             : 
     900             :                 zend_vm_stack_free_args(call TSRMLS_CC);
     901             :                 zend_vm_stack_free_call_frame(call TSRMLS_CC);
     902             : 
     903           0 :                 if (func->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
     904           0 :                         zend_string_release(func->common.function_name);
     905             :                 }
     906           0 :                 efree(func);
     907             : 
     908           0 :                 if (EG(exception)) {
     909           0 :                         zval_ptr_dtor(fci->retval);
     910           0 :                         ZVAL_UNDEF(fci->retval);
     911             :                 }
     912             :         }
     913             : 
     914      716230 :         if (fci->object) {
     915      463361 :                 OBJ_RELEASE(fci->object);
     916             :         }
     917             : 
     918      716230 :         EG(scope) = orig_scope;
     919      716230 :         if (EG(current_execute_data) == &dummy_execute_data) {
     920      107867 :                 EG(current_execute_data) = dummy_execute_data.prev_execute_data;
     921             :         }
     922             : 
     923      716230 :         if (EG(exception)) {
     924         268 :                 zend_throw_exception_internal(NULL TSRMLS_CC);
     925             :         }
     926      716227 :         return SUCCESS;
     927             : }
     928             : /* }}} */
     929             : 
     930      251394 : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload TSRMLS_DC) /* {{{ */
     931             : {
     932      251394 :         zend_class_entry *ce = NULL;
     933             :         zval args[1];
     934             :         zval local_retval;
     935             :         int retval;
     936             :         zend_string *lc_name;
     937             :         zend_fcall_info fcall_info;
     938             :         zend_fcall_info_cache fcall_cache;
     939             : 
     940      251394 :         if (key) {
     941       24591 :                 lc_name = Z_STR_P(key);
     942             :         } else {
     943      226803 :                 if (name == NULL || !name->len) {
     944          80 :                         return NULL;
     945             :                 }
     946             : 
     947      226723 :                 if (name->val[0] == '\\') {
     948          18 :                         lc_name = zend_string_alloc(name->len - 1, 0);
     949           9 :                         zend_str_tolower_copy(lc_name->val, name->val + 1, name->len - 1);
     950             :                 } else {
     951      453428 :                         lc_name = zend_string_alloc(name->len, 0);
     952      226714 :                         zend_str_tolower_copy(lc_name->val, name->val, name->len);
     953             :                 }
     954             :         }
     955             : 
     956      502628 :         ce = zend_hash_find_ptr(EG(class_table), lc_name);
     957      251314 :         if (ce) {
     958      250596 :                 if (!key) {
     959             :                         zend_string_free(lc_name);
     960             :                 }
     961      250596 :                 return ce;
     962             :         }
     963             : 
     964             :         /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
     965             :          * (doesn't impact functionality of __autoload()
     966             :         */
     967         718 :         if (!use_autoload || zend_is_compiling(TSRMLS_C)) {
     968         345 :                 if (!key) {
     969             :                         zend_string_free(lc_name);
     970             :                 }
     971         345 :                 return NULL;
     972             :         }
     973             : 
     974         373 :         if (!EG(autoload_func)) {
     975         434 :                 zend_function *func = zend_hash_str_find_ptr(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1);
     976         217 :                 if (func) {
     977          66 :                         EG(autoload_func) = func;
     978             :                 } else {
     979         151 :                         if (!key) {
     980             :                                 zend_string_free(lc_name);
     981             :                         }
     982         151 :                         return NULL;
     983             :                 }
     984             : 
     985             :         }
     986             :         
     987             :         /* Verify class name before passing it to __autoload() */
     988         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) {
     989          11 :                 if (!key) {
     990             :                         zend_string_free(lc_name);
     991             :                 }
     992          11 :                 return NULL;
     993             :         }
     994             :         
     995         211 :         if (EG(in_autoload) == NULL) {
     996          89 :                 ALLOC_HASHTABLE(EG(in_autoload));
     997          89 :                 zend_hash_init(EG(in_autoload), 8, NULL, NULL, 0);
     998             :         }
     999             : 
    1000         211 :         if (zend_hash_add_empty_element(EG(in_autoload), lc_name) == NULL) {
    1001           4 :                 if (!key) {
    1002             :                         zend_string_free(lc_name);
    1003             :                 }
    1004           4 :                 return NULL;
    1005             :         }
    1006             : 
    1007         207 :         ZVAL_UNDEF(&local_retval);
    1008             : 
    1009         207 :         if (name->val[0] == '\\') {
    1010           2 :                 ZVAL_STRINGL(&args[0], name->val + 1, name->len - 1);
    1011             :         } else {
    1012         206 :                 ZVAL_STR_COPY(&args[0], name);
    1013             :         }
    1014             : 
    1015         207 :         fcall_info.size = sizeof(fcall_info);
    1016         207 :         fcall_info.function_table = EG(function_table);
    1017         207 :         ZVAL_STR_COPY(&fcall_info.function_name, EG(autoload_func)->common.function_name);
    1018         207 :         fcall_info.symbol_table = NULL;
    1019         207 :         fcall_info.retval = &local_retval;
    1020         207 :         fcall_info.param_count = 1;
    1021         207 :         fcall_info.params = args;
    1022         207 :         fcall_info.object = NULL;
    1023         207 :         fcall_info.no_separation = 1;
    1024             : 
    1025         207 :         fcall_cache.initialized = 1;
    1026         207 :         fcall_cache.function_handler = EG(autoload_func);
    1027         207 :         fcall_cache.calling_scope = NULL;
    1028         207 :         fcall_cache.called_scope = NULL;
    1029         207 :         fcall_cache.object = NULL;
    1030             : 
    1031         207 :         zend_exception_save(TSRMLS_C);
    1032         207 :         retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC);
    1033         201 :         zend_exception_restore(TSRMLS_C);
    1034             : 
    1035         201 :         zval_ptr_dtor(&args[0]);
    1036             :         zval_dtor(&fcall_info.function_name);
    1037             : 
    1038         201 :         zend_hash_del(EG(in_autoload), lc_name);
    1039             : 
    1040         201 :         zval_ptr_dtor(&local_retval);
    1041             : 
    1042         201 :         if (retval == SUCCESS) {
    1043         402 :                 ce = zend_hash_find_ptr(EG(class_table), lc_name);
    1044             :         }
    1045         201 :         if (!key) {
    1046             :                 zend_string_free(lc_name);
    1047             :         }
    1048         201 :         return ce;
    1049             : }
    1050             : /* }}} */
    1051             : 
    1052      135887 : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name TSRMLS_DC) /* {{{ */
    1053             : {
    1054      135887 :         return zend_lookup_class_ex(name, NULL, 1 TSRMLS_CC);
    1055             : }
    1056             : /* }}} */
    1057             : 
    1058         162 : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
    1059             : {
    1060             :         zval pv;
    1061             :         zend_op_array *new_op_array;
    1062             :         uint32_t original_compiler_options;
    1063             :         int retval;
    1064             : 
    1065         162 :         if (retval_ptr) {
    1066         150 :                 ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 1));
    1067          75 :                 memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
    1068          75 :                 memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
    1069          75 :                 Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
    1070          75 :                 Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
    1071             :         } else {
    1072         174 :                 ZVAL_STRINGL(&pv, str, str_len);
    1073             :         }
    1074             : 
    1075             :         /*printf("Evaluating '%s'\n", pv.value.str.val);*/
    1076             : 
    1077         162 :         original_compiler_options = CG(compiler_options);
    1078         162 :         CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
    1079         162 :         new_op_array = zend_compile_string(&pv, string_name TSRMLS_CC);
    1080         162 :         CG(compiler_options) = original_compiler_options;
    1081             : 
    1082         162 :         if (new_op_array) {
    1083             :                 zval local_retval;
    1084             : 
    1085         153 :                 EG(no_extensions)=1;            
    1086             : 
    1087         153 :                 zend_try {
    1088         153 :                         ZVAL_UNDEF(&local_retval);
    1089         153 :                         zend_execute(new_op_array, &local_retval TSRMLS_CC);
    1090           1 :                 } zend_catch {
    1091           1 :                         destroy_op_array(new_op_array TSRMLS_CC);
    1092           1 :                         efree_size(new_op_array, sizeof(zend_op_array));
    1093           1 :                         zend_bailout();
    1094         152 :                 } zend_end_try();
    1095             : 
    1096         152 :                 if (Z_TYPE(local_retval) != IS_UNDEF) {
    1097         152 :                         if (retval_ptr) {
    1098          68 :                                 ZVAL_COPY_VALUE(retval_ptr, &local_retval);
    1099             :                         } else {
    1100          84 :                                 zval_ptr_dtor(&local_retval);
    1101             :                         }
    1102             :                 } else {
    1103           0 :                         if (retval_ptr) {
    1104           0 :                                 ZVAL_NULL(retval_ptr);
    1105             :                         }
    1106             :                 }
    1107             : 
    1108         152 :                 EG(no_extensions)=0;
    1109         152 :                 destroy_op_array(new_op_array TSRMLS_CC);
    1110         152 :                 efree_size(new_op_array, sizeof(zend_op_array));
    1111         152 :                 retval = SUCCESS;
    1112             :         } else {
    1113           9 :                 retval = FAILURE;
    1114             :         }
    1115             :         zval_dtor(&pv);
    1116         161 :         return retval;
    1117             : }
    1118             : /* }}} */
    1119             : 
    1120           0 : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
    1121             : {
    1122           0 :         return zend_eval_stringl(str, strlen(str), retval_ptr, string_name TSRMLS_CC);
    1123             : }
    1124             : /* }}} */
    1125             : 
    1126          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) /* {{{ */
    1127             : {
    1128             :         int result;
    1129             : 
    1130          25 :         result = zend_eval_stringl(str, str_len, retval_ptr, string_name TSRMLS_CC);
    1131          24 :         if (handle_exceptions && EG(exception)) {
    1132           0 :                 zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1133           0 :                 result = FAILURE;
    1134             :         }
    1135          24 :         return result;
    1136             : }
    1137             : /* }}} */
    1138             : 
    1139          25 : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
    1140             : {
    1141          25 :         return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions TSRMLS_CC);
    1142             : }
    1143             : /* }}} */
    1144             : 
    1145           3 : ZEND_API void zend_timeout(int dummy) /* {{{ */
    1146             : {
    1147             :         TSRMLS_FETCH();
    1148             : 
    1149           3 :         if (zend_on_timeout) {
    1150             : #ifdef ZEND_SIGNALS
    1151             :                 /*
    1152             :                    We got here because we got a timeout signal, so we are in a signal handler
    1153             :                    at this point. However, we want to be able to timeout any user-supplied
    1154             :                    shutdown functions, so pretend we are not in a signal handler while we are
    1155             :                    calling these
    1156             :                 */
    1157             :                 SIGG(running) = 0;
    1158             : #endif
    1159           3 :                 zend_on_timeout(EG(timeout_seconds) TSRMLS_CC);
    1160             :         }
    1161             : 
    1162           3 :         zend_error(E_ERROR, "Maximum execution time of %pd second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
    1163           0 : }
    1164             : /* }}} */
    1165             : 
    1166             : #ifdef ZEND_WIN32
    1167             : static LRESULT CALLBACK zend_timeout_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) /* {{{ */
    1168             : {
    1169             : #ifdef ZTS
    1170             :         THREAD_T thread_id = (THREAD_T)wParam;
    1171             : #endif
    1172             : 
    1173             :         switch (message) {
    1174             :                 case WM_DESTROY:
    1175             :                         PostQuitMessage(0);
    1176             :                         break;
    1177             :                 case WM_REGISTER_ZEND_TIMEOUT:
    1178             :                         /* wParam is the thread id pointer, lParam is the timeout amount in seconds */
    1179             :                         if (lParam == 0) {
    1180             :                                 KillTimer(timeout_window, wParam);
    1181             :                         } else {
    1182             : #ifdef ZTS
    1183             :                                 void ***tsrm_ls;
    1184             : #endif
    1185             :                                 SetTimer(timeout_window, wParam, lParam*1000, NULL);
    1186             : #ifdef ZTS
    1187             :                                 tsrm_ls = ts_resource_ex(0, &thread_id);
    1188             :                                 if (!tsrm_ls) {
    1189             :                                         /* shouldn't normally happen */
    1190             :                                         break;
    1191             :                                 }
    1192             : #endif
    1193             :                                 EG(timed_out) = 0;
    1194             :                         }
    1195             :                         break;
    1196             :                 case WM_UNREGISTER_ZEND_TIMEOUT:
    1197             :                         /* wParam is the thread id pointer */
    1198             :                         KillTimer(timeout_window, wParam);
    1199             :                         break;
    1200             :                 case WM_TIMER: {
    1201             : #ifdef ZTS
    1202             :                                 void ***tsrm_ls;
    1203             : 
    1204             :                                 tsrm_ls = ts_resource_ex(0, &thread_id);
    1205             :                                 if (!tsrm_ls) {
    1206             :                                         /* Thread died before receiving its timeout? */
    1207             :                                         break;
    1208             :                                 }
    1209             : #endif
    1210             :                                 KillTimer(timeout_window, wParam);
    1211             :                                 EG(timed_out) = 1;
    1212             :                         }
    1213             :                         break;
    1214             :                 default:
    1215             :                         return DefWindowProc(hWnd, message, wParam, lParam);
    1216             :         }
    1217             :         return 0;
    1218             : }
    1219             : /* }}} */
    1220             : 
    1221             : static unsigned __stdcall timeout_thread_proc(void *pArgs) /* {{{ */
    1222             : {
    1223             :         MSG message;
    1224             : 
    1225             :         wc.style=0;
    1226             :         wc.lpfnWndProc = zend_timeout_WndProc;
    1227             :         wc.cbClsExtra=0;
    1228             :         wc.cbWndExtra=0;
    1229             :         wc.hInstance=NULL;
    1230             :         wc.hIcon=NULL;
    1231             :         wc.hCursor=NULL;
    1232             :         wc.hbrBackground=(HBRUSH)(COLOR_BACKGROUND + 5);
    1233             :         wc.lpszMenuName=NULL;
    1234             :         wc.lpszClassName = "Zend Timeout Window";
    1235             :         if (!RegisterClass(&wc)) {
    1236             :                 return -1;
    1237             :         }
    1238             :         timeout_window = CreateWindow(wc.lpszClassName, wc.lpszClassName, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
    1239             :         SetEvent(timeout_thread_event);
    1240             :         while (GetMessage(&message, NULL, 0, 0)) {
    1241             :                 SendMessage(timeout_window, message.message, message.wParam, message.lParam);
    1242             :                 if (message.message == WM_QUIT) {
    1243             :                         break;
    1244             :                 }
    1245             :         }
    1246             :         DestroyWindow(timeout_window);
    1247             :         UnregisterClass(wc.lpszClassName, NULL);
    1248             :         SetEvent(timeout_thread_handle);
    1249             :         return 0;
    1250             : }
    1251             : /* }}} */
    1252             : 
    1253             : void zend_init_timeout_thread(void) /* {{{ */
    1254             : {
    1255             :         timeout_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
    1256             :         timeout_thread_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
    1257             :         _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id);
    1258             :         WaitForSingleObject(timeout_thread_event, INFINITE);
    1259             : }
    1260             : /* }}} */
    1261             : 
    1262             : void zend_shutdown_timeout_thread(void) /* {{{ */
    1263             : {
    1264             :         if (!timeout_thread_initialized) {
    1265             :                 return;
    1266             :         }
    1267             :         PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0);
    1268             : 
    1269             :         /* Wait for thread termination */
    1270             :         WaitForSingleObject(timeout_thread_handle, 5000);
    1271             :         CloseHandle(timeout_thread_handle);
    1272             :         timeout_thread_initialized = 0;
    1273             : }
    1274             : /* }}} */
    1275             : 
    1276             : #endif
    1277             : 
    1278             : /* This one doesn't exists on QNX */
    1279             : #ifndef SIGPROF
    1280             : #define SIGPROF 27
    1281             : #endif
    1282             : 
    1283       20502 : void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
    1284             : {
    1285             :         TSRMLS_FETCH();
    1286             : 
    1287       20502 :         EG(timeout_seconds) = seconds;
    1288             : 
    1289             : #ifdef ZEND_WIN32
    1290             :         if(!seconds) {
    1291             :                 return;
    1292             :         }
    1293             :         if (timeout_thread_initialized == 0 && InterlockedIncrement(&timeout_thread_initialized) == 1) {
    1294             :                 /* We start up this process-wide thread here and not in zend_startup(), because if Zend
    1295             :                  * is initialized inside a DllMain(), you're not supposed to start threads from it.
    1296             :                  */
    1297             :                 zend_init_timeout_thread();
    1298             :         }
    1299             :         PostThreadMessage(timeout_thread_id, WM_REGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) seconds);
    1300             : #else
    1301             : #       ifdef HAVE_SETITIMER
    1302             :         {
    1303             :                 struct itimerval t_r;           /* timeout requested */
    1304             :                 int signo;
    1305             : 
    1306       20502 :                 if(seconds) {
    1307         446 :                         t_r.it_value.tv_sec = seconds;
    1308         446 :                         t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
    1309             : 
    1310             : #       ifdef __CYGWIN__
    1311             :                         setitimer(ITIMER_REAL, &t_r, NULL);
    1312             :                 }
    1313             :                 signo = SIGALRM;
    1314             : #       else
    1315         446 :                         setitimer(ITIMER_PROF, &t_r, NULL);
    1316             :                 }
    1317       20502 :                 signo = SIGPROF;
    1318             : #       endif
    1319             : 
    1320       20502 :                 if (reset_signals) {
    1321             : #       ifdef ZEND_SIGNALS
    1322             :                         zend_signal(signo, zend_timeout TSRMLS_CC);
    1323             : #       else
    1324             :                         sigset_t sigset;
    1325             : 
    1326       20467 :                         signal(signo, zend_timeout);
    1327       20467 :                         sigemptyset(&sigset);
    1328       20467 :                         sigaddset(&sigset, signo);
    1329       20467 :                         sigprocmask(SIG_UNBLOCK, &sigset, NULL);
    1330             : #       endif
    1331             :                 }
    1332             :         }
    1333             : #       endif /* HAVE_SETITIMER */
    1334             : #endif
    1335       20502 : }
    1336             : /* }}} */
    1337             : 
    1338       41035 : void zend_unset_timeout(TSRMLS_D) /* {{{ */
    1339             : {
    1340             : #ifdef ZEND_WIN32
    1341             :         if(timeout_thread_initialized) {
    1342             :                 PostThreadMessage(timeout_thread_id, WM_UNREGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) 0);
    1343             :         }
    1344             : #else
    1345             : #       ifdef HAVE_SETITIMER
    1346       41035 :         if (EG(timeout_seconds)) {
    1347             :                 struct itimerval no_timeout;
    1348             : 
    1349         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;
    1350             : 
    1351             : #ifdef __CYGWIN__
    1352             :                 setitimer(ITIMER_REAL, &no_timeout, NULL);
    1353             : #else
    1354         876 :                 setitimer(ITIMER_PROF, &no_timeout, NULL);
    1355             : #endif
    1356             :         }
    1357             : #       endif
    1358             : #endif
    1359       41035 : }
    1360             : /* }}} */
    1361             : 
    1362       93513 : zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type TSRMLS_DC) /* {{{ */
    1363             : {
    1364             :         zend_class_entry *ce;
    1365       93513 :         int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
    1366       93513 :         int silent       = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
    1367             : 
    1368       93513 :         fetch_type &= ZEND_FETCH_CLASS_MASK;
    1369             : 
    1370             : check_fetch_type:
    1371       93519 :         switch (fetch_type) {
    1372             :                 case ZEND_FETCH_CLASS_SELF:
    1373        1689 :                         if (!EG(scope)) {
    1374           0 :                                 zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
    1375             :                         }
    1376        1689 :                         return EG(scope);
    1377             :                 case ZEND_FETCH_CLASS_PARENT:
    1378        1277 :                         if (!EG(scope)) {
    1379           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
    1380             :                         }
    1381        1277 :                         if (!EG(scope)->parent) {
    1382           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
    1383             :                         }
    1384        1277 :                         return EG(scope)->parent;
    1385             :                 case ZEND_FETCH_CLASS_STATIC:
    1386         111 :                         if (!EG(current_execute_data) || !EG(current_execute_data)->called_scope) {
    1387           0 :                                 zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
    1388             :                         }
    1389         111 :                         return EG(current_execute_data)->called_scope;
    1390             :                 case ZEND_FETCH_CLASS_AUTO: {
    1391       89155 :                                 fetch_type = zend_get_class_fetch_type(class_name);
    1392       89155 :                                 if (fetch_type!=ZEND_FETCH_CLASS_DEFAULT) {
    1393           6 :                                         goto check_fetch_type;
    1394             :                                 }
    1395             :                         }
    1396             :                         break;
    1397             :         }
    1398             : 
    1399       90436 :         if ((ce = zend_lookup_class_ex(class_name, NULL, use_autoload TSRMLS_CC)) == NULL) {
    1400          21 :                 if (use_autoload) {
    1401          16 :                         if (!silent && !EG(exception)) {
    1402          13 :                                 if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
    1403           0 :                                         zend_error(E_ERROR, "Interface '%s' not found", class_name->val);
    1404          13 :                                 } else if (fetch_type == ZEND_FETCH_CLASS_TRAIT) {
    1405           0 :                         zend_error(E_ERROR, "Trait '%s' not found", class_name->val);
    1406             :                 } else {
    1407          13 :                                         zend_error(E_ERROR, "Class '%s' not found", class_name->val);
    1408             :                                 }
    1409             :                         }
    1410             :                 }
    1411           8 :                 return NULL;
    1412             :         }
    1413       90414 :         return ce;
    1414             : }
    1415             : /* }}} */
    1416             : 
    1417       24604 : zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type TSRMLS_DC) /* {{{ */
    1418             : {
    1419             :         zend_class_entry *ce;
    1420       24604 :         int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
    1421             : 
    1422       24604 :         if ((ce = zend_lookup_class_ex(class_name, key, use_autoload TSRMLS_CC)) == NULL) {
    1423          30 :                 if (use_autoload) {
    1424          24 :                         if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) {
    1425          16 :                                 if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
    1426           2 :                                         zend_error(E_ERROR, "Interface '%s' not found", class_name->val);
    1427          14 :                                 } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
    1428           2 :                                         zend_error(E_ERROR, "Trait '%s' not found", class_name->val);
    1429             :                                 } else {
    1430          12 :                                         zend_error(E_ERROR, "Class '%s' not found", class_name->val);
    1431             :                                 }
    1432             :                         }
    1433             :                 }
    1434          14 :                 return NULL;
    1435             :         }
    1436       24570 :         return ce;
    1437             : }
    1438             : /* }}} */
    1439             : 
    1440             : #define MAX_ABSTRACT_INFO_CNT 3
    1441             : #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
    1442             : #define DISPLAY_ABSTRACT_FN(idx) \
    1443             :         ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
    1444             :         ai.afn[idx] ? "::" : "", \
    1445             :         ai.afn[idx] ? ai.afn[idx]->common.function_name->val : "", \
    1446             :         ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
    1447             : 
    1448             : typedef struct _zend_abstract_info {
    1449             :         zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
    1450             :         int cnt;
    1451             :         int ctor;
    1452             : } zend_abstract_info;
    1453             : 
    1454          43 : static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai TSRMLS_DC) /* {{{ */
    1455             : {
    1456          43 :         if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
    1457          14 :                 if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
    1458          14 :                         ai->afn[ai->cnt] = fn;
    1459             :                 }
    1460          14 :                 if (fn->common.fn_flags & ZEND_ACC_CTOR) {
    1461           1 :                         if (!ai->ctor) {
    1462           1 :                                 ai->cnt++;
    1463           1 :                                 ai->ctor = 1;
    1464             :                         } else {
    1465           0 :                                 ai->afn[ai->cnt] = NULL;
    1466             :                         }
    1467             :                 } else {
    1468          13 :                         ai->cnt++;
    1469             :                 }
    1470             :         }
    1471          43 : }
    1472             : /* }}} */
    1473             : 
    1474     1424425 : void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC) /* {{{ */
    1475             : {
    1476             :         zend_function *func;
    1477             :         zend_abstract_info ai;
    1478             : 
    1479     1424425 :         if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
    1480          23 :                 memset(&ai, 0, sizeof(ai));
    1481             : 
    1482         109 :                 ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
    1483          43 :                         zend_verify_abstract_class_function(func, &ai TSRMLS_CC);
    1484             :                 } ZEND_HASH_FOREACH_END();
    1485             : 
    1486          23 :                 if (ai.cnt) {
    1487         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 ")",
    1488          13 :                                 ce->name->val, ai.cnt,
    1489          13 :                                 ai.cnt > 1 ? "s" : "",
    1490         103 :                                 DISPLAY_ABSTRACT_FN(0),
    1491          68 :                                 DISPLAY_ABSTRACT_FN(1),
    1492          65 :                                 DISPLAY_ABSTRACT_FN(2)
    1493             :                                 );
    1494             :                 }
    1495             :         }
    1496     1424412 : }
    1497             : /* }}} */
    1498             : 
    1499         363 : ZEND_API int zend_delete_global_variable(zend_string *name TSRMLS_DC) /* {{{ */
    1500             : {
    1501         363 :     return zend_hash_del_ind(&EG(symbol_table).ht, name);
    1502             : }
    1503             : /* }}} */
    1504             : 
    1505       91932 : ZEND_API zend_array *zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
    1506             : {
    1507             :         int i;
    1508             :         zend_execute_data *ex;
    1509             :         zend_array *symbol_table;
    1510             : 
    1511             :         /* Search for last called user function */
    1512       91932 :         ex = EG(current_execute_data);
    1513      186624 :         while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) {
    1514        2760 :                 ex = ex->prev_execute_data;
    1515             :         }
    1516       91932 :         if (!ex) {
    1517           0 :                 return NULL;
    1518             :         }
    1519       91932 :         if (ex->symbol_table) {
    1520        4100 :                 return ex->symbol_table;
    1521             :         }
    1522             : 
    1523       87832 :         if (EG(symtable_cache_ptr) >= EG(symtable_cache)) {
    1524             :                 /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
    1525       87572 :                 symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--);
    1526             :         } else {
    1527         260 :                 symbol_table = ex->symbol_table = emalloc(sizeof(zend_array));
    1528         260 :                 GC_REFCOUNT(symbol_table) = 0;
    1529         260 :                 GC_TYPE_INFO(symbol_table) = IS_ARRAY;
    1530         260 :                 zend_hash_init(&symbol_table->ht, ex->func->op_array.last_var, NULL, ZVAL_PTR_DTOR, 0);
    1531             :                 /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
    1532             :         }
    1533      264946 :         for (i = 0; i < ex->func->op_array.last_var; i++) {
    1534             :                 zval zv;
    1535             : 
    1536      177114 :                 ZVAL_INDIRECT(&zv, EX_VAR_NUM_2(ex, i));
    1537      177114 :                 zend_hash_add_new(&symbol_table->ht,
    1538             :                         ex->func->op_array.vars[i], &zv);
    1539             :         }
    1540       87832 :         return symbol_table;
    1541             : }
    1542             : /* }}} */
    1543             : 
    1544       38525 : ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1545             : {
    1546             :         int i;
    1547       38525 :         zend_op_array *op_array = &execute_data->func->op_array;
    1548       38525 :         HashTable *ht = &execute_data->symbol_table->ht;
    1549             :         
    1550             :         /* copy real values from symbol table into CV slots and create
    1551             :            INDIRECT references to CV in symbol table  */
    1552      143833 :         for (i = 0; i < op_array->last_var; i++) {
    1553      105308 :                 zval *zv = zend_hash_find(ht, op_array->vars[i]);
    1554             : 
    1555      105308 :                 if (zv) {
    1556       39963 :                         if (Z_TYPE_P(zv) == IS_INDIRECT) {
    1557       28229 :                                 zval *val = Z_INDIRECT_P(zv);
    1558       28229 :                                 if (Z_TYPE_P(val) == IS_UNDEF) {
    1559       17730 :                                         ZVAL_UNDEF(EX_VAR_NUM(i));
    1560             :                                 } else {
    1561       10499 :                                         ZVAL_COPY_VALUE(EX_VAR_NUM(i), val);
    1562             :                                 }
    1563             :                         } else {
    1564       11734 :                                 ZVAL_COPY_VALUE(EX_VAR_NUM(i), zv);
    1565             :                         }
    1566             :                 } else {
    1567       65345 :                         ZVAL_UNDEF(EX_VAR_NUM(i));
    1568       65345 :                         zv = zend_hash_update(ht, op_array->vars[i], EX_VAR_NUM(i));
    1569             :                 }
    1570      105308 :                 ZVAL_INDIRECT(zv, EX_VAR_NUM(i));
    1571             :         }
    1572       38525 : }
    1573             : /* }}} */
    1574             : 
    1575       27759 : ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data) /* {{{ */
    1576             : {
    1577             :         int i;
    1578       27759 :         zend_op_array *op_array = &execute_data->func->op_array;
    1579       27759 :         HashTable *ht = &execute_data->symbol_table->ht;
    1580             :         
    1581             :         /* copy real values from CV slots into symbol table */
    1582      102992 :         for (i = 0; i < op_array->last_var; i++) {
    1583      150466 :                 if (Z_TYPE_P(EX_VAR_NUM(i)) == IS_UNDEF) {
    1584        7703 :                         zend_hash_del(ht, op_array->vars[i]);
    1585             :                 } else {
    1586       67530 :                         zend_hash_update(ht, op_array->vars[i], EX_VAR_NUM(i));
    1587       67530 :                         ZVAL_UNDEF(EX_VAR_NUM(i));
    1588             :                 }
    1589             :         }
    1590       27759 : }
    1591             : /* }}} */
    1592             : 
    1593         286 : ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force TSRMLS_DC) /* {{{ */
    1594             : {
    1595         286 :         zend_execute_data *execute_data = EG(current_execute_data);
    1596             : 
    1597         858 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1598         286 :                 execute_data = execute_data->prev_execute_data;
    1599             :         }
    1600             : 
    1601         286 :         if (execute_data) {
    1602         286 :                 if (!execute_data->symbol_table) {
    1603           0 :                         zend_ulong h = zend_string_hash_val(name);
    1604           0 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1605             :                         int i;
    1606             : 
    1607           0 :                         for (i = 0; i < op_array->last_var; i++) {
    1608           0 :                                 if (op_array->vars[i]->h == h &&
    1609           0 :                                     op_array->vars[i]->len == name->len &&
    1610           0 :                                     memcmp(op_array->vars[i]->val, name->val, name->len) == 0) {
    1611           0 :                                         ZVAL_COPY_VALUE(EX_VAR_NUM(i), value);
    1612           0 :                                         return SUCCESS;
    1613             :                                 }
    1614             :                         }
    1615           0 :                         if (force) {
    1616           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table(TSRMLS_C);
    1617           0 :                                 if (symbol_table) {
    1618           0 :                                         return zend_hash_update(&symbol_table->ht, name, value) ? SUCCESS : FAILURE;;
    1619             :                                 }
    1620             :                         }
    1621             :                 } else {
    1622         286 :                         return (zend_hash_update_ind(&execute_data->symbol_table->ht, name, value) != NULL) ? SUCCESS : FAILURE;
    1623             :                 }
    1624             :         }
    1625           0 :         return FAILURE;
    1626             : }
    1627             : /* }}} */
    1628             : 
    1629       39911 : ZEND_API int zend_set_local_var_str(const char *name, int len, zval *value, int force TSRMLS_DC) /* {{{ */
    1630             : {
    1631       39911 :         zend_execute_data *execute_data = EG(current_execute_data);
    1632             : 
    1633      115501 :         while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) {
    1634       35679 :                 execute_data = execute_data->prev_execute_data;
    1635             :         }
    1636             : 
    1637       39911 :         if (execute_data) {
    1638       39903 :                 if (!execute_data->symbol_table) {
    1639        5644 :                         zend_ulong h = zend_hash_func(name, len);
    1640        5644 :                         zend_op_array *op_array = &execute_data->func->op_array;
    1641             :                         int i;
    1642             : 
    1643       49228 :                         for (i = 0; i < op_array->last_var; i++) {
    1644       43590 :                                 if (op_array->vars[i]->h == h &&
    1645           2 :                                     op_array->vars[i]->len == len &&
    1646           2 :                                     memcmp(op_array->vars[i]->val, name, len) == 0) {
    1647           2 :                                         zval_ptr_dtor(EX_VAR_NUM(i));
    1648           2 :                                         ZVAL_COPY_VALUE(EX_VAR_NUM(i), value);
    1649           2 :                                         return SUCCESS;
    1650             :                                 }
    1651             :                         }
    1652             : 
    1653        5642 :                         if (force) {
    1654           0 :                                 zend_array *symbol_table = zend_rebuild_symbol_table(TSRMLS_C);
    1655           0 :                                 if (symbol_table) {
    1656           0 :                                         return zend_hash_str_update(&symbol_table->ht, name, len, value) ? SUCCESS : FAILURE;;
    1657             :                                 }
    1658             :                         }
    1659             :                 } else {
    1660       34259 :                         return (zend_hash_str_update_ind(&execute_data->symbol_table->ht, name, len, value) != NULL) ? SUCCESS : FAILURE;
    1661             :                 }
    1662             :         }
    1663        5650 :         return FAILURE;
    1664             : }
    1665             : /* }}} */
    1666             : 
    1667             : /*
    1668             :  * Local variables:
    1669             :  * tab-width: 4
    1670             :  * c-basic-offset: 4
    1671             :  * indent-tabs-mode: t
    1672             :  * End:
    1673             :  */

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:12 +0000 (3 days ago)

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