LTP GCOV extension - code coverage report
Current view: directory - Zend - zend.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 504
Code covered: 57.7 % Executed lines: 291
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5