PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_HEAD/Zend - zend.c
Test: PHP Code Coverage
Date: 2009-11-23 Instrumented lines: 820
Code covered: 78.7 % Executed lines: 645
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | Zend Engine                                                          |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1998-2009 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: zend.c 289987 2009-10-27 13:02:36Z dsp $ */
      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_unicode.h"
      33                 : #include "zend_dtrace.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                 : #ifndef __GNUC__
      48                 : ZEND_API zstr null_zstr;
      49                 : ZEND_API zstr empty_zstr;
      50                 : #endif
      51                 : 
      52                 : #if defined(ZEND_WIN32) && ZEND_DEBUG
      53                 : BOOL WINAPI IsDebuggerPresent(VOID);
      54                 : #endif
      55                 : 
      56                 : /* true multithread-shared globals */
      57                 : ZEND_API zend_class_entry *zend_standard_class_def = NULL;
      58                 : ZEND_API int (*zend_printf)(const char *format, ...);
      59                 : ZEND_API zend_write_func_t zend_write;
      60                 : ZEND_API int (*zend_path_encode)(char **encpath, int *encpath_len, const UChar *path, int path_len TSRMLS_DC);
      61                 : ZEND_API int (*zend_path_decode)(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC);
      62                 : ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
      63                 : ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
      64                 : ZEND_API void (*zend_block_interruptions)(void);
      65                 : ZEND_API void (*zend_unblock_interruptions)(void);
      66                 : ZEND_API void (*zend_ticks_function)(int ticks);
      67                 : ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
      68                 : int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
      69                 : ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
      70                 : ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
      71                 : 
      72                 : void (*zend_on_timeout)(int seconds TSRMLS_DC);
      73                 : 
      74                 : static void (*zend_message_dispatcher_p)(long message, void *data TSRMLS_DC);
      75                 : static int (*zend_get_configuration_directive_p)(const char *name, uint name_length, zval *contents);
      76                 : 
      77                 : static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
      78         2319462 : {
      79         2319462 :         if (!new_value) {
      80             126 :                 EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
      81                 :         } else {
      82         2319336 :                 EG(error_reporting) = atoi(new_value);
      83                 :         }
      84         2319462 :         return SUCCESS;
      85                 : }
      86                 : /* }}} */
      87                 : 
      88                 : static ZEND_INI_MH(OnUpdateEncoding) /* {{{ */
      89           68028 : {
      90                 :         UConverter **converter;
      91                 : #ifndef ZTS
      92           68028 :         char *base = (char *) mh_arg2;
      93                 : #else
      94                 :         char *base;
      95                 : 
      96                 :         base = (char *) ts_resource(*((int *) mh_arg2));
      97                 : #endif
      98                 : 
      99           68028 :         converter = (UConverter **) (base+(size_t) mh_arg1);
     100                 : 
     101           68028 :         if (!new_value && converter == &UG(fallback_encoding_conv)) {
     102           17007 :                 new_value = "UTF-8";
     103                 :         }
     104                 : 
     105           68028 :         if (new_value) {
     106           50775 :                 if (zend_set_converter_encoding(converter, new_value) == FAILURE) {
     107               0 :                         zend_error(E_CORE_ERROR, "Unrecognized encoding '%s' used for %s", new_value ? new_value : "null", entry->name);
     108               0 :                         return FAILURE;
     109                 :                 }
     110                 :         } else {
     111           17253 :                 if (*converter) {
     112               0 :                         ucnv_close(*converter);
     113                 :                 }
     114           17253 :                 *converter = NULL;
     115                 :         }
     116           68028 :         if (*converter) {
     117           50775 :                 zend_set_converter_error_mode(*converter, ZEND_FROM_UNICODE, UG(from_error_mode));
     118           50775 :                 zend_set_converter_error_mode(*converter, ZEND_TO_UNICODE, UG(to_error_mode));
     119           50775 :                 zend_set_converter_subst_char(*converter, UG(from_subst_char));
     120                 :         }
     121                 : 
     122           68028 :         return SUCCESS;
     123                 : }
     124                 : /* }}} */
     125                 : 
     126                 : #if 0
     127                 : static ZEND_INI_MH(OnUpdateErrorMode)
     128                 : {
     129                 :         uint8_t *error_mode;
     130                 : #ifndef ZTS
     131                 :         char *base = (char *) mh_arg2;
     132                 : #else
     133                 :         char *base;
     134                 : 
     135                 :         base = (char *) ts_resource(*((int *) mh_arg2));
     136                 : #endif
     137                 : 
     138                 :         error_mode = (uint8_t *) (base+(size_t) mh_arg1);
     139                 : 
     140                 :         if (new_value) {
     141                 :                 if (!strcasecmp(new_value, "stop")) {
     142                 :                         *error_mode = ZEND_FROM_U_ERROR_STOP;
     143                 :                 } else if (!strcasecmp(new_value, "skip")) {
     144                 :                         *error_mode = ZEND_FROM_U_ERROR_SKIP;
     145                 :                 } else if (!strcasecmp(new_value, "escape")) {
     146                 :                         *error_mode = ZEND_FROM_U_ERROR_ESCAPE;
     147                 :                 } else if (!strcasecmp(new_value, "substitute")) {
     148                 :                         *error_mode = ZEND_FROM_U_ERROR_SUBST;
     149                 :                 } else {
     150                 :                         zend_error(E_WARNING, "Illegal value for conversion error mode");
     151                 :                         return FAILURE;
     152                 :                 }
     153                 :         }
     154                 : 
     155                 :         return SUCCESS;
     156                 : }
     157                 : #endif
     158                 : 
     159                 : void zend_update_converters_error_behavior(TSRMLS_D) /* {{{ */
     160               3 : {
     161               3 :         if (UG(fallback_encoding_conv)) {
     162               3 :                 zend_set_converter_error_mode(UG(fallback_encoding_conv), ZEND_FROM_UNICODE, UG(from_error_mode));
     163               3 :                 zend_set_converter_error_mode(UG(fallback_encoding_conv), ZEND_TO_UNICODE, UG(to_error_mode));
     164               3 :                 zend_set_converter_subst_char(UG(fallback_encoding_conv), UG(from_subst_char));
     165                 :         }
     166               3 :         if (UG(runtime_encoding_conv)) {
     167               3 :                 zend_set_converter_error_mode(UG(runtime_encoding_conv), ZEND_FROM_UNICODE, UG(from_error_mode));
     168               3 :                 zend_set_converter_error_mode(UG(runtime_encoding_conv), ZEND_TO_UNICODE, UG(to_error_mode));
     169               3 :                 zend_set_converter_subst_char(UG(runtime_encoding_conv), UG(from_subst_char));
     170                 :         }
     171               3 :         if (UG(output_encoding_conv)) {
     172               3 :                 zend_set_converter_error_mode(UG(output_encoding_conv), ZEND_FROM_UNICODE, UG(from_error_mode));
     173               3 :                 zend_set_converter_subst_char(UG(output_encoding_conv), UG(from_subst_char));
     174                 :         }
     175               3 : }
     176                 : /* }}} */
     177                 : 
     178                 : static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
     179           17018 : {
     180           17018 :         OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
     181                 : 
     182           17018 :         if (GC_G(gc_enabled)) {
     183           17012 :                 gc_init(TSRMLS_C);
     184                 :         }
     185                 : 
     186           17018 :         return SUCCESS;
     187                 : }
     188                 : /* }}} */
     189                 :  
     190                 : ZEND_INI_BEGIN()
     191                 :         ZEND_INI_ENTRY("error_reporting",                     NULL,           ZEND_INI_ALL,           OnUpdateErrorReporting)
     192                 : 
     193                 :         STD_ZEND_INI_BOOLEAN("zend.enable_gc",                                "1",  ZEND_INI_ALL,           OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
     194                 : 
     195                 :         /* Unicode .ini entries */
     196                 :         STD_ZEND_INI_ENTRY("unicode.fallback_encoding",               NULL,   ZEND_INI_ALL, OnUpdateEncoding, fallback_encoding_conv, zend_unicode_globals, unicode_globals)
     197                 :         STD_ZEND_INI_ENTRY("unicode.runtime_encoding",                NULL,   ZEND_INI_ALL, OnUpdateEncoding, runtime_encoding_conv, zend_unicode_globals, unicode_globals)
     198                 :         STD_ZEND_INI_ENTRY("unicode.script_encoding",         NULL,   ZEND_INI_ALL, OnUpdateEncoding, script_encoding_conv, zend_unicode_globals, unicode_globals)
     199                 :         STD_ZEND_INI_ENTRY("unicode.filesystem_encoding",     NULL,   ZEND_INI_ALL, OnUpdateEncoding, filesystem_encoding_conv, zend_unicode_globals, unicode_globals)
     200                 :         /*
     201                 :          * This is used as a default for the stream contexts. It's not an actual
     202                 :          * UConverter because each stream needs its own.
     203                 :          */
     204                 :         STD_ZEND_INI_ENTRY("unicode.stream_encoding", "UTF-8", ZEND_INI_ALL, OnUpdateStringUnempty, stream_encoding, zend_unicode_globals, unicode_globals)
     205                 :         /*
     206                 :          * This is used as a default for the request encoding. It's not an actual
     207                 :          * UConverter because the request encoding converter is reset on each request.
     208                 :          */
     209                 :         STD_ZEND_INI_ENTRY("unicode.request_encoding_default",        "UTF-8",      ZEND_INI_ALL, OnUpdateStringUnempty, request_encoding_def, zend_unicode_globals, unicode_globals)
     210                 : ZEND_INI_END()
     211                 : 
     212                 : 
     213                 : #ifdef ZTS
     214                 : ZEND_API int compiler_globals_id;
     215                 : ZEND_API int executor_globals_id;
     216                 : static HashTable *global_function_table = NULL;
     217                 : static HashTable *global_class_table = NULL;
     218                 : static HashTable *global_constants_table = NULL;
     219                 : static HashTable *global_auto_globals_table = NULL;
     220                 : static HashTable *global_persistent_list = NULL;
     221                 : #endif
     222                 : 
     223                 : ZEND_API zend_utility_values zend_uv;
     224                 : 
     225                 : ZEND_API zval zval_used_for_init; /* True global variable */
     226                 : 
     227                 : /* version information */
     228                 : static char *zend_version_info;
     229                 : static uint zend_version_info_length;
     230                 : #define ZEND_CORE_VERSION_INFO  "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2009 Zend Technologies\n"
     231                 : #define PRINT_ZVAL_INDENT 4
     232                 : 
     233                 : static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
     234             938 : {
     235                 :         zval **tmp;
     236                 :         zstr string_key;
     237                 :         HashPosition iterator;
     238                 :         ulong num_key;
     239                 :         uint str_len;
     240                 :         int i;
     241                 :         zend_uchar ztype;
     242                 : 
     243            3658 :         for (i = 0; i < indent; i++) {
     244            2720 :                 ZEND_PUTS_EX(" ");
     245                 :         }
     246             938 :         ZEND_PUTS_EX("(\n");
     247             938 :         indent += PRINT_ZVAL_INDENT;
     248             938 :         zend_hash_internal_pointer_reset_ex(ht, &iterator);
     249            5116 :         while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
     250                 :                 zend_uchar key_type;
     251                 : 
     252           26592 :                 for (i = 0; i < indent; i++) {
     253           23352 :                         ZEND_PUTS_EX(" ");
     254                 :                 }
     255            3240 :                 ZEND_PUTS_EX("[");
     256            3240 :                 switch ((key_type = zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator))) {
     257                 :                         case HASH_KEY_IS_STRING:
     258              78 :                                 ztype = IS_STRING;
     259              78 :                                 goto str_type;
     260                 :                         case HASH_KEY_IS_UNICODE:
     261            1591 :                                 ztype = IS_UNICODE;
     262            1669 : str_type:
     263            1669 :                                 if (is_object) {
     264                 :                                         zstr prop_name, class_name;
     265                 : 
     266             510 :                                         int mangled = zend_u_unmangle_property_name(ztype, string_key, str_len - 1, &class_name, &prop_name);
     267                 : 
     268             510 :                                         if (ztype == IS_UNICODE) {
     269             503 :                                                 UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
     270             503 :                                                 UErrorCode status = U_ZERO_ERROR;
     271             503 :                                                 char *s = NULL;
     272                 :                                                 int s_len;
     273                 : 
     274             503 :                                                 zend_unicode_to_string_ex(conv, &s, &s_len, prop_name.u, u_strlen(prop_name.u), &status);
     275             503 :                                                 if (U_FAILURE(status)) {
     276               0 :                                                         zend_error(E_WARNING, "Could not convert Unicode to printable form");
     277               0 :                                                         return;
     278                 :                                                 }
     279             503 :                                                 ZEND_WRITE_EX(s, s_len);
     280             503 :                                                 efree(s);
     281                 :                                         } else {
     282               7 :                                                 ZEND_PUTS_EX(prop_name.s);
     283                 :                                         }
     284             510 :                                         if (class_name.v && mangled == SUCCESS) {
     285             194 :                                                 if (class_name.s[0]=='*') {
     286              87 :                                                         ZEND_PUTS_EX(":protected");
     287                 :                                                 } else {
     288             107 :                                                         UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
     289             107 :                                                         UErrorCode status = U_ZERO_ERROR;
     290             107 :                                                         char *s = NULL;
     291                 :                                                         int s_len;
     292                 : 
     293             107 :                                                         ZEND_PUTS_EX(":");
     294             107 :                                                         zend_unicode_to_string_ex(conv, &s, &s_len, class_name.u, u_strlen(class_name.u), &status);
     295             107 :                                                         if (U_FAILURE(status)) {
     296               0 :                                                                 zend_error(E_WARNING, "Could not convert Unicode to printable form");
     297               0 :                                                                 return;
     298                 :                                                         }
     299             107 :                                                         ZEND_WRITE_EX(s, s_len);
     300             107 :                                                         efree(s);
     301             107 :                                                         ZEND_PUTS_EX(":private");
     302                 :                                                 }
     303                 :                                         }
     304                 :                                 } else {
     305            1159 :                                         if (ztype == IS_UNICODE) {
     306            1088 :                                                 UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
     307            1088 :                                                 UErrorCode status = U_ZERO_ERROR;
     308            1088 :                                                 char *s = NULL;
     309                 :                                                 int s_len;
     310                 : 
     311            1088 :                                                 zend_unicode_to_string_ex(conv, &s, &s_len, string_key.u, str_len-1, &status);
     312            1088 :                                                 if (U_FAILURE(status)) {
     313               0 :                                                         zend_error(E_WARNING, "Could not convert Unicode to printable form");
     314               0 :                                                         return;
     315                 :                                                 }
     316            1088 :                                                 ZEND_WRITE_EX(s, s_len);
     317            1088 :                                                 efree(s);
     318                 :                                         } else {
     319              71 :                                                 ZEND_WRITE_EX(string_key.s, str_len-1);
     320                 :                                         }
     321                 :                                 }
     322            1669 :                                 break;
     323                 :                         case HASH_KEY_IS_LONG:
     324                 :                                 {
     325                 :                                         char key[25];
     326            1571 :                                         snprintf(key, sizeof(key), "%ld", num_key);
     327            1571 :                                         ZEND_PUTS_EX(key);
     328                 :                                 }
     329                 :                                 break;
     330                 :                 }
     331            3240 :                 ZEND_PUTS_EX("] => ");
     332            3240 :                 zend_print_zval_r_ex(write_func, *tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
     333            3240 :                 ZEND_PUTS_EX("\n");
     334            3240 :                 zend_hash_move_forward_ex(ht, &iterator);
     335                 :         }
     336             938 :         indent -= PRINT_ZVAL_INDENT;
     337            3658 :         for (i = 0; i < indent; i++) {
     338            2720 :                 ZEND_PUTS_EX(" ");
     339                 :         }
     340             938 :         ZEND_PUTS_EX(")\n");
     341                 : }
     342                 : /* }}} */
     343                 : 
     344                 : static void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
     345              18 : {
     346                 :         zval **tmp;
     347                 :         zstr string_key;
     348                 :         HashPosition iterator;
     349                 :         ulong num_key;
     350                 :         uint str_len;
     351              18 :         int i = 0;
     352                 : 
     353              18 :         zend_hash_internal_pointer_reset_ex(ht, &iterator);
     354             163 :         while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
     355             127 :                 if (i++ > 0) {
     356             118 :                         ZEND_PUTS(",");
     357                 :                 }
     358             127 :                 ZEND_PUTS("[");
     359             127 :                 switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
     360                 :                         case HASH_KEY_IS_STRING:
     361             102 :                                 ZEND_PUTS(string_key.s);
     362             102 :                                 break;
     363                 :                         case HASH_KEY_IS_UNICODE:
     364              21 :                                 zend_printf("%r", string_key.u);
     365              21 :                                 break;
     366                 :                         case HASH_KEY_IS_LONG:
     367               4 :                                 zend_printf("%ld", num_key);
     368                 :                                 break;
     369                 :                 }
     370             127 :                 ZEND_PUTS("] => ");
     371             127 :                 zend_print_flat_zval_r(*tmp TSRMLS_CC);
     372             127 :                 zend_hash_move_forward_ex(ht, &iterator);
     373                 :         }
     374              18 : }
     375                 : /* }}} */
     376                 : 
     377                 : ZEND_API void zend_make_string_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
     378        16176586 : {
     379        16176586 :         if (Z_TYPE_P(expr)==IS_STRING) {
     380        13417649 :                 *use_copy = 0;
     381        13417649 :                 return;
     382                 :         }
     383         2758937 :         switch (Z_TYPE_P(expr)) {
     384                 :                 case IS_OBJECT:
     385                 :                         {
     386                 :                                 TSRMLS_FETCH();
     387                 : 
     388               1 :                                 if (Z_OBJ_HT_P(expr)->cast_object && Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING, NULL TSRMLS_CC) == SUCCESS) {
     389               1 :                                         break;
     390                 :                                 }
     391               0 :                                 if (Z_OBJ_HANDLER_P(expr, get)) {
     392               0 :                                         zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC);
     393                 : 
     394               0 :                                         Z_ADDREF_P(z);
     395               0 :                                         if (Z_TYPE_P(z) != IS_OBJECT) {
     396               0 :                                                 zend_make_string_zval(z, expr_copy, use_copy);
     397               0 :                                                 if (*use_copy) {
     398               0 :                                                         zval_ptr_dtor(&z);
     399                 :                                                 } else {
     400               0 :                                                         ZVAL_ZVAL(expr_copy, z, 0, 1);
     401               0 :                                                         *use_copy = 1;
     402                 :                                                 }
     403               0 :                                                 return;
     404                 :                                         }
     405               0 :                                         zval_ptr_dtor(&z);
     406                 :                                 }
     407               0 :                                 zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %v could not be converted to string", Z_OBJCE_P(expr)->name);
     408               0 :                                 ZVAL_EMPTY_STRING(expr_copy);
     409               0 :                                 break;
     410                 :                         }
     411                 :                 default:
     412         2758936 :                         *expr_copy = *expr;
     413         2758936 :                         zval_copy_ctor(expr_copy);
     414         2758936 :                         convert_to_string(expr_copy);
     415                 :                         break;
     416                 :         }
     417         2758937 :         Z_TYPE_P(expr_copy) = IS_STRING;
     418         2758937 :         *use_copy = 1;
     419                 : }
     420                 : /* }}} */
     421                 : 
     422                 : ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
     423          205978 : {
     424          205978 :         UErrorCode temp = U_ZERO_ERROR;
     425                 :         TSRMLS_FETCH();
     426                 : 
     427          205978 :         if (
     428                 :                 /* UTODO: clean this up */
     429                 :                 (Z_TYPE_P(expr) == IS_STRING &&
     430                 :                 (!strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &temp), ucnv_getName(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &temp))))
     431                 :         ) {
     432              13 :                 *use_copy = 0;
     433              13 :                 return;
     434                 :         }
     435          205965 :         switch (Z_TYPE_P(expr)) {
     436                 :                 case IS_NULL:
     437             252 :                         Z_STRLEN_P(expr_copy) = 0;
     438             252 :                         Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
     439             252 :                         break;
     440                 :                 case IS_BOOL:
     441              79 :                         if (Z_LVAL_P(expr)) {
     442              27 :                                 Z_STRLEN_P(expr_copy) = 1;
     443              27 :                                 Z_STRVAL_P(expr_copy) = estrndup("1", 1);
     444                 :                         } else {
     445              52 :                                 Z_STRLEN_P(expr_copy) = 0;
     446              52 :                                 Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
     447                 :                         }
     448              79 :                         break;
     449                 :                 case IS_RESOURCE:
     450               7 :                         Z_STRVAL_P(expr_copy) = (char *) emalloc(sizeof("Resource id #") - 1 + MAX_LENGTH_OF_LONG);
     451               7 :                         Z_STRLEN_P(expr_copy) = sprintf(Z_STRVAL_P(expr_copy), "Resource id #%ld", Z_LVAL_P(expr));
     452               7 :                         break;
     453                 :                 case IS_ARRAY:
     454               9 :                         Z_STRLEN_P(expr_copy) = sizeof("Array") - 1;
     455               9 :                         Z_STRVAL_P(expr_copy) = estrndup("Array", Z_STRLEN_P(expr_copy));
     456               9 :                         break;
     457                 :                 case IS_OBJECT:
     458            4397 :                         if (Z_OBJ_HT_P(expr)->cast_object && Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING, ZEND_U_CONVERTER(UG(output_encoding_conv)) TSRMLS_CC) == SUCCESS) {
     459            4394 :                                 break;
     460                 :                         }
     461               3 :                         if (Z_OBJ_HANDLER_P(expr, get)) {
     462               0 :                                 zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC);
     463                 : 
     464               0 :                                 Z_ADDREF_P(z);
     465               0 :                                 if (Z_TYPE_P(z) != IS_OBJECT) {
     466               0 :                                         zend_make_printable_zval(z, expr_copy, use_copy);
     467               0 :                                         if (*use_copy) {
     468               0 :                                                 zval_ptr_dtor(&z);
     469                 :                                         } else {
     470               0 :                                                 ZVAL_ZVAL(expr_copy, z, 0, 1);
     471               0 :                                                 *use_copy = 1;
     472                 :                                         }
     473               0 :                                         return;
     474                 :                                 }
     475               0 :                                 zval_ptr_dtor(&z);
     476                 :                         }
     477               3 :                         zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %v could not be converted to string", Z_OBJCE_P(expr)->name);
     478               3 :                         ZVAL_EMPTY_STRING(expr_copy);
     479               3 :                         break;
     480                 :                 case IS_DOUBLE:
     481             667 :                         *expr_copy = *expr;
     482             667 :                         zval_copy_ctor(expr_copy);
     483             667 :                         zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
     484             667 :                         break;
     485                 :                 default:
     486          200554 :                         *expr_copy = *expr;
     487          200554 :                         zval_copy_ctor(expr_copy);
     488          200554 :                         convert_to_string_with_converter(expr_copy, ZEND_U_CONVERTER(UG(output_encoding_conv)));
     489                 :                         break;
     490                 :         }
     491          205965 :         Z_TYPE_P(expr_copy) = IS_STRING;
     492          205965 :         *use_copy = 1;
     493                 : }
     494                 : /* }}} */
     495                 : 
     496                 : ZEND_API void zend_make_unicode_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
     497         7788096 : {
     498                 :         TSRMLS_FETCH();
     499                 : 
     500         7788096 :         if (Z_TYPE_P(expr)==IS_UNICODE) {
     501         6444316 :                 *use_copy = 0;
     502         6444316 :                 return;
     503                 :         }
     504         1343780 :         switch (Z_TYPE_P(expr)) {
     505                 :                 case IS_OBJECT:
     506          100762 :                         if (Z_OBJ_HT_P(expr)->cast_object && Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_UNICODE, NULL TSRMLS_CC) == SUCCESS) {
     507          100712 :                                 break;
     508                 :                         }
     509              49 :                         if (Z_OBJ_HANDLER_P(expr, get)) {
     510               0 :                                 zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC);
     511                 : 
     512               0 :                                 Z_ADDREF_P(z);
     513               0 :                                 if (Z_TYPE_P(z) != IS_OBJECT) {
     514               0 :                                         zend_make_unicode_zval(z, expr_copy, use_copy);
     515               0 :                                         if (*use_copy) {
     516               0 :                                                 zval_ptr_dtor(&z);
     517                 :                                         } else {
     518               0 :                                                 ZVAL_ZVAL(expr_copy, z, 0, 1);
     519               0 :                                                 *use_copy = 1;
     520                 :                                         }
     521               0 :                                         return;
     522                 :                                 }
     523               0 :                                 zval_ptr_dtor(&z);
     524                 :                         }
     525              49 :                         zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %v could not be converted to string", Z_OBJCE_P(expr)->name);
     526              41 :                         ZVAL_EMPTY_UNICODE(expr_copy);
     527              41 :                         break;
     528                 :                 default:
     529         1243018 :                         *expr_copy = *expr;
     530         1243018 :                         zval_copy_ctor(expr_copy);
     531         1243018 :                         convert_to_unicode(expr_copy);
     532                 :                         break;
     533                 :         }
     534         1343771 :         Z_TYPE_P(expr_copy) = IS_UNICODE;
     535         1343771 :         *use_copy = 1;
     536                 : }
     537                 : /* }}} */
     538                 : 
     539                 : ZEND_API int zend_print_zval(zval *expr, int indent) /* {{{ */
     540          197668 : {
     541          197668 :         return zend_print_zval_ex(zend_write, expr, indent);
     542                 : }
     543                 : /* }}} */
     544                 : 
     545                 : ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
     546          200898 : {
     547                 :         zval expr_copy;
     548                 :         int use_copy;
     549                 : 
     550          200898 :         zend_make_printable_zval(expr, &expr_copy, &use_copy);
     551          200898 :         if (use_copy) {
     552          200885 :                 expr = &expr_copy;
     553                 :         }
     554          200898 :         if (Z_STRLEN_P(expr) == 0) { /* optimize away empty strings */
     555             490 :                 if (use_copy) {
     556             490 :                         zval_dtor(expr);
     557                 :                 }
     558             490 :                 return 0;
     559                 :         }
     560          200408 :         write_func(Z_STRVAL_P(expr), Z_STRLEN_P(expr));
     561          200406 :         if (use_copy) {
     562          200394 :                 zval_dtor(expr);
     563                 :         }
     564          200406 :         return Z_STRLEN_P(expr);
     565                 : }
     566                 : /* }}} */
     567                 : 
     568                 : ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
     569             147 : {
     570             147 :         switch (Z_TYPE_P(expr)) {
     571                 :                 case IS_ARRAY:
     572              19 :                         ZEND_PUTS("Array (");
     573              19 :                         if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
     574               2 :                                 ZEND_PUTS(" *RECURSION*");
     575               2 :                                 Z_ARRVAL_P(expr)->nApplyCount--;
     576               2 :                                 return;
     577                 :                         }
     578              17 :                         print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
     579              17 :                         ZEND_PUTS(")");
     580              17 :                         Z_ARRVAL_P(expr)->nApplyCount--;
     581              17 :                         break;
     582                 :                 case IS_OBJECT:
     583                 :                 {
     584               1 :                         HashTable *properties = NULL;
     585               1 :                         zstr class_name = NULL_ZSTR;
     586                 :                         zend_uint clen;
     587                 : 
     588               1 :                         if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
     589               1 :                                 Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
     590                 :                         }
     591               1 :                         if (class_name.v) {
     592               1 :                                 zend_printf("%v Object (", class_name.v);
     593                 :                         } else {
     594               0 :                                 zend_printf("%s Object (", "Unknown Class");
     595                 :                         }
     596               1 :                         if (class_name.v) {
     597               1 :                                 efree(class_name.v);
     598                 :                         }
     599               1 :                         if (Z_OBJ_HANDLER_P(expr, get_properties)) {
     600               1 :                                 properties = Z_OBJPROP_P(expr);
     601                 :                         }
     602               1 :                         if (properties) {
     603               1 :                                 if (++properties->nApplyCount>1) {
     604               0 :                                         ZEND_PUTS(" *RECURSION*");
     605               0 :                                         properties->nApplyCount--;
     606               0 :                                         return;
     607                 :                                 }
     608               1 :                                 print_flat_hash(properties TSRMLS_CC);
     609               1 :                                 properties->nApplyCount--;
     610                 :                         }
     611               1 :                         ZEND_PUTS(")");
     612               1 :                         break;
     613                 :                 }
     614                 :                 default:
     615             127 :                         zend_print_variable(expr);
     616                 :                         break;
     617                 :         }
     618                 : }
     619                 : /* }}} */
     620                 : 
     621                 : ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
     622             934 : {
     623             934 :         zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
     624             934 : }
     625                 : /* }}} */
     626                 : 
     627                 : ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
     628            4175 : {
     629            4175 :         switch (Z_TYPE_P(expr)) {
     630                 :                 case IS_ARRAY:
     631             745 :                         ZEND_PUTS_EX("Array\n");
     632             745 :                         if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
     633               0 :                                 ZEND_PUTS_EX(" *RECURSION*");
     634               0 :                                 Z_ARRVAL_P(expr)->nApplyCount--;
     635               0 :                                 return;
     636                 :                         }
     637             745 :                         print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
     638             745 :                         Z_ARRVAL_P(expr)->nApplyCount--;
     639             745 :                         break;
     640                 :                 case IS_OBJECT:
     641                 :                         {
     642                 :                                 HashTable *properties;
     643             200 :                                 zstr class_name = NULL_ZSTR;
     644                 :                                 zend_uint clen;
     645                 :                                 int is_temp;
     646                 : 
     647             200 :                                 if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
     648             200 :                                         Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
     649                 :                                 }
     650             200 :                                 if (class_name.v) {
     651             200 :                                         UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
     652             200 :                                         UErrorCode status = U_ZERO_ERROR;
     653             200 :                                         char *s = NULL;
     654                 :                                         int s_len;
     655                 : 
     656             200 :                                         zend_unicode_to_string_ex(conv, &s, &s_len, class_name.u, clen, &status);
     657             200 :                                         if (U_FAILURE(status)) {
     658               0 :                                                 zend_error(E_WARNING, "Could not convert Unicode to printable form");
     659               0 :                                                 return;
     660                 :                                         }
     661             200 :                                         ZEND_WRITE_EX(s, s_len);
     662             200 :                                         efree(s);
     663                 :                                 } else {
     664               0 :                                         ZEND_PUTS_EX("Unknown Class");
     665                 :                                 }
     666             200 :                                 ZEND_PUTS_EX(" Object\n");
     667             200 :                                 if (class_name.v) {
     668             200 :                                         efree(class_name.v);
     669                 :                                 }
     670             200 :                                 if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
     671               0 :                                         break;
     672                 :                                 }
     673             200 :                                 if (++properties->nApplyCount>1) {
     674               7 :                                         ZEND_PUTS_EX(" *RECURSION*");
     675               7 :                                         properties->nApplyCount--;
     676               7 :                                         return;
     677                 :                                 }
     678             193 :                                 print_hash(write_func, properties, indent, 1 TSRMLS_CC);
     679             193 :                                 properties->nApplyCount--;
     680             193 :                                 if (is_temp) {
     681              10 :                                         zend_hash_destroy(properties);
     682              10 :                                         efree(properties);
     683                 :                                 }
     684             193 :                                 break;
     685                 :                         }
     686                 :                 default:
     687            3230 :                         zend_print_zval_ex(write_func, expr, indent);
     688                 :                         break;
     689                 :         }
     690                 : }
     691                 : /* }}} */
     692                 : 
     693                 : static int zend_path_encode_wrapper(char **encpath, int *encpath_len, const UChar *path, int path_len TSRMLS_DC) /* {{{ */
     694               0 : {
     695               0 :         UErrorCode status = U_ZERO_ERROR;
     696                 : 
     697               0 :         zend_unicode_to_string_ex(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)), encpath, encpath_len, path, path_len, &status);
     698                 : 
     699               0 :         if (U_FAILURE(status)) {
     700               0 :                 efree(*encpath);
     701               0 :                 *encpath = NULL;
     702               0 :                 *encpath_len = 0;
     703               0 :                 return FAILURE;
     704                 :         }
     705                 : 
     706               0 :         return SUCCESS;
     707                 : }
     708                 : /* }}} */
     709                 : 
     710                 : static int zend_path_decode_wrapper(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC) /* {{{ */
     711               0 : {
     712               0 :         UErrorCode status = U_ZERO_ERROR;
     713                 : 
     714               0 :         zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)), decpath, decpath_len, path, path_len, &status);
     715                 : 
     716               0 :         if (U_FAILURE(status)) {
     717               0 :                 efree(*decpath);
     718               0 :                 *decpath = NULL;
     719               0 :                 *decpath_len = 0;
     720               0 :                 return FAILURE;
     721                 :         }
     722                 : 
     723               0 :         return SUCCESS;
     724                 : }
     725                 : /* }}} */
     726                 : 
     727                 : static FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
     728               0 : {
     729               0 :         if (opened_path) {
     730               0 :                 *opened_path = estrdup(filename);
     731                 :         }
     732               0 :         return fopen(filename, "rb");
     733                 : }
     734                 : /* }}} */
     735                 : 
     736                 : #ifdef ZTS
     737                 : static zend_bool asp_tags_default                       = 0;
     738                 : static zend_bool short_tags_default                     = 1;
     739                 : static zend_uint compiler_options_default       = ZEND_COMPILE_DEFAULT;
     740                 : #else
     741                 : # define asp_tags_default                       0
     742                 : # define short_tags_default                     1
     743                 : # define compiler_options_default       ZEND_COMPILE_DEFAULT
     744                 : #endif
     745                 : 
     746                 : static void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
     747           17007 : {
     748                 :         /* default compile-time values */
     749           17007 :         CG(asp_tags) = asp_tags_default;
     750           17007 :         CG(short_tags) = short_tags_default;
     751           17007 :         CG(compiler_options) = compiler_options_default;
     752           17007 :         CG(literal_type) = IS_UNICODE;
     753           17007 : }
     754                 : /* }}} */
     755                 : 
     756                 : #define ZEND_U_CONSTANT_DTOR (void (*)(void *)) free_u_zend_constant
     757                 : 
     758                 : static void zval_copy_persistent(zval *zv) /* {{{ */
     759               0 : {
     760               0 :         if (Z_TYPE_P(zv) == IS_STRING || (Z_TYPE_P(zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
     761                 :                 UChar *ustr;
     762                 : 
     763               0 :                 ustr = malloc(UBYTES(Z_STRLEN_P(zv) + 1));
     764               0 :                 u_charsToUChars(Z_STRVAL_P(zv), ustr, Z_STRLEN_P(zv) + 1);
     765               0 :                 free(Z_STRVAL_P(zv));
     766               0 :                 Z_USTRVAL_P(zv) = ustr;
     767               0 :                 if (Z_TYPE_P(zv) == IS_STRING) Z_TYPE_P(zv) = IS_UNICODE;
     768                 :         }
     769               0 : }
     770                 : /* }}} */
     771                 : 
     772                 : static void free_u_zend_constant(zend_constant *c) /* {{{ */
     773        34130822 : {
     774        34130822 :         if (!(c->flags & CONST_PERSISTENT)) {
     775           52822 :                 zval_dtor(&c->value);
     776                 :         } else {
     777        34078000 :                 zval_internal_dtor(&c->value);
     778                 :         }
     779        34130822 :         free(c->name.v);
     780        34130822 : }
     781                 : /* }}} */
     782                 : 
     783                 : static void function_to_unicode(zend_function *func TSRMLS_DC) /* {{{ */
     784               0 : {
     785               0 :         if (func->common.function_name.s) {
     786               0 :                 func->common.function_name.u = zend_ustrdup(func->common.function_name.u);
     787                 :         }
     788               0 :         if (func->common.arg_info) {
     789                 :                 zend_arg_info *args;
     790               0 :                 int n = func->common.num_args;
     791                 : 
     792               0 :                 args = malloc((n + 1) * sizeof(zend_arg_info));
     793               0 :                 memcpy(args, func->common.arg_info, (n + 1) * sizeof(zend_arg_info));
     794               0 :                 while (n > 0) {
     795               0 :                         --n;
     796               0 :                         if (args[n].name.s) {
     797               0 :                                 UChar *uname = malloc(UBYTES(args[n].name_len + 1));
     798               0 :                                 u_charsToUChars(args[n].name.s, uname, args[n].name_len + 1);
     799               0 :                                 args[n].name.u = uname;
     800                 :                         }
     801               0 :                         if (args[n].class_name.s) {
     802               0 :                                 UChar *uname = malloc(UBYTES(args[n].class_name_len + 1));
     803               0 :                                 u_charsToUChars(args[n].class_name.s, uname, args[n].class_name_len + 1);
     804               0 :                                 args[n].class_name.u = uname;
     805                 :                         }
     806                 :                 }
     807               0 :                 func->common.arg_info = args;
     808                 :         }
     809               0 : }
     810                 : /* }}} */
     811                 : 
     812                 : static void property_info_to_unicode(zend_property_info *info TSRMLS_DC) /* {{{ */
     813               0 : {
     814               0 :         if (info->name.s) {
     815                 :                 UChar *uname;
     816                 : 
     817               0 :                 uname = malloc(UBYTES(info->name_length + 1));
     818               0 :                 u_charsToUChars(info->name.s, uname, info->name_length + 1);
     819               0 :                 free(info->name.s);
     820               0 :                 info->name.u = uname;
     821               0 :                 info->h = zend_u_get_hash_value(IS_UNICODE, info->name, info->name_length + 1);
     822                 :         }
     823               0 : }
     824                 : /* }}} */
     825                 : 
     826                 : static void zval_ptr_to_unicode(zval **zv TSRMLS_DC) /* {{{ */
     827               0 : {
     828               0 :         zval_copy_persistent(*zv);
     829               0 : }
     830                 : /* }}} */
     831                 : 
     832                 : static void const_to_unicode(zend_constant *c) /* {{{ */
     833         1309539 : {
     834                 :         UChar *uname;
     835                 : 
     836         1309539 :         if (c->name.s) {
     837         1309539 :                 uname = malloc(UBYTES(c->name_len));
     838         1309539 :                 u_charsToUChars(c->name.s, uname, c->name_len);
     839         1309539 :                 free(c->name.s);
     840         1309539 :                 c->name.u = uname;
     841                 :         }
     842         1309539 :         if (Z_TYPE(c->value) == IS_STRING || (Z_TYPE(c->value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
     843                 :                 UChar *ustr;
     844                 : 
     845               0 :                 ustr = malloc(UBYTES(Z_STRLEN(c->value) + 1));
     846               0 :                 u_charsToUChars(Z_STRVAL(c->value), ustr, Z_STRLEN(c->value) + 1);
     847               0 :                 Z_USTRVAL(c->value) = ustr;
     848               0 :                 if (Z_TYPE(c->value) == IS_STRING) Z_TYPE(c->value) = IS_UNICODE;
     849                 :         }
     850         1309539 : }
     851                 : /* }}} */
     852                 : 
     853                 : static void class_to_unicode(zend_class_entry **ce TSRMLS_DC) /* {{{ */
     854               0 : {
     855                 :         /* Convert name to unicode */
     856               0 :         if ((*ce)->name.s) {
     857               0 :                 UChar *uname = malloc(UBYTES((*ce)->name_length + 1));
     858                 : 
     859               0 :                 u_charsToUChars((*ce)->name.s, uname, (*ce)->name_length + 1);
     860               0 :                 free((*ce)->name.s);
     861               0 :                 (*ce)->name.u = uname;
     862                 :         }
     863                 : 
     864               0 :         zend_hash_to_unicode(&(*ce)->function_table, (apply_func_t)function_to_unicode TSRMLS_CC);
     865               0 :         (*ce)->function_table.pDestructor = ZEND_U_FUNCTION_DTOR;
     866               0 :         zend_hash_to_unicode(&(*ce)->constants_table, (apply_func_t)zval_ptr_to_unicode TSRMLS_CC);
     867               0 :         zend_hash_to_unicode(&(*ce)->properties_info, (apply_func_t)property_info_to_unicode TSRMLS_CC);
     868               0 :         zend_hash_to_unicode(&(*ce)->default_properties, (apply_func_t)zval_ptr_to_unicode TSRMLS_CC);
     869               0 :         zend_hash_to_unicode(&(*ce)->default_static_members, (apply_func_t)zval_ptr_to_unicode TSRMLS_CC);
     870               0 : }
     871                 : /* }}} */
     872                 : 
     873                 : static void zend_init_exception_op(TSRMLS_D) /* {{{ */
     874           17007 : {
     875           17007 :         memset(EG(exception_op), 0, sizeof(EG(exception_op)));
     876           17007 :         EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
     877           17007 :         EG(exception_op)[0].op1.op_type = IS_UNUSED;
     878           17007 :         EG(exception_op)[0].op2.op_type = IS_UNUSED;
     879           17007 :         EG(exception_op)[0].result.op_type = IS_UNUSED;
     880           17007 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
     881           17007 :         EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
     882           17007 :         EG(exception_op)[1].op1.op_type = IS_UNUSED;
     883           17007 :         EG(exception_op)[1].op2.op_type = IS_UNUSED;
     884           17007 :         EG(exception_op)[1].result.op_type = IS_UNUSED;
     885           17007 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
     886           17007 :         EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
     887           17007 :         EG(exception_op)[2].op1.op_type = IS_UNUSED;
     888           17007 :         EG(exception_op)[2].op2.op_type = IS_UNUSED;
     889           17007 :         EG(exception_op)[2].result.op_type = IS_UNUSED;
     890           17007 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
     891           17007 : }
     892                 : /* }}} */
     893                 : 
     894                 : #ifdef ZTS
     895                 : static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
     896                 : {
     897                 :         zend_function tmp_func;
     898                 :         zend_class_entry *tmp_class;
     899                 : 
     900                 :         compiler_globals->compiled_filename = NULL;
     901                 : 
     902                 :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
     903                 :         zend_u_hash_init_ex(compiler_globals->function_table, global_function_table->nNumOfElements, NULL, ZEND_FUNCTION_DTOR, 1, UG(unicode), 0);
     904                 :         zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function));
     905                 : 
     906                 :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
     907                 :         zend_u_hash_init_ex(compiler_globals->class_table, global_class_table->nNumOfElements, NULL, ZEND_CLASS_DTOR, 1, UG(unicode), 0);
     908                 :         zend_hash_copy(compiler_globals->class_table, global_class_table, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry *));
     909                 : 
     910                 :         zend_set_default_compile_time_values(TSRMLS_C);
     911                 : 
     912                 :         CG(interactive) = 0;
     913                 :         CG(literal_type) = IS_UNICODE;
     914                 : 
     915                 :         compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
     916                 :         zend_u_hash_init_ex(compiler_globals->auto_globals, global_auto_globals_table->nNumOfElements, NULL, NULL, 1, UG(unicode), 0);
     917                 :         zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(zend_auto_global) /* empty element */);
     918                 : 
     919                 :         compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
     920                 :         if (compiler_globals->last_static_member) {
     921                 :                 compiler_globals->static_members = (HashTable**)calloc(compiler_globals->last_static_member, sizeof(HashTable*));
     922                 :         } else {
     923                 :                 compiler_globals->static_members = NULL;
     924                 :         }
     925                 : }
     926                 : /* }}} */
     927                 : 
     928                 : static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
     929                 : {
     930                 :         if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
     931                 :                 zend_hash_destroy(compiler_globals->function_table);
     932                 :                 free(compiler_globals->function_table);
     933                 :         }
     934                 :         if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
     935                 :                 zend_hash_destroy(compiler_globals->class_table);
     936                 :                 free(compiler_globals->class_table);
     937                 :         }
     938                 :         if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
     939                 :                 zend_hash_destroy(compiler_globals->auto_globals);
     940                 :                 free(compiler_globals->auto_globals);
     941                 :         }
     942                 :         if (compiler_globals->static_members) {
     943                 :                 free(compiler_globals->static_members);
     944                 :         }
     945                 :         compiler_globals->last_static_member = 0;
     946                 : }
     947                 : /* }}} */
     948                 : 
     949                 : static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
     950                 : {
     951                 :         zend_startup_constants(TSRMLS_C);
     952                 :         zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
     953                 :         zend_init_rsrc_plist(TSRMLS_C);
     954                 :         zend_init_exception_op(TSRMLS_C);
     955                 :         EG(lambda_count) = 0;
     956                 :         EG(user_error_handler) = NULL;
     957                 :         EG(user_exception_handler) = NULL;
     958                 :         EG(in_execution) = 0;
     959                 :         EG(in_autoload) = NULL;
     960                 :         EG(current_execute_data) = NULL;
     961                 :         EG(current_module) = NULL;
     962                 :         EG(exit_status) = 0;
     963                 :         EG(saved_fpu_cw) = NULL;
     964                 :         EG(active) = 0;
     965                 : }
     966                 : /* }}} */
     967                 : 
     968                 : static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
     969                 : {
     970                 :         zend_ini_shutdown(TSRMLS_C);
     971                 :         if (&executor_globals->persistent_list != global_persistent_list) {
     972                 :                 zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
     973                 :         }
     974                 :         if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
     975                 :                 zend_hash_destroy(executor_globals->zend_constants);
     976                 :                 free(executor_globals->zend_constants);
     977                 :         }
     978                 : }
     979                 : /* }}} */
     980                 : 
     981                 : static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
     982                 : {
     983                 :         if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
     984                 :                 zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
     985                 :         }
     986                 : }
     987                 : /* }}} */
     988                 : #endif
     989                 : 
     990                 : #if defined(__FreeBSD__) || defined(__DragonFly__)
     991                 : /* FreeBSD and DragonFly floating point precision fix */
     992                 : #include <floatingpoint.h>
     993                 : #endif
     994                 : 
     995                 : static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
     996           17007 : {
     997           17007 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     998           17007 : }
     999                 : /* }}} */
    1000                 : 
    1001                 : static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
    1002           17007 : {
    1003           17007 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
    1004           17007 : }
    1005                 : /* }}} */
    1006                 : 
    1007                 : static void unicode_globals_ctor(zend_unicode_globals *unicode_globals TSRMLS_DC) /* {{{ */
    1008           17007 : {
    1009           17007 :         unicode_globals->unicode = 1;
    1010           17007 :         unicode_globals->utf8_conv = NULL;
    1011           17007 :         unicode_globals->ascii_conv = NULL;
    1012           17007 :         unicode_globals->fallback_encoding_conv = NULL;
    1013           17007 :         unicode_globals->runtime_encoding_conv = NULL;
    1014           17007 :         unicode_globals->output_encoding_conv = NULL;
    1015           17007 :         unicode_globals->script_encoding_conv = NULL;
    1016           17007 :         unicode_globals->filesystem_encoding_conv = NULL;
    1017           17007 :         unicode_globals->request_encoding_conv = NULL;
    1018           17007 :         zend_set_converter_encoding(&unicode_globals->utf8_conv, "UTF-8");
    1019           17007 :         zend_set_converter_error_mode(unicode_globals->utf8_conv, ZEND_TO_UNICODE, ZEND_CONV_ERROR_STOP);
    1020           17007 :         zend_set_converter_encoding(&unicode_globals->ascii_conv, "US-ASCII");
    1021           17007 :         zend_set_converter_error_mode(unicode_globals->ascii_conv, ZEND_FROM_UNICODE, ZEND_CONV_ERROR_STOP);
    1022           17007 :         unicode_globals->from_error_mode = ZEND_CONV_ERROR_SUBST;
    1023           17007 :         memset(unicode_globals->from_subst_char, 0, 3 * sizeof(UChar));
    1024           17007 :         zend_codepoint_to_uchar(0x3f, unicode_globals->from_subst_char);
    1025           17007 :         unicode_globals->to_error_mode = ZEND_CONV_ERROR_STOP;
    1026           17007 :         unicode_globals->conv_error_handler = NULL;
    1027                 : 
    1028                 :         {
    1029           17007 :                 UErrorCode status = U_ZERO_ERROR;
    1030                 : 
    1031           17007 :                 unicode_globals->root_collator = ucol_open("en_US", &status);
    1032           17007 :                 ucol_setStrength(unicode_globals->root_collator, UCOL_PRIMARY);
    1033           17007 :                 unicode_globals->root_search = usearch_openFromCollator(EMPTY_STR, 1, EMPTY_STR, 1,
    1034                 :                                                                                                                                 unicode_globals->root_collator, NULL, &status);
    1035                 :         }
    1036                 : 
    1037           17007 :         zend_hash_init_ex(&unicode_globals->flex_compatible, 0, NULL, NULL, 1, 0);
    1038           17007 : }
    1039                 : /* }}} */
    1040                 : 
    1041                 : static void unicode_globals_dtor(zend_unicode_globals *unicode_globals TSRMLS_DC) /* {{{ */
    1042           17039 : {
    1043           17039 :         if (unicode_globals->root_collator) {
    1044           17039 :                 ucol_close(unicode_globals->root_collator);
    1045                 :         }
    1046           17039 :         if (unicode_globals->root_search) {
    1047           17039 :                 usearch_close(unicode_globals->root_search);
    1048                 :         }
    1049           17039 :         if (unicode_globals->fallback_encoding_conv &&
    1050                 :                 unicode_globals->fallback_encoding_conv != unicode_globals->utf8_conv &&
    1051                 :                 unicode_globals->fallback_encoding_conv != unicode_globals->ascii_conv) {
    1052           17039 :                 ucnv_close(unicode_globals->fallback_encoding_conv);
    1053                 :         }
    1054           17039 :         if (unicode_globals->runtime_encoding_conv &&
    1055                 :                 unicode_globals->runtime_encoding_conv != unicode_globals->utf8_conv &&
    1056                 :                 unicode_globals->runtime_encoding_conv != unicode_globals->ascii_conv) {
    1057           16919 :                 ucnv_close(unicode_globals->runtime_encoding_conv);
    1058                 :         }
    1059           17039 :         if (unicode_globals->output_encoding_conv &&
    1060                 :                 unicode_globals->output_encoding_conv != unicode_globals->utf8_conv &&
    1061                 :                 unicode_globals->output_encoding_conv != unicode_globals->ascii_conv) {
    1062           16919 :                 ucnv_close(unicode_globals->output_encoding_conv);
    1063                 :         }
    1064           17039 :         if (unicode_globals->script_encoding_conv &&
    1065                 :                 unicode_globals->script_encoding_conv != unicode_globals->utf8_conv &&
    1066                 :                 unicode_globals->script_encoding_conv != unicode_globals->ascii_conv) {
    1067           16919 :                 ucnv_close(unicode_globals->script_encoding_conv);
    1068                 :         }
    1069           17039 :         if (unicode_globals->utf8_conv) {
    1070           17039 :                 ucnv_close(unicode_globals->utf8_conv);
    1071                 :         }
    1072           17039 :         if (unicode_globals->ascii_conv) {
    1073           17039 :                 ucnv_close(unicode_globals->ascii_conv);
    1074                 :         }
    1075           17039 :         zend_hash_destroy(&unicode_globals->flex_compatible);
    1076           17039 : }
    1077                 : /* }}} */
    1078                 : 
    1079                 : void zend_init_opcodes_handlers(void);
    1080                 : 
    1081                 : int zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
    1082           17007 : {
    1083                 : #ifdef ZTS
    1084                 :         zend_compiler_globals *compiler_globals;
    1085                 :         zend_executor_globals *executor_globals;
    1086                 :         extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
    1087                 :         extern ZEND_API ts_rsrc_id language_scanner_globals_id;
    1088                 :         extern ZEND_API ts_rsrc_id unicode_globals_id;
    1089                 : #else
    1090                 :         extern zend_ini_scanner_globals ini_scanner_globals;
    1091                 :         extern zend_php_scanner_globals language_scanner_globals;
    1092                 :         extern zend_unicode_globals unicode_globals;
    1093                 : #endif
    1094                 : 
    1095                 : #ifndef __GNUC__
    1096                 :         null_zstr.v = NULL;
    1097                 :         empty_zstr.u = EMPTY_STR;
    1098                 : #endif
    1099                 : 
    1100           17007 :         start_memory_manager(TSRMLS_C);
    1101                 : 
    1102                 : #if defined(__FreeBSD__) || defined(__DragonFly__)
    1103                 :         /* FreeBSD and DragonFly floating point precision fix */
    1104                 :         fpsetmask(0);
    1105                 : #endif
    1106                 : 
    1107           17007 :         zend_startup_strtod();
    1108           17007 :         zend_startup_extensions_mechanism();
    1109                 : 
    1110                 :         /* Set up utility functions and values */
    1111           17007 :         zend_error_cb = utility_functions->error_function;
    1112           17007 :         zend_printf = utility_functions->printf_function;
    1113           17007 :         zend_write = (zend_write_func_t) utility_functions->write_function;
    1114           17007 :         zend_path_encode = utility_functions->path_encode_function;
    1115           17007 :         if (!zend_path_encode) {
    1116               0 :                 zend_path_encode = zend_path_encode_wrapper;
    1117                 :         }
    1118           17007 :         zend_path_decode = utility_functions->path_decode_function;
    1119           17007 :         if (!zend_path_decode) {
    1120               0 :                 zend_path_decode = zend_path_decode_wrapper;
    1121                 :         }
    1122           17007 :         zend_fopen = utility_functions->fopen_function;
    1123           17007 :         if (!zend_fopen) {
    1124               0 :                 zend_fopen = zend_fopen_wrapper;
    1125                 :         }
    1126           17007 :         zend_stream_open_function = utility_functions->stream_open_function;
    1127           17007 :         zend_message_dispatcher_p = utility_functions->message_handler;
    1128           17007 :         zend_block_interruptions = utility_functions->block_interruptions;
    1129           17007 :         zend_unblock_interruptions = utility_functions->unblock_interruptions;
    1130           17007 :         zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
    1131           17007 :         zend_ticks_function = utility_functions->ticks_function;
    1132           17007 :         zend_on_timeout = utility_functions->on_timeout;
    1133           17007 :         zend_vspprintf = utility_functions->vspprintf_function;
    1134           17007 :         zend_getenv = utility_functions->getenv_function;
    1135           17007 :         zend_resolve_path = utility_functions->resolve_path_function;
    1136                 : 
    1137                 : #if HAVE_SYS_SDT_H
    1138                 : /* build with dtrace support */
    1139                 :         zend_compile_file = dtrace_compile_file;
    1140                 :         zend_execute = dtrace_execute;
    1141                 :         zend_execute_internal = dtrace_execute_internal;
    1142                 : #else
    1143           17007 :         zend_compile_file = compile_file;
    1144           17007 :         zend_execute = execute;
    1145           17007 :         zend_execute_internal = NULL;
    1146                 : #endif /* HAVE_SYS_SDT_H */
    1147                 : 
    1148           17007 :         zend_compile_string = compile_string;
    1149           17007 :         zend_throw_exception_hook = NULL;
    1150                 : 
    1151           17007 :         zend_init_opcodes_handlers();
    1152                 : 
    1153                 :         /* set up version */
    1154           17007 :         zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
    1155           17007 :         zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
    1156                 : 
    1157           17007 :         GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
    1158           17007 :         GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
    1159           17007 :         GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
    1160           17007 :         GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
    1161                 : 
    1162           17007 :         zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
    1163           17007 :         zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
    1164           17007 :         zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, (dtor_func_t) zend_auto_global_dtor, 1, 0);
    1165           17007 :         zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
    1166                 : 
    1167           17007 :         zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
    1168           17007 :         zend_init_rsrc_list_dtors();
    1169                 : 
    1170                 :         /* This zval can be used to initialize allocate zval's to an uninit'ed value */
    1171           17007 :         Z_UNSET_ISREF(zval_used_for_init);
    1172           17007 :         Z_SET_REFCOUNT(zval_used_for_init, 1);
    1173           17007 :         Z_TYPE(zval_used_for_init) = IS_NULL;
    1174                 : 
    1175                 : #ifdef ZTS
    1176                 :         ts_allocate_id(&unicode_globals_id, sizeof(zend_unicode_globals), (ts_allocate_ctor) unicode_globals_ctor, (ts_allocate_dtor) unicode_globals_dtor);
    1177                 :         ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
    1178                 :         ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
    1179                 :         ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
    1180                 :         ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
    1181                 :         compiler_globals = ts_resource(compiler_globals_id);
    1182                 :         executor_globals = ts_resource(executor_globals_id);
    1183                 : 
    1184                 :         compiler_globals_dtor(compiler_globals TSRMLS_CC);
    1185                 :         compiler_globals->in_compilation = 0;
    1186                 :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
    1187                 :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
    1188                 : 
    1189                 :         *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
    1190                 :         *compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
    1191                 :         compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
    1192                 : 
    1193                 :         zend_hash_destroy(executor_globals->zend_constants);
    1194                 :         *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
    1195                 : #else
    1196           17007 :         unicode_globals_ctor(&unicode_globals TSRMLS_CC);
    1197           17007 :         ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
    1198           17007 :         php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
    1199           17007 :         zend_set_default_compile_time_values(TSRMLS_C);
    1200           17007 :         EG(user_error_handler) = NULL;
    1201           17007 :         EG(user_exception_handler) = NULL;
    1202                 : #endif
    1203                 : 
    1204           17007 :         zend_register_standard_constants(TSRMLS_C);
    1205           17007 :         zend_register_auto_global("GLOBALS", sizeof("GLOBALS") - 1, NULL TSRMLS_CC);
    1206                 : 
    1207                 : #ifndef ZTS
    1208           17007 :         zend_init_rsrc_plist(TSRMLS_C);
    1209           17007 :         zend_init_exception_op(TSRMLS_C);
    1210                 : #endif
    1211                 : 
    1212           17007 :         zend_ini_startup(TSRMLS_C);
    1213                 : 
    1214                 : #ifdef ZTS
    1215                 :         tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
    1216                 : #endif
    1217                 : 
    1218           17007 :         return SUCCESS;
    1219                 : }
    1220                 : /* }}} */
    1221                 : 
    1222                 : void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
    1223           17007 : {
    1224           17007 :         int module_number = 0;
    1225                 :         UConverter *old_runtime_encoding_conv;
    1226           17007 :         UErrorCode status = U_ZERO_ERROR;
    1227                 :                 
    1228           17007 :         REGISTER_INI_ENTRIES();
    1229                 : 
    1230                 :         /* Make copies of HashTables with UNICODE */
    1231           17007 :         old_runtime_encoding_conv = UG(runtime_encoding_conv);
    1232           17007 :         UG(runtime_encoding_conv) = ucnv_open("ASCII", &status);
    1233                 : 
    1234           17007 :         zend_hash_to_unicode(CG(function_table), (apply_func_t)function_to_unicode TSRMLS_CC);
    1235           17007 :         CG(function_table)->pDestructor = ZEND_U_FUNCTION_DTOR;
    1236           17007 :         zend_hash_to_unicode(CG(class_table), (apply_func_t)class_to_unicode TSRMLS_CC);
    1237           17007 :         zend_hash_to_unicode(CG(auto_globals), NULL TSRMLS_CC);
    1238           17007 :         zend_hash_to_unicode(EG(zend_constants), (apply_func_t)const_to_unicode TSRMLS_CC);
    1239           17007 :         EG(zend_constants)->pDestructor = ZEND_U_CONSTANT_DTOR;
    1240                 : 
    1241           17007 :         ucnv_close(UG(runtime_encoding_conv));
    1242           17007 :         UG(runtime_encoding_conv) = old_runtime_encoding_conv;
    1243                 : 
    1244           17007 :         zend_startup_builtin_functions(TSRMLS_C);
    1245           17007 : }
    1246                 : /* }}} */
    1247                 : 
    1248                 : /* Unlink the global (r/o) copies of the class, function and constant tables,
    1249                 :  * and use a fresh r/w copy for the startup thread
    1250                 :  */
    1251                 : void zend_post_startup(TSRMLS_D) /* {{{ */
    1252               0 : {
    1253                 : #ifdef ZTS
    1254                 :         zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
    1255                 :         zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
    1256                 : 
    1257                 :         *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
    1258                 :         *GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
    1259                 :         *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
    1260                 : 
    1261                 :         asp_tags_default = CG(asp_tags);
    1262                 :         short_tags_default = CG(short_tags);
    1263                 :         compiler_options_default = CG(compiler_options);
    1264                 : 
    1265                 :         zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
    1266                 :         free(compiler_globals->function_table);
    1267                 :         free(compiler_globals->class_table);
    1268                 :         compiler_globals_ctor(compiler_globals, tsrm_ls);
    1269                 :         free(EG(zend_constants));
    1270                 :         executor_globals_ctor(executor_globals, tsrm_ls);
    1271                 :         global_persistent_list = &EG(persistent_list);
    1272                 :         zend_copy_ini_directives(TSRMLS_C);
    1273                 : #endif
    1274               0 : }
    1275                 : /* }}} */
    1276                 : 
    1277                 : void zend_shutdown(TSRMLS_D) /* {{{ */
    1278           17039 : {
    1279                 : #ifdef ZEND_WIN32
    1280                 :         zend_shutdown_timeout_thread();
    1281                 : #endif
    1282           17039 :         zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
    1283           17039 :         zend_hash_graceful_reverse_destroy(&module_registry);
    1284                 : 
    1285           17039 :         zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
    1286           17039 :         zend_hash_destroy(GLOBAL_CLASS_TABLE);
    1287                 : 
    1288           17039 :         zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
    1289           17039 :         free(GLOBAL_AUTO_GLOBALS_TABLE);
    1290                 : 
    1291           17039 :         zend_shutdown_extensions(TSRMLS_C);
    1292           17039 :         free(zend_version_info);
    1293                 : 
    1294           17039 :         free(GLOBAL_FUNCTION_TABLE);
    1295           17039 :         free(GLOBAL_CLASS_TABLE);
    1296                 : 
    1297           17039 :         zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
    1298           17039 :         free(GLOBAL_CONSTANTS_TABLE);
    1299           17039 :         zend_shutdown_strtod();
    1300                 : 
    1301                 : #ifdef ZTS
    1302                 :         GLOBAL_FUNCTION_TABLE = NULL;
    1303                 :         GLOBAL_CLASS_TABLE = NULL;
    1304                 :         GLOBAL_AUTO_GLOBALS_TABLE = NULL;
    1305                 :         GLOBAL_CONSTANTS_TABLE = NULL;
    1306                 : #else
    1307           17039 :         unicode_globals_dtor(&unicode_globals TSRMLS_CC);
    1308                 : #endif
    1309           17039 :         zend_destroy_rsrc_list_dtors();
    1310                 : 
    1311                 :         /* free ICU cache and any open ICU item (collators, converters, ...) */
    1312                 :         /* u_cleanup(); */
    1313           17039 : }
    1314                 : /* }}} */
    1315                 : 
    1316                 : void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
    1317           17007 : {
    1318           17007 :         zend_uv = *utility_values;
    1319           17007 :         zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
    1320           17007 : }
    1321                 : /* }}} */
    1322                 : 
    1323                 : /* this should be compatible with the standard zenderror */
    1324                 : void zenderror(const char *error) /* {{{ */
    1325              29 : {
    1326              29 :         zend_error(E_PARSE, "%s", error);
    1327              29 : }
    1328                 : /* }}} */
    1329                 : 
    1330                 : BEGIN_EXTERN_C()
    1331                 : ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
    1332            1679 : {
    1333                 :         TSRMLS_FETCH();
    1334                 : 
    1335            1679 :         if (!EG(bailout)) {
    1336               0 :                 zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
    1337               0 :                 exit(-1);
    1338                 :         }
    1339            1679 :         CG(unclean_shutdown) = 1;
    1340            1679 :         CG(in_compilation) = EG(in_execution) = 0;
    1341            1679 :         EG(current_execute_data) = NULL;
    1342            1679 :         LONGJMP(*EG(bailout), FAILURE);
    1343                 : }
    1344                 : /* }}} */
    1345                 : END_EXTERN_C()
    1346                 : 
    1347                 : void zend_append_version_info(const zend_extension *extension) /* {{{ */
    1348               0 : {
    1349                 :         char *new_info;
    1350                 :         uint new_info_length;
    1351                 : 
    1352               0 :         new_info_length = sizeof("    with  v,  by \n")
    1353                 :                                                 + strlen(extension->name)
    1354                 :                                                 + strlen(extension->version)
    1355                 :                                                 + strlen(extension->copyright)
    1356                 :                                                 + strlen(extension->author);
    1357                 : 
    1358               0 :         new_info = (char *) malloc(new_info_length + 1);
    1359                 : 
    1360               0 :         sprintf(new_info, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
    1361                 : 
    1362               0 :         zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
    1363               0 :         strcat(zend_version_info, new_info);
    1364               0 :         zend_version_info_length += new_info_length;
    1365               0 :         free(new_info);
    1366               0 : }
    1367                 : /* }}} */
    1368                 : 
    1369                 : ZEND_API char *get_zend_version(void) /* {{{ */
    1370              53 : {
    1371              53 :         return zend_version_info;
    1372                 : }
    1373                 : /* }}} */
    1374                 : 
    1375                 : ZEND_API void zend_reset_locale_deps(TSRMLS_D) /* {{{ */
    1376           17017 : {
    1377                 :         UCollator *coll;
    1378           17017 :         UErrorCode status = U_ZERO_ERROR;
    1379                 : 
    1380           17017 :         if (UG(default_collator)) {
    1381              24 :                 zend_collator_destroy(UG(default_collator));
    1382                 :         }
    1383           17017 :         coll = ucol_open(UG(default_locale), &status);
    1384           17017 :         if (U_FAILURE(status)) {
    1385               0 :                 zend_error(E_ERROR, "Could not open collator for locale %s", UG(default_locale));
    1386                 :         }
    1387           17017 :         UG(default_collator) = zend_collator_create(coll);
    1388           17017 : }
    1389                 : /* }}} */
    1390                 : 
    1391                 : static void init_unicode_request_globals(TSRMLS_D) /* {{{ */
    1392           16993 : {
    1393           16993 :         UG(default_locale) = safe_estrdup(uloc_getDefault());
    1394           16993 :         UG(default_collator) = NULL;
    1395                 : 
    1396           16993 :         if (strcmp(UG(request_encoding_def), "binary") != 0) {
    1397           16993 :                 if (zend_set_converter_encoding(&UG(request_encoding_conv), UG(request_encoding_def)) == FAILURE) {
    1398               0 :                         zend_error(E_CORE_ERROR, "Unrecognized encoding '%s' used for request_encoding", UG(request_encoding_def));
    1399               0 :                         return;
    1400                 :                 }
    1401           16993 :                 zend_set_converter_error_mode(UG(request_encoding_conv), ZEND_TO_UNICODE, ZEND_CONV_ERROR_STOP);
    1402                 :         }
    1403                 : 
    1404           16993 :         zend_reset_locale_deps(TSRMLS_C);
    1405                 : }
    1406                 : /* }}} */
    1407                 : 
    1408                 : static void shutdown_unicode_request_globals(TSRMLS_D) /* {{{ */
    1409           17025 : {
    1410           17025 :         if (UG(request_encoding_conv)) {
    1411           17025 :                 ucnv_close(UG(request_encoding_conv));
    1412           17025 :                 UG(request_encoding_conv) = NULL;
    1413                 :         }
    1414           17025 :         zend_collator_destroy(UG(default_collator));
    1415           17025 :         efree(UG(default_locale));
    1416           17025 : }
    1417                 : /* }}} */
    1418                 : 
    1419                 : void zend_activate(TSRMLS_D) /* {{{ */
    1420           16993 : {
    1421           16993 :         gc_reset(TSRMLS_C);
    1422           16993 :         init_unicode_request_globals(TSRMLS_C);
    1423           16993 :         init_unicode_strings();
    1424           16993 :         init_compiler(TSRMLS_C);
    1425           16993 :         init_executor(TSRMLS_C);
    1426           16993 :         startup_scanner(TSRMLS_C);
    1427           16993 : }
    1428                 : /* }}} */
    1429                 : 
    1430                 : void zend_activate_modules(TSRMLS_D) /* {{{ */
    1431           16993 : {
    1432           16993 :         zend_hash_apply(&module_registry, (apply_func_t) module_registry_request_startup TSRMLS_CC);
    1433           16993 : }
    1434                 : /* }}} */
    1435                 : 
    1436                 : void zend_deactivate_modules(TSRMLS_D) /* {{{ */
    1437           17025 : {
    1438           17025 :         EG(opline_ptr) = NULL; /* we're no longer executing anything */
    1439                 : 
    1440           17025 :         zend_try {
    1441           17025 :                 zend_hash_reverse_apply(&module_registry, (apply_func_t) module_registry_cleanup TSRMLS_CC);
    1442           17025 :         } zend_end_try();
    1443           17025 : }
    1444                 : /* }}} */
    1445                 : 
    1446                 : void zend_call_destructors(TSRMLS_D) /* {{{ */
    1447           17025 : {
    1448           17025 :         zend_try {
    1449           17025 :                 shutdown_destructors(TSRMLS_C);
    1450           17025 :         } zend_end_try();
    1451           17025 : }
    1452                 : /* }}} */
    1453                 : 
    1454                 : void zend_deactivate(TSRMLS_D) /* {{{ */
    1455           17025 : {
    1456                 :         /* we're no longer executing anything */
    1457           17025 :         EG(opline_ptr) = NULL;
    1458           17025 :         EG(active_symbol_table) = NULL;
    1459                 : 
    1460           17025 :         shutdown_unicode_request_globals(TSRMLS_C);
    1461                 : 
    1462           17025 :         zend_try {
    1463           17025 :                 shutdown_scanner(TSRMLS_C);
    1464           17025 :         } zend_end_try();
    1465                 : 
    1466                 :         /* shutdown_executor() takes care of its own bailout handling */
    1467           17025 :         shutdown_executor(TSRMLS_C);
    1468                 : 
    1469           17025 :         zend_try {
    1470           17025 :                 shutdown_compiler(TSRMLS_C);
    1471           17025 :         } zend_end_try();
    1472                 : 
    1473           17025 :         zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
    1474                 : 
    1475                 : #ifdef ZEND_DEBUG
    1476           17025 :         if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
    1477           15546 :                 gc_collect_cycles(TSRMLS_C);
    1478                 :         }
    1479                 : #endif
    1480                 : 
    1481                 : #if GC_BENCH
    1482                 :         fprintf(stderr, "GC Statistics\n");
    1483                 :         fprintf(stderr, "-------------\n");
    1484                 :         fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
    1485                 :         fprintf(stderr, "Collected:          %d\n", GC_G(collected));
    1486                 :         fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
    1487                 :         fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
    1488                 :         fprintf(stderr, "      Possible            Remove from  Marked\n");
    1489                 :         fprintf(stderr, "        Root    Buffered     buffer     grey\n");
    1490                 :         fprintf(stderr, "      --------  --------  -----------  ------\n");
    1491                 :         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));
    1492                 :         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));
    1493                 : #endif
    1494                 : 
    1495           17025 :         zend_try {
    1496           17025 :                 zend_ini_deactivate(TSRMLS_C);
    1497           17025 :         } zend_end_try();
    1498           17025 : }
    1499                 : /* }}} */
    1500                 : 
    1501                 : static int exec_done_cb(zend_module_entry *module TSRMLS_DC) /* {{{ */
    1502         1175047 : {
    1503         1175047 :         if (module->post_deactivate_func) {
    1504               0 :                 module->post_deactivate_func();
    1505                 :         }
    1506         1175047 :         return 0;
    1507                 : }
    1508                 : /* }}} */
    1509                 : 
    1510                 : void zend_post_deactivate_modules(TSRMLS_D) /* {{{ */
    1511           17025 : {
    1512           17025 :         zend_hash_apply(&module_registry, (apply_func_t) exec_done_cb TSRMLS_CC);
    1513           17025 :         zend_hash_reverse_apply(&module_registry, (apply_func_t) module_registry_unload_temp TSRMLS_CC);
    1514           17025 : }
    1515                 : /* }}} */
    1516                 : 
    1517                 : BEGIN_EXTERN_C()
    1518                 : ZEND_API void zend_message_dispatcher(long message, void *data TSRMLS_DC) /* {{{ */
    1519              31 : {
    1520              31 :         if (zend_message_dispatcher_p) {
    1521              31 :                 zend_message_dispatcher_p(message, data TSRMLS_CC);
    1522                 :         }
    1523              28 : }
    1524                 : /* }}} */
    1525                 : END_EXTERN_C()
    1526                 : 
    1527                 : ZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */
    1528         3710152 : {
    1529         3710152 :         if (zend_get_configuration_directive_p) {
    1530         3710152 :                 return zend_get_configuration_directive_p(name, name_length, contents);
    1531                 :         } else {
    1532               0 :                 return FAILURE;
    1533                 :         }
    1534                 : }
    1535                 : /* }}} */
    1536                 : 
    1537                 : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
    1538         2726771 : {
    1539                 :         va_list args;
    1540                 :         va_list usr_copy;
    1541                 :         zval ***params;
    1542                 :         zval *retval;
    1543                 :         zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context;
    1544                 :         char *error_filename;
    1545                 :         uint error_lineno;
    1546                 :         zval *orig_user_error_handler;
    1547                 :         zend_bool in_compilation;
    1548                 :         zend_class_entry *saved_class_entry;
    1549                 :         TSRMLS_FETCH();
    1550                 : 
    1551                 :         /* Obtain relevant filename and lineno */
    1552         2726771 :         switch (type) {
    1553                 :                 case E_CORE_ERROR:
    1554                 :                 case E_CORE_WARNING:
    1555               1 :                         error_filename = NULL;
    1556               1 :                         error_lineno = 0;
    1557               1 :                         break;
    1558                 :                 case E_PARSE:
    1559                 :                 case E_COMPILE_ERROR:
    1560                 :                 case E_COMPILE_WARNING:
    1561                 :                 case E_ERROR:
    1562                 :                 case E_NOTICE:
    1563                 :                 case E_STRICT:
    1564                 :                 case E_DEPRECATED:
    1565                 :                 case E_WARNING:
    1566                 :                 case E_USER_ERROR:
    1567                 :                 case E_USER_WARNING:
    1568                 :                 case E_USER_NOTICE:
    1569                 :                 case E_USER_DEPRECATED:
    1570                 :                 case E_RECOVERABLE_ERROR:
    1571         2726770 :                         if (zend_is_compiling(TSRMLS_C)) {
    1572             267 :                                 error_filename = zend_get_compiled_filename(TSRMLS_C);
    1573             267 :                                 error_lineno = zend_get_compiled_lineno(TSRMLS_C);
    1574         2726503 :                         } else if (zend_is_executing(TSRMLS_C)) {
    1575         2726478 :                                 error_filename = zend_get_executed_filename(TSRMLS_C);
    1576         2726478 :                                 error_lineno = zend_get_executed_lineno(TSRMLS_C);
    1577                 :                         } else {
    1578              25 :                                 error_filename = NULL;
    1579              25 :                                 error_lineno = 0;
    1580                 :                         }
    1581         2726770 :                         break;
    1582                 :                 default:
    1583               0 :                         error_filename = NULL;
    1584               0 :                         error_lineno = 0;
    1585                 :                         break;
    1586                 :         }
    1587         2726771 :         if (!error_filename) {
    1588              26 :                 error_filename = "Unknown";
    1589                 :         }
    1590                 : 
    1591         2726771 :         va_start(args, format);
    1592                 : 
    1593                 : #ifdef HAVE_DTRACE
    1594                 :         if(DTRACE_ERROR_ENABLED()) {
    1595                 :                 char *dtrace_error_buffer;
    1596                 :                 zend_vspprintf(&dtrace_error_buffer, 0, format, args);
    1597                 :                 DTRACE_ERROR(dtrace_error_buffer, error_filename, error_lineno);
    1598                 :                 efree(dtrace_error_buffer);
    1599                 :         }
    1600                 : #endif /* HAVE_DTRACE */
    1601                 : 
    1602                 : 
    1603                 :         /* if we don't have a user defined error handler */
    1604         5450512 :         if (!EG(user_error_handler)
    1605                 :                 || !(EG(user_error_handler_error_reporting) & type)
    1606                 :                 || EG(error_handling) != EH_NORMAL) {
    1607         2724254 :                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1608            2517 :         } else switch (type) {
    1609                 :                 case E_ERROR:
    1610                 :                 case E_PARSE:
    1611                 :                 case E_CORE_ERROR:
    1612                 :                 case E_CORE_WARNING:
    1613                 :                 case E_COMPILE_ERROR:
    1614                 :                 case E_COMPILE_WARNING:
    1615                 :                         /* The error may not be safe to handle in user-space */
    1616               1 :                         zend_error_cb(type, error_filename, error_lineno, format, args);
    1617               0 :                         break;
    1618                 :                 default:
    1619                 :                         /* Handle the error in user space */
    1620            2516 :                         ALLOC_INIT_ZVAL(z_error_message);
    1621            2516 :                         ALLOC_INIT_ZVAL(z_error_type);
    1622            2516 :                         ALLOC_INIT_ZVAL(z_error_filename);
    1623            2516 :                         ALLOC_INIT_ZVAL(z_error_lineno);
    1624            2516 :                         ALLOC_INIT_ZVAL(z_context);
    1625                 : 
    1626                 : /* va_copy() is __va_copy() in old gcc versions.
    1627                 :  * According to the autoconf manual, using
    1628                 :  * memcpy(&dst, &src, sizeof(va_list))
    1629                 :  * gives maximum portability. */
    1630                 : #ifndef va_copy
    1631                 : # ifdef __va_copy
    1632                 : #  define va_copy(dest, src)    __va_copy((dest), (src))
    1633                 : # else
    1634                 : #  define va_copy(dest, src)    memcpy(&(dest), &(src), sizeof(va_list))
    1635                 : # endif
    1636                 : #endif
    1637            2516 :                         va_copy(usr_copy, args);
    1638            2516 :                         Z_STRLEN_P(z_error_message) = zend_vspprintf(&Z_STRVAL_P(z_error_message), 0, format, usr_copy);
    1639            2516 :                         Z_TYPE_P(z_error_message) = IS_STRING;
    1640                 :                         {
    1641            2516 :                                 char *str = Z_STRVAL_P(z_error_message);
    1642            2516 :                                 int len  = Z_STRLEN_P(z_error_message);
    1643                 : 
    1644            2516 :                                 ZVAL_RT_STRINGL(z_error_message, str, len, 1);
    1645            2516 :                                 efree(str);
    1646                 :                         }
    1647                 : #ifdef va_copy
    1648            2516 :                         va_end(usr_copy);
    1649                 : #endif
    1650                 : 
    1651            2516 :                         Z_LVAL_P(z_error_type) = type;
    1652            2516 :                         Z_TYPE_P(z_error_type) = IS_LONG;
    1653                 : 
    1654            2516 :                         if (error_filename) {
    1655            2516 :                                 ZVAL_RT_STRING(z_error_filename, error_filename, 1);
    1656                 :                         }
    1657                 : 
    1658            2516 :                         Z_LVAL_P(z_error_lineno) = error_lineno;
    1659            2516 :                         Z_TYPE_P(z_error_lineno) = IS_LONG;
    1660                 : 
    1661            2516 :                         if (!EG(active_symbol_table)) {
    1662              19 :                                 zend_rebuild_symbol_table(TSRMLS_C);
    1663                 :                         }
    1664                 :                         /* during shutdown the symbol table table can be still null */
    1665            2516 :                         if (!EG(active_symbol_table)) {
    1666               0 :                                 Z_TYPE_P(z_context) = IS_NULL;
    1667                 :                         } else {
    1668            2516 :                                 Z_ARRVAL_P(z_context) = EG(active_symbol_table);
    1669            2516 :                                 Z_TYPE_P(z_context) = IS_ARRAY;
    1670            2516 :                                 zval_copy_ctor(z_context);
    1671                 :                         }
    1672                 : 
    1673            2516 :                         params = (zval ***) emalloc(sizeof(zval **)*5);
    1674            2516 :                         params[0] = &z_error_type;
    1675            2516 :                         params[1] = &z_error_message;
    1676            2516 :                         params[2] = &z_error_filename;
    1677            2516 :                         params[3] = &z_error_lineno;
    1678            2516 :                         params[4] = &z_context;
    1679                 : 
    1680            2516 :                         orig_user_error_handler = EG(user_error_handler);
    1681            2516 :                         EG(user_error_handler) = NULL;
    1682                 : 
    1683                 :                         /* User error handler may include() additinal PHP files.
    1684                 :                          * If an error was generated during comilation PHP will compile
    1685                 :                          * such scripts recursivly, but some CG() variables may be
    1686                 :                          * inconsistent. */
    1687                 : 
    1688            2516 :                         in_compilation = zend_is_compiling(TSRMLS_C);
    1689            2516 :                         if (in_compilation) {
    1690               1 :                                 saved_class_entry = CG(active_class_entry);
    1691               1 :                                 CG(active_class_entry) = NULL;
    1692                 :                         }
    1693                 : 
    1694            2516 :                         if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC) == SUCCESS) {
    1695            2515 :                                 if (retval) {
    1696            2500 :                                         if (Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval) == 0) {
    1697               1 :                                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1698                 :                                         }
    1699            2500 :                                         zval_ptr_dtor(&retval);
    1700                 :                                 }
    1701               0 :                         } else if (!EG(exception)) {
    1702                 :                                 /* The user error handler failed, use built-in error handler */
    1703               0 :                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1704                 :                         }
    1705                 : 
    1706            2515 :                         if (in_compilation) {
    1707               0 :                                 CG(active_class_entry) = saved_class_entry;
    1708                 :                         }
    1709                 : 
    1710            2515 :                         if (!EG(user_error_handler)) {
    1711            2515 :                                 EG(user_error_handler) = orig_user_error_handler;
    1712                 :                         }
    1713                 :                         else {
    1714               0 :                                 zval_ptr_dtor(&orig_user_error_handler);
    1715                 :                         }
    1716                 : 
    1717            2515 :                         efree(params);
    1718            2515 :                         zval_ptr_dtor(&z_error_message);
    1719            2515 :                         zval_ptr_dtor(&z_error_type);
    1720            2515 :                         zval_ptr_dtor(&z_error_filename);
    1721            2515 :                         zval_ptr_dtor(&z_error_lineno);
    1722            2515 :                         zval_ptr_dtor(&z_context);
    1723                 :                         break;
    1724                 :         }
    1725                 : 
    1726         2726256 :         va_end(args);
    1727                 : 
    1728         2726256 :         if (type == E_PARSE) {
    1729              29 :                 EG(exit_status) = 255;
    1730              29 :                 zend_init_compiler_data_structures(TSRMLS_C);
    1731                 :         }
    1732         2726256 : }
    1733                 : /* }}} */
    1734                 : 
    1735                 : #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)
    1736                 : void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
    1737                 : #endif
    1738                 : 
    1739                 : ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */
    1740               0 : {
    1741                 : #if ZEND_DEBUG
    1742                 :         va_list args;
    1743                 : 
    1744                 :         va_start(args, format);
    1745                 : #       ifdef ZEND_WIN32
    1746                 :         {
    1747                 :                 char output_buf[1024];
    1748                 : 
    1749                 :                 vsnprintf(output_buf, 1024, format, args);
    1750                 :                 OutputDebugString(output_buf);
    1751                 :                 OutputDebugString("\n");
    1752                 :                 if (trigger_break && IsDebuggerPresent()) {
    1753                 :                         DebugBreak();
    1754                 :                 }
    1755                 :         }
    1756                 : #       else
    1757                 :         vfprintf(stderr, format, args);
    1758                 :         fprintf(stderr, "\n");
    1759                 : #       endif
    1760                 :         va_end(args);
    1761                 : #endif
    1762               0 : }
    1763                 : /* }}} */
    1764                 : 
    1765                 : ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...) /* {{{ */
    1766           16913 : {
    1767                 :         va_list files;
    1768                 :         int i;
    1769                 :         zend_file_handle *file_handle;
    1770           16913 :         zend_op_array *orig_op_array = EG(active_op_array);
    1771           16913 :         zval **orig_retval_ptr_ptr = EG(return_value_ptr_ptr);
    1772                 : 
    1773           16913 :         va_start(files, file_count);
    1774           64780 :         for (i = 0; i < file_count; i++) {
    1775           49303 :                 file_handle = va_arg(files, zend_file_handle *);
    1776           49303 :                 if (!file_handle) {
    1777           32389 :                         continue;
    1778                 :                 }
    1779           16914 :                 EG(active_op_array) = zend_compile_file(file_handle, type TSRMLS_CC);
    1780           16747 :                 if (file_handle->opened_path) {
    1781           16743 :                         int dummy = 1;
    1782           16743 :                         zend_hash_add(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path) + 1, (void *)&dummy, sizeof(int), NULL);
    1783                 :                 }
    1784           16747 :                 zend_destroy_file_handle(file_handle TSRMLS_CC);
    1785           16747 :                 if (EG(active_op_array)) {
    1786           16747 :                         EG(return_value_ptr_ptr) = retval ? retval : NULL;
    1787           16747 :                         zend_execute(EG(active_op_array) TSRMLS_CC);
    1788           15562 :                         zend_exception_restore(TSRMLS_C);
    1789           15562 :                         if (EG(exception)) {
    1790              92 :                                 EG(opline_ptr) = NULL;
    1791              92 :                                 if (EG(user_exception_handler)) {
    1792                 :                                         zval *orig_user_exception_handler;
    1793                 :                                         zval **params[1], *retval2, *old_exception;
    1794               9 :                                         old_exception = EG(exception);
    1795               9 :                                         EG(exception) = NULL;
    1796               9 :                                         params[0] = &old_exception;
    1797               9 :                                         orig_user_exception_handler = EG(user_exception_handler);
    1798               9 :                                         if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
    1799               8 :                                                 if (retval2 != NULL) {
    1800               8 :                                                         zval_ptr_dtor(&retval2);
    1801                 :                                                 }
    1802               8 :                                                 if (EG(exception)) {
    1803               0 :                                                         zval_ptr_dtor(&EG(exception));
    1804               0 :                                                         EG(exception) = NULL;
    1805                 :                                                 }
    1806               8 :                                                 zval_ptr_dtor(&old_exception);
    1807                 :                                         } else {
    1808               0 :                                                 EG(exception) = old_exception;
    1809               0 :                                                 zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1810                 :                                         }
    1811                 :                                 } else {
    1812              83 :                                         zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    1813                 :                                 }
    1814                 :                         }
    1815           15478 :                         destroy_op_array(EG(active_op_array) TSRMLS_CC);
    1816           15478 :                         efree(EG(active_op_array));
    1817               0 :                 } else if (type==ZEND_REQUIRE) {
    1818               0 :                         va_end(files);
    1819               0 :                         EG(active_op_array) = orig_op_array;
    1820               0 :                         EG(return_value_ptr_ptr) = orig_retval_ptr_ptr;
    1821               0 :                         return FAILURE;
    1822                 :                 }
    1823                 :         }
    1824           15477 :         va_end(files);
    1825           15477 :         EG(active_op_array) = orig_op_array;
    1826           15477 :         EG(return_value_ptr_ptr) = orig_retval_ptr_ptr;
    1827                 : 
    1828           15477 :         return SUCCESS;
    1829                 : }
    1830                 : /* }}} */
    1831                 : 
    1832                 : #define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
    1833                 : 
    1834                 : ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC) /* {{{ */
    1835             959 : {
    1836                 :         char *cur_filename;
    1837                 :         int cur_lineno;
    1838                 :         char *compiled_string_description;
    1839                 : 
    1840             959 :         if (zend_is_compiling(TSRMLS_C)) {
    1841               0 :                 cur_filename = zend_get_compiled_filename(TSRMLS_C);
    1842               0 :                 cur_lineno = zend_get_compiled_lineno(TSRMLS_C);
    1843             959 :         } else if (zend_is_executing(TSRMLS_C)) {
    1844             959 :                 cur_filename = zend_get_executed_filename(TSRMLS_C);
    1845             959 :                 cur_lineno = zend_get_executed_lineno(TSRMLS_C);
    1846                 :         } else {
    1847               0 :                 cur_filename = "Unknown";
    1848               0 :                 cur_lineno = 0;
    1849                 :         }
    1850                 : 
    1851             959 :         zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
    1852             959 :         return compiled_string_description;
    1853                 : }
    1854                 : /* }}} */
    1855                 : 
    1856                 : void free_estring(char **str_p) /* {{{ */
    1857           41602 : {
    1858           41602 :         efree(*str_p);
    1859           41602 : }
    1860                 : /* }}} */
    1861                 : 
    1862                 : /*
    1863                 :  * Local variables:
    1864                 :  * tab-width: 4
    1865                 :  * c-basic-offset: 4
    1866                 :  * indent-tabs-mode: t
    1867                 :  * End:
    1868                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Mon, 23 Nov 2009 17:39:26 +0000 (33 hours ago)

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