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.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 436 487 89.5 %
Date: 2014-11-10 Functions: 37 39 94.9 %
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 "zend.h"
      23             : #include "zend_extensions.h"
      24             : #include "zend_modules.h"
      25             : #include "zend_constants.h"
      26             : #include "zend_list.h"
      27             : #include "zend_API.h"
      28             : #include "zend_exceptions.h"
      29             : #include "zend_builtin_functions.h"
      30             : #include "zend_ini.h"
      31             : #include "zend_vm.h"
      32             : #include "zend_dtrace.h"
      33             : #include "zend_virtual_cwd.h"
      34             : 
      35             : #ifdef ZTS
      36             : # define GLOBAL_FUNCTION_TABLE          global_function_table
      37             : # define GLOBAL_CLASS_TABLE                     global_class_table
      38             : # define GLOBAL_CONSTANTS_TABLE         global_constants_table
      39             : # define GLOBAL_AUTO_GLOBALS_TABLE      global_auto_globals_table
      40             : #else
      41             : # define GLOBAL_FUNCTION_TABLE          CG(function_table)
      42             : # define GLOBAL_CLASS_TABLE                     CG(class_table)
      43             : # define GLOBAL_AUTO_GLOBALS_TABLE      CG(auto_globals)
      44             : # define GLOBAL_CONSTANTS_TABLE         EG(zend_constants)
      45             : #endif
      46             : 
      47             : /* true multithread-shared globals */
      48             : ZEND_API zend_class_entry *zend_standard_class_def = NULL;
      49             : ZEND_API size_t (*zend_printf)(const char *format, ...);
      50             : ZEND_API zend_write_func_t zend_write;
      51             : ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
      52             : ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
      53             : ZEND_API void (*zend_block_interruptions)(void);
      54             : ZEND_API void (*zend_unblock_interruptions)(void);
      55             : ZEND_API void (*zend_ticks_function)(int ticks TSRMLS_DC);
      56             : ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
      57             : size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
      58             : zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
      59             : ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
      60             : ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
      61             : 
      62             : void (*zend_on_timeout)(int seconds TSRMLS_DC);
      63             : 
      64             : static void (*zend_message_dispatcher_p)(zend_long message, const void *data TSRMLS_DC);
      65             : static zval *(*zend_get_configuration_directive_p)(zend_string *name);
      66             : 
      67       23497 : static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
      68             : {
      69       23497 :         if (!new_value) {
      70         183 :                 EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
      71             :         } else {
      72       23314 :                 EG(error_reporting) = atoi(new_value->val);
      73             :         }
      74       23497 :         return SUCCESS;
      75             : }
      76             : /* }}} */
      77             : 
      78       20492 : static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
      79             : {
      80       20492 :         OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
      81             : 
      82       20492 :         if (GC_G(gc_enabled)) {
      83       20485 :                 gc_init(TSRMLS_C);
      84             :         }
      85             : 
      86       20492 :         return SUCCESS;
      87             : }
      88             : /* }}} */
      89             : 
      90       20473 : static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
      91             : {
      92       20473 :         if (!CG(multibyte)) {
      93       20443 :                 return FAILURE;
      94             :         }
      95          30 :         if (!zend_multibyte_get_functions(TSRMLS_C)) {
      96          30 :                 return SUCCESS;
      97             :         }
      98           0 :         return zend_multibyte_set_script_encoding_by_string(new_value->val, new_value->len TSRMLS_CC);
      99             : }
     100             : /* }}} */
     101             : 
     102             : 
     103             : ZEND_INI_BEGIN()
     104             :         ZEND_INI_ENTRY("error_reporting",                             NULL,           ZEND_INI_ALL,           OnUpdateErrorReporting)
     105             :         STD_ZEND_INI_BOOLEAN("zend.enable_gc",                                "1",  ZEND_INI_ALL,           OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
     106             :         STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
     107             :         ZEND_INI_ENTRY("zend.script_encoding",                        NULL,           ZEND_INI_ALL,           OnUpdateScriptEncoding)
     108             :         STD_ZEND_INI_BOOLEAN("zend.detect_unicode",                   "1",  ZEND_INI_ALL,           OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
     109             : #ifdef ZEND_SIGNALS
     110             :         STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
     111             : #endif
     112             : ZEND_INI_END()
     113             : 
     114             : 
     115             : #ifdef ZTS
     116             : ZEND_API int compiler_globals_id;
     117             : ZEND_API int executor_globals_id;
     118             : static HashTable *global_function_table = NULL;
     119             : static HashTable *global_class_table = NULL;
     120             : static HashTable *global_constants_table = NULL;
     121             : static HashTable *global_auto_globals_table = NULL;
     122             : static HashTable *global_persistent_list = NULL;
     123             : #endif
     124             : 
     125             : ZEND_API zend_utility_values zend_uv;
     126             : 
     127             : /* version information */
     128             : static char *zend_version_info;
     129             : static uint zend_version_info_length;
     130             : #define ZEND_CORE_VERSION_INFO  "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2014 Zend Technologies\n"
     131             : #define PRINT_ZVAL_INDENT 4
     132             : 
     133        1338 : static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
     134             : {
     135             :         zval *tmp;
     136             :         zend_string *string_key;
     137             :         zend_ulong num_key;
     138             :         int i;
     139             : 
     140        5946 :         for (i = 0; i < indent; i++) {
     141        4608 :                 ZEND_PUTS_EX(" ");
     142             :         }
     143        1338 :         ZEND_PUTS_EX("(\n");
     144        1338 :         indent += PRINT_ZVAL_INDENT;
     145       14018 :         ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
     146        6264 :                 if (Z_TYPE_P(tmp) == IS_INDIRECT) {
     147         394 :                         tmp = Z_INDIRECT_P(tmp);
     148         394 :                         if (Z_TYPE_P(tmp) == IS_UNDEF) {
     149           0 :                                 continue;
     150             :                         }
     151             :                 }
     152       45200 :                 for (i = 0; i < indent; i++) {
     153       38936 :                         ZEND_PUTS_EX(" ");
     154             :                 }
     155        6264 :                 ZEND_PUTS_EX("[");
     156        6264 :                 if (string_key) {
     157        4324 :                         if (is_object) {
     158             :                                 const char *prop_name, *class_name;
     159             :                                 size_t prop_len;
     160         753 :                                 int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
     161             : 
     162         753 :                                 ZEND_WRITE_EX(prop_name, prop_len);
     163         753 :                                 if (class_name && mangled == SUCCESS) {
     164         215 :                                         if (class_name[0]=='*') {
     165         105 :                                                 ZEND_PUTS_EX(":protected");
     166             :                                         } else {
     167         110 :                                                 ZEND_PUTS_EX(":");
     168         110 :                                                 ZEND_PUTS_EX(class_name);
     169         110 :                                                 ZEND_PUTS_EX(":private");
     170             :                                         }
     171             :                                 }
     172             :                         } else {
     173        3571 :                                 ZEND_WRITE_EX(string_key->val, string_key->len);
     174             :                         }
     175             :                 } else {
     176             :                         char key[25];
     177        1940 :                         snprintf(key, sizeof(key), ZEND_LONG_FMT, num_key);
     178        1940 :                         ZEND_PUTS_EX(key);
     179             :                 }
     180        6264 :                 ZEND_PUTS_EX("] => ");
     181        6264 :                 zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
     182        6264 :                 ZEND_PUTS_EX("\n");
     183             :         } ZEND_HASH_FOREACH_END();
     184        1338 :         indent -= PRINT_ZVAL_INDENT;
     185        5946 :         for (i = 0; i < indent; i++) {
     186        4608 :                 ZEND_PUTS_EX(" ");
     187             :         }
     188        1338 :         ZEND_PUTS_EX(")\n");
     189        1338 : }
     190             : /* }}} */
     191             : 
     192          19 : static void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
     193             : {
     194             :         zval *tmp;
     195             :         zend_string *string_key;
     196             :         zend_ulong num_key;
     197          19 :         int i = 0;
     198             : 
     199         406 :         ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
     200         129 :                 if (i++ > 0) {
     201         120 :                         ZEND_PUTS(",");
     202             :                 }
     203         129 :                 ZEND_PUTS("[");
     204         129 :                 if (string_key) {
     205         125 :                         ZEND_WRITE(string_key->val, string_key->len);
     206             :                 } else {
     207           4 :                         zend_printf(ZEND_ULONG_FMT, num_key);
     208             :                 }
     209         129 :                 ZEND_PUTS("] => ");
     210         129 :                 zend_print_flat_zval_r(tmp TSRMLS_CC);
     211             :         } ZEND_HASH_FOREACH_END();
     212          19 : }
     213             : /* }}} */
     214             : 
     215      177079 : ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy TSRMLS_DC) /* {{{ */
     216             : {
     217      177079 :         if (Z_TYPE_P(expr) == IS_STRING) {
     218          87 :                 return 0;
     219             :         } else {
     220      176992 :                 ZVAL_STR(expr_copy, _zval_get_string_func(expr TSRMLS_CC));
     221      176984 :                 return 1;
     222             :         }
     223             : }
     224             : /* }}} */
     225             : 
     226      221526 : ZEND_API size_t zend_print_zval(zval *expr, int indent TSRMLS_DC) /* {{{ */
     227             : {
     228      221526 :         return zend_print_zval_ex(zend_write, expr, indent TSRMLS_CC);
     229             : }
     230             : /* }}} */
     231             : 
     232      227686 : ZEND_API size_t zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
     233             : {
     234      227684 :         zend_string *str = zval_get_string(expr);
     235      227684 :         size_t len = str->len;
     236             : 
     237      227684 :         if (len != 0) {
     238      226793 :                 write_func(str->val, len);
     239             :         }
     240             : 
     241             :         zend_string_release(str);
     242      227683 :         return len;
     243             : }
     244             : /* }}} */
     245             : 
     246         180 : ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
     247             : {
     248         180 :         switch (Z_TYPE_P(expr)) {
     249             :                 case IS_ARRAY:
     250          17 :                         ZEND_PUTS("Array (");
     251          51 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
     252          34 :                             ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
     253           0 :                                 ZEND_PUTS(" *RECURSION*");
     254           0 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     255           0 :                                 return;
     256             :                         }
     257          17 :                         print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
     258          17 :                         ZEND_PUTS(")");
     259          17 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
     260          17 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     261             :                         }
     262          17 :                         break;
     263             :                 case IS_OBJECT:
     264             :                 {
     265           2 :                         HashTable *properties = NULL;
     266           2 :                         zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr) TSRMLS_CC);
     267           2 :                         zend_printf("%s Object (", class_name->val);
     268             :                         zend_string_release(class_name);
     269             : 
     270           2 :                         if (Z_OBJ_HANDLER_P(expr, get_properties)) {
     271           2 :                                 properties = Z_OBJPROP_P(expr);
     272             :                         }
     273           2 :                         if (properties) {
     274           2 :                                 if (++properties->u.v.nApplyCount>1) {
     275           0 :                                         ZEND_PUTS(" *RECURSION*");
     276           0 :                                         properties->u.v.nApplyCount--;
     277           0 :                                         return;
     278             :                                 }
     279           2 :                                 print_flat_hash(properties TSRMLS_CC);
     280           2 :                                 properties->u.v.nApplyCount--;
     281             :                         }
     282           2 :                         ZEND_PUTS(")");
     283           2 :                         break;
     284             :                 }
     285             :                 default:
     286         161 :                         zend_print_variable(expr TSRMLS_CC);
     287             :                         break;
     288             :         }
     289             : }
     290             : /* }}} */
     291             : 
     292        1246 : ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
     293             : {
     294        1246 :         zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
     295        1246 : }
     296             : /* }}} */
     297             : 
     298        7511 : ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
     299             : {
     300        7511 :         ZVAL_DEREF(expr);
     301        7511 :         switch (Z_TYPE_P(expr)) {
     302             :                 case IS_ARRAY:
     303        1054 :                         ZEND_PUTS_EX("Array\n");
     304        3162 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
     305        2108 :                             ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
     306           0 :                                 ZEND_PUTS_EX(" *RECURSION*");
     307           0 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     308           0 :                                 return;
     309             :                         }
     310        1054 :                         print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
     311        1054 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
     312        1054 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     313             :                         }
     314        1054 :                         break;
     315             :                 case IS_OBJECT:
     316             :                         {
     317             :                                 HashTable *properties;
     318             :                                 int is_temp;
     319             : 
     320         297 :                                 zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr) TSRMLS_CC);
     321         297 :                                 ZEND_PUTS_EX(class_name->val);
     322             :                                 zend_string_release(class_name);
     323             : 
     324         297 :                                 ZEND_PUTS_EX(" Object\n");
     325         297 :                                 if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
     326           0 :                                         break;
     327             :                                 }
     328         297 :                                 if (++properties->u.v.nApplyCount>1) {
     329          13 :                                         ZEND_PUTS_EX(" *RECURSION*");
     330          13 :                                         properties->u.v.nApplyCount--;
     331          13 :                                         return;
     332             :                                 }
     333         284 :                                 print_hash(write_func, properties, indent, 1 TSRMLS_CC);
     334         284 :                                 properties->u.v.nApplyCount--;
     335         284 :                                 if (is_temp) {
     336          19 :                                         zend_hash_destroy(properties);
     337          19 :                                         FREE_HASHTABLE(properties);
     338             :                                 }
     339         284 :                                 break;
     340             :                         }
     341             :                 default:
     342        6160 :                         zend_print_zval_ex(write_func, expr, indent TSRMLS_CC);
     343             :                         break;
     344             :         }
     345             : }
     346             : /* }}} */
     347             : 
     348           0 : static FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
     349             : {
     350           0 :         if (opened_path) {
     351           0 :                 *opened_path = estrdup(filename);
     352             :         }
     353           0 :         return fopen(filename, "rb");
     354             : }
     355             : /* }}} */
     356             : 
     357             : #ifdef ZTS
     358             : static zend_bool short_tags_default      = 1;
     359             : static uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT;
     360             : #else
     361             : # define short_tags_default                     1
     362             : # define compiler_options_default       ZEND_COMPILE_DEFAULT
     363             : #endif
     364             : 
     365       20473 : static void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
     366             : {
     367             :         /* default compile-time values */
     368       20473 :         CG(short_tags) = short_tags_default;
     369       20473 :         CG(compiler_options) = compiler_options_default;
     370       20473 : }
     371             : /* }}} */
     372             : 
     373       20473 : static void zend_init_exception_op(TSRMLS_D) /* {{{ */
     374             : {
     375       20473 :         memset(EG(exception_op), 0, sizeof(EG(exception_op)));
     376       20473 :         EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
     377       20473 :         EG(exception_op)[0].op1_type = IS_UNUSED;
     378       20473 :         EG(exception_op)[0].op2_type = IS_UNUSED;
     379       20473 :         EG(exception_op)[0].result_type = IS_UNUSED;
     380       20473 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
     381       20473 :         EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
     382       20473 :         EG(exception_op)[1].op1_type = IS_UNUSED;
     383       20473 :         EG(exception_op)[1].op2_type = IS_UNUSED;
     384       20473 :         EG(exception_op)[1].result_type = IS_UNUSED;
     385       20473 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
     386       20473 :         EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
     387       20473 :         EG(exception_op)[2].op1_type = IS_UNUSED;
     388       20473 :         EG(exception_op)[2].op2_type = IS_UNUSED;
     389       20473 :         EG(exception_op)[2].result_type = IS_UNUSED;
     390       20473 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
     391       20473 : }
     392             : /* }}} */
     393             : 
     394             : #ifdef ZTS
     395             : static void function_copy_ctor(zval *zv)
     396             : {
     397             :         zend_function *old_func = Z_FUNC_P(zv);
     398             :         Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1);
     399             :         memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function));
     400             :         function_add_ref(Z_FUNC_P(zv));
     401             : }
     402             : 
     403             : static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
     404             : {
     405             :         compiler_globals->compiled_filename = NULL;
     406             : 
     407             :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
     408             :         zend_hash_init_ex(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
     409             :         zend_hash_copy(compiler_globals->function_table, global_function_table, function_copy_ctor);
     410             : 
     411             :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
     412             :         zend_hash_init_ex(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
     413             :         zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
     414             : 
     415             :         zend_set_default_compile_time_values(TSRMLS_C);
     416             : 
     417             :         compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
     418             :         zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
     419             :         zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL /* empty element */);
     420             : 
     421             :         compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
     422             :         if (compiler_globals->last_static_member) {
     423             :                 compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval*));
     424             :         } else {
     425             :                 compiler_globals->static_members_table = NULL;
     426             :         }
     427             :         compiler_globals->script_encoding_list = NULL;
     428             : 
     429             : #ifdef ZTS
     430             :         zend_interned_empty_string_init(&compiler_globals->empty_string TSRMLS_CC);
     431             : 
     432             :         memset(compiler_globals->one_char_string, 0, sizeof(compiler_globals->one_char_string));
     433             : #endif
     434             : }
     435             : /* }}} */
     436             : 
     437             : static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
     438             : {
     439             :         if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
     440             :                 zend_hash_destroy(compiler_globals->function_table);
     441             :                 free(compiler_globals->function_table);
     442             :         }
     443             :         if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
     444             :                 zend_hash_destroy(compiler_globals->class_table);
     445             :                 free(compiler_globals->class_table);
     446             :         }
     447             :         if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
     448             :                 zend_hash_destroy(compiler_globals->auto_globals);
     449             :                 free(compiler_globals->auto_globals);
     450             :         }
     451             :         if (compiler_globals->static_members_table) {
     452             :                 free(compiler_globals->static_members_table);
     453             :         }
     454             :         if (compiler_globals->script_encoding_list) {
     455             :                 pefree((char*)compiler_globals->script_encoding_list, 1);
     456             :         }
     457             :         compiler_globals->last_static_member = 0;
     458             : 
     459             : #ifdef ZTS
     460             :         zend_interned_empty_string_free(&compiler_globals->empty_string TSRMLS_CC);
     461             : #endif
     462             : }
     463             : /* }}} */
     464             : 
     465             : static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
     466             : {
     467             :         zend_startup_constants(TSRMLS_C);
     468             :         zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
     469             :         zend_init_rsrc_plist(TSRMLS_C);
     470             :         zend_init_exception_op(TSRMLS_C);
     471             :         EG(lambda_count) = 0;
     472             :         ZVAL_UNDEF(&EG(user_error_handler));
     473             :         ZVAL_UNDEF(&EG(user_exception_handler));
     474             :         EG(in_autoload) = NULL;
     475             :         EG(current_execute_data) = NULL;
     476             :         EG(current_module) = NULL;
     477             :         EG(exit_status) = 0;
     478             : #if XPFPA_HAVE_CW
     479             :         EG(saved_fpu_cw) = 0;
     480             : #endif
     481             :         EG(saved_fpu_cw_ptr) = NULL;
     482             :         EG(active) = 0;
     483             : }
     484             : /* }}} */
     485             : 
     486             : static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
     487             : {
     488             :         zend_ini_shutdown(TSRMLS_C);
     489             :         if (&executor_globals->persistent_list != global_persistent_list) {
     490             :                 zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
     491             :         }
     492             :         if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
     493             :                 zend_hash_destroy(executor_globals->zend_constants);
     494             :                 free(executor_globals->zend_constants);
     495             :         }
     496             : }
     497             : /* }}} */
     498             : 
     499             : static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
     500             : {
     501             :         if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
     502             :                 zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
     503             :         }
     504             : }
     505             : /* }}} */
     506             : #endif
     507             : 
     508             : #if defined(__FreeBSD__) || defined(__DragonFly__)
     509             : /* FreeBSD and DragonFly floating point precision fix */
     510             : #include <floatingpoint.h>
     511             : #endif
     512             : 
     513       20473 : static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
     514             : {
     515       20473 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     516       20473 : }
     517             : /* }}} */
     518             : 
     519       20473 : static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
     520             : {
     521       20473 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     522       20473 : }
     523             : /* }}} */
     524             : 
     525             : void zend_init_opcodes_handlers(void);
     526             : 
     527     1476749 : static void module_destructor_zval(zval *zv) /* {{{ */
     528             : {
     529     1476749 :         zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
     530             : 
     531     1476749 :         module_destructor(module);
     532     1476749 :         free(module);
     533     1476749 : }
     534             : /* }}} */
     535             : 
     536      184563 : static void auto_global_dtor(zval *zv) /* {{{ */
     537             : {
     538      184563 :         free(Z_PTR_P(zv));
     539      184563 : }
     540             : /* }}} */
     541             : 
     542         169 : static zend_bool php_auto_globals_create_globals(zend_string *name TSRMLS_DC) /* {{{ */
     543             : {
     544             :         zval globals;
     545             : 
     546         169 :         ZVAL_ARR(&globals, &EG(symbol_table));
     547         169 :         ZVAL_NEW_REF(&globals, &globals);
     548         169 :         zend_hash_update(&EG(symbol_table).ht, name, &globals);
     549         169 :         return 0;
     550             : }
     551             : /* }}} */
     552             : 
     553       20473 : int zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
     554             : {
     555             : #ifdef ZTS
     556             :         zend_compiler_globals *compiler_globals;
     557             :         zend_executor_globals *executor_globals;
     558             :         extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
     559             :         extern ZEND_API ts_rsrc_id language_scanner_globals_id;
     560             : #else
     561             :         extern zend_ini_scanner_globals ini_scanner_globals;
     562             :         extern zend_php_scanner_globals language_scanner_globals;
     563             : #endif
     564             : 
     565       20473 :         start_memory_manager(TSRMLS_C);
     566             : 
     567       20473 :         virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
     568             : 
     569             : #if defined(__FreeBSD__) || defined(__DragonFly__)
     570             :         /* FreeBSD and DragonFly floating point precision fix */
     571             :         fpsetmask(0);
     572             : #endif
     573             : 
     574       20473 :         zend_startup_strtod();
     575       20473 :         zend_startup_extensions_mechanism();
     576             : 
     577             :         /* Set up utility functions and values */
     578       20473 :         zend_error_cb = utility_functions->error_function;
     579       20473 :         zend_printf = utility_functions->printf_function;
     580       20473 :         zend_write = (zend_write_func_t) utility_functions->write_function;
     581       20473 :         zend_fopen = utility_functions->fopen_function;
     582       20473 :         if (!zend_fopen) {
     583           0 :                 zend_fopen = zend_fopen_wrapper;
     584             :         }
     585       20473 :         zend_stream_open_function = utility_functions->stream_open_function;
     586       20473 :         zend_message_dispatcher_p = utility_functions->message_handler;
     587             : #ifndef ZEND_SIGNALS
     588       20473 :         zend_block_interruptions = utility_functions->block_interruptions;
     589       20473 :         zend_unblock_interruptions = utility_functions->unblock_interruptions;
     590             : #endif
     591       20473 :         zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
     592       20473 :         zend_ticks_function = utility_functions->ticks_function;
     593       20473 :         zend_on_timeout = utility_functions->on_timeout;
     594       20473 :         zend_vspprintf = utility_functions->vspprintf_function;
     595       20473 :         zend_vstrpprintf = utility_functions->vstrpprintf_function;
     596       20473 :         zend_getenv = utility_functions->getenv_function;
     597       20473 :         zend_resolve_path = utility_functions->resolve_path_function;
     598             : 
     599             : #if HAVE_DTRACE
     600             : /* build with dtrace support */
     601             :         zend_compile_file = dtrace_compile_file;
     602             :         zend_execute_ex = dtrace_execute_ex;
     603             :         zend_execute_internal = dtrace_execute_internal;
     604             : #else
     605       20473 :         zend_compile_file = compile_file;
     606       20473 :         zend_execute_ex = execute_ex;
     607       20473 :         zend_execute_internal = NULL;
     608             : #endif /* HAVE_SYS_SDT_H */
     609       20473 :         zend_compile_string = compile_string;
     610       20473 :         zend_throw_exception_hook = NULL;
     611             : 
     612       20473 :         zend_init_opcodes_handlers();
     613             : 
     614             :         /* set up version */
     615       20473 :         zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
     616       20473 :         zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
     617             : 
     618       20473 :         GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
     619       20473 :         GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     620       20473 :         GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     621       20473 :         GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     622             : 
     623       20473 :         zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
     624       20473 :         zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
     625       20473 :         zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0);
     626       20473 :         zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0);
     627             : 
     628       20473 :         zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0);
     629       20473 :         zend_init_rsrc_list_dtors();
     630             : 
     631             : #ifdef ZTS
     632             :         ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
     633             :         ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
     634             :         ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
     635             :         ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
     636             :         compiler_globals = ts_resource(compiler_globals_id);
     637             :         executor_globals = ts_resource(executor_globals_id);
     638             : 
     639             :         compiler_globals_dtor(compiler_globals TSRMLS_CC);
     640             :         compiler_globals->in_compilation = 0;
     641             :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
     642             :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
     643             : 
     644             :         *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
     645             :         *compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
     646             :         compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
     647             : 
     648             :         zend_hash_destroy(executor_globals->zend_constants);
     649             :         *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
     650             : #else
     651       20473 :         ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
     652       20473 :         php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
     653       20473 :         zend_set_default_compile_time_values(TSRMLS_C);
     654       20473 :         ZVAL_UNDEF(&EG(user_error_handler));
     655       20473 :         ZVAL_UNDEF(&EG(user_exception_handler));
     656             : #endif
     657             : 
     658       20473 :         zend_interned_strings_init(TSRMLS_C);
     659       20473 :         zend_startup_builtin_functions(TSRMLS_C);
     660       20473 :         zend_register_standard_constants(TSRMLS_C);
     661       20473 :         zend_register_auto_global(zend_string_init("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals TSRMLS_CC);
     662             : 
     663             : #ifndef ZTS
     664       20473 :         zend_init_rsrc_plist(TSRMLS_C);
     665       20473 :         zend_init_exception_op(TSRMLS_C);
     666             : #endif
     667             : 
     668       20473 :         zend_ini_startup(TSRMLS_C);
     669             : 
     670             : #ifdef ZTS
     671             :         tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
     672             : #endif
     673             : 
     674       20473 :         return SUCCESS;
     675             : }
     676             : /* }}} */
     677             : 
     678       20473 : void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
     679             : {
     680       20473 :         int module_number = 0;
     681             : 
     682       20473 :         REGISTER_INI_ENTRIES();
     683       20473 : }
     684             : /* }}} */
     685             : 
     686             : /* Unlink the global (r/o) copies of the class, function and constant tables,
     687             :  * and use a fresh r/w copy for the startup thread
     688             :  */
     689       20473 : void zend_post_startup(TSRMLS_D) /* {{{ */
     690             : {
     691             : #ifdef ZTS
     692             :         zend_encoding **script_encoding_list;
     693             : 
     694             :         zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
     695             :         zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
     696             : 
     697             :         *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
     698             :         *GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
     699             :         *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
     700             : 
     701             :         short_tags_default = CG(short_tags);
     702             :         compiler_options_default = CG(compiler_options);
     703             : 
     704             :         zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
     705             :         free(compiler_globals->function_table);
     706             :         free(compiler_globals->class_table);
     707             :         if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
     708             :                 compiler_globals_ctor(compiler_globals, tsrm_ls);
     709             :                 compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
     710             :         } else {
     711             :                 compiler_globals_ctor(compiler_globals, tsrm_ls);
     712             :         }
     713             :         free(EG(zend_constants));
     714             : 
     715             :         virtual_cwd_deactivate(TSRMLS_C);
     716             : 
     717             :         executor_globals_ctor(executor_globals, tsrm_ls);
     718             :         global_persistent_list = &EG(persistent_list);
     719             :         zend_copy_ini_directives(TSRMLS_C);
     720             : #else
     721       20473 :         virtual_cwd_deactivate(TSRMLS_C);
     722             : #endif
     723       20473 : }
     724             : /* }}} */
     725             : 
     726       20507 : void zend_shutdown(TSRMLS_D) /* {{{ */
     727             : {
     728             : #ifdef ZEND_SIGNALS
     729             :         zend_signal_shutdown(TSRMLS_C);
     730             : #endif
     731             : #ifdef ZEND_WIN32
     732             :         zend_shutdown_timeout_thread();
     733             : #endif
     734       20507 :         zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
     735       20507 :         if (EG(active))
     736             :         {
     737             :                 /*
     738             :                  * The order of destruction is important here.
     739             :                  * See bugs #65463 and 66036.
     740             :                  */
     741             :                 zend_function *func;
     742             :                 zend_class_entry *ce;
     743             : 
     744           0 :                 ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_FUNCTION_TABLE, func) {
     745           0 :                         if (func->type == ZEND_USER_FUNCTION) {
     746           0 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     747             :                         }
     748             :                 } ZEND_HASH_FOREACH_END();
     749           0 :                 ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_CLASS_TABLE, ce) {
     750           0 :                         if (ce->type == ZEND_USER_CLASS) {
     751           0 :                                 zend_cleanup_user_class_data(ce TSRMLS_CC);
     752             :                         } else {
     753           0 :                                 break;
     754             :                         }
     755             :                 } ZEND_HASH_FOREACH_END();
     756           0 :                 zend_cleanup_internal_classes(TSRMLS_C);
     757           0 :                 zend_hash_reverse_apply(GLOBAL_FUNCTION_TABLE, (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
     758           0 :                 zend_hash_reverse_apply(GLOBAL_CLASS_TABLE, (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
     759             :         }
     760       20507 :         zend_destroy_modules();
     761             : 
     762       20507 :         virtual_cwd_deactivate(TSRMLS_C);
     763       20507 :         virtual_cwd_shutdown();
     764             : 
     765       20507 :         zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
     766       20507 :         zend_hash_destroy(GLOBAL_CLASS_TABLE);
     767             : 
     768       20507 :         zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
     769       20507 :         free(GLOBAL_AUTO_GLOBALS_TABLE);
     770             : 
     771       20507 :         zend_shutdown_extensions(TSRMLS_C);
     772       20507 :         free(zend_version_info);
     773             : 
     774       20507 :         free(GLOBAL_FUNCTION_TABLE);
     775       20507 :         free(GLOBAL_CLASS_TABLE);
     776             : 
     777       20507 :         zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
     778       20507 :         free(GLOBAL_CONSTANTS_TABLE);
     779       20507 :         zend_shutdown_strtod();
     780             : 
     781             : #ifdef ZTS
     782             :         GLOBAL_FUNCTION_TABLE = NULL;
     783             :         GLOBAL_CLASS_TABLE = NULL;
     784             :         GLOBAL_AUTO_GLOBALS_TABLE = NULL;
     785             :         GLOBAL_CONSTANTS_TABLE = NULL;
     786             : #endif
     787       20507 :         zend_destroy_rsrc_list_dtors();
     788             : 
     789       20507 :         zend_interned_strings_dtor(TSRMLS_C);
     790       20507 : }
     791             : /* }}} */
     792             : 
     793       20473 : void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
     794             : {
     795       20473 :         zend_uv = *utility_values;
     796       20473 :         zend_uv.import_use_extension_length = (uint)strlen(zend_uv.import_use_extension);
     797       20473 : }
     798             : /* }}} */
     799             : 
     800             : /* this should be compatible with the standard zenderror */
     801          40 : void zenderror(const char *error) /* {{{ */
     802             : {
     803          40 :         zend_error(E_PARSE, "%s", error);
     804          40 : }
     805             : /* }}} */
     806             : 
     807             : BEGIN_EXTERN_C()
     808        2183 : ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
     809             : {
     810             :         TSRMLS_FETCH();
     811             : 
     812        2183 :         if (!EG(bailout)) {
     813           0 :                 zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
     814           0 :                 exit(-1);
     815             :         }
     816        2183 :         CG(unclean_shutdown) = 1;
     817        2183 :         CG(active_class_entry) = NULL;
     818        2183 :         CG(in_compilation) = 0;
     819        2183 :         EG(current_execute_data) = NULL;
     820        2183 :         LONGJMP(*EG(bailout), FAILURE);
     821             : }
     822             : /* }}} */
     823             : END_EXTERN_C()
     824             : 
     825       20314 : ZEND_API void zend_append_version_info(const zend_extension *extension) /* {{{ */
     826             : {
     827             :         char *new_info;
     828             :         uint new_info_length;
     829             : 
     830       81256 :         new_info_length = (uint)(sizeof("    with  v, , by \n")
     831       20314 :                                                 + strlen(extension->name)
     832       20314 :                                                 + strlen(extension->version)
     833       20314 :                                                 + strlen(extension->copyright)
     834       20314 :                                                 + strlen(extension->author));
     835             : 
     836       20314 :         new_info = (char *) malloc(new_info_length + 1);
     837             : 
     838       20314 :         snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
     839             : 
     840       20314 :         zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
     841       20314 :         strncat(zend_version_info, new_info, new_info_length);
     842       20314 :         zend_version_info_length += new_info_length;
     843       20314 :         free(new_info);
     844       20314 : }
     845             : /* }}} */
     846             : 
     847         166 : ZEND_API char *get_zend_version(void) /* {{{ */
     848             : {
     849         166 :         return zend_version_info;
     850             : }
     851             : /* }}} */
     852             : 
     853       20430 : ZEND_API void zend_activate(TSRMLS_D) /* {{{ */
     854             : {
     855             : #ifdef ZTS
     856             :         virtual_cwd_activate(TSRMLS_C);
     857             : #endif
     858       20430 :         gc_reset(TSRMLS_C);
     859       20430 :         init_compiler(TSRMLS_C);
     860       20430 :         init_executor(TSRMLS_C);
     861       20430 :         startup_scanner(TSRMLS_C);
     862       20430 : }
     863             : /* }}} */
     864             : 
     865       20466 : void zend_call_destructors(TSRMLS_D) /* {{{ */
     866             : {
     867       20466 :         zend_try {
     868       20466 :                 shutdown_destructors(TSRMLS_C);
     869       20466 :         } zend_end_try();
     870       20466 : }
     871             : /* }}} */
     872             : 
     873       20466 : ZEND_API void zend_deactivate(TSRMLS_D) /* {{{ */
     874             : {
     875             :         /* we're no longer executing anything */
     876       20466 :         EG(current_execute_data) = NULL;
     877             : 
     878       20466 :         zend_try {
     879       20466 :                 shutdown_scanner(TSRMLS_C);
     880       20466 :         } zend_end_try();
     881             : 
     882             :         /* shutdown_executor() takes care of its own bailout handling */
     883       20466 :         shutdown_executor(TSRMLS_C);
     884             : 
     885       20466 :         zend_try {
     886       20466 :                 shutdown_compiler(TSRMLS_C);
     887       20466 :         } zend_end_try();
     888             : 
     889       20466 :         zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
     890             : 
     891             : #if ZEND_DEBUG
     892             :         if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
     893             :                 gc_collect_cycles(TSRMLS_C);
     894             :         }
     895             : #endif
     896             : 
     897             : #if GC_BENCH
     898             :         fprintf(stderr, "GC Statistics\n");
     899             :         fprintf(stderr, "-------------\n");
     900             :         fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
     901             :         fprintf(stderr, "Collected:          %d\n", GC_G(collected));
     902             :         fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
     903             :         fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
     904             :         fprintf(stderr, "      Possible            Remove from  Marked\n");
     905             :         fprintf(stderr, "        Root    Buffered     buffer     grey\n");
     906             :         fprintf(stderr, "      --------  --------  -----------  ------\n");
     907             :         fprintf(stderr, "ZVAL  %8d  %8d  %9d  %8d\n", GC_G(zval_possible_root), GC_G(zval_buffered), GC_G(zval_remove_from_buffer), GC_G(zval_marked_grey));
     908             :         fprintf(stderr, "ZOBJ  %8d  %8d  %9d  %8d\n", GC_G(zobj_possible_root), GC_G(zobj_buffered), GC_G(zobj_remove_from_buffer), GC_G(zobj_marked_grey));
     909             : #endif
     910             : 
     911       20466 :         zend_try {
     912       20466 :                 zend_ini_deactivate(TSRMLS_C);
     913       20466 :         } zend_end_try();
     914       20466 : }
     915             : /* }}} */
     916             : 
     917             : BEGIN_EXTERN_C()
     918          34 : ZEND_API void zend_message_dispatcher(zend_long message, const void *data TSRMLS_DC) /* {{{ */
     919             : {
     920          34 :         if (zend_message_dispatcher_p) {
     921          34 :                 zend_message_dispatcher_p(message, data TSRMLS_CC);
     922             :         }
     923          31 : }
     924             : /* }}} */
     925             : END_EXTERN_C()
     926             : 
     927     5526675 : ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
     928             : {
     929     5526675 :         if (zend_get_configuration_directive_p) {
     930     5526675 :                 return zend_get_configuration_directive_p(name);
     931             :         } else {
     932           0 :                 return NULL;
     933             :         }
     934             : }
     935             : /* }}} */
     936             : 
     937             : #define SAVE_STACK(stack) do { \
     938             :                 if (CG(stack).top) { \
     939             :                         memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
     940             :                         CG(stack).top = CG(stack).max = 0; \
     941             :                         CG(stack).elements = NULL; \
     942             :                 } else { \
     943             :                         stack.top = 0; \
     944             :                 } \
     945             :         } while (0)
     946             : 
     947             : #define RESTORE_STACK(stack) do { \
     948             :                 if (stack.top) { \
     949             :                         zend_stack_destroy(&CG(stack)); \
     950             :                         memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
     951             :                 } \
     952             :         } while (0)
     953             : 
     954             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
     955      373771 : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
     956             : #else
     957             : static void zend_error_va_list(int type, const char *format, va_list args)
     958             : #endif
     959             : {
     960             :         char *str;
     961             :         int len;
     962             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
     963             :         va_list args;
     964             : #endif
     965             :         va_list usr_copy;
     966             :         zval params[5];
     967             :         zval retval;
     968             :         const char *error_filename;
     969      373771 :         uint error_lineno = 0;
     970             :         zval orig_user_error_handler;
     971             :         zend_bool in_compilation;
     972             :         zend_class_entry *saved_class_entry;
     973             :         zend_stack loop_var_stack;
     974             :         zend_stack delayed_oplines_stack;
     975             :         zend_stack context_stack;
     976             :         zend_array *symbol_table;
     977             :         TSRMLS_FETCH();
     978             : 
     979             :         /* Report about uncaught exception in case of fatal errors */
     980      373771 :         if (EG(exception)) {
     981             :                 zend_execute_data *ex;
     982             :                 const zend_op *opline;
     983             : 
     984          46 :                 switch (type) {
     985             :                         case E_CORE_ERROR:
     986             :                         case E_ERROR:
     987             :                         case E_RECOVERABLE_ERROR:
     988             :                         case E_PARSE:
     989             :                         case E_COMPILE_ERROR:
     990             :                         case E_USER_ERROR:
     991           3 :                                 ex = EG(current_execute_data);
     992           3 :                                 opline = NULL;
     993           8 :                                 while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     994           2 :                                         ex = ex->prev_execute_data;
     995             :                                 }
     996           4 :                                 if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
     997           1 :                                     EG(opline_before_exception)) {
     998           1 :                                         opline = EG(opline_before_exception);
     999             :                                 }
    1000           3 :                                 zend_exception_error(EG(exception), E_WARNING TSRMLS_CC);
    1001           3 :                                 EG(exception) = NULL;
    1002           3 :                                 if (opline) {
    1003           1 :                                         ex->opline = opline;
    1004             :                                 }
    1005             :                                 break;
    1006             :                         default:
    1007             :                                 break;
    1008             :                 }
    1009             :         }
    1010             : 
    1011             :         /* Obtain relevant filename and lineno */
    1012      373771 :         switch (type) {
    1013             :                 case E_CORE_ERROR:
    1014             :                 case E_CORE_WARNING:
    1015           6 :                         error_filename = NULL;
    1016           6 :                         error_lineno = 0;
    1017           6 :                         break;
    1018             :                 case E_PARSE:
    1019             :                 case E_COMPILE_ERROR:
    1020             :                 case E_COMPILE_WARNING:
    1021             :                 case E_ERROR:
    1022             :                 case E_NOTICE:
    1023             :                 case E_STRICT:
    1024             :                 case E_DEPRECATED:
    1025             :                 case E_WARNING:
    1026             :                 case E_USER_ERROR:
    1027             :                 case E_USER_WARNING:
    1028             :                 case E_USER_NOTICE:
    1029             :                 case E_USER_DEPRECATED:
    1030             :                 case E_RECOVERABLE_ERROR:
    1031      373765 :                         if (zend_is_compiling(TSRMLS_C)) {
    1032         308 :                                 error_filename = zend_get_compiled_filename(TSRMLS_C)->val;
    1033         308 :                                 error_lineno = zend_get_compiled_lineno(TSRMLS_C);
    1034      373457 :                         } else if (zend_is_executing(TSRMLS_C)) {
    1035      373368 :                                 error_filename = zend_get_executed_filename(TSRMLS_C);
    1036      373368 :                                 if (error_filename[0] == '[') { /* [no active file] */
    1037           6 :                                         error_filename = NULL;
    1038           6 :                                         error_lineno = 0;
    1039             :                                 } else {
    1040      373362 :                                         error_lineno = zend_get_executed_lineno(TSRMLS_C);
    1041             :                                 }
    1042             :                         } else {
    1043          89 :                                 error_filename = NULL;
    1044          89 :                                 error_lineno = 0;
    1045             :                         }
    1046      373765 :                         break;
    1047             :                 default:
    1048           0 :                         error_filename = NULL;
    1049           0 :                         error_lineno = 0;
    1050             :                         break;
    1051             :         }
    1052      373771 :         if (!error_filename) {
    1053         101 :                 error_filename = "Unknown";
    1054             :         }
    1055             : 
    1056             : #ifdef HAVE_DTRACE
    1057             :         if(DTRACE_ERROR_ENABLED()) {
    1058             :                 char *dtrace_error_buffer;
    1059             :                 va_start(args, format);
    1060             :                 zend_vspprintf(&dtrace_error_buffer, 0, format, args);
    1061             :                 DTRACE_ERROR(dtrace_error_buffer, (char *)error_filename, error_lineno);
    1062             :                 efree(dtrace_error_buffer);
    1063             :                 va_end(args);
    1064             :         }
    1065             : #endif /* HAVE_DTRACE */
    1066             : 
    1067             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
    1068      373771 :         va_start(args, format);
    1069             : #endif
    1070             : 
    1071             :         /* if we don't have a user defined error handler */
    1072      750608 :         if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF
    1073        3774 :                 || !(EG(user_error_handler_error_reporting) & type)
    1074        3744 :                 || EG(error_handling) != EH_NORMAL) {
    1075      370027 :                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1076        3744 :         } else switch (type) {
    1077             :                 case E_ERROR:
    1078             :                 case E_PARSE:
    1079             :                 case E_CORE_ERROR:
    1080             :                 case E_CORE_WARNING:
    1081             :                 case E_COMPILE_ERROR:
    1082             :                 case E_COMPILE_WARNING:
    1083             :                         /* The error may not be safe to handle in user-space */
    1084           5 :                         zend_error_cb(type, error_filename, error_lineno, format, args);
    1085           0 :                         break;
    1086             :                 default:
    1087             :                         /* Handle the error in user space */
    1088             : /* va_copy() is __va_copy() in old gcc versions.
    1089             :  * According to the autoconf manual, using
    1090             :  * memcpy(&dst, &src, sizeof(va_list))
    1091             :  * gives maximum portability. */
    1092             : #ifndef va_copy
    1093             : # ifdef __va_copy
    1094             : #  define va_copy(dest, src)    __va_copy((dest), (src))
    1095             : # else
    1096             : #  define va_copy(dest, src)    memcpy(&(dest), &(src), sizeof(va_list))
    1097             : # endif
    1098             : #endif
    1099        3739 :                         va_copy(usr_copy, args);
    1100        3739 :                         len = (int)zend_vspprintf(&str, 0, format, usr_copy);
    1101        7478 :                         ZVAL_NEW_STR(&params[1], zend_string_init(str, len, 0));
    1102        3739 :                         efree(str);
    1103             : #ifdef va_copy
    1104        3739 :                         va_end(usr_copy);
    1105             : #endif
    1106             : 
    1107        3739 :                         ZVAL_LONG(&params[0], type);
    1108             : 
    1109        3739 :                         if (error_filename) {
    1110        7478 :                                 ZVAL_STRING(&params[2], error_filename);
    1111             :                         } else {
    1112           0 :                                 ZVAL_NULL(&params[2]);
    1113             :                         }
    1114             : 
    1115        3739 :                         ZVAL_LONG(&params[3], error_lineno);
    1116             : 
    1117        3739 :                         symbol_table = zend_rebuild_symbol_table(TSRMLS_C);
    1118             : 
    1119             :                         /* during shutdown the symbol table table can be still null */
    1120        3739 :                         if (!symbol_table) {
    1121           0 :                                 ZVAL_NULL(&params[4]);
    1122             :                         } else {
    1123        3739 :                                 ZVAL_NEW_ARR(&params[4]);
    1124        3739 :                                 zend_array_dup(Z_ARRVAL(params[4]), &symbol_table->ht);
    1125             :                         }
    1126             : 
    1127        3739 :                         ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));
    1128        3739 :                         ZVAL_UNDEF(&EG(user_error_handler));
    1129             : 
    1130             :                         /* User error handler may include() additinal PHP files.
    1131             :                          * If an error was generated during comilation PHP will compile
    1132             :                          * such scripts recursivly, but some CG() variables may be
    1133             :                          * inconsistent. */
    1134             : 
    1135        3739 :                         in_compilation = CG(in_compilation);
    1136        3739 :                         if (in_compilation) {
    1137           2 :                                 saved_class_entry = CG(active_class_entry);
    1138           2 :                                 CG(active_class_entry) = NULL;
    1139           2 :                                 SAVE_STACK(loop_var_stack);
    1140           2 :                                 SAVE_STACK(delayed_oplines_stack);
    1141           2 :                                 SAVE_STACK(context_stack);
    1142           2 :                                 CG(in_compilation) = 0;
    1143             :                         }
    1144             : 
    1145        3739 :                         ZVAL_UNDEF(&retval);
    1146        3739 :                         if (call_user_function_ex(CG(function_table), NULL, &orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC) == SUCCESS) {
    1147        3739 :                                 if (Z_TYPE(retval) != IS_UNDEF) {
    1148        3715 :                                         if (Z_TYPE(retval) == IS_FALSE) {
    1149           1 :                                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1150             :                                         }
    1151        3715 :                                         zval_ptr_dtor(&retval);
    1152             :                                 }
    1153           0 :                         } else if (!EG(exception)) {
    1154             :                                 /* The user error handler failed, use built-in error handler */
    1155           0 :                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1156             :                         }
    1157             : 
    1158        3739 :                         if (in_compilation) {
    1159           2 :                                 CG(active_class_entry) = saved_class_entry;
    1160           2 :                                 RESTORE_STACK(loop_var_stack);
    1161           2 :                                 RESTORE_STACK(delayed_oplines_stack);
    1162           2 :                                 RESTORE_STACK(context_stack);
    1163           2 :                                 CG(in_compilation) = 1;
    1164             :                         }
    1165             : 
    1166        3739 :                         zval_ptr_dtor(&params[4]);
    1167        3739 :                         zval_ptr_dtor(&params[3]);
    1168        3739 :                         zval_ptr_dtor(&params[2]);
    1169        3739 :                         zval_ptr_dtor(&params[1]);
    1170        3739 :                         zval_ptr_dtor(&params[0]);
    1171             : 
    1172        3739 :                         if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF) {
    1173        3739 :                                 ZVAL_COPY_VALUE(&EG(user_error_handler), &orig_user_error_handler);
    1174             :                         } else {
    1175           0 :                                 zval_ptr_dtor(&orig_user_error_handler);
    1176             :                         }
    1177             :                         break;
    1178             :         }
    1179             : 
    1180             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
    1181      373058 :         va_end(args);
    1182             : #endif
    1183             : 
    1184      373058 :         if (type == E_PARSE) {
    1185             :                 /* eval() errors do not affect exit_status */
    1186          86 :                 if (!(EG(current_execute_data) &&
    1187          16 :                         EG(current_execute_data)->func &&
    1188          16 :                         ZEND_USER_CODE(EG(current_execute_data)->func->type) &&
    1189           7 :                         EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL &&
    1190           7 :                         EG(current_execute_data)->opline->extended_value == ZEND_EVAL)) {
    1191          37 :                         EG(exit_status) = 255;
    1192             :                 }
    1193             :         }
    1194      373058 : }
    1195             : /* }}} */
    1196             : 
    1197             : #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__))
    1198             : void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
    1199             : #elif defined(ZEND_WIN32) || defined(DARWIN)
    1200             : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
    1201             : {
    1202             :         va_list va;
    1203             : 
    1204             :         va_start(va, format);
    1205             :         zend_error_va_list(type, format, va);
    1206             :         va_end(va);
    1207             : }
    1208             : 
    1209             : ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
    1210             : {
    1211             :         va_list va;
    1212             : 
    1213             :         va_start(va, format);
    1214             :         zend_error_va_list(type, format, va);
    1215             :         va_end(va);
    1216             : }
    1217             : /* }}} */
    1218             : #endif
    1219             : 
    1220           0 : ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */
    1221             : {
    1222             : #if ZEND_DEBUG
    1223             :         va_list args;
    1224             : 
    1225             :         va_start(args, format);
    1226             : #       ifdef ZEND_WIN32
    1227             :         {
    1228             :                 char output_buf[1024];
    1229             : 
    1230             :                 vsnprintf(output_buf, 1024, format, args);
    1231             :                 OutputDebugString(output_buf);
    1232             :                 OutputDebugString("\n");
    1233             :                 if (trigger_break && IsDebuggerPresent()) {
    1234             :                         DebugBreak();
    1235             :                 }
    1236             :         }
    1237             : #       else
    1238             :         vfprintf(stderr, format, args);
    1239             :         fprintf(stderr, "\n");
    1240             : #       endif
    1241             :         va_end(args);
    1242             : #endif
    1243           0 : }
    1244             : /* }}} */
    1245             : 
    1246       20371 : ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval *retval, int file_count, ...) /* {{{ */
    1247             : {
    1248             :         va_list files;
    1249             :         int i;
    1250             :         zend_file_handle *file_handle;
    1251             :         zend_op_array *op_array;
    1252             : 
    1253       20371 :         va_start(files, file_count);
    1254       77794 :         for (i = 0; i < file_count; i++) {
    1255       59268 :                 file_handle = va_arg(files, zend_file_handle *);
    1256       59268 :                 if (!file_handle) {
    1257       38896 :                         continue;
    1258             :                 }
    1259             :        
    1260       20372 :                 op_array = zend_compile_file(file_handle, type TSRMLS_CC);
    1261       20155 :                 if (file_handle->opened_path) {
    1262       20152 :                         zend_hash_str_add_empty_element(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path));
    1263             :                 }
    1264       20155 :                 zend_destroy_file_handle(file_handle TSRMLS_CC);
    1265       20155 :                 if (op_array) {
    1266       20155 :                         zend_execute(op_array, retval TSRMLS_CC);
    1267       18633 :                         zend_exception_restore(TSRMLS_C);
    1268       18633 :                         if (EG(exception)) {
    1269         114 :                                 if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
    1270             :                                         zval orig_user_exception_handler;
    1271             :                                         zval params[1], retval2;
    1272             :                                         zend_object *old_exception;
    1273          10 :                                         old_exception = EG(exception);
    1274          10 :                                         EG(exception) = NULL;
    1275          10 :                                         ZVAL_OBJ(&params[0], old_exception);
    1276          10 :                                         ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler));
    1277          10 :                                         ZVAL_UNDEF(&retval2);
    1278          10 :                                         if (call_user_function_ex(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
    1279           8 :                                                 zval_ptr_dtor(&retval2);
    1280           8 :                                                 if (EG(exception)) {
    1281           0 :                                                         OBJ_RELEASE(EG(exception));
    1282           0 :                                                         EG(exception) = NULL;
    1283             :                                                 }
    1284             :                                                 OBJ_RELEASE(old_exception);
    1285             :                                         } else {
    1286           0 :                                                 EG(exception) = old_exception;
    1287           0 :                                                 zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1288             :                                         }
    1289             :                                 } else {
    1290         104 :                                         zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1291             :                                 }
    1292             :                         }
    1293       18527 :                         destroy_op_array(op_array TSRMLS_CC);
    1294       18527 :                         efree_size(op_array, sizeof(zend_op_array));
    1295           0 :                 } else if (type==ZEND_REQUIRE) {
    1296           0 :                         va_end(files);
    1297           0 :                         return FAILURE;
    1298             :                 }
    1299             :         }
    1300       18526 :         va_end(files);
    1301             : 
    1302       18526 :         return SUCCESS;
    1303             : }
    1304             : /* }}} */
    1305             : 
    1306             : #define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
    1307             : 
    1308        1078 : ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC) /* {{{ */
    1309             : {
    1310             :         const char *cur_filename;
    1311             :         int cur_lineno;
    1312             :         char *compiled_string_description;
    1313             : 
    1314        1078 :         if (zend_is_compiling(TSRMLS_C)) {
    1315           0 :                 cur_filename = zend_get_compiled_filename(TSRMLS_C)->val;
    1316           0 :                 cur_lineno = zend_get_compiled_lineno(TSRMLS_C);
    1317        1078 :         } else if (zend_is_executing(TSRMLS_C)) {
    1318        1078 :                 cur_filename = zend_get_executed_filename(TSRMLS_C);
    1319        1078 :                 cur_lineno = zend_get_executed_lineno(TSRMLS_C);
    1320             :         } else {
    1321           0 :                 cur_filename = "Unknown";
    1322           0 :                 cur_lineno = 0;
    1323             :         }
    1324             : 
    1325        1078 :         zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
    1326        1078 :         return compiled_string_description;
    1327             : }
    1328             : /* }}} */
    1329             : 
    1330       20314 : void free_estring(char **str_p) /* {{{ */
    1331             : {
    1332       20314 :         efree(*str_p);
    1333       20314 : }
    1334             : /* }}} */
    1335             : 
    1336       28933 : void free_string_zval(zval *zv) /* {{{ */
    1337             : {
    1338       28933 :         zend_string *str = Z_PTR_P(zv);
    1339             :         zend_string_release(str);
    1340       28933 : }
    1341             : /* }}} */
    1342             : 
    1343             : /*
    1344             :  * Local variables:
    1345             :  * tab-width: 4
    1346             :  * c-basic-offset: 4
    1347             :  * indent-tabs-mode: t
    1348             :  * End:
    1349             :  */

Generated by: LCOV version 1.10

Generated at Mon, 10 Nov 2014 22:46:36 +0000 (11 days ago)

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