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

LCOV - code coverage report
Current view: top level - Zend - zend.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 483 546 88.5 %
Date: 2014-04-18 Functions: 34 38 89.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:23 +0000 (2 days ago)

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