diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/opcache/ZendAccelerator.c | 209 | ||||
-rw-r--r-- | ext/opcache/ZendAccelerator.h | 8 | ||||
-rw-r--r-- | ext/opcache/zend_accelerator_hash.c | 26 | ||||
-rw-r--r-- | ext/opcache/zend_accelerator_hash.h | 10 | ||||
-rw-r--r-- | ext/opcache/zend_accelerator_module.c | 32 | ||||
-rw-r--r-- | ext/opcache/zend_persist.c | 6 | ||||
-rw-r--r-- | ext/opcache/zend_persist.h | 4 | ||||
-rw-r--r-- | ext/opcache/zend_persist_calc.c | 6 | ||||
-rw-r--r-- | ext/phar/phar.c | 35 | ||||
-rw-r--r-- | ext/phar/phar_internal.h | 4 | ||||
-rw-r--r-- | ext/phar/phar_object.c | 5 | ||||
-rw-r--r-- | ext/phar/util.c | 6 | ||||
-rw-r--r-- | ext/readline/readline_cli.c | 2 | ||||
-rw-r--r-- | ext/spl/php_spl.c | 22 | ||||
-rwxr-xr-x | ext/standard/basic_functions.c | 22 | ||||
-rw-r--r-- | ext/standard/browscap.c | 7 | ||||
-rw-r--r-- | ext/standard/streamsfuncs.c | 7 |
17 files changed, 188 insertions, 223 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index d2349b90bd..5ef84b2a2a 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -120,8 +120,8 @@ bool fallback_process = 0; /* process uses file cache fallback */ static zend_op_array *(*accelerator_orig_compile_file)(zend_file_handle *file_handle, int type); static zend_class_entry* (*accelerator_orig_inheritance_cache_get)(zend_class_entry *ce, zend_class_entry *parent, zend_class_entry **traits_and_interfaces); static zend_class_entry* (*accelerator_orig_inheritance_cache_add)(zend_class_entry *ce, zend_class_entry *proto, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, HashTable *dependencies); -static zend_result (*accelerator_orig_zend_stream_open_function)(const char *filename, zend_file_handle *handle ); -static zend_string *(*accelerator_orig_zend_resolve_path)(const char *filename, size_t filename_len); +static zend_result (*accelerator_orig_zend_stream_open_function)(zend_file_handle *handle ); +static zend_string *(*accelerator_orig_zend_resolve_path)(zend_string *filename); static void (*accelerator_orig_zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); static zif_handler orig_chdir = NULL; static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL; @@ -952,7 +952,7 @@ accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_ if (sapi_module.get_stat && !EG(current_execute_data) && - file_handle->filename == SG(request_info).path_translated) { + file_handle->primary_script) { zend_stat_t *tmpbuf = sapi_module.get_stat(); @@ -974,7 +974,7 @@ accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_ switch (file_handle->type) { case ZEND_HANDLE_FP: if (zend_fstat(fileno(file_handle->handle.fp), &statbuf) == -1) { - if (zend_get_stream_timestamp(file_handle->filename, &statbuf) != SUCCESS) { + if (zend_get_stream_timestamp(ZSTR_VAL(file_handle->filename), &statbuf) != SUCCESS) { return 0; } } @@ -993,7 +993,7 @@ accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_ } } - if (zend_get_stream_timestamp(file_handle->filename, &statbuf) != SUCCESS) { + if (zend_get_stream_timestamp(ZSTR_VAL(file_handle->filename), &statbuf) != SUCCESS) { return 0; } break; @@ -1039,6 +1039,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri { zend_file_handle ps_handle; zend_string *full_path_ptr = NULL; + int ret; /** check that the persistent script is indeed the same file we cached * (if part of the path is a symlink than it possible that the user will change it) @@ -1050,7 +1051,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri return FAILURE; } } else { - full_path_ptr = accelerator_orig_zend_resolve_path(file_handle->filename, strlen(file_handle->filename)); + full_path_ptr = accelerator_orig_zend_resolve_path(file_handle->filename); if (full_path_ptr && persistent_script->script.filename != full_path_ptr && !zend_string_equal_content(persistent_script->script.filename, full_path_ptr)) { @@ -1080,14 +1081,15 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri file_handle->opened_path = NULL; } - zend_stream_init_filename(&ps_handle, ZSTR_VAL(persistent_script->script.filename)); + zend_stream_init_filename_ex(&ps_handle, persistent_script->script.filename); ps_handle.opened_path = persistent_script->script.filename; - if (zend_get_file_handle_timestamp(&ps_handle, NULL) == persistent_script->timestamp) { - return SUCCESS; - } + ret = zend_get_file_handle_timestamp(&ps_handle, NULL) == persistent_script->timestamp + ? SUCCESS : FAILURE; - return FAILURE; + zend_destroy_file_handle(&ps_handle); + + return ret; } int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle) @@ -1119,23 +1121,25 @@ int validate_timestamp_and_record_ex(zend_persistent_script *persistent_script, /* Instead of resolving full real path name each time we need to identify file, * we create a key that consist from requested file name, current working * directory, current include_path, etc */ -char *accel_make_persistent_key(const char *path, size_t path_length, int *key_len) +zend_string *accel_make_persistent_key(zend_string *str) { + const char *path = ZSTR_VAL(str); + size_t path_length = ZSTR_LEN(str); + char *key; int key_length; + ZSTR_LEN(&ZCG(key)) = 0; + /* CWD and include_path don't matter for absolute file names and streams */ if (IS_ABSOLUTE_PATH(path, path_length)) { /* pass */ - ZCG(key_len) = 0; } else if (UNEXPECTED(is_stream_path(path))) { if (!is_cacheable_stream_path(path)) { return NULL; } /* pass */ - ZCG(key_len) = 0; } else if (UNEXPECTED(!ZCG(accel_directives).use_cwd)) { /* pass */ - ZCG(key_len) = 0; } else { const char *include_path = NULL, *cwd = NULL; int include_path_len = 0, cwd_len = 0; @@ -1233,7 +1237,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l } /* Calculate key length */ - if (UNEXPECTED((size_t)(cwd_len + path_length + include_path_len + 2) >= sizeof(ZCG(key)))) { + if (UNEXPECTED((size_t)(cwd_len + path_length + include_path_len + 2) >= sizeof(ZCG(_key)))) { return NULL; } @@ -1242,16 +1246,17 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l * since in itself, it may include colons (which we use to separate * different components of the key) */ - memcpy(ZCG(key), path, path_length); - ZCG(key)[path_length] = ':'; + key = ZSTR_VAL(&ZCG(key)); + memcpy(key, path, path_length); + key[path_length] = ':'; key_length = path_length + 1; - memcpy(ZCG(key) + key_length, cwd, cwd_len); + memcpy(key + key_length, cwd, cwd_len); key_length += cwd_len; if (include_path_len) { - ZCG(key)[key_length] = ':'; + key[key_length] = ':'; key_length += 1; - memcpy(ZCG(key) + key_length, include_path, include_path_len); + memcpy(key + key_length, include_path, include_path_len); key_length += include_path_len; } @@ -1265,25 +1270,27 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l parent_script_len = ZSTR_LEN(parent_script); while ((--parent_script_len > 0) && !IS_SLASH(ZSTR_VAL(parent_script)[parent_script_len])); - if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= sizeof(ZCG(key)))) { + if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= sizeof(ZCG(_key)))) { return NULL; } - ZCG(key)[key_length] = ':'; + key[key_length] = ':'; key_length += 1; - memcpy(ZCG(key) + key_length, ZSTR_VAL(parent_script), parent_script_len); + memcpy(key + key_length, ZSTR_VAL(parent_script), parent_script_len); key_length += parent_script_len; } - ZCG(key)[key_length] = '\0'; - *key_len = ZCG(key_len) = key_length; - return ZCG(key); + key[key_length] = '\0'; + GC_SET_REFCOUNT(&ZCG(key), 1); + GC_TYPE_INFO(&ZCG(key)) = GC_STRING; + ZSTR_H(&ZCG(key)) = 0; + ZSTR_LEN(&ZCG(key)) = key_length; + return &ZCG(key); } /* not use_cwd */ - *key_len = path_length; - return (char*)path; + return str; } -int zend_accel_invalidate(const char *filename, size_t filename_len, bool force) +int zend_accel_invalidate(zend_string *filename, bool force) { zend_string *realpath; zend_persistent_script *persistent_script; @@ -1292,7 +1299,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, bool force) return FAILURE; } - realpath = accelerator_orig_zend_resolve_path(filename, filename_len); + realpath = accelerator_orig_zend_resolve_path(filename); if (!realpath) { return FAILURE; @@ -1305,7 +1312,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, bool force) persistent_script = zend_accel_hash_find(&ZCSG(hash), realpath); if (persistent_script && !persistent_script->corrupted) { zend_file_handle file_handle; - zend_stream_init_filename(&file_handle, ZSTR_VAL(realpath)); + zend_stream_init_filename_ex(&file_handle, realpath); file_handle.opened_path = realpath; if (force || @@ -1328,6 +1335,9 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, bool force) SHM_PROTECT(); HANDLE_UNBLOCK_INTERRUPTIONS(); } + + file_handle.opened_path = NULL; + zend_destroy_file_handle(&file_handle); } accelerator_shm_read_unlock(); @@ -1337,18 +1347,18 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, bool force) } /* Adds another key for existing cached script */ -static void zend_accel_add_key(const char *key, unsigned int key_length, zend_accel_hash_entry *bucket) +static void zend_accel_add_key(zend_string *key, zend_accel_hash_entry *bucket) { - if (!zend_accel_hash_str_find(&ZCSG(hash), key, key_length)) { + if (!zend_accel_hash_find(&ZCSG(hash), key)) { if (zend_accel_hash_is_full(&ZCSG(hash))) { zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!"); ZSMMG(memory_exhausted) = 1; zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH); } else { - char *new_key = zend_shared_alloc(key_length + 1); + char *new_key = zend_shared_alloc(ZSTR_LEN(key) + 1); if (new_key) { - memcpy(new_key, key, key_length + 1); - if (zend_accel_hash_update(&ZCSG(hash), new_key, key_length, 1, bucket)) { + memcpy(new_key, ZSTR_VAL(key), ZSTR_LEN(key) + 1); + if (zend_accel_hash_update(&ZCSG(hash), new_key, ZSTR_LEN(key), 1, bucket)) { zend_accel_error(ACCEL_LOG_INFO, "Added key '%s'", new_key); } } else { @@ -1372,7 +1382,7 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script zend_shared_alloc_init_xlat_table(); /* Calculate the required memory size */ - memory_used = zend_accel_script_persist_calc(new_persistent_script, NULL, 0, 0); + memory_used = zend_accel_script_persist_calc(new_persistent_script, 0); /* Allocate memory block */ #if defined(__AVX__) || defined(__SSE2__) @@ -1390,7 +1400,7 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script zend_shared_alloc_clear_xlat_table(); /* Copy into memory block */ - new_persistent_script = zend_accel_script_persist(new_persistent_script, NULL, 0, 0); + new_persistent_script = zend_accel_script_persist(new_persistent_script, 0); zend_shared_alloc_destroy_xlat_table(); @@ -1430,7 +1440,7 @@ static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script return store_script_in_file_cache(new_persistent_script); } -static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, const char *key, unsigned int key_length, int *from_shared_memory) +static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, zend_string *key, int *from_shared_memory) { zend_accel_hash_entry *bucket; uint32_t memory_used; @@ -1460,7 +1470,7 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr if (key && (!ZCG(accel_directives).validate_timestamps || (new_persistent_script->timestamp == existing_persistent_script->timestamp))) { - zend_accel_add_key(key, key_length, bucket); + zend_accel_add_key(key, bucket); } zend_shared_alloc_unlock(); #if 1 @@ -1489,7 +1499,7 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr zend_shared_alloc_init_xlat_table(); /* Calculate the required memory size */ - memory_used = zend_accel_script_persist_calc(new_persistent_script, key, key_length, 1); + memory_used = zend_accel_script_persist_calc(new_persistent_script, 1); /* Allocate shared memory */ #if defined(__AVX__) || defined(__SSE2__) @@ -1547,7 +1557,7 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr zend_shared_alloc_clear_xlat_table(); /* Copy into shared memory */ - new_persistent_script = zend_accel_script_persist(new_persistent_script, &key, key_length, 1); + new_persistent_script = zend_accel_script_persist(new_persistent_script, 1); zend_shared_alloc_destroy_xlat_table(); @@ -1573,15 +1583,21 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr if (key && /* key may contain non-persistent PHAR aliases (see issues #115 and #149) */ memcmp(key, "phar://", sizeof("phar://") - 1) != 0 && - (ZSTR_LEN(new_persistent_script->script.filename) != key_length || - memcmp(ZSTR_VAL(new_persistent_script->script.filename), key, key_length) != 0)) { + !zend_string_equals(new_persistent_script->script.filename, key)) { /* link key to the same persistent script in hash table */ - if (zend_accel_hash_update(&ZCSG(hash), key, key_length, 1, bucket)) { - zend_accel_error(ACCEL_LOG_INFO, "Added key '%s'", key); + char *new_key = zend_shared_alloc(ZSTR_LEN(key) + 1); + + if (new_key) { + memcpy(new_key, ZSTR_VAL(key), ZSTR_LEN(key) + 1); + if (zend_accel_hash_update(&ZCSG(hash), new_key, ZSTR_LEN(key), 1, bucket)) { + zend_accel_error(ACCEL_LOG_INFO, "Added key '%s'", ZSTR_VAL(key)); + } else { + zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!"); + ZSMMG(memory_exhausted) = 1; + zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH); + } } else { - zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!"); - ZSMMG(memory_exhausted) = 1; - zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH); + zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM); } } } @@ -1701,7 +1717,7 @@ static void free_recorded_warnings() { ZCG(num_warnings) = 0; } -static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handle, int type, const char *key, zend_op_array **op_array_p) +static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handle, int type, zend_op_array **op_array_p) { zend_persistent_script *new_persistent_script; uint32_t orig_functions_count, orig_class_count; @@ -1714,13 +1730,13 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl /* Try to open file */ if (file_handle->type == ZEND_HANDLE_FILENAME) { - if (accelerator_orig_zend_stream_open_function(file_handle->filename, file_handle) != SUCCESS) { + if (accelerator_orig_zend_stream_open_function(file_handle) != SUCCESS) { *op_array_p = NULL; if (!EG(exception)) { if (type == ZEND_REQUIRE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, ZSTR_VAL(file_handle->filename)); } else { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, ZSTR_VAL(file_handle->filename)); } } return NULL; @@ -1852,7 +1868,7 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl if (file_handle->opened_path) { new_persistent_script->script.filename = zend_string_copy(file_handle->opened_path); } else { - new_persistent_script->script.filename = zend_string_init(file_handle->filename, strlen(file_handle->filename), 0); + new_persistent_script->script.filename = zend_string_copy(file_handle->filename); } zend_string_hash_val(new_persistent_script->script.filename); @@ -1866,19 +1882,19 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type) zend_op_array *op_array = NULL; int from_memory; /* if the script we've got is stored in SHM */ - if (is_stream_path(file_handle->filename) && - !is_cacheable_stream_path(file_handle->filename)) { + if (is_stream_path(ZSTR_VAL(file_handle->filename)) && + !is_cacheable_stream_path(ZSTR_VAL(file_handle->filename))) { return accelerator_orig_compile_file(file_handle, type); } if (!file_handle->opened_path) { if (file_handle->type == ZEND_HANDLE_FILENAME && - accelerator_orig_zend_stream_open_function(file_handle->filename, file_handle) == FAILURE) { + accelerator_orig_zend_stream_open_function(file_handle) == FAILURE) { if (!EG(exception)) { if (type == ZEND_REQUIRE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, ZSTR_VAL(file_handle->filename)); } else { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, ZSTR_VAL(file_handle->filename)); } } return NULL; @@ -1914,7 +1930,6 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type) } } replay_warnings(persistent_script); - zend_file_handle_dtor(file_handle); if (persistent_script->ping_auto_globals_mask) { zend_accel_set_auto_globals(persistent_script->ping_auto_globals_mask); @@ -1923,7 +1938,7 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type) return zend_accel_load_script(persistent_script, 1); } - persistent_script = opcache_compile_file(file_handle, type, NULL, &op_array); + persistent_script = opcache_compile_file(file_handle, type, &op_array); if (persistent_script) { from_memory = 0; @@ -1961,8 +1976,7 @@ int check_persistent_script_access(zend_persistent_script *persistent_script) zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) { zend_persistent_script *persistent_script = NULL; - char *key = NULL; - int key_length; + zend_string *key = NULL; int from_shared_memory; /* if the script we've got is stored in SHM */ if (!file_handle->filename || !ZCG(accelerator_enabled)) { @@ -1994,7 +2008,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) * persistent script already found */ if (ZCG(cache_persistent_script) && ((!EG(current_execute_data) && - file_handle->filename == SG(request_info).path_translated && + file_handle->primary_script && ZCG(cache_opline) == NULL) || (EG(current_execute_data) && EG(current_execute_data)->func && @@ -2002,22 +2016,21 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) ZCG(cache_opline) == EG(current_execute_data)->opline))) { persistent_script = ZCG(cache_persistent_script); - if (ZCG(key_len)) { - key = ZCG(key); - key_length = ZCG(key_len); + if (ZSTR_LEN(&ZCG(key))) { + key = &ZCG(key); } } else { if (!ZCG(accel_directives).revalidate_path) { /* try to find cached script by key */ - key = accel_make_persistent_key(file_handle->filename, strlen(file_handle->filename), &key_length); + key = accel_make_persistent_key(file_handle->filename); if (!key) { ZCG(cache_opline) = NULL; ZCG(cache_persistent_script) = NULL; return accelerator_orig_compile_file(file_handle, type); } - persistent_script = zend_accel_hash_str_find(&ZCSG(hash), key, key_length); - } else if (UNEXPECTED(is_stream_path(file_handle->filename) && !is_cacheable_stream_path(file_handle->filename))) { + persistent_script = zend_accel_hash_find(&ZCSG(hash), key); + } else if (UNEXPECTED(is_stream_path(ZSTR_VAL(file_handle->filename)) && !is_cacheable_stream_path(ZSTR_VAL(file_handle->filename)))) { ZCG(cache_opline) = NULL; ZCG(cache_persistent_script) = NULL; return accelerator_orig_compile_file(file_handle, type); @@ -2028,13 +2041,13 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) zend_accel_hash_entry *bucket; /* open file to resolve the path */ - if (file_handle->type == ZEND_HANDLE_FILENAME && - accelerator_orig_zend_stream_open_function(file_handle->filename, file_handle) == FAILURE) { + if (file_handle->type == ZEND_HANDLE_FILENAME + && accelerator_orig_zend_stream_open_function(file_handle) == FAILURE) { if (!EG(exception)) { if (type == ZEND_REQUIRE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, ZSTR_VAL(file_handle->filename)); } else { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, ZSTR_VAL(file_handle->filename)); } } return NULL; @@ -2050,7 +2063,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) HANDLE_BLOCK_INTERRUPTIONS(); SHM_UNPROTECT(); zend_shared_alloc_lock(); - zend_accel_add_key(key, key_length, bucket); + zend_accel_add_key(key, bucket); zend_shared_alloc_unlock(); SHM_PROTECT(); HANDLE_UNBLOCK_INTERRUPTIONS(); @@ -2089,9 +2102,9 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) UNEXPECTED(check_persistent_script_access(persistent_script))) { if (!EG(exception)) { if (type == ZEND_REQUIRE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, ZSTR_VAL(file_handle->filename)); } else { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, ZSTR_VAL(file_handle->filename)); } } return NULL; @@ -2169,7 +2182,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) SHM_PROTECT(); HANDLE_UNBLOCK_INTERRUPTIONS(); - persistent_script = opcache_compile_file(file_handle, type, key, &op_array); + persistent_script = opcache_compile_file(file_handle, type, &op_array); HANDLE_BLOCK_INTERRUPTIONS(); SHM_UNPROTECT(); @@ -2178,7 +2191,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) */ from_shared_memory = 0; if (persistent_script) { - persistent_script = cache_script_in_shared_memory(persistent_script, key, key ? key_length : 0, &from_shared_memory); + persistent_script = cache_script_in_shared_memory(persistent_script, key, &from_shared_memory); } /* Caching is disabled, returning op_array; @@ -2234,7 +2247,6 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) } } replay_warnings(persistent_script); - zend_file_handle_dtor(file_handle); from_shared_memory = 1; } @@ -2478,12 +2490,12 @@ static int accel_gen_uname_id(void) #endif /* zend_stream_open_function() replacement for PHP 5.3 and above */ -static zend_result persistent_stream_open_function(const char *filename, zend_file_handle *handle) +static zend_result persistent_stream_open_function(zend_file_handle *handle) { if (ZCG(cache_persistent_script)) { /* check if callback is called from include_once or it's a main request */ if ((!EG(current_execute_data) && - filename == SG(request_info).path_translated && + handle->primary_script && ZCG(cache_opline) == NULL) || (EG(current_execute_data) && EG(current_execute_data)->func && @@ -2491,25 +2503,23 @@ static zend_result persistent_stream_open_function(const char *filename, zend_fi ZCG(cache_opline) == EG(current_execute_data)->opline)) { /* we are in include_once or FastCGI request */ - zend_stream_init_filename(handle, (char*) filename); handle->opened_path = zend_string_copy(ZCG(cache_persistent_script)->script.filename); return SUCCESS; } ZCG(cache_opline) = NULL; ZCG(cache_persistent_script) = NULL; } - return accelerator_orig_zend_stream_open_function(filename, handle); + return accelerator_orig_zend_stream_open_function(handle); } /* zend_resolve_path() replacement for PHP 5.3 and above */ -static zend_string* persistent_zend_resolve_path(const char *filename, size_t filename_len) +static zend_string* persistent_zend_resolve_path(zend_string *filename) { if (!file_cache_only && ZCG(accelerator_enabled)) { /* check if callback is called from include_once or it's a main request */ - if ((!EG(current_execute_data) && - filename == SG(request_info).path_translated) || + if ((!EG(current_execute_data)) || (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type) && @@ -2519,14 +2529,13 @@ static zend_string* persistent_zend_resolve_path(const char *filename, size_t fi /* we are in include_once or FastCGI request */ zend_string *resolved_path; - int key_length; - char *key = NULL; + zend_string *key = NULL; if (!ZCG(accel_directives).revalidate_path) { /* lookup by "not-real" path */ - key = accel_make_persistent_key(filename, filename_len, &key_length); + key = accel_make_persistent_key(filename); if (key) { - zend_accel_hash_entry *bucket = zend_accel_hash_str_find_entry(&ZCSG(hash), key, key_length); + zend_accel_hash_entry *bucket = zend_accel_hash_find_entry(&ZCSG(hash), key); if (bucket != NULL) { zend_persistent_script *persistent_script = (zend_persistent_script *)bucket->data; if (!persistent_script->corrupted) { @@ -2538,12 +2547,12 @@ static zend_string* persistent_zend_resolve_path(const char *filename, size_t fi } else { ZCG(cache_opline) = NULL; ZCG(cache_persistent_script) = NULL; - return accelerator_orig_zend_resolve_path(filename, filename_len); + return accelerator_orig_zend_resolve_path(filename); } } /* find the full real path */ - resolved_path = accelerator_orig_zend_resolve_path(filename, filename_len); + resolved_path = accelerator_orig_zend_resolve_path(filename); if (resolved_path) { /* lookup by real path */ @@ -2556,12 +2565,12 @@ static zend_string* persistent_zend_resolve_path(const char *filename, size_t fi HANDLE_BLOCK_INTERRUPTIONS(); SHM_UNPROTECT(); zend_shared_alloc_lock(); - zend_accel_add_key(key, key_length, bucket); + zend_accel_add_key(key, bucket); zend_shared_alloc_unlock(); SHM_PROTECT(); HANDLE_UNBLOCK_INTERRUPTIONS(); } else { - ZCG(key_len) = 0; + ZSTR_LEN(&ZCG(key)) = 0; } ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL; ZCG(cache_persistent_script) = persistent_script; @@ -2577,7 +2586,7 @@ static zend_string* persistent_zend_resolve_path(const char *filename, size_t fi } ZCG(cache_opline) = NULL; ZCG(cache_persistent_script) = NULL; - return accelerator_orig_zend_resolve_path(filename, filename_len); + return accelerator_orig_zend_resolve_path(filename); } static void zend_reset_cache_vars(void) @@ -4211,7 +4220,7 @@ static zend_string *preload_resolve_path(zend_string *filename) if (is_stream_path(ZSTR_VAL(filename))) { return NULL; } - return zend_resolve_path(ZSTR_VAL(filename), ZSTR_LEN(filename)); + return zend_resolve_path(filename); } static void preload_remove_empty_includes(void) @@ -4393,7 +4402,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s checkpoint = zend_shared_alloc_checkpoint_xlat_table(); /* Calculate the required memory size */ - memory_used = zend_accel_script_persist_calc(new_persistent_script, NULL, 0, 1); + memory_used = zend_accel_script_persist_calc(new_persistent_script, 1); /* Allocate shared memory */ #if defined(__AVX__) || defined(__SSE2__) @@ -4445,7 +4454,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s zend_shared_alloc_restore_xlat_table(checkpoint); /* Copy into shared memory */ - new_persistent_script = zend_accel_script_persist(new_persistent_script, NULL, 0, 1); + new_persistent_script = zend_accel_script_persist(new_persistent_script, 1); new_persistent_script->is_phar = is_phar_file(new_persistent_script->script.filename); diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 663cffca14..fab1b71666 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -234,8 +234,8 @@ typedef struct _zend_accel_globals { const zend_op *cache_opline; zend_persistent_script *cache_persistent_script; /* preallocated buffer for keys */ - int key_len; - char key[MAXPATHLEN * 8]; + zend_string key; + char _key[MAXPATHLEN * 8]; } zend_accel_globals; typedef struct _zend_string_table { @@ -317,11 +317,11 @@ void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason); accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_t *size); int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle); int validate_timestamp_and_record_ex(zend_persistent_script *persistent_script, zend_file_handle *file_handle); -int zend_accel_invalidate(const char *filename, size_t filename_len, bool force); +int zend_accel_invalidate(zend_string *filename, bool force); int accelerator_shm_read_lock(void); void accelerator_shm_read_unlock(void); -char *accel_make_persistent_key(const char *path, size_t path_length, int *key_len); +zend_string *accel_make_persistent_key(zend_string *path); zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type); #define IS_ACCEL_INTERNED(str) \ diff --git a/ext/opcache/zend_accelerator_hash.c b/ext/opcache/zend_accelerator_hash.c index b3f2dfce20..e18960fb7d 100644 --- a/ext/opcache/zend_accelerator_hash.c +++ b/ext/opcache/zend_accelerator_hash.c @@ -200,32 +200,6 @@ zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, z 0); } -/* Returns the data associated with key on success - * Returns NULL if data doesn't exist - */ -void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, const char *key, uint32_t key_length) -{ - return zend_accel_hash_find_ex( - accel_hash, - key, - key_length, - zend_inline_hash_func(key, key_length), - 1); -} - -/* Returns the hash entry associated with key on success - * Returns NULL if it doesn't exist - */ -zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_hash, const char *key, uint32_t key_length) -{ - return (zend_accel_hash_entry *)zend_accel_hash_find_ex( - accel_hash, - key, - key_length, - zend_inline_hash_func(key, key_length), - 0); -} - int zend_accel_hash_unlink(zend_accel_hash *accel_hash, const char *key, uint32_t key_length) { zend_ulong hash_value; diff --git a/ext/opcache/zend_accelerator_hash.h b/ext/opcache/zend_accelerator_hash.h index 88edbd23d8..b2feba5ed2 100644 --- a/ext/opcache/zend_accelerator_hash.h +++ b/ext/opcache/zend_accelerator_hash.h @@ -79,16 +79,6 @@ zend_accel_hash_entry* zend_accel_hash_find_entry( zend_accel_hash *accel_hash, zend_string *key); -void* zend_accel_hash_str_find( - zend_accel_hash *accel_hash, - const char *key, - uint32_t key_length); - -zend_accel_hash_entry* zend_accel_hash_str_find_entry( - zend_accel_hash *accel_hash, - const char *key, - uint32_t key_length); - int zend_accel_hash_unlink( zend_accel_hash *accel_hash, const char *key, diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index a3c7bd7a14..d2d847678e 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -310,17 +310,21 @@ ZEND_INI_END() static int filename_is_in_cache(zend_string *filename) { - char *key; - int key_length; + zend_string *key; - key = accel_make_persistent_key(ZSTR_VAL(filename), ZSTR_LEN(filename), &key_length); + key = accel_make_persistent_key(filename); if (key != NULL) { - zend_persistent_script *persistent_script = zend_accel_hash_str_find(&ZCSG(hash), key, key_length); + zend_persistent_script *persistent_script = zend_accel_hash_find(&ZCSG(hash), key); if (persistent_script && !persistent_script->corrupted) { if (ZCG(accel_directives).validate_timestamps) { zend_file_handle handle; - zend_stream_init_filename(&handle, ZSTR_VAL(filename)); - return validate_timestamp_and_record_ex(persistent_script, &handle) == SUCCESS; + int ret; + + zend_stream_init_filename_ex(&handle, filename); + ret = validate_timestamp_and_record_ex(persistent_script, &handle) == SUCCESS + ? 1 : 0; + zend_destroy_file_handle(&handle); + return ret; } return 1; @@ -836,11 +840,10 @@ ZEND_FUNCTION(opcache_reset) /* {{{ Invalidates cached script (in necessary or forced) */ ZEND_FUNCTION(opcache_invalidate) { - char *script_name; - size_t script_name_len; + zend_string *script_name; bool force = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &script_name, &script_name_len, &force) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &script_name, &force) == FAILURE) { RETURN_THROWS(); } @@ -848,7 +851,7 @@ ZEND_FUNCTION(opcache_invalidate) RETURN_FALSE; } - if (zend_accel_invalidate(script_name, script_name_len, force) == SUCCESS) { + if (zend_accel_invalidate(script_name, force) == SUCCESS) { RETURN_TRUE; } else { RETURN_FALSE; @@ -857,14 +860,13 @@ ZEND_FUNCTION(opcache_invalidate) ZEND_FUNCTION(opcache_compile_file) { - char *script_name; - size_t script_name_len; + zend_string *script_name; zend_file_handle handle; zend_op_array *op_array = NULL; zend_execute_data *orig_execute_data = NULL; uint32_t orig_compiler_options; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &script_name, &script_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &script_name) == FAILURE) { RETURN_THROWS(); } @@ -873,7 +875,7 @@ ZEND_FUNCTION(opcache_compile_file) RETURN_FALSE; } - zend_stream_init_filename(&handle, script_name); + zend_stream_init_filename_ex(&handle, script_name); orig_execute_data = EG(current_execute_data); orig_compiler_options = CG(compiler_options); @@ -889,7 +891,7 @@ ZEND_FUNCTION(opcache_compile_file) op_array = persistent_compile_file(&handle, ZEND_INCLUDE); } zend_catch { EG(current_execute_data) = orig_execute_data; - zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not compile file %s", handle.filename); + zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not compile file %s", ZSTR_VAL(handle.filename)); } zend_end_try(); } diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 1fb7281721..216b6a1eb0 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -1247,7 +1247,7 @@ static void zend_persist_warnings(zend_persistent_script *script) { } } -zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length, int for_shm) +zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, int for_shm) { Bucket *p; @@ -1256,10 +1256,6 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */ script = zend_shared_memdup_free(script, sizeof(zend_persistent_script)); - if (key && *key) { - *key = zend_shared_memdup_put((void*)*key, key_length + 1); - } - script->corrupted = 0; ZCG(current_persistent_script) = script; diff --git a/ext/opcache/zend_persist.h b/ext/opcache/zend_persist.h index 38afac39d9..f491cb8ca6 100644 --- a/ext/opcache/zend_persist.h +++ b/ext/opcache/zend_persist.h @@ -22,8 +22,8 @@ #ifndef ZEND_PERSIST_H #define ZEND_PERSIST_H -uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, const char *key, unsigned int key_length, int for_shm); -zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length, int for_shm); +uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, int for_shm); +zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, int for_shm); void zend_persist_class_entry_calc(zend_class_entry *ce); zend_class_entry *zend_persist_class_entry(zend_class_entry *ce); diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index ad27d539be..092fcb0c67 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -558,7 +558,7 @@ static void zend_persist_warnings_calc(zend_persistent_script *script) { } } -uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, const char *key, unsigned int key_length, int for_shm) +uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, int for_shm) { Bucket *p; @@ -573,10 +573,6 @@ uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_s } ADD_SIZE(sizeof(zend_persistent_script)); - if (key) { - ADD_SIZE(key_length + 1); - zend_shared_alloc_register_xlat_entry(key, key); - } ADD_STRING(new_persistent_script->script.filename); #if defined(__AVX__) || defined(__SSE2__) diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 7339b0eed2..99502478be 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -26,7 +26,7 @@ static void destroy_phar_data(zval *zv); ZEND_DECLARE_MODULE_GLOBALS(phar) -zend_string *(*phar_save_resolve_path)(const char *filename, size_t filename_len); +static zend_string *(*phar_save_resolve_path)(zend_string *filename); /** * set's phar->is_writeable based on the current INI value @@ -3292,41 +3292,41 @@ static size_t phar_zend_stream_fsizer(void *handle) /* {{{ */ } /* }}} */ zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type); -#define phar_orig_zend_open zend_stream_open_function -static zend_string *phar_resolve_path(const char *filename, size_t filename_len) +static zend_string *phar_resolve_path(zend_string *filename) { - return phar_find_in_include_path((char *) filename, filename_len, NULL); + zend_string *ret = phar_find_in_include_path(ZSTR_VAL(filename), ZSTR_LEN(filename), NULL); + if (!ret) { + ret = phar_save_resolve_path(filename); + } + return ret; } static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type) /* {{{ */ { zend_op_array *res; - char *name = NULL; + zend_string *name = NULL; int failed; phar_archive_data *phar; if (!file_handle || !file_handle->filename) { return phar_orig_compile_file(file_handle, type); } - if (strstr(file_handle->filename, ".phar") && !strstr(file_handle->filename, "://")) { - if (SUCCESS == phar_open_from_filename((char*)file_handle->filename, strlen(file_handle->filename), NULL, 0, 0, &phar, NULL)) { + if (strstr(ZSTR_VAL(file_handle->filename), ".phar") && !strstr(ZSTR_VAL(file_handle->filename), "://")) { + if (SUCCESS == phar_open_from_filename(ZSTR_VAL(file_handle->filename), ZSTR_LEN(file_handle->filename), NULL, 0, 0, &phar, NULL)) { if (phar->is_zip || phar->is_tar) { - zend_file_handle f = *file_handle; + zend_file_handle f; /* zip or tar-based phar */ - spprintf(&name, 4096, "phar://%s/%s", file_handle->filename, ".phar/stub.php"); - if (SUCCESS == phar_orig_zend_open((const char *)name, &f)) { - - efree(name); - name = NULL; - + name = zend_strpprintf(4096, "phar://%s/%s", ZSTR_VAL(file_handle->filename), ".phar/stub.php"); + zend_stream_init_filename_ex(&f, name); + if (SUCCESS == zend_stream_open_function(&f)) { + zend_string_release(f.filename); f.filename = file_handle->filename; if (f.opened_path) { - efree(f.opened_path); + zend_string_release(f.opened_path); } f.opened_path = file_handle->opened_path; - f.free_filename = file_handle->free_filename; switch (file_handle->type) { case ZEND_HANDLE_STREAM: @@ -3341,7 +3341,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type) *file_handle = f; } } else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) { - zend_file_handle_dtor(file_handle); /* compressed phar */ file_handle->type = ZEND_HANDLE_STREAM; /* we do our own reading directly from the phar, don't change the next line */ @@ -3367,7 +3366,7 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type) } zend_end_try(); if (name) { - efree(name); + zend_string_release(name); } if (failed) { diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index dab3688ba4..89344a3f22 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -475,10 +475,6 @@ union _phar_entry_object { phar_entry_info *entry; }; -#ifndef PHAR_MAIN -extern zend_string *(*phar_save_resolve_path)(const char *filename, size_t filename_len); -#endif - BEGIN_EXTERN_C() #ifdef PHP_WIN32 diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 2100356d9b..f67855af18 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -247,13 +247,12 @@ static int phar_file_action(phar_archive_data *phar, phar_entry_info *info, char if (!new_op_array) { zend_hash_str_del(&EG(included_files), name, name_len); } - - zend_destroy_file_handle(&file_handle); - } else { efree(name); new_op_array = NULL; } + + zend_destroy_file_handle(&file_handle); #ifdef PHP_WIN32 efree(arch); #endif diff --git a/ext/phar/util.c b/ext/phar/util.c index 59362bbc72..4011a996ca 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -253,7 +253,7 @@ zend_string *phar_find_in_include_path(char *filename, size_t filename_len, phar } if (!zend_is_executing() || !PHAR_G(cwd)) { - return phar_save_resolve_path(filename, filename_len); + return NULL; } fname = (char*)zend_get_executed_filename(); @@ -267,7 +267,7 @@ zend_string *phar_find_in_include_path(char *filename, size_t filename_len, phar } if (fname_len < 7 || memcmp(fname, "phar://", 7) || SUCCESS != phar_split_fname(fname, strlen(fname), &arch, &arch_len, &entry, &entry_len, 1, 0)) { - return phar_save_resolve_path(filename, filename_len); + return NULL; } efree(entry); @@ -277,7 +277,7 @@ zend_string *phar_find_in_include_path(char *filename, size_t filename_len, phar if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL)) { efree(arch); - return phar_save_resolve_path(filename, filename_len); + return NULL; } splitted: if (pphar) { diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index 2930796ae7..b13cd4ea81 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -598,8 +598,10 @@ static int readline_shell_run(void) /* {{{ */ if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { zend_file_handle prepend_file; + zend_stream_init_filename(&prepend_file, PG(auto_prepend_file)); zend_execute_scripts(ZEND_REQUIRE, NULL, 1, &prepend_file); + zend_destroy_file_handle(&prepend_file); } #ifndef PHP_WIN32 diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 5981d2385f..9520fb2a9e 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -239,20 +239,19 @@ PHP_FUNCTION(spl_classes) static int spl_autoload(zend_string *class_name, zend_string *lc_name, const char *ext, int ext_len) /* {{{ */ { - char *class_file; - int class_file_len; + zend_string *class_file; zval dummy; zend_file_handle file_handle; zend_op_array *new_op_array; zval result; int ret; - class_file_len = (int)spprintf(&class_file, 0, "%s%.*s", ZSTR_VAL(lc_name), ext_len, ext); + class_file = zend_strpprintf(0, "%s%.*s", ZSTR_VAL(lc_name), ext_len, ext); #if DEFAULT_SLASH != '\\' { - char *ptr = class_file; - char *end = ptr + class_file_len; + char *ptr = ZSTR_VAL(class_file); + char *end = ptr + ZSTR_LEN(class_file); while ((ptr = memchr(ptr, '\\', (end - ptr))) != NULL) { *ptr = DEFAULT_SLASH; @@ -260,21 +259,20 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha } #endif - ret = php_stream_open_for_zend_ex(class_file, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE); + zend_stream_init_filename_ex(&file_handle, class_file); + ret = php_stream_open_for_zend_ex(&file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE); if (ret == SUCCESS) { zend_string *opened_path; if (!file_handle.opened_path) { - file_handle.opened_path = zend_string_init(class_file, class_file_len, 0); + file_handle.opened_path = zend_string_copy(class_file); } opened_path = zend_string_copy(file_handle.opened_path); ZVAL_NULL(&dummy); if (zend_hash_add(&EG(included_files), opened_path, &dummy)) { new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE); - zend_destroy_file_handle(&file_handle); } else { new_op_array = NULL; - zend_file_handle_dtor(&file_handle); } zend_string_release_ex(opened_path, 0); if (new_op_array) { @@ -287,11 +285,13 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha zval_ptr_dtor(&result); } - efree(class_file); + zend_destroy_file_handle(&file_handle); + zend_string_release(class_file); return zend_hash_exists(EG(class_table), lc_name); } } - efree(class_file); + zend_destroy_file_handle(&file_handle); + zend_string_release(class_file); return 0; } /* }}} */ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 1a6326624b..1f598aa540 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1900,32 +1900,32 @@ PHP_FUNCTION(highlight_file) /* {{{ Return source with stripped comments and whitespace */ PHP_FUNCTION(php_strip_whitespace) { - char *filename; - size_t filename_len; + zend_string *filename; zend_lex_state original_lex_state; zend_file_handle file_handle; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_PATH(filename, filename_len) + Z_PARAM_PATH_STR(filename) ZEND_PARSE_PARAMETERS_END(); php_output_start_default(); - zend_stream_init_filename(&file_handle, filename); + zend_stream_init_filename_ex(&file_handle, filename); zend_save_lexical_state(&original_lex_state); if (open_file_for_scanning(&file_handle) == FAILURE) { zend_restore_lexical_state(&original_lex_state); php_output_end(); + zend_destroy_file_handle(&file_handle); RETURN_EMPTY_STRING(); } zend_strip(); - zend_destroy_file_handle(&file_handle); zend_restore_lexical_state(&original_lex_state); php_output_get_contents(return_value); php_output_discard(); + zend_destroy_file_handle(&file_handle); } /* }}} */ @@ -2606,21 +2606,20 @@ static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, zval *arg3, /* {{{ Parse configuration file */ PHP_FUNCTION(parse_ini_file) { - char *filename = NULL; - size_t filename_len = 0; + zend_string *filename = NULL; bool process_sections = 0; zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL; zend_file_handle fh; zend_ini_parser_cb_t ini_parser_cb; ZEND_PARSE_PARAMETERS_START(1, 3) - Z_PARAM_PATH(filename, filename_len) + Z_PARAM_PATH_STR(filename) Z_PARAM_OPTIONAL Z_PARAM_BOOL(process_sections) Z_PARAM_LONG(scanner_mode) ZEND_PARSE_PARAMETERS_END(); - if (filename_len == 0) { + if (ZSTR_LEN(filename) == 0) { zend_argument_value_error(1, "cannot be empty"); RETURN_THROWS(); } @@ -2634,13 +2633,14 @@ PHP_FUNCTION(parse_ini_file) } /* Setup filehandle */ - zend_stream_init_filename(&fh, filename); + zend_stream_init_filename_ex(&fh, filename); array_init(return_value); if (zend_parse_ini_file(&fh, 0, (int)scanner_mode, ini_parser_cb, return_value) == FAILURE) { zend_array_destroy(Z_ARR_P(return_value)); - RETURN_FALSE; + RETVAL_FALSE; } + zend_destroy_file_handle(&fh); } /* }}} */ diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index e5a565798b..8b53c29c09 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -406,16 +406,18 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis { zend_file_handle fh; browscap_parser_ctx ctx = {0}; + FILE *fp; if (filename == NULL || filename[0] == '\0') { return FAILURE; } - zend_stream_init_fp(&fh, VCWD_FOPEN(filename, "r"), filename); - if (!fh.handle.fp) { + fp = VCWD_FOPEN(filename, "r"); + if (!fp) { zend_error(E_CORE_WARNING, "Cannot open \"%s\" for reading", filename); return FAILURE; } + zend_stream_init_fp(&fh, fp, filename); browdata->htab = pemalloc(sizeof *browdata->htab, persistent); zend_hash_init(browdata->htab, 0, NULL, @@ -439,6 +441,7 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis zend_string_release(ctx.current_section_name); } zend_hash_destroy(&ctx.str_interned); + zend_destroy_file_handle(&fh); return SUCCESS; } diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 83471fcb62..128004bfc2 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1525,15 +1525,14 @@ PHP_FUNCTION(stream_socket_enable_crypto) /* {{{ Determine what file will be opened by calls to fopen() with a relative path */ PHP_FUNCTION(stream_resolve_include_path) { - char *filename; - size_t filename_len; + zend_string *filename; zend_string *resolved_path; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_PATH(filename, filename_len) + Z_PARAM_PATH_STR(filename) ZEND_PARSE_PARAMETERS_END(); - resolved_path = zend_resolve_path(filename, filename_len); + resolved_path = zend_resolve_path(filename); if (resolved_path) { RETURN_STR(resolved_path); |