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

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_5_2/Zend - zend.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 504
Code covered: 85.7 % Executed lines: 432
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | Zend Engine                                                          |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1998-2009 Zend Technologies Ltd. (http://www.zend.com) |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 2.00 of the Zend license,     |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.zend.com/license/2_00.txt.                                |
      11                 :    | If you did not receive a copy of the Zend license and are unable to  |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@zend.com so we can mail you a copy immediately.              |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16                 :    |          Zeev Suraski <zeev@zend.com>                                |
      17                 :    +----------------------------------------------------------------------+
      18                 : */
      19                 : 
      20                 : /* $Id: zend.c 282249 2009-06-16 16:09:04Z rasmus $ */
      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         1700478 : {
      69         1700478 :         if (!new_value) {
      70             101 :                 EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT;
      71                 :         } else {
      72         1700377 :                 EG(error_reporting) = atoi(new_value);
      73                 :         }
      74         1700478 :         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-2009 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             738 : {
     111                 :         zval **tmp;
     112                 :         char *string_key;
     113                 :         HashPosition iterator;
     114                 :         ulong num_key;
     115                 :         uint str_len;
     116                 :         int i;
     117                 : 
     118            2938 :         for (i=0; i<indent; i++) {
     119            2200 :                 ZEND_PUTS_EX(" ");
     120                 :         }
     121             738 :         ZEND_PUTS_EX("(\n");
     122             738 :         indent += PRINT_ZVAL_INDENT;
     123             738 :         zend_hash_internal_pointer_reset_ex(ht, &iterator);
     124            4038 :         while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
     125           21466 :                 for (i=0; i<indent; i++) {
     126           18904 :                         ZEND_PUTS_EX(" ");
     127                 :                 }
     128            2562 :                 ZEND_PUTS_EX("[");
     129            2562 :                 switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
     130                 :                         case HASH_KEY_IS_STRING:
     131            1231 :                                 if (is_object) {
     132                 :                                         char *prop_name, *class_name;
     133                 : 
     134             485 :                                         int mangled = zend_unmangle_property_name(string_key, str_len-1, &class_name, &prop_name);
     135             485 :                                         ZEND_PUTS_EX(prop_name);
     136             485 :                                         if (class_name && mangled == SUCCESS) {
     137             183 :                                                 if (class_name[0]=='*') {
     138              87 :                                                         ZEND_PUTS_EX(":protected");
     139                 :                                                 } else {
     140              96 :                                                         ZEND_PUTS_EX(":private");
     141                 :                                                 }
     142                 :                                         }
     143                 :                                 } else {
     144             746 :                                         ZEND_WRITE_EX(string_key, str_len-1);
     145                 :                                 }
     146            1231 :                                 break;
     147                 :                         case HASH_KEY_IS_LONG:
     148                 :                                 {
     149                 :                                         char key[25];
     150            1331 :                                         snprintf(key, sizeof(key), "%ld", num_key);
     151            1331 :                                         ZEND_PUTS_EX(key);
     152                 :                                 }
     153                 :                                 break;
     154                 :                 }
     155            2562 :                 ZEND_PUTS_EX("] => ");
     156            2562 :                 zend_print_zval_r_ex(write_func, *tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
     157            2562 :                 ZEND_PUTS_EX("\n");
     158            2562 :                 zend_hash_move_forward_ex(ht, &iterator);
     159                 :         }
     160             738 :         indent -= PRINT_ZVAL_INDENT;
     161            2938 :         for (i=0; i<indent; i++) {
     162            2200 :                 ZEND_PUTS_EX(" ");
     163                 :         }
     164             738 :         ZEND_PUTS_EX(")\n");
     165             738 : }
     166                 : 
     167                 : static void print_flat_hash(HashTable *ht TSRMLS_DC)
     168              35 : {
     169                 :     zval **tmp;
     170                 :     char *string_key;
     171                 :     HashPosition iterator;
     172                 :     ulong num_key;
     173                 :     uint str_len;
     174              35 :     int i = 0;
     175                 : 
     176              35 :     zend_hash_internal_pointer_reset_ex(ht, &iterator);
     177             509 :     while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
     178             439 :         if (i++ > 0) {
     179             422 :             ZEND_PUTS(",");
     180                 :         }
     181             439 :         ZEND_PUTS("[");
     182             439 :         switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
     183                 :             case HASH_KEY_IS_STRING:
     184             433 :                 ZEND_PUTS(string_key);
     185             433 :                 break;
     186                 :             case HASH_KEY_IS_LONG:
     187               6 :                 zend_printf("%ld", num_key);
     188                 :                 break;
     189                 :         }
     190             439 :         ZEND_PUTS("] => ");
     191             439 :         zend_print_flat_zval_r(*tmp TSRMLS_CC);
     192             439 :         zend_hash_move_forward_ex(ht, &iterator);
     193                 :     }
     194              35 : }
     195                 : 
     196                 : ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy)
     197         5086185 : {
     198         5086185 :         if (expr->type==IS_STRING) {
     199         3835145 :                 *use_copy = 0;
     200         3835145 :                 return;
     201                 :         }
     202         1251040 :         switch (expr->type) {
     203                 :                 case IS_NULL:
     204            1296 :                         expr_copy->value.str.len = 0;
     205            1296 :                         expr_copy->value.str.val = STR_EMPTY_ALLOC();
     206            1296 :                         break;
     207                 :                 case IS_BOOL:
     208           17218 :                         if (expr->value.lval) {
     209            1414 :                                 expr_copy->value.str.len = 1;
     210            1414 :                                 expr_copy->value.str.val = estrndup("1", 1);
     211                 :                         } else {
     212           15804 :                                 expr_copy->value.str.len = 0;
     213           15804 :                                 expr_copy->value.str.val = STR_EMPTY_ALLOC();
     214                 :                         }
     215           17218 :                         break;
     216                 :                 case IS_RESOURCE:
     217            4807 :                         expr_copy->value.str.len = zend_spprintf(&expr_copy->value.str.val, 0, "Resource id #%ld", expr->value.lval);
     218            4807 :                         break;
     219                 :                 case IS_ARRAY:
     220             947 :                         expr_copy->value.str.len = sizeof("Array")-1;
     221             947 :                         expr_copy->value.str.val = estrndup("Array", expr_copy->value.str.len);
     222             947 :                         break;
     223                 :                 case IS_OBJECT:
     224                 :                         {
     225                 :                                 TSRMLS_FETCH();
     226                 : 
     227          100857 :                                 if(Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
     228          100801 :                                         break;
     229                 :                                 }
     230                 :                                 /* Standard PHP objects */
     231              55 :                                 if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HANDLER_P(expr, cast_object)) {
     232              55 :                                         if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
     233               0 :                                                 break;
     234                 :                                         }
     235                 :                                 }
     236              55 :                                 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              55 :                                 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              48 :                                 expr_copy->value.str.len = 0;
     254              48 :                                 expr_copy->value.str.val = STR_EMPTY_ALLOC();
     255                 :                         }
     256              48 :                         break;
     257                 :                 case IS_DOUBLE:
     258           16729 :                         *expr_copy = *expr;
     259           16729 :                         zval_copy_ctor(expr_copy);
     260           16729 :                         zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
     261           16729 :                         break;
     262                 :                 default:
     263         1109186 :                         *expr_copy = *expr;
     264         1109186 :                         zval_copy_ctor(expr_copy);
     265         1109186 :                         convert_to_string(expr_copy);
     266                 :                         break;
     267                 :         }
     268         1251032 :         expr_copy->type = IS_STRING;
     269         1251032 :         *use_copy = 1;
     270                 : }
     271                 : 
     272                 : 
     273                 : ZEND_API int zend_print_zval(zval *expr, int indent)
     274          187278 : {
     275          187278 :         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          189872 : {
     281                 :         zval expr_copy;
     282                 :         int use_copy;
     283                 : 
     284          189872 :         zend_make_printable_zval(expr, &expr_copy, &use_copy);
     285          189872 :         if (use_copy) {
     286            3159 :                 expr = &expr_copy;
     287                 :         }
     288          189872 :         if (expr->value.str.len==0) { /* optimize away empty strings */
     289             619 :                 if (use_copy) {
     290             475 :                         zval_dtor(expr);
     291                 :                 }
     292             619 :                 return 0;
     293                 :         }
     294          189253 :         write_func(expr->value.str.val, expr->value.str.len);
     295          189251 :         if (use_copy) {
     296            2684 :                 zval_dtor(expr);
     297                 :         }
     298          189251 :         return expr->value.str.len;
     299                 : }
     300                 : 
     301                 : ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC)
     302             456 : {
     303             456 :     switch (expr->type) {
     304                 :         case IS_ARRAY:
     305              37 :             ZEND_PUTS("Array (");
     306              37 :             if (++expr->value.ht->nApplyCount>1) {
     307               2 :                 ZEND_PUTS(" *RECURSION*");
     308               2 :                 expr->value.ht->nApplyCount--;
     309               2 :                 return;
     310                 :             }
     311              35 :             print_flat_hash(expr->value.ht TSRMLS_CC);
     312              35 :             ZEND_PUTS(")");
     313              35 :             expr->value.ht->nApplyCount--;
     314              35 :             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             419 :             zend_print_variable(expr);
     345                 :             break;
     346                 :     }
     347                 : }
     348                 : 
     349                 : ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC)
     350             776 : {
     351             776 :         zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
     352             776 : }
     353                 : 
     354                 : 
     355                 : ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC)
     356            3339 : {
     357            3339 :         switch (expr->type) {
     358                 :                 case IS_ARRAY:
     359             553 :                         ZEND_PUTS_EX("Array\n");
     360             553 :                         if (++expr->value.ht->nApplyCount>1) {
     361               0 :                                 ZEND_PUTS_EX(" *RECURSION*");
     362               0 :                                 expr->value.ht->nApplyCount--;
     363               0 :                                 return;
     364                 :                         }
     365             553 :                         print_hash(write_func, expr->value.ht, indent, 0 TSRMLS_CC);
     366             553 :                         expr->value.ht->nApplyCount--;
     367             553 :                         break;
     368                 :                 case IS_OBJECT:
     369                 :                         {
     370             192 :                                 HashTable *properties = NULL;
     371             192 :                                 char *class_name = NULL;
     372                 :                                 zend_uint clen;
     373                 :                                 
     374             192 :                                 if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
     375             192 :                                         Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
     376                 :                                 }
     377             192 :                                 if (class_name) {
     378             192 :                                         ZEND_PUTS_EX(class_name);
     379                 :                                 } else {
     380               0 :                                         ZEND_PUTS_EX("Unknown Class");
     381                 :                                 }
     382             192 :                                 ZEND_PUTS_EX(" Object\n");
     383             192 :                                 if (class_name) {
     384             192 :                                         efree(class_name);
     385                 :                                 }
     386             192 :                                 if (Z_OBJ_HANDLER_P(expr, get_properties)) {
     387             192 :                                         properties = Z_OBJPROP_P(expr);
     388                 :                                 }
     389             192 :                                 if (properties) {
     390             192 :                                         if (++properties->nApplyCount>1) {
     391               7 :                                                 ZEND_PUTS_EX(" *RECURSION*");
     392               7 :                                                 properties->nApplyCount--;
     393               7 :                                                 return;
     394                 :                                         }
     395             185 :                                         print_hash(write_func, properties, indent, 1 TSRMLS_CC);
     396             185 :                                         properties->nApplyCount--;
     397                 :                                 }
     398             185 :                                 break;
     399                 :                         }
     400                 :                 default:
     401            2594 :                         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           13565 : {
     418           13565 :         zend_standard_class_def = calloc(1, sizeof(zend_class_entry));
     419                 : 
     420           13565 :         zend_standard_class_def->type = ZEND_INTERNAL_CLASS;
     421           13565 :         zend_standard_class_def->name_length = sizeof("stdClass") - 1;
     422           13565 :         zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
     423           13565 :         zend_initialize_class_data(zend_standard_class_def, 1 TSRMLS_CC);
     424                 : 
     425           13565 :         zend_hash_add(CG(class_table), "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL);
     426           13565 : }
     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           13565 : {
     442                 :         /* default compile-time values */
     443           13565 :         CG(asp_tags) = asp_tags_default;
     444           13565 :         CG(short_tags) = short_tags_default;
     445           13565 :         CG(allow_call_time_pass_reference) = ct_pass_ref_default;
     446           13565 :         CG(extended_info) = extended_info_default;
     447           13565 : }
     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           27130 : {
     550           27130 :         scanner_globals_p->c_buf_p = (char *) 0;
     551           27130 :         scanner_globals_p->init = 1;
     552           27130 :         scanner_globals_p->start = 0;
     553           27130 :         scanner_globals_p->current_buffer = NULL;
     554           27130 :         scanner_globals_p->yy_in = NULL;
     555           27130 :         scanner_globals_p->yy_out = NULL;
     556           27130 :         scanner_globals_p->_yy_more_flag = 0;
     557           27130 :         scanner_globals_p->_yy_more_len = 0;
     558           27130 :         scanner_globals_p->yy_start_stack_ptr = 0;
     559           27130 :         scanner_globals_p->yy_start_stack_depth = 0;
     560           27130 :         scanner_globals_p->yy_start_stack = 0;
     561           27130 : }
     562                 : 
     563                 : void zend_init_opcodes_handlers(void);
     564                 : 
     565                 : int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions)
     566           13565 : {
     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           13565 :         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           13565 :         zend_startup_strtod();
     586           13565 :         zend_startup_extensions_mechanism();
     587                 : 
     588                 :         /* Set up utility functions and values */
     589           13565 :         zend_error_cb = utility_functions->error_function;
     590           13565 :         zend_printf = utility_functions->printf_function;
     591           13565 :         zend_write = (zend_write_func_t) utility_functions->write_function;
     592           13565 :         zend_fopen = utility_functions->fopen_function;
     593           13565 :         if (!zend_fopen) {
     594               0 :                 zend_fopen = zend_fopen_wrapper;
     595                 :         }
     596           13565 :         zend_stream_open_function = utility_functions->stream_open_function;
     597           13565 :         zend_message_dispatcher_p = utility_functions->message_handler;
     598           13565 :         zend_block_interruptions = utility_functions->block_interruptions;
     599           13565 :         zend_unblock_interruptions = utility_functions->unblock_interruptions;
     600           13565 :         zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
     601           13565 :         zend_ticks_function = utility_functions->ticks_function;
     602           13565 :         zend_on_timeout = utility_functions->on_timeout;
     603           13565 :         zend_vspprintf = utility_functions->vspprintf_function;
     604           13565 :         zend_getenv = utility_functions->getenv_function;
     605                 : 
     606           13565 :         zend_compile_file = compile_file;
     607           13565 :         zend_compile_string = compile_string;
     608           13565 :         zend_execute = execute;
     609           13565 :         zend_execute_internal = NULL;
     610           13565 :         zend_throw_exception_hook = NULL;
     611                 : 
     612           13565 :         zend_init_opcodes_handlers();
     613                 : 
     614                 :         /* set up version */
     615           13565 :         zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
     616           13565 :         zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1;
     617                 : 
     618           13565 :         GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
     619           13565 :         GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     620           13565 :         GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     621                 : #ifdef ZTS
     622                 :         GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     623                 : #endif
     624           13565 :         zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
     625           13565 :         zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
     626                 : 
     627           13565 :         zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
     628           13565 :         zend_init_rsrc_list_dtors();
     629                 : 
     630                 : 
     631                 :         /* This zval can be used to initialize allocate zval's to an uninit'ed value */
     632           13565 :         zval_used_for_init.is_ref = 0;
     633           13565 :         zval_used_for_init.refcount = 1;
     634           13565 :         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           13565 :         zend_hash_init_ex(CG(auto_globals), 8, NULL, (dtor_func_t) zend_auto_global_dtor, 1, 0);
     660           13565 :         scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
     661           13565 :         scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
     662           13565 :         zend_startup_constants();
     663           13565 :         zend_set_default_compile_time_values(TSRMLS_C);
     664           13565 :         EG(user_error_handler) = NULL;
     665           13565 :         EG(user_exception_handler) = NULL;
     666                 : #endif
     667           13565 :         register_standard_class(TSRMLS_C);
     668           13565 :         zend_register_standard_constants(TSRMLS_C);
     669           13565 :         zend_register_auto_global("GLOBALS", sizeof("GLOBALS")-1, NULL TSRMLS_CC);
     670                 : 
     671                 : #ifndef ZTS
     672           13565 :         zend_init_rsrc_plist(TSRMLS_C);
     673                 : #endif
     674                 : 
     675           13565 :         if (start_builtin_functions) {
     676           13565 :                 zend_startup_builtin_functions(TSRMLS_C);
     677                 :         }
     678                 : 
     679           13565 :         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           13565 :         return SUCCESS;
     686                 : }
     687                 : 
     688                 : 
     689                 : void zend_register_standard_ini_entries(TSRMLS_D)
     690           13565 : {
     691           13565 :         int module_number = 0;
     692                 : 
     693           13565 :         REGISTER_INI_ENTRIES();
     694           13565 : }
     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           13598 : {
     729                 : #ifdef ZEND_WIN32
     730                 :         zend_shutdown_timeout_thread();
     731                 : #endif
     732           13598 :         zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
     733           13598 :         zend_hash_graceful_reverse_destroy(&module_registry);
     734                 : 
     735           13597 :         zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
     736           13597 :         zend_hash_destroy(GLOBAL_CLASS_TABLE);
     737                 : 
     738           13597 :         zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
     739           13597 :         free(GLOBAL_AUTO_GLOBALS_TABLE);
     740                 : 
     741           13597 :         zend_shutdown_extensions(TSRMLS_C);
     742           13597 :         free(zend_version_info);
     743                 : 
     744           13597 :         free(GLOBAL_FUNCTION_TABLE);
     745           13597 :         free(GLOBAL_CLASS_TABLE);
     746                 : 
     747           13597 :         zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
     748           13597 :         free(GLOBAL_CONSTANTS_TABLE);
     749                 : 
     750           13597 :         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           13597 :         zend_destroy_rsrc_list_dtors();
     758           13597 : }
     759                 : 
     760                 : 
     761                 : void zend_set_utility_values(zend_utility_values *utility_values)
     762           13565 : {
     763           13565 :         zend_uv = *utility_values;
     764           13565 :         zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
     765           13565 : }
     766                 : 
     767                 : 
     768                 : /* this should be compatible with the standard zenderror */
     769                 : void zenderror(char *error)
     770              20 : {
     771              20 :         zend_error(E_PARSE, "%s", error);
     772              20 : }
     773                 : 
     774                 : 
     775                 : BEGIN_EXTERN_C()
     776                 : ZEND_API void _zend_bailout(char *filename, uint lineno)
     777             920 : {
     778                 :         TSRMLS_FETCH();
     779                 : 
     780             920 :         if (!EG(bailout)) {
     781               1 :                 zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
     782               1 :                 exit(-1);
     783                 :         }
     784             919 :         CG(unclean_shutdown) = 1;
     785             919 :         CG(in_compilation) = EG(in_execution) = 0;
     786             919 :         EG(current_execute_data) = NULL;
     787             919 :         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(void)
     815              27 : {
     816              27 :         return zend_version_info;
     817                 : }
     818                 : 
     819                 : 
     820                 : void zend_activate(TSRMLS_D)
     821           13551 : {
     822           13551 :         init_compiler(TSRMLS_C);
     823           13551 :         init_executor(TSRMLS_C);
     824           13551 :         startup_scanner(TSRMLS_C);
     825           13551 : }
     826                 : 
     827                 : 
     828                 : void zend_activate_modules(TSRMLS_D)
     829           13551 : {
     830           13551 :         zend_hash_apply(&module_registry, (apply_func_t) module_registry_request_startup TSRMLS_CC);
     831           13551 : }
     832                 : 
     833                 : void zend_deactivate_modules(TSRMLS_D)
     834           13584 : {
     835           13584 :         EG(opline_ptr) = NULL; /* we're no longer executing anything */
     836                 : 
     837           13584 :         zend_try {
     838           13584 :                 zend_hash_reverse_apply(&module_registry, (apply_func_t) module_registry_cleanup TSRMLS_CC);
     839           13584 :         } zend_end_try();
     840           13584 : }
     841                 : 
     842                 : void zend_call_destructors(TSRMLS_D) 
     843           13584 : {
     844           13584 :         zend_try {
     845           13584 :                 shutdown_destructors(TSRMLS_C);
     846           13584 :         } zend_end_try();
     847           13584 : }
     848                 : 
     849                 : void zend_deactivate(TSRMLS_D)
     850           13584 : {
     851                 :         /* we're no longer executing anything */
     852           13584 :         EG(opline_ptr) = NULL;
     853           13584 :         EG(active_symbol_table) = NULL;
     854                 : 
     855           13584 :         zend_try {
     856           13584 :                 shutdown_scanner(TSRMLS_C);
     857           13584 :         } zend_end_try();
     858                 : 
     859                 :         /* shutdown_executor() takes care of its own bailout handling */
     860           13584 :         shutdown_executor(TSRMLS_C);
     861                 : 
     862           13584 :         zend_try {
     863           13584 :                 shutdown_compiler(TSRMLS_C);
     864           13584 :         } zend_end_try();
     865                 : 
     866           13584 :         zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
     867                 : 
     868           13584 :         zend_try {
     869           13584 :                 zend_ini_deactivate(TSRMLS_C);
     870           13584 :         } zend_end_try();
     871           13584 : }
     872                 : 
     873                 : 
     874                 : static int exec_done_cb(zend_module_entry *module TSRMLS_DC)
     875          815135 : {
     876          815135 :         if (module->post_deactivate_func) {
     877               0 :                 module->post_deactivate_func();
     878                 :         }
     879          815135 :         return 0;
     880                 : }
     881                 : 
     882                 : 
     883                 : void zend_post_deactivate_modules(TSRMLS_D)
     884           13584 : {
     885           13584 :         zend_hash_apply(&module_registry, (apply_func_t) exec_done_cb TSRMLS_CC);
     886           13584 :         zend_hash_reverse_apply(&module_registry, (apply_func_t) module_registry_unload_temp TSRMLS_CC);
     887           13584 : }
     888                 : 
     889                 : 
     890                 : BEGIN_EXTERN_C()
     891                 : ZEND_API void zend_message_dispatcher(long message, void *data)
     892              11 : {
     893              11 :         if (zend_message_dispatcher_p) {
     894              11 :                 zend_message_dispatcher_p(message, data);
     895                 :         }
     896               8 : }
     897                 : END_EXTERN_C()
     898                 : 
     899                 : 
     900                 : ZEND_API int zend_get_configuration_directive(char *name, uint name_length, zval *contents)
     901         2645567 : {
     902         2645567 :         if (zend_get_configuration_directive_p) {
     903         2645567 :                 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         2057263 : {
     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         2057263 :         switch (type) {
     926                 :                 case E_CORE_ERROR:
     927                 :                 case E_CORE_WARNING:
     928               2 :                         error_filename = NULL;
     929               2 :                         error_lineno = 0;
     930               2 :                         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         2057261 :                         if (zend_is_compiling(TSRMLS_C)) {
     943             178 :                                 error_filename = zend_get_compiled_filename(TSRMLS_C);
     944             178 :                                 error_lineno = zend_get_compiled_lineno(TSRMLS_C);
     945         2057083 :                         } else if (zend_is_executing(TSRMLS_C)) {
     946         2057066 :                                 error_filename = zend_get_executed_filename(TSRMLS_C);
     947         2057066 :                                 error_lineno = zend_get_executed_lineno(TSRMLS_C);
     948                 :                         } else {
     949              17 :                                 error_filename = NULL;
     950              17 :                                 error_lineno = 0;
     951                 :                         }
     952         2057261 :                         break;
     953                 :                 default:
     954               0 :                         error_filename = NULL;
     955               0 :                         error_lineno = 0;
     956                 :                         break;
     957                 :         }
     958         2057263 :         if (!error_filename) {
     959              19 :                 error_filename = "Unknown";
     960                 :         }
     961                 : 
     962         2057263 :         va_start(args, format);
     963                 : 
     964                 :         /* if we don't have a user defined error handler */
     965         4111968 :         if (!EG(user_error_handler)
     966                 :                 || !(EG(user_error_handler_error_reporting) & type)) {
     967         2055036 :                 zend_error_cb(type, error_filename, error_lineno, format, args);
     968            2227 :         } 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               1 :                         zend_error_cb(type, error_filename, error_lineno, format, args);
     977               0 :                         break;
     978                 :                 default:
     979                 :                         /* Handle the error in user space */
     980            2226 :                         ALLOC_INIT_ZVAL(z_error_message);
     981            2226 :                         ALLOC_INIT_ZVAL(z_error_type);
     982            2226 :                         ALLOC_INIT_ZVAL(z_error_filename);
     983            2226 :                         ALLOC_INIT_ZVAL(z_error_lineno);
     984            2226 :                         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            2226 :                         va_copy(usr_copy, args);
     998            2226 :                         z_error_message->value.str.len = zend_vspprintf(&z_error_message->value.str.val, 0, format, usr_copy);
     999                 : #ifdef va_copy
    1000            2226 :                         va_end(usr_copy);
    1001                 : #endif
    1002            2226 :                         z_error_message->type = IS_STRING;
    1003                 : 
    1004            2226 :                         z_error_type->value.lval = type;
    1005            2226 :                         z_error_type->type = IS_LONG;
    1006                 : 
    1007            2226 :                         if (error_filename) {
    1008            2226 :                                 z_error_filename->value.str.len = strlen(error_filename);
    1009            2226 :                                 z_error_filename->value.str.val = estrndup(error_filename, z_error_filename->value.str.len);
    1010            2226 :                                 z_error_filename->type = IS_STRING;
    1011                 :                         }
    1012                 : 
    1013            2226 :                         z_error_lineno->value.lval = error_lineno;
    1014            2226 :                         z_error_lineno->type = IS_LONG;
    1015                 : 
    1016            2226 :                         z_context->value.ht = EG(active_symbol_table);
    1017            2226 :                         z_context->type = IS_ARRAY;
    1018            2226 :                         zval_copy_ctor(z_context);
    1019                 : 
    1020            2226 :                         params = (zval ***) emalloc(sizeof(zval **)*5);
    1021            2226 :                         params[0] = &z_error_type;
    1022            2226 :                         params[1] = &z_error_message;
    1023            2226 :                         params[2] = &z_error_filename;
    1024            2226 :                         params[3] = &z_error_lineno;
    1025            2226 :                         params[4] = &z_context;
    1026                 : 
    1027            2226 :                         orig_user_error_handler = EG(user_error_handler);
    1028            2226 :                         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            2226 :                         in_compilation = zend_is_compiling(TSRMLS_C);
    1036            2226 :                         if (in_compilation) {
    1037               1 :                                 saved_class_entry = CG(active_class_entry);
    1038               1 :                                 CG(active_class_entry) = NULL;
    1039                 :                         }
    1040                 : 
    1041            2226 :                         if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC)==SUCCESS) {
    1042            2225 :                                 if (retval) {
    1043            2210 :                                         if (Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval) == 0) {
    1044               1 :                                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1045                 :                                         }
    1046            2210 :                                         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            2225 :                         if (in_compilation) {
    1054               0 :                                 CG(active_class_entry) = saved_class_entry;
    1055                 :                         }
    1056                 : 
    1057            2225 :                         if (!EG(user_error_handler)) {
    1058            2225 :                                 EG(user_error_handler) = orig_user_error_handler;
    1059                 :                         } 
    1060                 :                         else {
    1061               0 :                                 zval_ptr_dtor(&orig_user_error_handler);
    1062                 :                         }
    1063                 : 
    1064            2225 :                         efree(params);
    1065            2225 :                         zval_ptr_dtor(&z_error_message);
    1066            2225 :                         zval_ptr_dtor(&z_error_type);
    1067            2225 :                         zval_ptr_dtor(&z_error_filename);
    1068            2225 :                         zval_ptr_dtor(&z_error_lineno);
    1069            2225 :                         zval_ptr_dtor(&z_context);
    1070                 :                         break;
    1071                 :         }
    1072                 : 
    1073         2056930 :         va_end(args);
    1074                 : 
    1075         2056930 :         if (type == E_PARSE) {
    1076              20 :                 EG(exit_status) = 255;
    1077              20 :                 zend_init_compiler_data_structures(TSRMLS_C);
    1078                 :         }
    1079         2056930 : }
    1080                 : 
    1081                 : #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)
    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               1 : {
    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               1 : }
    1109                 : 
    1110                 : 
    1111                 : ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...)
    1112           13483 : {
    1113                 :         va_list files;
    1114                 :         int i;
    1115                 :         zend_file_handle *file_handle;
    1116           13483 :         zend_op_array *orig_op_array = EG(active_op_array);
    1117           13483 :         zval **orig_retval_ptr_ptr = EG(return_value_ptr_ptr);
    1118           13483 :         zval *local_retval=NULL;
    1119                 : 
    1120           13483 :         va_start(files, file_count);
    1121           52234 :         for (i=0; i<file_count; i++) {
    1122           39600 :                 file_handle = va_arg(files, zend_file_handle *);
    1123           39600 :                 if (!file_handle) {
    1124           26116 :                         continue;
    1125                 :                 }
    1126           13484 :                 EG(active_op_array) = zend_compile_file(file_handle, type TSRMLS_CC);
    1127           13364 :                 if(file_handle->opened_path) {
    1128           13364 :                         int dummy=1;
    1129           13364 :                         zend_hash_add(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path)+1, (void *)&dummy, sizeof(int), NULL);
    1130                 :                 }
    1131           13364 :                 zend_destroy_file_handle(file_handle TSRMLS_CC);
    1132           13364 :                 if (EG(active_op_array)) {
    1133           13364 :                         EG(return_value_ptr_ptr) = retval ? retval : &local_retval;
    1134           13364 :                         zend_execute(EG(active_op_array) TSRMLS_CC);
    1135           12665 :                         if (EG(exception)) {
    1136              36 :                                 if (EG(user_exception_handler)) {
    1137                 :                                         zval *orig_user_exception_handler;
    1138                 :                                         zval ***params, *retval2, *old_exception;
    1139               7 :                                         params = (zval ***)emalloc(sizeof(zval **));
    1140               7 :                                         old_exception = EG(exception);
    1141               7 :                                         EG(exception) = NULL;
    1142               7 :                                         params[0] = &old_exception;
    1143               7 :                                         orig_user_exception_handler = EG(user_exception_handler);
    1144               7 :                                         if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
    1145               6 :                                                 if (retval2 != NULL) {
    1146               6 :                                                         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               6 :                                         efree(params);
    1155               6 :                                         zval_ptr_dtor(&old_exception);
    1156               6 :                                         if (EG(exception)) {
    1157               0 :                                                 zval_ptr_dtor(&EG(exception));
    1158               0 :                                                 EG(exception) = NULL;
    1159                 :                                         }
    1160                 :                                 } else {
    1161              29 :                                         zend_exception_error(EG(exception) TSRMLS_CC);
    1162                 :                                 }
    1163               6 :                                 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           12629 :                         } else if (!retval && *EG(return_value_ptr_ptr)) {
    1168           12629 :                                 zval_ptr_dtor(EG(return_value_ptr_ptr));
    1169           12629 :                                 local_retval = NULL;
    1170                 :                         }
    1171           12635 :                         destroy_op_array(EG(active_op_array) TSRMLS_CC);
    1172           12635 :                         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           12634 :         va_end(files);
    1181           12634 :         EG(active_op_array) = orig_op_array;
    1182           12634 :         EG(return_value_ptr_ptr) = orig_retval_ptr_ptr;
    1183                 : 
    1184           12634 :         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             917 : {
    1191                 :         char *cur_filename;
    1192                 :         int cur_lineno;
    1193                 :         char *compiled_string_description;
    1194                 : 
    1195             917 :         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             917 :         } else if (zend_is_executing(TSRMLS_C)) {
    1199             917 :                 cur_filename = zend_get_executed_filename(TSRMLS_C);
    1200             917 :                 cur_lineno = zend_get_executed_lineno(TSRMLS_C);
    1201                 :         } else {
    1202               0 :                 cur_filename = "Unknown";
    1203               0 :                 cur_lineno = 0;
    1204                 :         }
    1205                 : 
    1206             917 :         zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
    1207             917 :         return compiled_string_description;
    1208                 : }
    1209                 : 
    1210                 : 
    1211                 : void free_estring(char **str_p)
    1212           17757 : {
    1213           17757 :         efree(*str_p);
    1214           17757 : }
    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

Generated at Thu, 19 Nov 2009 08:20:04 +0000 (5 days ago)

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