diff options
Diffstat (limited to 'ext/standard/basic_functions.c')
-rwxr-xr-x | ext/standard/basic_functions.c | 211 |
1 files changed, 109 insertions, 102 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 876ef347eb..1f598aa540 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -283,7 +283,10 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ #endif #endif - php_register_incomplete_class(); + php_ce_incomplete_class = register_class___PHP_Incomplete_Class(); + php_register_incomplete_class_handlers(); + + assertion_error_ce = register_class_AssertionError(zend_ce_error); REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CONNECTION_NORMAL", PHP_CONNECTION_NORMAL, CONST_CS | CONST_PERSISTENT); @@ -463,8 +466,6 @@ PHP_RINIT_FUNCTION(basic) /* {{{ */ BG(strtok_last) = NULL; BG(ctype_string) = NULL; BG(locale_changed) = 0; - BG(array_walk_fci) = empty_fcall_info; - BG(array_walk_fci_cache) = empty_fcall_info_cache; BG(user_compare_fci) = empty_fcall_info; BG(user_compare_fci_cache) = empty_fcall_info_cache; BG(page_uid) = -1; @@ -729,98 +730,98 @@ PHP_FUNCTION(long2ip) * System Functions * ********************/ -/* {{{ Get the value of an environment variable or every available environment variable - if no varname is present */ -PHP_FUNCTION(getenv) -{ - char *ptr, *str = NULL; - size_t str_len; - zend_bool local_only = 0; - - ZEND_PARSE_PARAMETERS_START(0, 2) - Z_PARAM_OPTIONAL - Z_PARAM_STRING_OR_NULL(str, str_len) - Z_PARAM_BOOL(local_only) - ZEND_PARSE_PARAMETERS_END(); - - if (!str) { - array_init(return_value); - php_import_environment_variables(return_value); - return; - } - - if (!local_only) { - /* SAPI method returns an emalloc()'d string */ - ptr = sapi_getenv(str, str_len); - if (ptr) { - // TODO: avoid reallocation ??? - RETVAL_STRING(ptr); - efree(ptr); - return; - } - } +PHPAPI zend_string *php_getenv(const char *str, size_t str_len) { #ifdef PHP_WIN32 { - wchar_t dummybuf; - DWORD size; - wchar_t *keyw, *valw; - - keyw = php_win32_cp_conv_any_to_w(str, str_len, PHP_WIN32_CP_IGNORE_LEN_P); + wchar_t *keyw = php_win32_cp_conv_any_to_w(str, str_len, PHP_WIN32_CP_IGNORE_LEN_P); if (!keyw) { - RETURN_FALSE; + return NULL; } SetLastError(0); - /*If the given buffer is not large enough to hold the data, the return value is - the buffer size, in characters, required to hold the string and its terminating - null character. We use this return value to alloc the final buffer. */ - size = GetEnvironmentVariableW(keyw, &dummybuf, 0); + /* If the given buffer is not large enough to hold the data, the return value is + * the buffer size, in characters, required to hold the string and its terminating + * null character. We use this return value to alloc the final buffer. */ + wchar_t dummybuf; + DWORD size = GetEnvironmentVariableW(keyw, &dummybuf, 0); if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { - /* The environment variable doesn't exist. */ - free(keyw); - RETURN_FALSE; + /* The environment variable doesn't exist. */ + free(keyw); + return NULL; } if (size == 0) { - /* env exists, but it is empty */ - free(keyw); - RETURN_EMPTY_STRING(); + /* env exists, but it is empty */ + free(keyw); + return ZSTR_EMPTY_ALLOC(); } - valw = emalloc((size + 1) * sizeof(wchar_t)); + wchar_t *valw = emalloc((size + 1) * sizeof(wchar_t)); size = GetEnvironmentVariableW(keyw, valw, size); if (size == 0) { - /* has been removed between the two calls */ - free(keyw); - efree(valw); - RETURN_EMPTY_STRING(); + /* has been removed between the two calls */ + free(keyw); + efree(valw); + return ZSTR_EMPTY_ALLOC(); } else { - ptr = php_win32_cp_w_to_any(valw); - RETVAL_STRING(ptr); + char *ptr = php_win32_cp_w_to_any(valw); + zend_string *result = zend_string_init(ptr, strlen(ptr), 0); free(ptr); free(keyw); efree(valw); - return; + return result; } } #else - tsrm_env_lock(); /* system method returns a const */ - ptr = getenv(str); - + char *ptr = getenv(str); + zend_string *result = NULL; if (ptr) { - RETVAL_STRING(ptr); + result = zend_string_init(ptr, strlen(ptr), 0); } tsrm_env_unlock(); + return result; +#endif +} - if (ptr) { - return; - } +/* {{{ Get the value of an environment variable or every available environment variable + if no varname is present */ +PHP_FUNCTION(getenv) +{ + char *str = NULL; + size_t str_len; + bool local_only = 0; -#endif + ZEND_PARSE_PARAMETERS_START(0, 2) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(str, str_len) + Z_PARAM_BOOL(local_only) + ZEND_PARSE_PARAMETERS_END(); + + if (!str) { + array_init(return_value); + php_import_environment_variables(return_value); + return; + } + + if (!local_only) { + /* SAPI method returns an emalloc()'d string */ + char *ptr = sapi_getenv(str, str_len); + if (ptr) { + // TODO: avoid reallocation ??? + RETVAL_STRING(ptr); + efree(ptr); + return; + } + } + + zend_string *res = php_getenv(str, str_len); + if (res) { + RETURN_STR(res); + } RETURN_FALSE; } /* }}} */ @@ -1172,7 +1173,7 @@ PHP_FUNCTION(getopt) int optname_int = atoi(optname); if ((args = zend_hash_index_find(Z_ARRVAL_P(return_value), optname_int)) != NULL) { if (Z_TYPE_P(args) != IS_ARRAY) { - convert_to_array_ex(args); + convert_to_array(args); } zend_hash_next_index_insert(Z_ARRVAL_P(args), &val); } else { @@ -1182,7 +1183,7 @@ PHP_FUNCTION(getopt) /* other strings */ if ((args = zend_hash_str_find(Z_ARRVAL_P(return_value), optname, strlen(optname))) != NULL) { if (Z_TYPE_P(args) != IS_ARRAY) { - convert_to_array_ex(args); + convert_to_array(args); } zend_hash_next_index_insert(Z_ARRVAL_P(args), &val); } else { @@ -1472,7 +1473,7 @@ PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_le return FAILURE; case 3: /*save to a file */ - stream = php_stream_open_wrapper(opt, "a", IGNORE_URL_WIN | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(opt, "a", REPORT_ERRORS, NULL); if (!stream) { return FAILURE; } @@ -1809,7 +1810,7 @@ PHP_FUNCTION(register_shutdown_function) } /* }}} */ -PHPAPI zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ +PHPAPI bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ { if (!BG(user_shutdown_function_names)) { ALLOC_HASHTABLE(BG(user_shutdown_function_names)); @@ -1821,7 +1822,7 @@ PHPAPI zend_bool register_user_shutdown_function(const char *function_name, size } /* }}} */ -PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len) /* {{{ */ +PHPAPI bool remove_user_shutdown_function(const char *function_name, size_t function_len) /* {{{ */ { if (BG(user_shutdown_function_names)) { return zend_hash_str_del(BG(user_shutdown_function_names), function_name, function_len) != FAILURE; @@ -1831,7 +1832,7 @@ PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t } /* }}} */ -PHPAPI zend_bool append_user_shutdown_function(php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ +PHPAPI bool append_user_shutdown_function(php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ { if (!BG(user_shutdown_function_names)) { ALLOC_HASHTABLE(BG(user_shutdown_function_names)); @@ -1859,7 +1860,7 @@ PHP_FUNCTION(highlight_file) size_t filename_len; int ret; zend_syntax_highlighter_ini syntax_highlighter_ini; - zend_bool i = 0; + bool i = 0; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(filename, filename_len) @@ -1899,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); } /* }}} */ @@ -1934,7 +1935,7 @@ PHP_FUNCTION(highlight_string) zend_string *str; zend_syntax_highlighter_ini syntax_highlighter_ini; char *hicompiled_string_description; - zend_bool i = 0; + bool i = 0; int old_error_reporting = EG(error_reporting); ZEND_PARSE_PARAMETERS_START(1, 2) @@ -1953,12 +1954,8 @@ PHP_FUNCTION(highlight_string) hicompiled_string_description = zend_make_compiled_string_description("highlighted code"); - // TODO: Accept zend_string in highlight_string API. - zval str_zv; - ZVAL_STR_COPY(&str_zv, str); - highlight_string(&str_zv, &syntax_highlighter_ini, hicompiled_string_description); + highlight_string(str, &syntax_highlighter_ini, hicompiled_string_description); efree(hicompiled_string_description); - zval_ptr_dtor(&str_zv); EG(error_reporting) = old_error_reporting; @@ -2013,7 +2010,7 @@ PHP_FUNCTION(ini_get_all) char *extname = NULL; size_t extname_len = 0, module_number = 0; zend_module_entry *module; - zend_bool details = 1; + bool details = 1; zend_string *key; zend_ini_entry *ini_entry; @@ -2092,14 +2089,19 @@ static int php_ini_check_path(char *option_name, size_t option_len, char *new_op PHP_FUNCTION(ini_set) { zend_string *varname; - zend_string *new_value; + zval *new_value; zend_string *val; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(varname) - Z_PARAM_STR(new_value) + Z_PARAM_ZVAL(new_value) ZEND_PARSE_PARAMETERS_END(); + if (Z_TYPE_P(new_value) > IS_STRING) { + zend_argument_type_error(2, "must be of type string|int|float|bool|null"); + RETURN_THROWS(); + } + val = zend_ini_get_value(varname); if (val) { @@ -2108,6 +2110,9 @@ PHP_FUNCTION(ini_set) RETVAL_FALSE; } + zend_string *new_value_tmp_str; + zend_string *new_value_str = zval_get_tmp_string(new_value, &new_value_tmp_str); + #define _CHECK_PATH(var, var_len, ini) php_ini_check_path(var, var_len, ini, sizeof(ini)) /* open basedir check */ if (PG(open_basedir)) { @@ -2117,18 +2122,20 @@ PHP_FUNCTION(ini_set) _CHECK_PATH(ZSTR_VAL(varname), ZSTR_LEN(varname), "mail.log") || _CHECK_PATH(ZSTR_VAL(varname), ZSTR_LEN(varname), "java.library.path") || _CHECK_PATH(ZSTR_VAL(varname), ZSTR_LEN(varname), "vpopmail.directory")) { - if (php_check_open_basedir(ZSTR_VAL(new_value))) { + if (php_check_open_basedir(ZSTR_VAL(new_value_str))) { zval_ptr_dtor_str(return_value); + zend_tmp_string_release(new_value_tmp_str); RETURN_FALSE; } } } #undef _CHECK_PATH - if (zend_alter_ini_entry_ex(varname, new_value, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == FAILURE) { + if (zend_alter_ini_entry_ex(varname, new_value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == FAILURE) { zval_ptr_dtor_str(return_value); - RETURN_FALSE; + RETVAL_FALSE; } + zend_tmp_string_release(new_value_tmp_str); } /* }}} */ @@ -2197,7 +2204,7 @@ PHP_FUNCTION(get_include_path) PHP_FUNCTION(print_r) { zval *var; - zend_bool do_return = 0; + bool do_return = 0; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(var) @@ -2235,8 +2242,8 @@ PHP_FUNCTION(connection_status) /* {{{ Set whether we want to ignore a user abort event or not */ PHP_FUNCTION(ignore_user_abort) { - zend_bool arg = 0; - zend_bool arg_is_null = 1; + bool arg = 0; + bool arg_is_null = 1; int old_setting; ZEND_PARSE_PARAMETERS_START(0, 1) @@ -2399,7 +2406,7 @@ PHP_FUNCTION(register_tick_function) } if (Z_TYPE(tick_fe.arguments[0]) != IS_ARRAY && Z_TYPE(tick_fe.arguments[0]) != IS_OBJECT) { - convert_to_string_ex(&tick_fe.arguments[0]); + convert_to_string(&tick_fe.arguments[0]); } if (!BG(user_tick_functions)) { @@ -2470,7 +2477,7 @@ PHP_FUNCTION(move_uploaded_file) { char *path, *new_path; size_t path_len, new_path_len; - zend_bool successful = 0; + bool successful = 0; #ifndef PHP_WIN32 int oldmask; int ret; @@ -2599,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_bool process_sections = 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(); } @@ -2627,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); } /* }}} */ @@ -2642,7 +2649,7 @@ PHP_FUNCTION(parse_ini_string) { char *string = NULL, *str = NULL; size_t str_len = 0; - zend_bool process_sections = 0; + bool process_sections = 0; zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL; zend_ini_parser_cb_t ini_parser_cb; |