static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{{ */ { compiler_globals->compiled_filename = NULL; compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); zend_hash_init_ex(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0); zend_hash_copy(compiler_globals->function_table, global_function_table, function_copy_ctor); compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); zend_hash_init_ex(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1, 0); zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref); zend_set_default_compile_time_values(); compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable)); zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, auto_global_dtor, 1, 0); zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, auto_global_copy_ctor); compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table); if (compiler_globals->last_static_member) { compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval*)); } else { compiler_globals->static_members_table = NULL; } compiler_globals->script_encoding_list = NULL; compiler_globals->empty_string = zend_zts_interned_string_init("", sizeof("")-1); memset(compiler_globals->one_char_string, 0, sizeof(compiler_globals->one_char_string)); zend_known_interned_strings_init(&compiler_globals->known_strings, &compiler_globals->known_strings_count); }
static void register_standard_class(TSRMLS_D) { zend_standard_class_def.type = ZEND_INTERNAL_CLASS; zend_standard_class_def.name_length = sizeof("stdClass") - 1; zend_standard_class_def.name = zend_strndup("stdClass", zend_standard_class_def.name_length); zend_standard_class_def.parent = NULL; zend_hash_init_ex(&zend_standard_class_def.default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0); zend_hash_init_ex(&zend_standard_class_def.function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0); zend_standard_class_def.handle_function_call = NULL; zend_standard_class_def.handle_property_get = NULL; zend_standard_class_def.handle_property_set = NULL; zend_standard_class_def.refcount = (int *) malloc(sizeof(int)); *zend_standard_class_def.refcount = 1; zend_hash_add(CG(class_table), "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry), NULL); }
static void sapi_globals_ctor(sapi_globals_struct *sapi_globals) { #ifdef ZTS ZEND_TSRMLS_CACHE_UPDATE(); #endif memset(sapi_globals, 0, sizeof(*sapi_globals)); zend_hash_init_ex(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1, 0); php_setup_sapi_content_types(); }
static int browscap_read_file(char *filename, browser_data *browdata, int persistent) /* {{{ */ { zend_file_handle fh; browscap_parser_ctx ctx = {0}; if (filename == NULL || filename[0] == '\0') { return FAILURE; } fh.handle.fp = VCWD_FOPEN(filename, "r"); fh.opened_path = NULL; fh.free_filename = 0; if (!fh.handle.fp) { zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename); return FAILURE; } fh.filename = filename; fh.type = ZEND_HANDLE_FP; browdata->htab = pemalloc(sizeof *browdata->htab, persistent); if (browdata->htab == NULL) { return FAILURE; } zend_hash_init_ex(browdata->htab, 0, NULL, persistent ? browscap_entry_dtor_persistent : browscap_entry_dtor, persistent, 0); browdata->kv_size = 16 * 1024; browdata->kv_used = 0; browdata->kv = pemalloc(sizeof(browscap_kv) * browdata->kv_size, persistent); /* Create parser context */ ctx.bdata = browdata; ctx.current_entry = NULL; ctx.current_section_name = NULL; ctx.str_empty = zend_string_init("", sizeof("")-1, persistent); ctx.str_one = zend_string_init("1", sizeof("1")-1, persistent); zend_hash_init(&ctx.str_interned, 8, NULL, NULL, persistent); zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW, (zend_ini_parser_cb_t) php_browscap_parser_cb, &ctx); /* Destroy parser context */ if (ctx.current_section_name) { zend_string_release(ctx.current_section_name); } zend_string_release(ctx.str_one); zend_string_release(ctx.str_empty); zend_hash_destroy(&ctx.str_interned); return SUCCESS; }
static int browscap_read_file(char *filename, browser_data *browdata, int persistent) /* {{{ */ { zend_file_handle fh = {{0}}; if (filename == NULL || filename[0] == '\0') { return FAILURE; } browdata->htab = pemalloc(sizeof *browdata->htab, persistent); if (browdata->htab == NULL) { return FAILURE; } zend_hash_init_ex(browdata->htab, 0, NULL, (dtor_func_t) (persistent?browscap_entry_dtor_persistent :browscap_entry_dtor_request), persistent, 0); fh.handle.fp = VCWD_FOPEN(filename, "r"); fh.opened_path = NULL; fh.free_filename = 0; if (!fh.handle.fp) { zend_hash_destroy(browdata->htab); pefree(browdata->htab, persistent); browdata->htab = NULL; zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename); return FAILURE; } fh.filename = filename; fh.type = ZEND_HANDLE_FP; browdata->current_section_name = NULL; zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW, (zend_ini_parser_cb_t) php_browscap_parser_cb, browdata); if (browdata->current_section_name != NULL) { pefree(browdata->current_section_name, persistent); browdata->current_section_name = NULL; } return SUCCESS; }
int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */ { #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; extern ZEND_API ts_rsrc_id ini_scanner_globals_id; extern ZEND_API ts_rsrc_id language_scanner_globals_id; ZEND_TSRMLS_CACHE_UPDATE(); #else extern zend_ini_scanner_globals ini_scanner_globals; extern zend_php_scanner_globals language_scanner_globals; #endif start_memory_manager(); virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */ #if defined(__FreeBSD__) || defined(__DragonFly__) /* FreeBSD and DragonFly floating point precision fix */ fpsetmask(0); #endif zend_startup_strtod(); zend_startup_extensions_mechanism(); /* Set up utility functions and values */ zend_error_cb = utility_functions->error_function; zend_printf = utility_functions->printf_function; zend_write = (zend_write_func_t) utility_functions->write_function; zend_fopen = utility_functions->fopen_function; if (!zend_fopen) { zend_fopen = zend_fopen_wrapper; } zend_stream_open_function = utility_functions->stream_open_function; zend_message_dispatcher_p = utility_functions->message_handler; #ifndef ZEND_SIGNALS zend_block_interruptions = utility_functions->block_interruptions; zend_unblock_interruptions = utility_functions->unblock_interruptions; #endif zend_get_configuration_directive_p = utility_functions->get_configuration_directive; zend_ticks_function = utility_functions->ticks_function; zend_on_timeout = utility_functions->on_timeout; zend_vspprintf = utility_functions->vspprintf_function; zend_vstrpprintf = utility_functions->vstrpprintf_function; zend_getenv = utility_functions->getenv_function; zend_resolve_path = utility_functions->resolve_path_function; #if HAVE_DTRACE /* build with dtrace support */ zend_compile_file = dtrace_compile_file; zend_execute_ex = dtrace_execute_ex; zend_execute_internal = dtrace_execute_internal; #else zend_compile_file = compile_file; zend_execute_ex = execute_ex; zend_execute_internal = NULL; #endif /* HAVE_SYS_SDT_H */ zend_compile_string = compile_string; zend_throw_exception_hook = NULL; /* Set up the default garbage collection implementation. */ gc_collect_cycles = zend_gc_collect_cycles; zend_init_opcodes_handlers(); /* set up version */ zend_version_info = strdup(ZEND_CORE_VERSION_INFO); zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1; GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable)); zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0); zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0); zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0); zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0); zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0); zend_init_rsrc_list_dtors(); #ifdef ZTS ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL); ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL); compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); compiler_globals_dtor(compiler_globals); compiler_globals->in_compilation = 0; compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE; *compiler_globals->class_table = *GLOBAL_CLASS_TABLE; compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE; zend_hash_destroy(executor_globals->zend_constants); *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE; #else ini_scanner_globals_ctor(&ini_scanner_globals); php_scanner_globals_ctor(&language_scanner_globals); zend_set_default_compile_time_values(); #ifdef ZEND_WIN32 zend_get_windows_version_info(&EG(windows_version_info)); #endif #endif EG(error_reporting) = E_ALL & ~E_NOTICE; zend_interned_strings_init(); zend_startup_builtin_functions(); zend_register_standard_constants(); zend_register_auto_global(zend_string_init("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals); #ifndef ZTS zend_init_rsrc_plist(); zend_init_exception_op(); zend_init_call_trampoline_op(); #endif zend_ini_startup(); #ifdef ZTS tsrm_set_new_thread_end_handler(zend_new_thread_end_handler); #endif return SUCCESS; }
void zend_ext_api_init() { zend_hash_init_ex(&ext_api_registry, 10, NULL, zend_ext_api_free_api, 1, 0); }