diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-16 16:40:54 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-16 16:44:37 +0200 |
commit | 49bac9b77bc9cacc0f984092d226e951ae336b43 (patch) | |
tree | f705f93aa693fc5e0ea5c44231585fd41f42dd57 | |
parent | 46faf8f018e95de27873dbcf7c094af18c4c08e4 (diff) | |
download | php-git-49bac9b77bc9cacc0f984092d226e951ae336b43.tar.gz |
Introduce zend_stream_init_filename()
Avoid more ad-hoc initialization of zend_file_handle structures.
-rw-r--r-- | Zend/zend_language_scanner.l | 11 | ||||
-rw-r--r-- | Zend/zend_stream.c | 6 | ||||
-rw-r--r-- | Zend/zend_stream.h | 1 | ||||
-rw-r--r-- | ext/opcache/ZendAccelerator.c | 18 | ||||
-rw-r--r-- | ext/opcache/zend_accelerator_module.c | 12 | ||||
-rw-r--r-- | ext/phar/phar_object.c | 5 | ||||
-rw-r--r-- | ext/readline/readline_cli.c | 12 | ||||
-rw-r--r-- | ext/standard/basic_functions.c | 10 | ||||
-rw-r--r-- | main/main.c | 12 | ||||
-rw-r--r-- | sapi/apache2handler/sapi_apache2.c | 6 | ||||
-rw-r--r-- | sapi/cgi/cgi_main.c | 6 | ||||
-rw-r--r-- | sapi/cli/php_cli_server.c | 12 | ||||
-rw-r--r-- | sapi/litespeed/lsapi_main.c | 6 |
13 files changed, 29 insertions, 88 deletions
diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 5824b6b763..5526a0a0b3 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -659,11 +659,7 @@ zend_op_array *compile_filename(int type, zval *filename) ZVAL_STR(&tmp, zval_get_string(filename)); filename = &tmp; } - file_handle.filename = Z_STRVAL_P(filename); - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - file_handle.handle.fp = NULL; + zend_stream_init_filename(&file_handle, Z_STRVAL_P(filename)); retval = zend_compile_file(&file_handle, type); if (retval && file_handle.handle.stream.handle) { @@ -789,10 +785,7 @@ int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlight zend_lex_state original_lex_state; zend_file_handle file_handle; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; + zend_stream_init_filename(&file_handle, filename); zend_save_lexical_state(&original_lex_state); if (open_file_for_scanning(&file_handle)==FAILURE) { zend_message_dispatcher(ZMSG_FAILED_HIGHLIGHT_FOPEN, filename); diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c index fc0523ee96..08a1db2583 100644 --- a/Zend/zend_stream.c +++ b/Zend/zend_stream.c @@ -101,6 +101,12 @@ ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char handle->filename = filename; } +ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *filename) { + memset(handle, 0, sizeof(zend_file_handle)); + handle->type = ZEND_HANDLE_FILENAME; + handle->filename = filename; +} + ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle) /* {{{ */ { if (zend_stream_open_function) { diff --git a/Zend/zend_stream.h b/Zend/zend_stream.h index 1438a51dea..18b07d6b3c 100644 --- a/Zend/zend_stream.h +++ b/Zend/zend_stream.h @@ -70,6 +70,7 @@ typedef struct _zend_file_handle { BEGIN_EXTERN_C() ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char *filename); +ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *filename); ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle); ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len); ZEND_API void zend_file_handle_dtor(zend_file_handle *fh); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 81d579d9a8..cc57637642 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1071,8 +1071,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri file_handle->opened_path = NULL; } - ps_handle.type = ZEND_HANDLE_FILENAME; - ps_handle.filename = ZSTR_VAL(persistent_script->script.filename); + zend_stream_init_filename(&ps_handle, ZSTR_VAL(persistent_script->script.filename)); ps_handle.opened_path = persistent_script->script.filename; if (zend_get_file_handle_timestamp(&ps_handle, NULL) == persistent_script->timestamp) { @@ -1297,9 +1296,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f persistent_script = zend_accel_hash_find(&ZCSG(hash), realpath); if (persistent_script && !persistent_script->corrupted) { zend_file_handle file_handle; - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = ZSTR_VAL(realpath); + zend_stream_init_filename(&file_handle, ZSTR_VAL(realpath)); file_handle.opened_path = realpath; if (force || @@ -2198,10 +2195,8 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl ZCG(cache_opline) == EG(current_execute_data)->opline)) { /* we are in include_once or FastCGI request */ - handle->filename = (char*)filename; - handle->free_filename = 0; + zend_stream_init_filename(handle, (char*) filename); handle->opened_path = zend_string_copy(ZCG(cache_persistent_script)->script.filename); - handle->type = ZEND_HANDLE_FILENAME; return SUCCESS; } ZCG(cache_opline) = NULL; @@ -4139,12 +4134,7 @@ static int accel_preload(const char *config) orig_map_ptr_last = CG(map_ptr_last); /* Compile and execute proloading script */ - memset(&file_handle, 0, sizeof(file_handle)); - file_handle.filename = (char*)config; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - file_handle.handle.fp = NULL; + zend_stream_init_filename(&file_handle, (char *) config); preload_scripts = emalloc(sizeof(HashTable)); zend_hash_init(preload_scripts, 0, NULL, NULL, 0); diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index a8a1fc99a6..bcbc927703 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -332,12 +332,9 @@ static int filename_is_in_cache(zend_string *filename) if (key != NULL) { zend_persistent_script *persistent_script = zend_accel_hash_str_find(&ZCSG(hash), key, key_length); if (persistent_script && !persistent_script->corrupted) { - zend_file_handle handle = {{0}, NULL, NULL, 0, 0}; - - handle.filename = ZSTR_VAL(filename); - handle.type = ZEND_HANDLE_FILENAME; - 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; } @@ -849,10 +846,7 @@ static ZEND_FUNCTION(opcache_compile_file) return; } - handle.filename = script_name; - handle.free_filename = 0; - handle.opened_path = NULL; - handle.type = ZEND_HANDLE_FILENAME; + zend_stream_init_filename(&handle, script_name); orig_execute_data = EG(current_execute_data); orig_compiler_options = CG(compiler_options); diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 783b7f77f8..3478507499 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -219,10 +219,7 @@ static int phar_file_action(phar_archive_data *phar, phar_entry_info *info, char name_len = spprintf(&name, 4096, "phar://%s/%s", arch, entry); } - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = name; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; + zend_stream_init_filename(&file_handle, name); PHAR_G(cwd) = NULL; PHAR_G(cwd_len) = 0; diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index 956386c532..c533fc2743 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -592,17 +592,9 @@ static int readline_shell_run(void) /* {{{ */ int history_lines_to_write = 0; if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { - zend_file_handle *prepend_file_p; zend_file_handle prepend_file; - - memset(&prepend_file, 0, sizeof(prepend_file)); - prepend_file.filename = PG(auto_prepend_file); - prepend_file.opened_path = NULL; - prepend_file.free_filename = 0; - prepend_file.type = ZEND_HANDLE_FILENAME; - prepend_file_p = &prepend_file; - - zend_execute_scripts(ZEND_REQUIRE, NULL, 1, prepend_file_p); + zend_stream_init_filename(&prepend_file, PG(auto_prepend_file)); + zend_execute_scripts(ZEND_REQUIRE, NULL, 1, &prepend_file); } #ifndef PHP_WIN32 diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 6bbd24f6cc..cfe59fb8ec 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -5315,11 +5315,7 @@ PHP_FUNCTION(php_strip_whitespace) php_output_start_default(); - memset(&file_handle, 0, sizeof(file_handle)); - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; + zend_stream_init_filename(&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); @@ -6082,9 +6078,7 @@ PHP_FUNCTION(parse_ini_file) } /* Setup filehandle */ - memset(&fh, 0, sizeof(fh)); - fh.filename = filename; - fh.type = ZEND_HANDLE_FILENAME; + zend_stream_init_filename(&fh, filename); array_init(return_value); if (zend_parse_ini_file(&fh, 0, (int)scanner_mode, ini_parser_cb, return_value) == FAILURE) { diff --git a/main/main.c b/main/main.c index c9d37ac2e0..90cf190f43 100644 --- a/main/main.c +++ b/main/main.c @@ -2517,7 +2517,7 @@ void php_module_shutdown(void) PHPAPI int php_execute_script(zend_file_handle *primary_file) { zend_file_handle *prepend_file_p, *append_file_p; - zend_file_handle prepend_file = {{0}, NULL, NULL, 0, 0}, append_file = {{0}, NULL, NULL, 0, 0}; + zend_file_handle prepend_file, append_file; #if HAVE_BROKEN_GETCWD volatile int old_cwd_fd = -1; #else @@ -2569,20 +2569,14 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file) } if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { - prepend_file.filename = PG(auto_prepend_file); - prepend_file.opened_path = NULL; - prepend_file.free_filename = 0; - prepend_file.type = ZEND_HANDLE_FILENAME; + zend_stream_init_filename(&prepend_file, PG(auto_prepend_file)); prepend_file_p = &prepend_file; } else { prepend_file_p = NULL; } if (PG(auto_append_file) && PG(auto_append_file)[0]) { - append_file.filename = PG(auto_append_file); - append_file.opened_path = NULL; - append_file.free_filename = 0; - append_file.type = ZEND_HANDLE_FILENAME; + zend_stream_init_filename(&append_file, PG(auto_append_file)); append_file_p = &append_file; } else { append_file_p = NULL; diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 193420eca4..1cc5670eaa 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -694,11 +694,7 @@ zend_first_try { highlight_file((char *)r->filename, &syntax_highlighter_ini); } else { zend_file_handle zfd; - - zfd.type = ZEND_HANDLE_FILENAME; - zfd.filename = (char *) r->filename; - zfd.free_filename = 0; - zfd.opened_path = NULL; + zend_stream_init_filename(&zfd, (char *) r->filename); if (!parent_req) { php_execute_script(&zfd); diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 1068930c39..81de65351f 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -2476,11 +2476,7 @@ parent_loop_end: we need in the environment. */ if (SG(request_info).path_translated || cgi || fastcgi) { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.handle.fp = NULL; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; + zend_stream_init_filename(&file_handle, SG(request_info).path_translated); } else { zend_stream_init_fp(&file_handle, stdin, "Standard input code"); } diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 40fad8c10b..f00d8dee54 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -2072,11 +2072,7 @@ static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server } { zend_file_handle zfd; - zfd.type = ZEND_HANDLE_FILENAME; - zfd.filename = SG(request_info).path_translated; - zfd.handle.fp = NULL; - zfd.free_filename = 0; - zfd.opened_path = NULL; + zend_stream_init_filename(&zfd, SG(request_info).path_translated); zend_try { php_execute_script(&zfd); } zend_end_try(); @@ -2197,11 +2193,7 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server old_cwd[0] = '\0'; php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1)); - zfd.type = ZEND_HANDLE_FILENAME; - zfd.filename = server->router; - zfd.handle.fp = NULL; - zfd.free_filename = 0; - zfd.opened_path = NULL; + zend_stream_init_filename(&zfd, server->router); zend_try { zval retval; diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index bec0eacb81..baff98df1e 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -657,11 +657,7 @@ static int lsapi_execute_script( zend_file_handle * file_handle) { char *p; int len; - file_handle->type = ZEND_HANDLE_FILENAME; - file_handle->handle.fd = 0; - file_handle->filename = SG(request_info).path_translated; - file_handle->free_filename = 0; - file_handle->opened_path = NULL; + zend_stream_init_filename(file_handle, SG(request_info).path_translated); p = argv0; *p++ = ':'; |