diff options
Diffstat (limited to 'ext/standard/basic_functions.c')
-rw-r--r-- | ext/standard/basic_functions.c | 165 |
1 files changed, 98 insertions, 67 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 99a8837869..ef628cc6cb 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -23,6 +23,7 @@ #include "php_streams.h" #include "php_main.h" #include "php_globals.h" +#include "php_variables.h" #include "php_ini.h" #include "php_standard.h" #include "php_math.h" @@ -34,6 +35,7 @@ #include "zend_operators.h" #include "ext/standard/php_dns.h" #include "ext/standard/php_uuencode.h" +#include "ext/standard/php_mt_rand.h" #ifdef PHP_WIN32 #include "win32/php_win32_globals.h" @@ -646,6 +648,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_getopt, 0, 0, 1) ZEND_ARG_INFO(0, options) ZEND_ARG_INFO(0, opts) /* ARRAY_INFO(0, opts, 1) */ + ZEND_ARG_INFO(1, optind) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_flush, 0) @@ -872,12 +875,10 @@ ZEND_END_ARG_INFO() /* }}} */ /* {{{ crypt.c */ -#if HAVE_CRYPT ZEND_BEGIN_ARG_INFO_EX(arginfo_crypt, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, salt) ZEND_END_ARG_INFO() -#endif /* }}} */ /* {{{ cyr_convert.c */ ZEND_BEGIN_ARG_INFO(arginfo_convert_cyr_string, 0) @@ -1884,18 +1885,10 @@ ZEND_BEGIN_ARG_INFO(arginfo_quoted_printable_encode, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() /* }}} */ -/* {{{ rand.c */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_srand, 0, 0, 0) - ZEND_ARG_INFO(0, seed) -ZEND_END_ARG_INFO() - +/* {{{ mt_rand.c */ ZEND_BEGIN_ARG_INFO_EX(arginfo_mt_srand, 0, 0, 0) ZEND_ARG_INFO(0, seed) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_rand, 0, 0, 0) - ZEND_ARG_INFO(0, min) - ZEND_ARG_INFO(0, max) + ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_mt_rand, 0, 0, 0) @@ -1903,9 +1896,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_mt_rand, 0, 0, 0) ZEND_ARG_INFO(0, max) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_getrandmax, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO(arginfo_mt_getrandmax, 0) ZEND_END_ARG_INFO() /* }}} */ @@ -2565,6 +2555,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_is_callable, 0, 0, 1) ZEND_ARG_INFO(0, syntax_only) ZEND_ARG_INFO(1, callable_name) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_is_iterable, 0, 0, 1) + ZEND_ARG_INFO(0, var) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ uniqid.c */ #ifdef HAVE_GETTIMEOFDAY @@ -2599,6 +2593,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_get_headers, 0, 0, 1) ZEND_ARG_INFO(0, url) ZEND_ARG_INFO(0, format) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() /* }}} */ /* {{{ user_filters.c */ @@ -2676,6 +2671,25 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_version_compare, 0, 0, 2) ZEND_ARG_INFO(0, oper) ZEND_END_ARG_INFO() /* }}} */ +/* {{{ win32/codepage.c */ +#ifdef PHP_WIN32 +ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_cp_set, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, code_page, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_cp_get, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_cp_is_utf8, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_cp_conv, 0, 0, 3) + ZEND_ARG_INFO(0, in_codepage) + ZEND_ARG_INFO(0, out_codepage) + ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0) +ZEND_END_ARG_INFO() +#endif +/* }}} */ /* }}} */ const zend_function_entry basic_functions[] = { /* {{{ */ @@ -2837,10 +2851,10 @@ const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(proc_nice, arginfo_proc_nice) #endif - PHP_FE(rand, arginfo_rand) - PHP_FE(srand, arginfo_srand) - PHP_FE(getrandmax, arginfo_getrandmax) - PHP_FE(mt_rand, arginfo_mt_rand) + PHP_FE(rand, arginfo_mt_rand) + PHP_FALIAS(srand, mt_srand, arginfo_mt_srand) + PHP_FALIAS(getrandmax, mt_getrandmax, arginfo_mt_getrandmax) + PHP_FE(mt_rand, arginfo_mt_rand) PHP_FE(mt_srand, arginfo_mt_srand) PHP_FE(mt_getrandmax, arginfo_mt_getrandmax) @@ -3061,6 +3075,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(is_object, arginfo_is_object) PHP_FE(is_scalar, arginfo_is_scalar) PHP_FE(is_callable, arginfo_is_callable) + PHP_FE(is_iterable, arginfo_is_iterable) /* functions from file.c */ PHP_FE(pclose, arginfo_pclose) @@ -3169,10 +3184,8 @@ const zend_function_entry basic_functions[] = { /* {{{ */ /* functions from browscap.c */ PHP_FE(get_browser, arginfo_get_browser) -#if HAVE_CRYPT /* functions from crypt.c */ PHP_FE(crypt, arginfo_crypt) -#endif /* functions from dir.c */ PHP_FE(opendir, arginfo_opendir) @@ -3371,6 +3384,12 @@ const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(sys_get_temp_dir, arginfo_sys_get_temp_dir) +#ifdef PHP_WIN32 + PHP_FE(sapi_windows_cp_set, arginfo_sapi_windows_cp_set) + PHP_FE(sapi_windows_cp_get, arginfo_sapi_windows_cp_get) + PHP_FE(sapi_windows_cp_is_utf8, arginfo_sapi_windows_cp_is_utf8) + PHP_FE(sapi_windows_cp_conv, arginfo_sapi_windows_cp_conv) +#endif PHP_FE_END }; /* }}} */ @@ -3450,8 +3469,8 @@ static void php_putenv_destructor(zval *zv) /* {{{ */ static void basic_globals_ctor(php_basic_globals *basic_globals_p) /* {{{ */ { - BG(rand_is_seeded) = 0; BG(mt_rand_is_seeded) = 0; + BG(mt_rand_mode) = MT_RAND_MT19937; BG(umask) = -1; BG(next) = NULL; BG(left) = -1; @@ -3462,7 +3481,8 @@ static void basic_globals_ctor(php_basic_globals *basic_globals_p) /* {{{ */ memset(&BG(serialize), 0, sizeof(BG(serialize))); memset(&BG(unserialize), 0, sizeof(BG(unserialize))); - memset(&BG(url_adapt_state_ex), 0, sizeof(BG(url_adapt_state_ex))); + memset(&BG(url_adapt_session_ex), 0, sizeof(BG(url_adapt_session_ex))); + memset(&BG(url_adapt_output_ex), 0, sizeof(BG(url_adapt_output_ex))); #if defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T) memset(&BG(mblen_state), 0, sizeof(BG(mblen_state))); @@ -3476,9 +3496,13 @@ static void basic_globals_ctor(php_basic_globals *basic_globals_p) /* {{{ */ static void basic_globals_dtor(php_basic_globals *basic_globals_p) /* {{{ */ { - if (basic_globals_p->url_adapt_state_ex.tags) { - zend_hash_destroy(basic_globals_p->url_adapt_state_ex.tags); - free(basic_globals_p->url_adapt_state_ex.tags); + if (basic_globals_p->url_adapt_session_ex.tags) { + zend_hash_destroy(basic_globals_p->url_adapt_session_ex.tags); + free(basic_globals_p->url_adapt_session_ex.tags); + } + if (basic_globals_p->url_adapt_output_ex.tags) { + zend_hash_destroy(basic_globals_p->url_adapt_output_ex.tags); + free(basic_globals_p->url_adapt_output_ex.tags); } } /* }}} */ @@ -3492,8 +3516,8 @@ PHPAPI double php_get_nan(void) /* {{{ */ return HUGE_VAL + -HUGE_VAL; #elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha) double val = 0.0; - ((php_uint32*)&val)[1] = PHP_DOUBLE_QUIET_NAN_HIGH; - ((php_uint32*)&val)[0] = 0; + ((uint32_t*)&val)[1] = PHP_DOUBLE_QUIET_NAN_HIGH; + ((uint32_t*)&val)[0] = 0; return val; #elif HAVE_ATOF_ACCEPTS_NAN return atof("NAN"); @@ -3509,8 +3533,8 @@ PHPAPI double php_get_inf(void) /* {{{ */ return HUGE_VAL; #elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha) double val = 0.0; - ((php_uint32*)&val)[1] = PHP_DOUBLE_INFINITY_HIGH; - ((php_uint32*)&val)[0] = 0; + ((uint32_t*)&val)[1] = PHP_DOUBLE_INFINITY_HIGH; + ((uint32_t*)&val)[0] = 0; return val; #elif HAVE_ATOF_ACCEPTS_INF return atof("INF"); @@ -3633,6 +3657,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ BASIC_MINIT_SUBMODULE(standard_filters) BASIC_MINIT_SUBMODULE(user_filters) BASIC_MINIT_SUBMODULE(password) + BASIC_MINIT_SUBMODULE(mt_rand) #if defined(HAVE_LOCALECONV) && defined(ZTS) BASIC_MINIT_SUBMODULE(localeconv) @@ -3642,10 +3667,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ BASIC_MINIT_SUBMODULE(nl_langinfo) #endif -#if HAVE_CRYPT BASIC_MINIT_SUBMODULE(crypt) -#endif - BASIC_MINIT_SUBMODULE(lcg) BASIC_MINIT_SUBMODULE(dir) @@ -3714,10 +3736,7 @@ PHP_MSHUTDOWN_FUNCTION(basic) /* {{{ */ #if defined(HAVE_LOCALECONV) && defined(ZTS) BASIC_MSHUTDOWN_SUBMODULE(localeconv) #endif -#if HAVE_CRYPT BASIC_MSHUTDOWN_SUBMODULE(crypt) -#endif - BASIC_MSHUTDOWN_SUBMODULE(random) zend_hash_destroy(&basic_submodules); @@ -3843,20 +3862,21 @@ PHP_FUNCTION(constant) { zend_string *const_name; zval *c; + zend_class_entry *scope; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &const_name) == FAILURE) { return; } - c = zend_get_constant_ex(const_name, NULL, ZEND_FETCH_CLASS_SILENT); + scope = zend_get_executed_scope(); + c = zend_get_constant_ex(const_name, scope, ZEND_FETCH_CLASS_SILENT); if (c) { - ZVAL_COPY_VALUE(return_value, c); + ZVAL_DUP(return_value, c); if (Z_CONSTANT_P(return_value)) { - if (UNEXPECTED(zval_update_constant_ex(return_value, 1, NULL) != SUCCESS)) { + if (UNEXPECTED(zval_update_constant_ex(return_value, scope) != SUCCESS)) { return; } } - zval_copy_ctor(return_value); } else { php_error_docref(NULL, E_WARNING, "Couldn't find constant %s", ZSTR_VAL(const_name)); RETURN_NULL(); @@ -3978,22 +3998,17 @@ PHP_FUNCTION(ip2long) Converts an (IPv4) Internet network address into a string in Internet standard dotted format */ PHP_FUNCTION(long2ip) { - /* "It's a long but it's not, PHP ints are signed */ - char *ip; - size_t ip_len; - uint32_t n; + zend_ulong ip; struct in_addr myaddr; #ifdef HAVE_INET_PTON char str[40]; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ip, &ip_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ip) == FAILURE) { return; } - n = strtoul(ip, NULL, 0); - - myaddr.s_addr = htonl(n); + myaddr.s_addr = htonl(ip); #ifdef HAVE_INET_PTON if (inet_ntop(AF_INET, &myaddr, str, sizeof(str))) { RETURN_STRING(str); @@ -4010,18 +4025,25 @@ PHP_FUNCTION(long2ip) * System Functions * ********************/ -/* {{{ proto string getenv(string varname[, bool local_only]) - Get the value of an environment variable */ +/* {{{ proto string getenv(string varname[, bool local_only] + Get the value of an environment variable or every available environment variable + if no varname is present */ PHP_FUNCTION(getenv) { - char *ptr, *str; + char *ptr, *str = NULL; size_t str_len; zend_bool local_only = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &str, &str_len, &local_only) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sb", &str, &str_len, &local_only) == FAILURE) { RETURN_FALSE; } + 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); @@ -4248,7 +4270,7 @@ static int parse_opts(char * opts, opt_struct ** result) } /* }}} */ -/* {{{ proto array getopt(string options [, array longopts]) +/* {{{ proto array getopt(string options [, array longopts [, int &optind]]) Get options from the command line argument list */ PHP_FUNCTION(getopt) { @@ -4260,13 +4282,20 @@ PHP_FUNCTION(getopt) char *php_optarg = NULL; int php_optind = 1; zval val, *args = NULL, *p_longopts = NULL; + zval *zoptind = NULL; int optname_len = 0; opt_struct *opts, *orig_opts; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a", &options, &options_len, &p_longopts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|az/", &options, &options_len, &p_longopts, &zoptind) == FAILURE) { RETURN_FALSE; } + /* Init zoptind to 1 */ + if (zoptind) { + zval_dtor(zoptind); + ZVAL_LONG(zoptind, 1); + } + /* Get argv from the global symbol table. We calculate argc ourselves * in order to be on the safe side, even though it is also available * from the symbol table. */ @@ -4408,6 +4437,11 @@ PHP_FUNCTION(getopt) php_optarg = NULL; } + /* Set zoptind to php_optind */ + if (zoptind) { + ZVAL_LONG(zoptind, php_optind); + } + free_longopts(orig_opts); efree(orig_opts); free_argv(argv, argc); @@ -4706,14 +4740,14 @@ PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, cha case 4: /* send to SAPI */ if (sapi_module.log_message) { - sapi_module.log_message(message); + sapi_module.log_message(message, -1); } else { return FAILURE; } break; default: - php_log_err(message); + php_log_err_with_severity(message, LOG_NOTICE); break; } return SUCCESS; @@ -4834,7 +4868,8 @@ PHP_FUNCTION(forward_static_call) } if (!EX(prev_execute_data)->func->common.scope) { - zend_error(E_ERROR, "Cannot call forward_static_call() when no class scope is active"); + zend_throw_error(NULL, "Cannot call forward_static_call() when no class scope is active"); + return; } fci.retval = &retval; @@ -5124,7 +5159,8 @@ ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highl PHP_FUNCTION(highlight_file) { char *filename; - size_t filename_len, ret; + size_t filename_len; + int ret; zend_syntax_highlighter_ini syntax_highlighter_ini; zend_bool i = 0; @@ -5167,7 +5203,7 @@ PHP_FUNCTION(php_strip_whitespace) char *filename; size_t filename_len; zend_lex_state original_lex_state; - zend_file_handle file_handle = {{0}}; + zend_file_handle file_handle; if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { RETURN_FALSE; @@ -5175,6 +5211,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; @@ -5486,15 +5523,9 @@ PHP_FUNCTION(print_r) } if (do_return) { - php_output_start_default(); - } - - zend_print_zval_r(var, 0); - - if (do_return) { - php_output_get_contents(return_value); - php_output_discard(); + RETURN_STR(zend_print_zval_r_to_str(var, 0)); } else { + zend_print_zval_r(var, 0); RETURN_TRUE; } } |