diff options
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r-- | sapi/cli/php_cli.c | 129 |
1 files changed, 53 insertions, 76 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 91f400aca4..d28f5a5378 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -56,6 +54,7 @@ #include "php_main.h" #include "fopen_wrappers.h" #include "ext/standard/php_standard.h" +#include "ext/standard/dl_arginfo.h" #include "cli.h" #ifdef PHP_WIN32 #include <io.h> @@ -80,6 +79,7 @@ #include "ps_title.h" #include "php_cli_process_title.h" +#include "php_cli_process_title_arginfo.h" #ifndef PHP_WIN32 # define php_select(m, r, w, e, t) select(m, r, w, e, t) @@ -120,7 +120,7 @@ static DWORD orig_cp = 0; #define PHP_MODE_SHOW_INI_CONFIG 13 cli_shell_callbacks_t cli_shell_callbacks = { NULL, NULL, NULL }; -PHP_CLI_API cli_shell_callbacks_t *php_cli_get_shell_callbacks() +PHP_CLI_API cli_shell_callbacks_t *php_cli_get_shell_callbacks(void) { return &cli_shell_callbacks; } @@ -175,11 +175,8 @@ const opt_struct OPTIONS[] = { {'-', 0, NULL} /* end of args */ }; -static int module_name_cmp(const void *a, const void *b) /* {{{ */ +static int module_name_cmp(Bucket *f, Bucket *s) /* {{{ */ { - Bucket *f = (Bucket *) a; - Bucket *s = (Bucket *) b; - return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name, ((zend_module_entry *)Z_PTR(s->val))->name); } @@ -200,10 +197,9 @@ static void print_modules(void) /* {{{ */ } /* }}} */ -static int print_extension_info(zend_extension *ext, void *arg) /* {{{ */ +static void print_extension_info(zend_extension *ext) /* {{{ */ { php_printf("%s\n", ext->name); - return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -360,7 +356,7 @@ static void sapi_cli_register_variables(zval *track_vars_array) /* {{{ */ } /* }}} */ -static void sapi_cli_log_message(char *message, int syslog_type_int) /* {{{ */ +static void sapi_cli_log_message(const char *message, int syslog_type_int) /* {{{ */ { fprintf(stderr, "%s\n", message); #ifdef PHP_WIN32 @@ -416,7 +412,7 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */ /* {{{ sapi_cli_ini_defaults */ -/* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ +/* overwritable ini defaults must be set in sapi_cli_ini_defaults() */ #define INI_DEFAULT(name,value)\ ZVAL_NEW_STR(&tmp, zend_string_init(value, sizeof(value)-1, 1));\ zend_hash_str_update(configuration_hash, name, sizeof(name)-1, &tmp);\ @@ -424,13 +420,11 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */ static void sapi_cli_ini_defaults(HashTable *configuration_hash) { zval tmp; - INI_DEFAULT("report_zend_debug", "0"); INI_DEFAULT("display_errors", "1"); } /* }}} */ -/* {{{ sapi_module_struct cli_sapi_module - */ +/* {{{ sapi_module_struct cli_sapi_module */ static sapi_module_struct cli_sapi_module = { "cli", /* name */ "Command Line Interface", /* pretty name */ @@ -464,12 +458,6 @@ static sapi_module_struct cli_sapi_module = { }; /* }}} */ -/* {{{ arginfo ext/standard/dl.c */ -ZEND_BEGIN_ARG_INFO(arginfo_dl, 0) - ZEND_ARG_INFO(0, extension_filename) -ZEND_END_ARG_INFO() -/* }}} */ - static const zend_function_entry additional_functions[] = { ZEND_FE(dl, arginfo_dl) PHP_FE(cli_set_process_title, arginfo_cli_set_process_title) @@ -477,8 +465,7 @@ static const zend_function_entry additional_functions[] = { PHP_FE_END }; -/* {{{ php_cli_usage - */ +/* {{{ php_cli_usage */ static void php_cli_usage(char *argv0) { char *prog; @@ -498,7 +485,7 @@ static void php_cli_usage(char *argv0) " %s [options] -- [args...]\n" " %s [options] -a\n" "\n" -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) +#if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)) && !defined(COMPILE_DL_READLINE) " -a Run as interactive shell\n" #else " -a Run interactively\n" @@ -587,8 +574,7 @@ static void cli_register_file_handles(void) /* {{{ */ static const char *param_mode_conflict = "Either execute direct code, process stdin or use a file.\n"; -/* {{{ cli_seek_file_begin - */ +/* {{{ cli_seek_file_begin */ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file) { FILE *fp = VCWD_FOPEN(script_file, "rb"); @@ -620,7 +606,6 @@ static int do_cli(int argc, char **argv) /* {{{ */ int behavior = PHP_MODE_STANDARD; char *reflection_what = NULL; volatile int request_started = 0; - volatile int exit_status = 0; char *php_optarg = NULL, *orig_optarg = NULL; int php_optind = 1, orig_optind = 1; char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL; @@ -644,13 +629,13 @@ static int do_cli(int argc, char **argv) /* {{{ */ request_started = 1; php_print_info(0xFFFFFFFF); php_output_end_all(); - exit_status = (c == '?' && argc > 1 && !strchr(argv[1], c)); + EG(exit_status) = (c == '?' && argc > 1 && !strchr(argv[1], c)); goto out; case 'v': /* show php version & quit */ php_printf("PHP %s (%s) (built: %s %s) ( %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__, -#if ZTS +#ifdef ZTS "ZTS " #else "NTS " @@ -686,7 +671,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ print_extensions(); php_printf("\n"); php_output_end_all(); - exit_status=0; + EG(exit_status) = 0; goto out; default: @@ -861,7 +846,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ if (param_error) { PUTS(param_error); - exit_status=1; + EG(exit_status) = 1; goto err; } @@ -880,7 +865,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ #endif if (interactive) { -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) +#if (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)) && !defined(COMPILE_DL_READLINE) printf("Interactive shell\n\n"); #else printf("Interactive mode enabled\n\n"); @@ -911,7 +896,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ } else { /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */ /* here but this would make things only more complicated. And it */ - /* is consitent with the way -R works where the stdin file handle*/ + /* is consistent with the way -R works where the stdin file handle*/ /* is also accessible. */ zend_stream_init_fp(&file_handle, stdin, "Standard input code"); } @@ -959,15 +944,14 @@ static int do_cli(int argc, char **argv) /* {{{ */ } if (interactive && cli_shell_callbacks.cli_shell_run) { - exit_status = cli_shell_callbacks.cli_shell_run(); + EG(exit_status) = cli_shell_callbacks.cli_shell_run(); } else { php_execute_script(&file_handle); - exit_status = EG(exit_status); } break; case PHP_MODE_LINT: - exit_status = php_lint_script(&file_handle); - if (exit_status==SUCCESS) { + EG(exit_status) = php_lint_script(&file_handle); + if (EG(exit_status) == SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { zend_printf("Errors parsing %s\n", file_handle.filename); @@ -992,9 +976,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ break; case PHP_MODE_CLI_DIRECT: cli_register_file_handles(); - if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1) == FAILURE) { - exit_status=254; - } + zend_eval_string_ex(exec_direct, NULL, "Command line code", 1); break; case PHP_MODE_PROCESS_STDIN: @@ -1005,10 +987,10 @@ static int do_cli(int argc, char **argv) /* {{{ */ cli_register_file_handles(); - if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1) == FAILURE) { - exit_status=254; + if (exec_begin) { + zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1); } - while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) { + while (EG(exit_status) == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) { len = strlen(input); while (len > 0 && len-- && (input[len]=='\n' || input[len]=='\r')) { input[len] = '\0'; @@ -1018,24 +1000,21 @@ static int do_cli(int argc, char **argv) /* {{{ */ ZVAL_LONG(&argi, ++index); zend_hash_str_update(&EG(symbol_table), "argi", sizeof("argi")-1, &argi); if (exec_run) { - if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1) == FAILURE) { - exit_status=254; - } + zend_eval_string_ex(exec_run, NULL, "Command line run code", 1); } else { if (script_file) { if (cli_seek_file_begin(&file_handle, script_file) != SUCCESS) { - exit_status = 1; + EG(exit_status) = 1; } else { CG(skip_shebang) = 1; php_execute_script(&file_handle); - exit_status = EG(exit_status); } } } efree(input); } - if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1) == FAILURE) { - exit_status=254; + if (exec_end) { + zend_eval_string_ex(exec_end, NULL, "Command line end code", 1); } break; @@ -1076,15 +1055,14 @@ static int do_cli(int argc, char **argv) /* {{{ */ memset(&execute_data, 0, sizeof(zend_execute_data)); EG(current_execute_data) = &execute_data; - zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, &arg); + zend_call_known_instance_method_with_1_params( + pce->constructor, Z_OBJ(ref), NULL, &arg); if (EG(exception)) { - zval tmp, *msg, rv; - - ZVAL_OBJ(&tmp, EG(exception)); - msg = zend_read_property(zend_ce_exception, &tmp, "message", sizeof("message")-1, 0, &rv); + zval rv; + zval *msg = zend_read_property(zend_ce_exception, EG(exception), "message", sizeof("message")-1, 0, &rv); zend_printf("Exception: %s\n", Z_STRVAL_P(msg)); - zval_ptr_dtor(&tmp); + zend_object_release(EG(exception)); EG(exception) = NULL; } else { zend_print_zval(&ref, 0); @@ -1106,7 +1084,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ display_ini_entries(NULL); } else { zend_printf("Extension '%s' not present.\n", reflection_what); - exit_status = 1; + EG(exit_status) = 1; } } else { php_info_print_module(module); @@ -1134,20 +1112,16 @@ out: if (translated_path) { free(translated_path); } - if (exit_status == 0) { - exit_status = EG(exit_status); - } - return exit_status; + return EG(exit_status); err: sapi_deactivate(); zend_ini_deactivate(); - exit_status = 1; + EG(exit_status) = 1; goto out; } /* }}} */ -/* {{{ main - */ +/* {{{ main */ #ifdef PHP_CLI_WIN32_NO_CONSOLE int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) #else @@ -1189,20 +1163,23 @@ int main(int argc, char *argv[]) cli_sapi_module.additional_functions = additional_functions; -#if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) +#if defined(PHP_WIN32) && defined(_DEBUG) { - int tmp_flag; - _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); - tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmp_flag |= _CRTDBG_LEAK_CHECK_DF; - - _CrtSetDbgFlag(tmp_flag); + char *tmp = getenv("PHP_WIN32_DEBUG_HEAP"); + if (tmp && zend_atoi(tmp, 0)) { + int tmp_flag; + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmp_flag |= _CRTDBG_LEAK_CHECK_DF; + + _CrtSetDbgFlag(tmp_flag); + } } #endif |