From 9340e035d4194481c48c3c248a6c2a514074080e Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Sat, 24 Mar 2012 14:24:47 -0700 Subject: [PATCH] parameter skipping patch - phase 1 --- Zend/tests/default_params01.phpt | 67 +++ Zend/tests/default_params02.phpt | 43 ++ Zend/tests/default_params03.phpt | 21 + Zend/tests/default_params04.phpt | 50 +++ Zend/tests/default_params05.phpt | 20 + Zend/tests/default_params06.phpt | 19 + Zend/tests/default_params07.phpt | 22 + Zend/tests/default_params08.phpt | 16 + Zend/tests/default_params09.phpt | 42 ++ Zend/tests/default_params10.phpt | 24 ++ Zend/tests/default_params11.phpt | 33 ++ Zend/tests/default_params12.phpt | 16 + Zend/tests/default_params13.phpt | 12 + Zend/tests/default_params14.phpt | 22 + Zend/zend_API.c | 35 ++ Zend/zend_API.h | 42 +- Zend/zend_ast.h | 1 + Zend/zend_builtin_functions.c | 4 +- Zend/zend_compile.c | 15 + Zend/zend_compile.h | 6 +- Zend/zend_execute.c | 24 +- Zend/zend_execute_API.c | 7 + Zend/zend_language_parser.y | 1 + Zend/zend_vm_def.h | 70 +++- Zend/zend_vm_execute.h | 187 +++++++-- ext/bcmath/bcmath.c | 91 ++--- ext/bz2/bz2.c | 20 +- ext/date/php_date.c | 46 +-- ext/dba/dba.c | 3 +- ext/enchant/enchant.c | 2 +- ext/ereg/ereg.c | 35 +- ext/gd/gd.c | 26 +- ext/gd/gd_ctx.c | 16 +- ext/hash/hash.c | 3 +- ext/iconv/iconv.c | 4 +- ext/imap/php_imap.c | 51 +-- ext/interbase/ibase_blobs.c | 41 +- ext/interbase/ibase_query.c | 7 + ext/interbase/interbase.c | 10 +- ext/intl/grapheme/grapheme_string.c | 7 + ext/ldap/ldap.c | 6 +- ext/mbstring/mbstring.c | 74 ++-- ext/mbstring/php_mbregex.c | 29 +- .../mb_str_functions_opt-parameter2.phpt | 32 ++ ext/mssql/php_mssql.c | 19 +- ext/mysql/php_mysql.c | 2 +- ext/mysqli/mysqli.c | 54 +-- ext/mysqli/mysqli_warning.c | 5 +- ext/oci8/oci8.c | 9 +- ext/oci8/oci8_interface.c | 167 ++++---- ext/odbc/php_odbc.c | 280 +++++++------ ext/pcntl/pcntl.c | 4 +- ext/pdo/pdo_stmt.c | 130 +++--- ext/pdo/php_pdo_driver.h | 2 +- ext/pdo/tests/bug_44173.phpt | 2 +- ext/pgsql/pgsql.c | 381 ++++++------------ ext/pspell/pspell.c | 10 +- ext/reflection/php_reflection.c | 29 +- ext/simplexml/simplexml.c | 12 +- ext/skeleton/create_stubs | 6 +- ext/snmp/snmp.c | 6 +- ext/soap/soap.c | 2 +- ext/sockets/sockets.c | 14 +- ext/spl/spl_array.c | 2 +- ext/spl/spl_directory.c | 181 ++++----- ext/spl/spl_fixedarray.c | 2 +- ext/standard/array.c | 98 +++-- ext/standard/assert.c | 13 +- ext/standard/basic_functions.c | 15 +- ext/standard/dir.c | 2 +- ext/standard/file.c | 39 +- ext/standard/filestat.c | 6 +- ext/standard/image.c | 9 +- ext/standard/math.c | 4 +- ext/standard/rand.c | 4 +- ext/standard/streamsfuncs.c | 11 +- ext/standard/string.c | 70 ++-- ext/standard/tests/array/array_rand.phpt | 2 + .../tests/array/array_slice_variation1.phpt | 10 +- .../tests/array/array_slice_variation3.phpt | 36 +- ext/standard/type.c | 5 +- ext/standard/versioning.c | 9 +- ext/sybase_ct/php_sybase_ct.c | 2 +- ext/xmlrpc/xmlrpc-epi-php.c | 8 +- sapi/cgi/cgi_main.c | 12 +- 85 files changed, 1681 insertions(+), 1295 deletions(-) create mode 100644 Zend/tests/default_params01.phpt create mode 100644 Zend/tests/default_params02.phpt create mode 100644 Zend/tests/default_params03.phpt create mode 100644 Zend/tests/default_params04.phpt create mode 100644 Zend/tests/default_params05.phpt create mode 100644 Zend/tests/default_params06.phpt create mode 100644 Zend/tests/default_params07.phpt create mode 100644 Zend/tests/default_params08.phpt create mode 100644 Zend/tests/default_params09.phpt create mode 100644 Zend/tests/default_params10.phpt create mode 100644 Zend/tests/default_params11.phpt create mode 100644 Zend/tests/default_params12.phpt create mode 100644 Zend/tests/default_params13.phpt create mode 100644 Zend/tests/default_params14.phpt create mode 100644 ext/mbstring/tests/mb_str_functions_opt-parameter2.phpt diff --git a/Zend/tests/default_params01.phpt b/Zend/tests/default_params01.phpt new file mode 100644 index 0000000000000..08f1b4857d958 --- /dev/null +++ b/Zend/tests/default_params01.phpt @@ -0,0 +1,67 @@ +--TEST-- +Default parameters - 1 +--FILE-- + +--EXPECTF-- +7 +int(7) +int(2) +int(3) +array(1) { + [0]=> + int(7) +} +default,4,5 +int(1) +int(4) +int(5) +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(5) +} +default,default,8 +int(1) +int(2) +int(8) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) +} +3,default,5 +int(3) +int(2) +int(5) +array(3) { + [0]=> + int(3) + [1]=> + int(2) + [2]=> + int(5) +} +3,default,7,default,6 + +Fatal error: Defaults can be used only for declared optional parameters in %s line %d diff --git a/Zend/tests/default_params02.phpt b/Zend/tests/default_params02.phpt new file mode 100644 index 0000000000000..ee03c1597069e --- /dev/null +++ b/Zend/tests/default_params02.phpt @@ -0,0 +1,43 @@ +--TEST-- +Default parameters - 2 +--FILE-- + +--EXPECTF-- +int(1) +int(2) +int(3) +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +int(1) +int(1) +int(3) +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(3) +} + +Fatal error: Defaults can be used only for declared optional parameters in %s line %d diff --git a/Zend/tests/default_params03.phpt b/Zend/tests/default_params03.phpt new file mode 100644 index 0000000000000..fdd25243546de --- /dev/null +++ b/Zend/tests/default_params03.phpt @@ -0,0 +1,21 @@ +--TEST-- +Default parameters - 3 +--FILE-- + +--EXPECTF-- +array(2) { + [0]=> + int(7) + [1]=> + int(2) +} +int(2) +Done diff --git a/Zend/tests/default_params04.phpt b/Zend/tests/default_params04.phpt new file mode 100644 index 0000000000000..65537ea935d13 --- /dev/null +++ b/Zend/tests/default_params04.phpt @@ -0,0 +1,50 @@ +--TEST-- +Default parameters - 4, call_user_func +--FILE-- +43, 4=>44)); +echo "Done\n"; +?> +--EXPECTF-- +int(1) +int(1) +int(5) +int(6) +int(4) +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(5) + [3]=> + int(6) +} +== +int(0) +int(1) +int(7) +int(3) +int(4) +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(7) + [3]=> + int(3) +} +== +Done diff --git a/Zend/tests/default_params05.phpt b/Zend/tests/default_params05.phpt new file mode 100644 index 0000000000000..83eedfbe1edcb --- /dev/null +++ b/Zend/tests/default_params05.phpt @@ -0,0 +1,20 @@ +--TEST-- +Default parameters - 5 +--FILE-- + +--EXPECTF-- +#0 test(7) called at [%s:%d] +#0 test(1, 4, 5) called at [%s.php:%d] +#0 test(1, 2, 8) called at [%s:%d] +#0 test(3, 2, 5) called at [%s:%d] +Done diff --git a/Zend/tests/default_params06.phpt b/Zend/tests/default_params06.phpt new file mode 100644 index 0000000000000..4d245a20589d7 --- /dev/null +++ b/Zend/tests/default_params06.phpt @@ -0,0 +1,19 @@ +--TEST-- +Default parameters - 6, by-refs +--FILE-- + +--EXPECTF-- +int(7) +int(2) +int(7) +int(2) +Done \ No newline at end of file diff --git a/Zend/tests/default_params07.phpt b/Zend/tests/default_params07.phpt new file mode 100644 index 0000000000000..7ec6b48ebc2f5 --- /dev/null +++ b/Zend/tests/default_params07.phpt @@ -0,0 +1,22 @@ +--TEST-- +Default parameters - 7, by-refs +--FILE-- + +--EXPECTF-- +int(7) +int(2) +int(7) +int(2) +Done + diff --git a/Zend/tests/default_params08.phpt b/Zend/tests/default_params08.phpt new file mode 100644 index 0000000000000..873342f8f7bf8 --- /dev/null +++ b/Zend/tests/default_params08.phpt @@ -0,0 +1,16 @@ +--TEST-- +Default parameters - 8, by-refs +--FILE-- + +--EXPECTF-- +bool(true) +bool(false) +string(15) "is_not_callable" +Done diff --git a/Zend/tests/default_params09.phpt b/Zend/tests/default_params09.phpt new file mode 100644 index 0000000000000..38a2f9f7ef71c --- /dev/null +++ b/Zend/tests/default_params09.phpt @@ -0,0 +1,42 @@ +--TEST-- +Default parameters - 9, internal funcs +--FILE-- + +--EXPECTF-- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +Done \ No newline at end of file diff --git a/Zend/tests/default_params10.phpt b/Zend/tests/default_params10.phpt new file mode 100644 index 0000000000000..9e9701c2c2c1d --- /dev/null +++ b/Zend/tests/default_params10.phpt @@ -0,0 +1,24 @@ +--TEST-- +Default parameters - 10, shutdown func +--FILE-- + +--EXPECTF-- +Done +int(3) +int(2) +int(1) +array(3) { + [0]=> + int(3) + [1]=> + int(2) + [2]=> + int(1) +} diff --git a/Zend/tests/default_params11.phpt b/Zend/tests/default_params11.phpt new file mode 100644 index 0000000000000..f709b7d162e6f --- /dev/null +++ b/Zend/tests/default_params11.phpt @@ -0,0 +1,33 @@ +--TEST-- +Default parameters - 11, call_user_func +--FILE-- + +--EXPECTF-- +int(5) +int(6) +int(3) +int(8) +int(4) +array(4) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(3) + [3]=> + int(8) +} +== +Done diff --git a/Zend/tests/default_params12.phpt b/Zend/tests/default_params12.phpt new file mode 100644 index 0000000000000..13d7f767eba86 --- /dev/null +++ b/Zend/tests/default_params12.phpt @@ -0,0 +1,16 @@ +--TEST-- +Default parameters - 12, call_user_func +--FILE-- + +--EXPECTF-- +Fatal error: Defaults can be used only for declared optional parameters in %s line %d \ No newline at end of file diff --git a/Zend/tests/default_params13.phpt b/Zend/tests/default_params13.phpt new file mode 100644 index 0000000000000..1b1f0fbdced0a --- /dev/null +++ b/Zend/tests/default_params13.phpt @@ -0,0 +1,12 @@ +--TEST-- +Default parameters - 13, disallowed defaults +--INI-- +date.timezone=UTC +--FILE-- + +--EXPECTF-- +Warning: Default can not be used for parameter 1 in %s/default_params13.php on line 2 +Done \ No newline at end of file diff --git a/Zend/tests/default_params14.phpt b/Zend/tests/default_params14.phpt new file mode 100644 index 0000000000000..715354843cec4 --- /dev/null +++ b/Zend/tests/default_params14.phpt @@ -0,0 +1,22 @@ +--TEST-- +Default parameters - 14, FAST_ZPP +--FILE-- + 1, "b" => 2, "c" => 3, "d" => 4], 2, 2, true)); +var_dump(array_slice(["a" => 1, "b" => 2, "c" => 3, "d" => 4], 2, default, true)); +echo "Done\n"; +?> +--EXPECTF-- +array(2) { + ["c"]=> + int(3) + ["d"]=> + int(4) +} +array(2) { + ["c"]=> + int(3) + ["d"]=> + int(4) +} +Done diff --git a/Zend/zend_API.c b/Zend/zend_API.c index f160bb4456ffe..9180a54bb181c 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -341,6 +341,22 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons spec_walk++; } + if(UNEXPECTED(Z_ISUNDEF_P(arg))) { + /* consume the arg part */ + va_arg(*va, void*); + if (check_null) { + zend_bool *p = va_arg(*va, zend_bool *); + /* TODO (SKIP): treat default as null-value? */ + *p = 1; + } + /* ones needing more than one va_list entry */ + if(strchr("psf", c) != NULL) { + va_arg(*va, void*); + } + *spec = spec_walk; + return NULL; + } + switch (c) { case 'l': case 'L': @@ -751,6 +767,22 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, arg = ZEND_CALL_ARG(EG(current_execute_data), i + 1); + if(UNEXPECTED(Z_ISUNDEF_P(arg))) { + /* default arg */ + if((flags & ZEND_PARSE_PARAMS_NODEFAULT) != 0) { + if(!quiet) { + zend_error(E_WARNING, "Default can not be used for parameter %d", i+1); + } + return FAILURE; + } + if(i < min_num_args) { + if(!quiet) { + zend_error(E_WARNING, "Default can not be used for mandatory parameter %d", i+1); + } + return FAILURE; + } + } + if (zend_parse_arg(i+1, arg, va, &type_spec, quiet) == FAILURE) { /* clean up varargs array if it was used */ if (varargs && *varargs) { @@ -1996,6 +2028,9 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio if (info->return_reference) { internal_function->fn_flags |= ZEND_ACC_RETURN_REFERENCE; } + if (info->allow_default) { + internal_function->fn_flags |= ZEND_ACC_ALLOWS_DEFAULT; + } if (ptr->arg_info[ptr->num_args].is_variadic) { internal_function->fn_flags |= ZEND_ACC_VARIADIC; /* Don't count the variadic argument */ diff --git a/Zend/zend_API.h b/Zend/zend_API.h index e3be8d713895b..12f1d05e9f4d7 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -108,6 +108,9 @@ typedef struct _zend_fcall_info_cache { #define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args) \ static const zend_internal_arg_info name[] = { \ { (const char*)(zend_uintptr_t)(required_num_args), NULL, 0, return_reference, 0, 0 }, +#define ZEND_BEGIN_ARG_INFO_DEFAULT(name, _unused, return_reference, required_num_args) \ + static const zend_internal_arg_info name[] = { \ + { (const char*)(zend_uintptr_t)(required_num_args), NULL, 0, return_reference, 1, 0 }, #define ZEND_BEGIN_ARG_INFO(name, _unused) \ ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1) #define ZEND_END_ARG_INFO() }; @@ -249,6 +252,8 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array); /* Parameter parsing API -- andrei */ #define ZEND_PARSE_PARAMS_QUIET (1<<1) +#define ZEND_PARSE_PARAMS_NODEFAULT (1<<2) + ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...); ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...); ZEND_API char *zend_zval_type_name(const zval *arg); @@ -705,6 +710,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); #define ZPP_ERROR_WRONG_CLASS 3 #define ZPP_ERROR_WRONG_ARG 4 #define ZPP_ERROR_WRONG_COUNT 5 +#define ZPP_ERROR_WRONG_DEFAULT 6 #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \ const int _flags = (flags); \ @@ -752,7 +758,9 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); zend_wrong_paramer_class_error(_i, _error, _arg); \ } else if (error_code == ZPP_ERROR_WRONG_ARG) { \ zend_wrong_paramer_type_error(_i, _expected_type, _arg); \ - } \ + } else if(error_code == ZPP_ERROR_WRONG_DEFAULT) { \ + zend_error(E_WARNING, "Default can not be used for mandatory parameter %d", _i);\ + }\ } \ failure; \ } \ @@ -768,6 +776,10 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); } \ _real_arg++; \ _arg = _real_arg; \ + if(UNEXPECTED(Z_ISUNDEF_P(_arg) && !_optional)) { \ + error_code = ZPP_ERROR_WRONG_DEFAULT; \ + break; \ + } \ ZVAL_DEREF(_arg); \ if (separate) { \ SEPARATE_ZVAL_NOREF(_arg); \ @@ -1032,6 +1044,14 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); #define Z_PARAM_VARIADIC(spec, dest, dest_num) \ Z_PARAM_VARIADIC_EX(spec, dest, dest_num, 0) +#define Z_PARAM_CHECK_DEFAULT(arg, is_null, check_null) \ + if(UNEXPECTED(Z_ISUNDEF_P(arg))) { \ + if(check_null && is_null != NULL) { \ + *(zend_bool *)is_null = 1; \ + } \ + return 1; \ + } + #endif /* FAST_ZPP */ /* End of new parameter parsing API */ @@ -1043,6 +1063,7 @@ ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, in static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, is_null, check_null); if (check_null) { *is_null = 0; } @@ -1063,6 +1084,7 @@ static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, ze static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int strict) { + Z_PARAM_CHECK_DEFAULT(arg, is_null, check_null); if (check_null) { *is_null = 0; } @@ -1119,6 +1141,7 @@ static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, ze static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zend_bool *is_null, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, is_null, check_null); if (check_null) { *is_null = 0; } @@ -1152,6 +1175,7 @@ static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zen static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) { *dest = Z_STR_P(arg); } else if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) { @@ -1176,6 +1200,8 @@ static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size { zend_string *str; + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); + if (!zend_parse_arg_str(arg, &str, check_null)) { return 0; } @@ -1202,6 +1228,7 @@ static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t { zend_string *str; + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (!zend_parse_arg_path_str(arg, &str, check_null)) { return 0; } @@ -1217,6 +1244,7 @@ static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t static zend_always_inline int zend_parse_arg_array(zval *arg, zval **dest, int check_null, int or_object) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY) || (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT))) { *dest = arg; @@ -1230,6 +1258,7 @@ static zend_always_inline int zend_parse_arg_array(zval *arg, zval **dest, int c static zend_always_inline int zend_parse_arg_array_ht(zval *arg, HashTable **dest, int check_null, int or_object) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) { *dest = Z_ARRVAL_P(arg); } else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) { @@ -1244,6 +1273,7 @@ static zend_always_inline int zend_parse_arg_array_ht(zval *arg, HashTable **des static zend_always_inline int zend_parse_arg_object(zval *arg, zval **dest, zend_class_entry *ce, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) && (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) { *dest = arg; @@ -1257,6 +1287,7 @@ static zend_always_inline int zend_parse_arg_object(zval *arg, zval **dest, zend static zend_always_inline int zend_parse_arg_resource(zval *arg, zval **dest, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) { *dest = arg; } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) { @@ -1269,6 +1300,7 @@ static zend_always_inline int zend_parse_arg_resource(zval *arg, zval **dest, in static zend_always_inline int zend_parse_arg_func(zval *arg, zend_fcall_info *dest_fci, zend_fcall_info_cache *dest_fcc, int check_null, char **error) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) { dest_fci->size = 0; dest_fcc->initialized = 0; @@ -1279,17 +1311,21 @@ static zend_always_inline int zend_parse_arg_func(zval *arg, zend_fcall_info *de return 1; } -static zend_always_inline void zend_parse_arg_zval(zval *arg, zval **dest, int check_null) +static zend_always_inline int zend_parse_arg_zval(zval *arg, zval **dest, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); *dest = (check_null && (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) || (UNEXPECTED(Z_ISREF_P(arg)) && UNEXPECTED(Z_TYPE_P(Z_REFVAL_P(arg)) == IS_NULL)))) ? NULL : arg; + return 1; } -static zend_always_inline void zend_parse_arg_zval_deref(zval *arg, zval **dest, int check_null) +static zend_always_inline int zend_parse_arg_zval_deref(zval *arg, zval **dest, int check_null) { + Z_PARAM_CHECK_DEFAULT(arg, NULL, check_null); *dest = (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) ? NULL : arg; + return 1; } END_EXTERN_C() diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 5165925696f26..74615daae25f8 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -62,6 +62,7 @@ enum _zend_ast_kind { /* 0 child nodes */ ZEND_AST_MAGIC_CONST = 0 << ZEND_AST_NUM_CHILDREN_SHIFT, ZEND_AST_TYPE, + ZEND_AST_DEFAULT, /* 1 child node */ ZEND_AST_VAR = 1 << ZEND_AST_NUM_CHILDREN_SHIFT, diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 2fce4b796434e..80839058b391c 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -922,14 +922,14 @@ ZEND_FUNCTION(get_called_class) Retrieves the parent class name for object or class or current scope. */ ZEND_FUNCTION(get_parent_class) { - zval *arg; + zval *arg = NULL; zend_class_entry *ce = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) { return; } - if (!ZEND_NUM_ARGS()) { + if (!ZEND_NUM_ARGS() || arg == NULL) { ce = EG(scope); if (ce && ce->parent) { RETURN_STR(zend_string_copy(ce->parent->name)); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index bc114530e3e28..fb3fa6da616ba 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2436,6 +2436,19 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */ } arg_count++; + + if(arg->kind == ZEND_AST_DEFAULT) { + /* default arg */ + // TODO (SKIP): should we prevent default from being sent by-ref? + //if (fbc && ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) { + // zend_error_noreturn(E_COMPILE_ERROR, "By-reference parameter can not use default"); + //} + opline = zend_emit_op(NULL, ZEND_SEND_VAL, NULL, NULL); + opline->op2.opline_num = arg_num; + opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, arg_num); + continue; + } + if (zend_is_variable(arg)) { if (zend_is_call(arg)) { zend_compile_var(&arg_node, arg, BP_VAR_R); @@ -2743,6 +2756,8 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcnam if (zend_is_variable(arg_ast) && !zend_is_call(arg_ast)) { zend_compile_var(&arg_node, arg_ast, BP_VAR_FUNC_ARG | (i << BP_VAR_SHIFT)); send_user = 1; + } else if(arg_ast->kind == ZEND_AST_DEFAULT) { + arg_node.op_type = IS_UNUSED; } else { zend_compile_expr(&arg_node, arg_ast); if (arg_node.op_type & (IS_VAR|IS_CV)) { diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index ce73d0191a591..3f5c6194fe8ba 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -243,6 +243,9 @@ typedef struct _zend_try_catch_element { /* internal function is allocated at arena */ #define ZEND_ACC_ARENA_ALLOCATED 0x20000000 +/* internal function allows defaults in varargs */ +#define ZEND_ACC_ALLOWS_DEFAULT 0x40000000 + #define ZEND_CE_IS_TRAIT(ce) (((ce)->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) char *zend_visibility_string(uint32_t fn_flags); @@ -294,7 +297,7 @@ typedef struct _zend_internal_function_info { const char *_class_name; zend_uchar _type_hint; zend_bool return_reference; - zend_bool _allow_null; + zend_bool allow_default; zend_bool _is_variadic; } zend_internal_function_info; @@ -415,6 +418,7 @@ struct _zend_execute_data { #define ZEND_CALL_FREE_EXTRA_ARGS (1 << 2) /* equal to IS_TYPE_REFCOUNTED */ #define ZEND_CALL_CTOR (1 << 3) #define ZEND_CALL_CTOR_RESULT_UNUSED (1 << 4) +#define ZEND_CALL_HAS_DEFAULT (1 << 5) #define ZEND_CALL_INFO(call) \ (Z_TYPE_INFO((call)->This) >> 24) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 3092d05a96903..cd82a6330b3cc 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1622,7 +1622,11 @@ static zend_always_inline void i_init_func_execute_data(zend_execute_data *execu if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ - EX(opline) += first_extra_arg; + if(UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_HAS_DEFAULT) != 0)) { + EX(opline) += op_array->required_num_args; + } else { + EX(opline) += first_extra_arg; + } } /* move extra args into separate array after all CV and TMP vars */ @@ -1646,7 +1650,11 @@ static zend_always_inline void i_init_func_execute_data(zend_execute_data *execu ZEND_ADD_CALL_FLAG(execute_data, ((type_flags >> Z_TYPE_FLAGS_SHIFT) & IS_TYPE_REFCOUNTED)); } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ - EX(opline) += num_args; + if(UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_HAS_DEFAULT) != 0)) { + EX(opline) += MIN(op_array->required_num_args, num_args); + } else { + EX(opline) += num_args; + } } /* Initialize CV variables (skip arguments) */ @@ -1722,7 +1730,11 @@ static zend_always_inline void i_init_execute_data(zend_execute_data *execute_da if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ - EX(opline) += first_extra_arg; + if(UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_HAS_DEFAULT) != 0)) { + EX(opline) += op_array->required_num_args; + } else { + EX(opline) += first_extra_arg; + } } /* move extra args into separate array after all CV and TMP vars */ @@ -1746,7 +1758,11 @@ static zend_always_inline void i_init_execute_data(zend_execute_data *execute_da ZEND_ADD_CALL_FLAG(execute_data, ((type_flags >> Z_TYPE_FLAGS_SHIFT) & IS_TYPE_REFCOUNTED)); } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ - EX(opline) += num_args; + if(UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_HAS_DEFAULT) != 0)) { + EX(opline) += MIN(op_array->required_num_args, num_args); + } else { + EX(opline) += num_args; + } } /* Initialize CV variables (skip arguments) */ diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index c9da46d819382..717cb7a457a2e 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -752,6 +752,13 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / for (i=0; iparam_count; i++) { zval *param; + if(Z_ISUNDEF(fci->params[i])) { + if(i < func->common.required_num_args + || (i >= func->common.num_args && !(func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(call, ZEND_CALL_HAS_DEFAULT); + } if (ARG_SHOULD_BE_SENT_BY_REF(func, i + 1)) { // TODO: Scalar values don't have reference counters anymore. // They are assumed to be 1, and they may be easily passed by diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 69fc0995a7e88..e28f5eb9b1911 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -592,6 +592,7 @@ non_empty_argument_list: argument: expr { $$ = $1; } | T_ELLIPSIS expr { $$ = zend_ast_create(ZEND_AST_UNPACK, $2); } + | T_DEFAULT { $$ = zend_ast_create_ex(ZEND_AST_DEFAULT, IS_UNDEF); } ; global_var_list: diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 5f13a88f8b1a9..26ea61f309b09 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3144,25 +3144,35 @@ ZEND_VM_HANDLER(107, ZEND_CATCH, CONST, CV) } } -ZEND_VM_HANDLER(65, ZEND_SEND_VAL, CONST|TMP, ANY) +ZEND_VM_HANDLER(65, ZEND_SEND_VAL, CONST|TMP|UNUSED, ANY) { USE_OPLINE zval *value, *arg; zend_free_op free_op1; SAVE_OPLINE(); - value = GET_OP1_ZVAL_PTR(BP_VAR_R); arg = ZEND_CALL_VAR(EX(call), opline->result.var); - ZVAL_COPY_VALUE(arg, value); - if (OP1_TYPE == IS_CONST) { - if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { - zval_copy_ctor_func(arg); + if(UNEXPECTED(OP1_TYPE == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = GET_OP1_ZVAL_PTR(BP_VAR_R); + ZVAL_COPY_VALUE(arg, value); + if (OP1_TYPE == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } } } ZEND_VM_NEXT_OPCODE(); } -ZEND_VM_HANDLER(116, ZEND_SEND_VAL_EX, CONST|TMP, ANY) +ZEND_VM_HANDLER(116, ZEND_SEND_VAL_EX, CONST|TMP|UNUSED, ANY) { USE_OPLINE zval *value, *arg; @@ -3172,12 +3182,22 @@ ZEND_VM_HANDLER(116, ZEND_SEND_VAL_EX, CONST|TMP, ANY) if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num)) { zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.num); } - value = GET_OP1_ZVAL_PTR(BP_VAR_R); - arg = ZEND_CALL_VAR(EX(call), opline->result.var); - ZVAL_COPY_VALUE(arg, value); - if (OP1_TYPE == IS_CONST) { - if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { - zval_copy_ctor_func(arg); + if(UNEXPECTED(OP1_TYPE == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = GET_OP1_ZVAL_PTR(BP_VAR_R); + arg = ZEND_CALL_VAR(EX(call), opline->result.var); + ZVAL_COPY_VALUE(arg, value); + if (OP1_TYPE == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } } } ZEND_VM_NEXT_OPCODE(); @@ -3519,6 +3539,26 @@ ZEND_VM_C_LABEL(send_array): arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); ZEND_HASH_FOREACH_VAL(ht, arg) { +// TODO (SKIP): this would work but introduces requirement for call_user_func_array arrays to be +// numerically indexed, and also needs +// if(UNEXPECTED(arg_idx > arg_num-1)) { +// uint32_t expected_arg_num = arg_num-1; +// /* skip in parameter list */ +// for(expected_arg_num < arg_idx; expected_arg_num++) { +// if(expected_arg_num < EX(call)->func->common.required_num_args +// || (expected_arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { +// zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); +// } +// ZVAL_UNDEF(param); +// param++; +// arg_num++; +// } +// continue; +// } +// if(UNEXPECTED(arg_idx != arg_num - 1)) { +// zend_error_noreturn(E_WARNING, "Bad parameter key sequence in array: expected %d, found %d", arg_num-1, arg_idx); +// ZEND_VM_C_GOTO(parameter_error); +// } if (ARG_SHOULD_BE_SENT_BY_REF(EX(call)->func, arg_num)) { // TODO: Scalar values don't have reference counters anymore. // They are assumed to be 1, and they may be easily passed by @@ -3545,7 +3585,7 @@ ZEND_VM_C_LABEL(send_array): EX(call)->func->common.scope ? EX(call)->func->common.scope->name->val : "", EX(call)->func->common.scope ? "::" : "", EX(call)->func->common.function_name->val); - +ZEND_VM_C_LABEL(parameter_error): if (EX(call)->func->common.fn_flags & ZEND_ACC_CLOSURE) { OBJ_RELEASE((zend_object*)EX(call)->func->common.prototype); } @@ -3694,7 +3734,7 @@ ZEND_VM_HANDLER(64, ZEND_RECV_INIT, ANY, CONST) SAVE_OPLINE(); param = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->result.var); - if (arg_num > EX_NUM_ARGS()) { + if (arg_num > EX_NUM_ARGS() || Z_ISUNDEF_P(param)) { ZVAL_COPY_VALUE(param, EX_CONSTANT(opline->op2)); if (Z_OPT_CONSTANT_P(param)) { zval_update_constant(param, 0); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 66c3832fbbb49..2c7d062de5a9f 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -901,6 +901,26 @@ static int ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); ZEND_HASH_FOREACH_VAL(ht, arg) { +// TODO (SKIP): this would work but introduces requirement for call_user_func_array arrays to be +// numerically indexed, and also needs +// if(UNEXPECTED(arg_idx > arg_num-1)) { +// uint32_t expected_arg_num = arg_num-1; +// /* skip in parameter list */ +// for(expected_arg_num < arg_idx; expected_arg_num++) { +// if(expected_arg_num < EX(call)->func->common.required_num_args +// || (expected_arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { +// zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); +// } +// ZVAL_UNDEF(param); +// param++; +// arg_num++; +// } +// continue; +// } +// if(UNEXPECTED(arg_idx != arg_num - 1)) { +// zend_error_noreturn(E_WARNING, "Bad parameter key sequence in array: expected %d, found %d", arg_num-1, arg_idx); +// goto parameter_error; +// } if (ARG_SHOULD_BE_SENT_BY_REF(EX(call)->func, arg_num)) { // TODO: Scalar values don't have reference counters anymore. // They are assumed to be 1, and they may be easily passed by @@ -927,7 +947,7 @@ static int ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) EX(call)->func->common.scope ? EX(call)->func->common.scope->name->val : "", EX(call)->func->common.scope ? "::" : "", EX(call)->func->common.function_name->val); - +parameter_error: if (EX(call)->func->common.fn_flags & ZEND_ACC_CLOSURE) { OBJ_RELEASE((zend_object*)EX(call)->func->common.prototype); } @@ -1747,7 +1767,7 @@ static int ZEND_FASTCALL ZEND_RECV_INIT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ SAVE_OPLINE(); param = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->result.var); - if (arg_num > EX_NUM_ARGS()) { + if (arg_num > EX_NUM_ARGS() || Z_ISUNDEF_P(param)) { ZVAL_COPY_VALUE(param, EX_CONSTANT(opline->op2)); if (Z_OPT_CONSTANT_P(param)) { zval_update_constant(param, 0); @@ -2628,12 +2648,22 @@ static int ZEND_FASTCALL ZEND_SEND_VAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A SAVE_OPLINE(); - value = EX_CONSTANT(opline->op1); arg = ZEND_CALL_VAR(EX(call), opline->result.var); - ZVAL_COPY_VALUE(arg, value); - if (IS_CONST == IS_CONST) { - if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { - zval_copy_ctor_func(arg); + if(UNEXPECTED(IS_CONST == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = EX_CONSTANT(opline->op1); + ZVAL_COPY_VALUE(arg, value); + if (IS_CONST == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } } } ZEND_VM_NEXT_OPCODE(); @@ -2649,12 +2679,22 @@ static int ZEND_FASTCALL ZEND_SEND_VAL_EX_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLE if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num)) { zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.num); } - value = EX_CONSTANT(opline->op1); - arg = ZEND_CALL_VAR(EX(call), opline->result.var); - ZVAL_COPY_VALUE(arg, value); - if (IS_CONST == IS_CONST) { - if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { - zval_copy_ctor_func(arg); + if(UNEXPECTED(IS_CONST == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = EX_CONSTANT(opline->op1); + arg = ZEND_CALL_VAR(EX(call), opline->result.var); + ZVAL_COPY_VALUE(arg, value); + if (IS_CONST == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } } } ZEND_VM_NEXT_OPCODE(); @@ -8803,12 +8843,22 @@ static int ZEND_FASTCALL ZEND_SEND_VAL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG zend_free_op free_op1; SAVE_OPLINE(); - value = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); arg = ZEND_CALL_VAR(EX(call), opline->result.var); - ZVAL_COPY_VALUE(arg, value); - if (IS_TMP_VAR == IS_CONST) { - if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { - zval_copy_ctor_func(arg); + if(UNEXPECTED(IS_TMP_VAR == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); + ZVAL_COPY_VALUE(arg, value); + if (IS_TMP_VAR == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } } } ZEND_VM_NEXT_OPCODE(); @@ -8824,12 +8874,22 @@ static int ZEND_FASTCALL ZEND_SEND_VAL_EX_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num)) { zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.num); } - value = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); - arg = ZEND_CALL_VAR(EX(call), opline->result.var); - ZVAL_COPY_VALUE(arg, value); - if (IS_TMP_VAR == IS_CONST) { - if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { - zval_copy_ctor_func(arg); + if(UNEXPECTED(IS_TMP_VAR == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); + arg = ZEND_CALL_VAR(EX(call), opline->result.var); + ZVAL_COPY_VALUE(arg, value); + if (IS_TMP_VAR == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } } } ZEND_VM_NEXT_OPCODE(); @@ -18059,6 +18119,65 @@ static int ZEND_FASTCALL ZEND_ASSIGN_POW_SPEC_VAR_TMPVAR_HANDLER(ZEND_OPCODE_HA return zend_binary_assign_op_helper_SPEC_VAR_TMPVAR(pow_function, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); } +static int ZEND_FASTCALL ZEND_SEND_VAL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + zval *value, *arg; + + + SAVE_OPLINE(); + arg = ZEND_CALL_VAR(EX(call), opline->result.var); + if(UNEXPECTED(IS_UNUSED == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = NULL; + ZVAL_COPY_VALUE(arg, value); + if (IS_UNUSED == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } + } + } + ZEND_VM_NEXT_OPCODE(); +} + +static int ZEND_FASTCALL ZEND_SEND_VAL_EX_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + zval *value, *arg; + + + SAVE_OPLINE(); + if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num)) { + zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.num); + } + if(UNEXPECTED(IS_UNUSED == IS_UNUSED)) { + uint32_t arg_num = opline->op2.num-1; + if(arg_num < EX(call)->func->common.required_num_args + || (arg_num >= EX(call)->func->common.num_args && !(EX(call)->func->common.fn_flags & ZEND_ACC_ALLOWS_DEFAULT))) { + zend_error_noreturn(E_ERROR, "Defaults can be used only for declared optional parameters"); + } + ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_HAS_DEFAULT); + ZVAL_UNDEF(arg); + } else { + value = NULL; + arg = ZEND_CALL_VAR(EX(call), opline->result.var); + ZVAL_COPY_VALUE(arg, value); + if (IS_UNUSED == IS_CONST) { + if (UNEXPECTED(Z_OPT_COPYABLE_P(arg))) { + zval_copy_ctor_func(arg); + } + } + } + ZEND_VM_NEXT_OPCODE(); +} + static int ZEND_FASTCALL ZEND_CLONE_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE @@ -37960,11 +38079,11 @@ void zend_init_opcodes_handlers(void) ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, + ZEND_SEND_VAL_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_SPEC_UNUSED_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, @@ -39235,11 +39354,11 @@ void zend_init_opcodes_handlers(void) ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, + ZEND_SEND_VAL_EX_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_EX_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_EX_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_EX_SPEC_UNUSED_HANDLER, + ZEND_SEND_VAL_EX_SPEC_UNUSED_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index 31f6537614b21..1b71a609d6e76 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -212,18 +212,16 @@ static void php_str2num(bc_num *num, char *str) PHP_FUNCTION(bcadd) { char *left, *right; - zend_long scale_param = 0; + zend_long scale_param = BCG(bc_precision); bc_num first, second, result; size_t left_len, right_len; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } - - if (argc == 3) { - scale = (int) (scale_param < 0 ? 0 : scale_param); - } + + scale = (int) (scale_param < 0 ? 0 : scale_param); bc_init_num(&first); bc_init_num(&second); @@ -250,17 +248,14 @@ PHP_FUNCTION(bcsub) { char *left, *right; size_t left_len, right_len; - zend_long scale_param = 0; + zend_long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } - - if (argc == 3) { - scale = (int) ((int)scale_param < 0 ? 0 : scale_param); - } + scale = (int) ((int)scale_param < 0) ? 0 : scale_param; bc_init_num(&first); bc_init_num(&second); @@ -287,18 +282,15 @@ PHP_FUNCTION(bcmul) { char *left, *right; size_t left_len, right_len; - zend_long scale_param = 0; + zend_long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } - - if (argc == 3) { - scale = (int) ((int)scale_param < 0 ? 0 : scale_param); - } - + scale = (int) ((int)scale_param < 0) ? 0 : scale_param; + bc_init_num(&first); bc_init_num(&second); bc_init_num(&result); @@ -324,18 +316,15 @@ PHP_FUNCTION(bcdiv) { char *left, *right; size_t left_len, right_len; - zend_long scale_param = 0; + zend_long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } - - if (argc == 3) { - scale = (int) ((int)scale_param < 0 ? 0 : scale_param); - } - + scale = (int) ((int)scale_param < 0) ? 0 : scale_param; + bc_init_num(&first); bc_init_num(&second); bc_init_num(&result); @@ -408,6 +397,7 @@ PHP_FUNCTION(bcpowmod) if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) { return; } + scale_int = (int) ((int)scale < 0) ? 0 : scale; bc_init_num(&first); bc_init_num(&second); @@ -417,8 +407,6 @@ PHP_FUNCTION(bcpowmod) php_str2num(&second, right); php_str2num(&mod, modulous); - scale_int = (int) ((int)scale < 0 ? 0 : scale); - if (bc_raisemod(first, second, mod, &result, scale_int) != -1) { if (result->n_scale > scale) { result->n_scale = (int)scale; @@ -442,17 +430,14 @@ PHP_FUNCTION(bcpow) { char *left, *right; size_t left_len, right_len; - zend_long scale_param = 0; + zend_long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } - - if (argc == 3) { - scale = (int) ((int)scale_param < 0 ? 0 : scale_param); - } + scale = (int) ((int)scale_param < 0) ? 0 : scale_param; bc_init_num(&first); bc_init_num(&second); @@ -479,17 +464,14 @@ PHP_FUNCTION(bcsqrt) { char *left; size_t left_len; - zend_long scale_param = 0; - bc_num result; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + zend_long scale_param = BCG(bc_precision); + bc_num first, second, result; + int scale; - if (zend_parse_parameters(argc, "s|l", &left, &left_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &left, &left_len, &scale_param) == FAILURE) { return; } - - if (argc == 2) { - scale = (int) ((int)scale_param < 0 ? 0 : scale_param); - } + scale = (int) ((int)scale_param < 0) ? 0 : scale_param; bc_init_num(&result); php_str2num(&result, left); @@ -513,18 +495,15 @@ PHP_FUNCTION(bcsqrt) PHP_FUNCTION(bccomp) { char *left, *right; - size_t left_len, right_len; - zend_long scale_param = 0; - bc_num first, second; - int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int left_len, right_len; + long scale_param = BCG(bc_precision); + bc_num first, second, result; + int scale; - if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } - - if (argc == 3) { - scale = (int) ((int)scale_param < 0 ? 0 : scale_param); - } + scale = (int) ((int)scale_param < 0) ? 0 : scale_param; bc_init_num(&first); bc_init_num(&second); diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index 9b59942f26175..1c60d054e7bfb 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -510,18 +510,15 @@ static PHP_FUNCTION(bzerror) static PHP_FUNCTION(bzcompress) { char *source; /* Source data to compress */ - zend_long zblock_size = 0; /* Optional block size to use */ - zend_long zwork_factor = 0;/* Optional work factor to use */ + zend_long zblock_size = 4; /* Optional block size to use */ + zend_long zwork_factor = 0;/* Optional work factor to use */ zend_string *dest = NULL; /* Destination to place the compressed data into */ int error, /* Error Container */ block_size = 4, /* Block size for compression algorithm */ - work_factor = 0, /* Work factor for compression algorithm */ - argc; /* Argument count */ - size_t source_len; /* Length of the source data */ + work_factor = 0; /* Work factor for compression algorithm */ + size_t source_len; /* Length of the source data */ unsigned int dest_len; /* Length of the destination buffer */ - argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ll", &source, &source_len, &zblock_size, &zwork_factor) == FAILURE) { return; } @@ -536,13 +533,8 @@ static PHP_FUNCTION(bzcompress) dest = zend_string_alloc(dest_len, 0); /* Handle the optional arguments */ - if (argc > 1) { - block_size = zblock_size; - } - - if (argc > 2) { - work_factor = zwork_factor; - } + block_size = zblock_size; + work_factor = zwork_factor; error = BZ2_bzBuffToBuffCompress(dest->val, &dest_len, source, source_len, block_size, 0, work_factor); if (error != BZ_OK) { diff --git a/ext/date/php_date.c b/ext/date/php_date.c index c6db35b70960c..79b8ecc136a6b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1221,12 +1221,10 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime) size_t format_len; zend_long ts; + ts = (zend_long)time(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &format, &format_len, &ts) == FAILURE) { RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 1) { - ts = time(NULL); - } RETURN_STR(php_format_date(format, format_len, ts, localtime)); } @@ -1378,6 +1376,7 @@ PHP_FUNCTION(idate) zend_long ts = 0; int ret; + ts = (zend_long)time(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &format, &format_len, &ts) == FAILURE) { RETURN_FALSE; } @@ -1387,10 +1386,6 @@ PHP_FUNCTION(idate) RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 1) { - ts = time(NULL); - } - ret = php_idate(format[0], ts, 0); if (ret == -1) { php_error_docref(NULL, E_WARNING, "Unrecognized date format token."); @@ -1449,6 +1444,7 @@ PHP_FUNCTION(strtotime) timelib_time *t, *now; timelib_tzinfo *tzi; + preset_ts = (zend_long)time(NULL); if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|l", ×, &time_len, &preset_ts) == FAILURE || !time_len) { RETURN_FALSE; } @@ -1458,8 +1454,7 @@ PHP_FUNCTION(strtotime) now = timelib_time_ctor(); now->tz_info = tzi; now->zone_type = TIMELIB_ZONETYPE_ID; - timelib_unixtime2local(now, - (ZEND_NUM_ARGS() == 2) ? (timelib_sll) preset_ts : (timelib_sll) time(NULL)); + timelib_unixtime2local(now, (timelib_sll) preset_ts); t = timelib_strtotime(times, time_len, &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); error1 = error->error_count; @@ -1488,7 +1483,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) zend_long ts, adjust_seconds = 0; int error; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|llllll", &hou, &min, &sec, &mon, &day, &yea) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "|llllll", &hou, &min, &sec, &mon, &day, &yea) == FAILURE) { RETURN_FALSE; } /* Initialize structure with current time */ @@ -4595,40 +4590,25 @@ PHP_FUNCTION(date_default_timezone_get) */ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_sunset) { - double latitude = 0.0, longitude = 0.0, zenith = 0.0, gmt_offset = 0, altitude; + double latitude = INI_FLT("date.default_latitude"), longitude = INI_FLT("date.default_latitude"), zenith = 0.0, gmt_offset = 0, altitude; double h_rise, h_set, N; timelib_sll rise, set, transit; - zend_long time, retformat = 0; + zend_long time, retformat = SUNFUNCS_RET_STRING; int rs; timelib_time *t; timelib_tzinfo *tzi; zend_string *retstr; + if (calc_sunset) { + zenith = INI_FLT("date.sunset_zenith"); + } else { + zenith = INI_FLT("date.sunrise_zenith"); + } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ldddd", &time, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) { RETURN_FALSE; } - switch (ZEND_NUM_ARGS()) { - case 1: - retformat = SUNFUNCS_RET_STRING; - case 2: - latitude = INI_FLT("date.default_latitude"); - case 3: - longitude = INI_FLT("date.default_longitude"); - case 4: - if (calc_sunset) { - zenith = INI_FLT("date.sunset_zenith"); - } else { - zenith = INI_FLT("date.sunrise_zenith"); - } - case 5: - case 6: - break; - default: - php_error_docref(NULL, E_WARNING, "invalid format"); - RETURN_FALSE; - break; - } if (retformat != SUNFUNCS_RET_TIMESTAMP && retformat != SUNFUNCS_RET_STRING && retformat != SUNFUNCS_RET_DOUBLE) diff --git a/ext/dba/dba.c b/ext/dba/dba.c index 739652afffd6a..bf693ef09ac2e 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -554,13 +554,12 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) size_t val_len; zval *id; dba_info *info = NULL; - int ac = ZEND_NUM_ARGS(); zval *key; char *val; char *key_str, *key_free; size_t key_len; - if (zend_parse_parameters(ac, "zsr", &key, &val, &val_len, &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zsr", &key, &val, &val_len, &id) == FAILURE) { return; } diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c index 3beb6832cf591..9cdb95938bff8 100644 --- a/ext/enchant/enchant.c +++ b/ext/enchant/enchant.c @@ -732,7 +732,7 @@ PHP_FUNCTION(enchant_dict_quick_check) size_t n_sugg_st; char **suggs; - if (!sugg && ZEND_NUM_ARGS() == 2) { + if (!sugg) { RETURN_FALSE; } diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c index 93057cbd2c9c8..ac9fc6eb70f8f 100644 --- a/ext/ereg/ereg.c +++ b/ext/ereg/ereg.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf | | Jim Winstead | - | Jaakko Hyv�tti | + | Jaakko Hyvätti | +----------------------------------------------------------------------+ */ /* $Id$ */ @@ -29,7 +29,7 @@ /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO_EX(arginfo_ereg, 0, 0, 2) ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) + ZEND_ARG_INFO(0, string) ZEND_ARG_INFO(1, registers) /* ARRAY_INFO(1, registers, 1) */ ZEND_END_ARG_INFO() @@ -41,8 +41,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_split, 0, 0, 2) ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, limit) + ZEND_ARG_INFO(0, string) + ZEND_ARG_INFO(0, limit) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_sql_regcase, 0) @@ -303,17 +303,16 @@ static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase) off_t start, end; char *buf = NULL; char *string = NULL; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "zs|z/", ®ex, &findin, &findin_len, &array) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|z/", ®ex, &findin, &findin_len, &array) == FAILURE) { return; } if (icase) { copts |= REG_ICASE; } - - if (argc == 2) { + + if (array == NULL) { copts |= REG_NOSUB; } @@ -340,7 +339,7 @@ static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase) /* allocate storage for (sub-)expression-matches */ subs = (regmatch_t *)ecalloc(sizeof(regmatch_t),re.re_nsub+1); - + /* actually execute the regular expression */ err = regexec(&re, string, re.re_nsub+1, subs, 0); if (err && err != REG_NOMATCH) { @@ -458,7 +457,7 @@ PHP_EREG_API char *php_ereg_replace(const char *pattern, const char *replace, co 1) find out how long the string will be, and allocate buf 2) copy the part before match, replacement and backrefs to buf - Jaakko Hyv�tti + Jaakko Hyvätti */ new_l = strlen(buf) + subs[0].rm_so; /* part before the match */ @@ -494,7 +493,7 @@ PHP_EREG_API char *php_ereg_replace(const char *pattern, const char *replace, co if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1 /* this next case shouldn't happen. it does. */ && subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { - + tmp = subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; memcpy (walkbuf, &string[pos + subs[walk[1] - '0'].rm_so], tmp); walkbuf += tmp; @@ -558,7 +557,7 @@ static void php_do_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase) zend_string *string; zend_string *replace; char *ret; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzS", &arg_pattern, &arg_replace, &arg_string) == FAILURE) { return; } @@ -666,9 +665,9 @@ static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase) } else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) { /* No more matches */ regfree(&re); - + php_error_docref(NULL, E_WARNING, "Invalid Regular Expression"); - + zend_hash_destroy(Z_ARRVAL_P(return_value)); efree(Z_ARR_P(return_value)); RETURN_FALSE; @@ -677,7 +676,7 @@ static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase) /* make a copy of the substring */ size = subs[0].rm_so; - + /* add it to the array */ add_next_index_stringl(return_value, strp, size); @@ -703,7 +702,7 @@ static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase) /* otherwise we just have one last element to add to the array */ size = endp - strp; - + add_next_index_stringl(return_value, strp, size); regfree(&re); @@ -740,9 +739,9 @@ PHP_EREG_API PHP_FUNCTION(sql_regcase) if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &string, &string_len) == FAILURE) { return; } - + tmp = safe_emalloc(string_len, 4, 1); - + for (i = j = 0; i < string_len; i++) { c = (unsigned char) string[i]; if (isalpha(c)) { diff --git a/ext/gd/gd.c b/ext/gd/gd.c index a928c8ecf912a..885824661c46b 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -2549,36 +2549,26 @@ PHP_FUNCTION(imagecreatefromgd2part) static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) { zval *imgind; - char *file = NULL; - zend_long quality = 0, type = 0; + zend_long quality = -1, type = 1; gdImagePtr im; char *fn = NULL; FILE *fp; size_t file_len = 0; - int argc = ZEND_NUM_ARGS(); int q = -1, i, t = 1; /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */ /* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */ /* The quality parameter for gd2 stands for chunk size */ - if (zend_parse_parameters(argc, "r|pll", &imgind, &file, &file_len, &quality, &type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|pll", &imgind, &fn, &file_len, &quality, &type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", le_gd); + q = quality; + t = type; - if (argc > 1) { - fn = file; - if (argc == 3) { - q = quality; - } - if (argc == 4) { - t = type; - } - } - - if (argc >= 2 && file_len) { + if (fn != NULL && file_len) { PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename"); fp = VCWD_FOPEN(fn, "wb"); @@ -3273,7 +3263,7 @@ PHP_FUNCTION(imagecolorstotal) PHP_FUNCTION(imagecolortransparent) { zval *IM; - zend_long COL = 0; + zend_long COL = -1; gdImagePtr im; int argc = ZEND_NUM_ARGS(); @@ -3297,7 +3287,7 @@ PHP_FUNCTION(imageinterlace) { zval *IM; int argc = ZEND_NUM_ARGS(); - zend_long INT = 0; + zend_long INT = 1; gdImagePtr im; if (zend_parse_parameters(argc, "r|l", &IM, &INT) == FAILURE) { @@ -4244,7 +4234,7 @@ PHP_FUNCTION(imagepsbbox) ZEND_WRONG_PARAM_COUNT(); } - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Srl|lld", &str, &fnt, &sz, &sp, &wd, &angle) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) { return; } diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c index 028a37e4353e9..a5e001387ef73 100644 --- a/ext/gd/gd_ctx.c +++ b/ext/gd/gd_ctx.c @@ -74,9 +74,8 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, zval *imgind; char *file = NULL; size_t file_len = 0; - zend_long quality, basefilter; + zend_long quality = -1, basefilter = -1; gdImagePtr im; - int argc = ZEND_NUM_ARGS(); int q = -1, i; int f = -1; gdIOCtx *ctx = NULL; @@ -104,15 +103,10 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, } ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd()); + q = quality; /* or colorindex for foreground of BW images (defaults to black) */ + f = basefilter; - if (argc >= 3) { - q = quality; /* or colorindex for foreground of BW images (defaults to black) */ - if (argc == 4) { - f = basefilter; - } - } - - if (argc > 1 && to_zval != NULL) { + if (to_zval != NULL) { if (Z_TYPE_P(to_zval) == IS_RESOURCE) { php_stream_from_zval_no_verify(stream, to_zval); if (stream == NULL) { @@ -172,7 +166,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, break; case PHP_GDIMG_TYPE_XBM: case PHP_GDIMG_TYPE_WBM: - if (argc < 3) { + if (ZEND_NUM_ARGS() < 3) { for(i=0; i < gdImageColorsTotal(im); i++) { if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; } diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 555934dc30c22..7c85ef05c56f0 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -330,13 +330,12 @@ PHP_FUNCTION(hash_init) { char *algo, *key = NULL; size_t algo_len, key_len = 0; - int argc = ZEND_NUM_ARGS(); zend_long options = 0; void *context; const php_hash_ops *ops; php_hash_data *hash; - if (zend_parse_parameters(argc, "s|ls", &algo, &algo_len, &options, &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls", &algo, &algo_len, &options, &key, &key_len) == FAILURE) { return; } diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 486f65d622794..b711f83eedae0 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -2052,7 +2052,7 @@ PHP_FUNCTION(iconv_substr) char *charset = get_internal_encoding(); size_t charset_len = 0; zend_string *str; - zend_long offset, length = 0; + zend_long offset, length = ZEND_LONG_MAX; php_iconv_err_t err; @@ -2069,7 +2069,7 @@ PHP_FUNCTION(iconv_substr) RETURN_FALSE; } - if (ZEND_NUM_ARGS() < 3) { + if (length == ZEND_LONG_MAX) { length = str->len; } diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 0e3ec533a6a35..ce220f48d989f 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -1713,18 +1713,17 @@ PHP_FUNCTION(imap_body) PHP_FUNCTION(imap_mail_copy) { zval *streamind; - zend_long options = 0; + zend_long options = NIL; zend_string *seq, *folder; - int argc = ZEND_NUM_ARGS(); pils *imap_le_struct; - if (zend_parse_parameters(argc, "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(, "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) { return; } ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap); - if (mail_copy_full(imap_le_struct->imap_stream, seq->val, folder->val, (argc == 4 ? options : NIL)) == T) { + if (mail_copy_full(imap_le_struct->imap_stream, seq->val, folder->val, options) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1978,10 +1977,9 @@ PHP_FUNCTION(imap_delete) { zval *streamind, *sequence; pils *imap_le_struct; - zend_long flags = 0; - int argc = ZEND_NUM_ARGS(); + zend_long flags = NIL; - if (zend_parse_parameters(argc, "rz|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz|l", &streamind, &sequence, &flags) == FAILURE) { return; } @@ -1989,7 +1987,7 @@ PHP_FUNCTION(imap_delete) convert_to_string_ex(sequence); - mail_setflag_full(imap_le_struct->imap_stream, Z_STRVAL_P(sequence), "\\DELETED", (argc == 3 ? flags : NIL)); + mail_setflag_full(imap_le_struct->imap_stream, Z_STRVAL_P(sequence), "\\DELETED", flags); RETVAL_TRUE; } /* }}} */ @@ -1999,11 +1997,10 @@ PHP_FUNCTION(imap_delete) PHP_FUNCTION(imap_undelete) { zval *streamind, *sequence; - zend_long flags = 0; + zend_long flags = NIL; pils *imap_le_struct; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rz|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz|l", &streamind, &sequence, &flags) == FAILURE) { return; } @@ -2011,7 +2008,7 @@ PHP_FUNCTION(imap_undelete) convert_to_string_ex(sequence); - mail_clearflag_full(imap_le_struct->imap_stream, Z_STRVAL_P(sequence), "\\DELETED", (argc == 3 ? flags : NIL)); + mail_clearflag_full(imap_le_struct->imap_stream, Z_STRVAL_P(sequence), "\\DELETED", flags); RETVAL_TRUE; } /* }}} */ @@ -2023,7 +2020,7 @@ PHP_FUNCTION(imap_headerinfo) zval *streamind; zend_string *defaulthost = NULL; int argc = ZEND_NUM_ARGS(); - zend_long msgno, fromlength, subjectlength; + zend_long msgno, fromlength = 0, subjectlength = 0; pils *imap_le_struct; MESSAGECACHE *cache; ENVELOPE *en; @@ -2040,16 +2037,12 @@ PHP_FUNCTION(imap_headerinfo) php_error_docref(NULL, E_WARNING, "From length has to be between 0 and %d", MAILTMPLEN); RETURN_FALSE; } - } else { - fromlength = 0x00; } if (argc >= 4) { if (subjectlength < 0 || subjectlength > MAILTMPLEN) { php_error_docref(NULL, E_WARNING, "Subject length has to be between 0 and %d", MAILTMPLEN); RETURN_FALSE; } - } else { - subjectlength = 0x00; } PHP_IMAP_CHECK_MSGNO(msgno); @@ -2105,13 +2098,12 @@ PHP_FUNCTION(imap_rfc822_parse_headers) { zend_string *headers, *defaulthost = NULL; ENVELOPE *en; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "S|S", &headers, &defaulthost) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &headers, &defaulthost) == FAILURE) { return; } - if (argc == 2) { + if (defaulthost != NULL) { rfc822_parse_msg(&en, NULL, headers->val, headers->len, NULL, defaulthost->val, NIL); } else { rfc822_parse_msg(&en, NULL, headers->val, headers->len, NULL, "UNKNOWN", NIL); @@ -3036,17 +3028,16 @@ PHP_FUNCTION(imap_clearflag_full) { zval *streamind; zend_string *sequence, *flag; - zend_long flags = 0; + zend_long flags = NIL; pils *imap_le_struct; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rSS|l", &streamind, &sequence, &flag, &flags) ==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &sequence, &flag, &flags) ==FAILURE) { return; } ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap); - mail_clearflag_full(imap_le_struct->imap_stream, sequence->val, flag->val, (argc == 4 ? flags : NIL)); + mail_clearflag_full(imap_le_struct->imap_stream, sequence->val, flag->val, flags); RETURN_TRUE; } /* }}} */ @@ -3349,7 +3340,6 @@ PHP_FUNCTION(imap_fetch_overview) zval myoverview; zend_string *address; zend_long status, flags = 0L; - int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters(argc, "rS|l", &streamind, &sequence, &flags) == FAILURE) { return; @@ -3997,9 +3987,8 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * PHP_FUNCTION(imap_mail) { zend_string *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *cc=NULL, *bcc=NULL, *rpath=NULL; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "SSS|SSSS", &to, &subject, &message, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSS|SSSS", &to, &subject, &message, &headers, &cc, &bcc, &rpath) == FAILURE) { return; } @@ -4042,10 +4031,9 @@ PHP_FUNCTION(imap_search) pils *imap_le_struct; char *search_criteria; MESSAGELIST *cur; - int argc = ZEND_NUM_ARGS(); SEARCHPGM *pgm = NIL; - if (zend_parse_parameters(argc, "rs|lS", &streamind, &criteria, &flags, &charset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lS", &streamind, &criteria, &flags, &charset) == FAILURE) { return; } @@ -4056,7 +4044,7 @@ PHP_FUNCTION(imap_search) IMAPG(imap_messages) = IMAPG(imap_messages_tail) = NIL; pgm = mail_criteria(search_criteria); - mail_search_full(imap_le_struct->imap_stream, (argc == 4 ? charset->val : NIL), pgm, flags); + mail_search_full(imap_le_struct->imap_stream, (charset != NULL ? charset->val : NIL), pgm, flags); if (pgm && !(flags & SE_FREE)) { mail_free_searchpgm(&pgm); @@ -4643,10 +4631,9 @@ PHP_FUNCTION(imap_thread) zend_long flags = SE_FREE; char criteria[] = "ALL"; THREADNODE *top; - int argc = ZEND_NUM_ARGS(); SEARCHPGM *pgm = NIL; - if (zend_parse_parameters(argc, "r|l", &streamind, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &streamind, &flags) == FAILURE) { return; } diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c index 99c5f34bdad03..e0fd3a3d7278a 100644 --- a/ext/interbase/ibase_blobs.c +++ b/ext/interbase/ibase_blobs.c @@ -128,18 +128,16 @@ int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long m } /* }}} */ -int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob) /* {{{ */ +int _php_ibase_blob_add(const char *str, size_t str_len, ibase_blob *ib_blob) /* {{{ */ { - unsigned long put_cnt = 0, rem_cnt; + size_t put_cnt = 0, rem_cnt; unsigned short chunk_size; - convert_to_string_ex(string_arg); - - for (rem_cnt = Z_STRLEN_P(string_arg); rem_cnt > 0; rem_cnt -= chunk_size) { + for (rem_cnt = str_len; rem_cnt > 0; rem_cnt -= chunk_size) { chunk_size = rem_cnt > USHRT_MAX ? USHRT_MAX : (unsigned short)rem_cnt; - if (isc_put_segment(IB_STATUS, &ib_blob->bl_handle, chunk_size, &Z_STRVAL_P(string_arg)[put_cnt] )) { + if (isc_put_segment(IB_STATUS, &ib_blob->bl_handle, chunk_size, &str[put_cnt] )) { _php_ibase_error(); return FAILURE; } @@ -295,23 +293,25 @@ PHP_FUNCTION(ibase_blob_open) Add data into created blob */ PHP_FUNCTION(ibase_blob_add) { - zval *blob_arg, *string_arg; + zval *blob_handle = NULL; + char *str; + size_t str_len; ibase_blob *ib_blob; RESET_ERRMSG; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &blob_arg, &string_arg) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &blob_handle, &str, &str_len)) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(ib_blob, ibase_blob *, blob_arg, -1, "Interbase blob", le_blob); + ZEND_FETCH_RESOURCE(ib_blob, ibase_blob *, blob_handle, -1, "Interbase blob", le_blob); if (ib_blob->type != BLOB_INPUT) { _php_ibase_module_error("BLOB is not open for input"); RETURN_FALSE; } - if (_php_ibase_blob_add(string_arg, ib_blob) != SUCCESS) { + if (_php_ibase_blob_add(str, str_len, ib_blob) != SUCCESS) { RETURN_FALSE; } } @@ -321,25 +321,24 @@ PHP_FUNCTION(ibase_blob_add) Get len bytes data from open blob */ PHP_FUNCTION(ibase_blob_get) { - zval *blob_arg, *len_arg; + zval *blob_handle = NULL; + zend_long len; ibase_blob *ib_blob; RESET_ERRMSG; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &blob_arg, &len_arg) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &blob_handle, &len) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(ib_blob, ibase_blob *, blob_arg, -1, "Interbase blob", le_blob); + ZEND_FETCH_RESOURCE(ib_blob, ibase_blob *, blob_handle, -1, "Interbase blob", le_blob); if (ib_blob->type != BLOB_OUTPUT) { _php_ibase_module_error("BLOB is not open for output"); RETURN_FALSE; } - convert_to_long_ex(len_arg); - - if (_php_ibase_blob_get(return_value, ib_blob, Z_LVAL_P(len_arg)) != SUCCESS) { + if (_php_ibase_blob_get(return_value, ib_blob, len) != SUCCESS) { RETURN_FALSE; } } @@ -347,13 +346,13 @@ PHP_FUNCTION(ibase_blob_get) static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{ */ { - zval *blob_arg; - ibase_blob *ib_blob; + zval * blob_arg = NULL; + ibase_blob *ib_blob = NULL; char *s; RESET_ERRMSG; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &blob_arg) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", & blob_arg) == FAILURE) { WRONG_PARAM_COUNT; } @@ -544,7 +543,7 @@ PHP_FUNCTION(ibase_blob_echo) Create blob, copy file in it, and close it */ PHP_FUNCTION(ibase_blob_import) { - zval *link = NULL, *file; + zval *link = NULL, *file = NULL; int size; unsigned short b; ibase_blob ib_blob = { NULL, 0 }; @@ -557,7 +556,7 @@ PHP_FUNCTION(ibase_blob_import) RESET_ERRMSG; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "r|r", - (ZEND_NUM_ARGS()-1) ? &link : &file, &file)) { + (ZEND_NUM_ARGS()-1) ? &link : &file, &file)) { RETURN_FALSE; } diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index a4259c54f6af3..3fbca237c1f9b 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -1172,6 +1172,13 @@ PHP_FUNCTION(ibase_query) if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &bind_args, &bind_num) == FAILURE) { return; } + if(bind_num != expected_n) { + php_error_docref(NULL TSRMLS_CC, (bind_num < expected_n) ? E_WARNING : E_NOTICE, + "Statement expects %d arguments, %d given", expected_n, bind_num); + if (bind_num < expected_n) { + break; + } + } } if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, &ib_query, diff --git a/ext/interbase/interbase.c b/ext/interbase/interbase.c index 8f88d6017ad6b..e813e186935ce 100644 --- a/ext/interbase/interbase.c +++ b/ext/interbase/interbase.c @@ -156,8 +156,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_query, 0, 0, 0) ZEND_ARG_INFO(0, link_identifier) ZEND_ARG_INFO(0, link_identifier) ZEND_ARG_INFO(0, query) - ZEND_ARG_INFO(0, bind_arg) - ZEND_ARG_INFO(0, bind_arg) +/* ZEND_ARG_INFO(0, bind_arg) + ZEND_ARG_INFO(0, bind_arg) */ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_affected_rows, 0, 0, 0) @@ -1063,7 +1063,7 @@ PHP_FUNCTION(ibase_close) return; } - if (ZEND_NUM_ARGS() == 0) { + if (link_arg == NULL) { link_id = IBG(default_link); CHECK_LINK(link_id); IBG(default_link) = -1; @@ -1101,7 +1101,7 @@ PHP_FUNCTION(ibase_drop_db) return; } - if (ZEND_NUM_ARGS() == 0) { + if (link_arg == NULL) { link_id = IBG(default_link); CHECK_LINK(link_id); IBG(default_link) = -1; @@ -1333,7 +1333,7 @@ static void _php_ibase_trans_end(INTERNAL_FUNCTION_PARAMETERS, int commit) /* {{ return; } - if (ZEND_NUM_ARGS() == 0) { + if (arg == NULL) { ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link), LE_LINK, le_link, le_plink); if (ib_link->tr_list == NULL || ib_link->tr_list->trans == NULL) { /* this link doesn't have a default transaction */ diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 70b188eeddb35..e6dbffbe65c62 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -390,6 +390,13 @@ PHP_FUNCTION(grapheme_substr) "grapheme_substr: unable to parse input param", 0 ); RETURN_FALSE; } + if(no_length) { + length = str_len; + } else if(length < INT32_MIN) { + length = INT32_MIN; + } else if(length > INT32_MAX) { + length = INT32_MAX; + } if ( OUTSIDE_STRING(lstart, str_len)) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: start not contained in string", 1 ); diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 0d0f6d430102e..d7fdaa38fdef1 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -629,7 +629,7 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) { zval *link, *base_dn, *filter, *attrs = NULL, *attr; - zend_long attrsonly, sizelimit, timelimit, deref; + zend_long attrsonly = 0, sizelimit = -1, timelimit = -1, deref = -1; char *ldap_base_dn = NULL, *ldap_filter = NULL, **ldap_attrs = NULL; ldap_linkdata *ld = NULL; LDAPMessage *ldap_res; @@ -653,6 +653,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) case 5: ldap_attrsonly = attrsonly; case 4: + if(attrs == NULL) break; + num_attribs = zend_hash_num_elements(Z_ARRVAL_P(attrs)); ldap_attrs = safe_emalloc((num_attribs+1), sizeof(char *), 0); @@ -2201,7 +2203,7 @@ PHP_FUNCTION(ldap_set_option) Extract information from result */ PHP_FUNCTION(ldap_parse_result) { - zval *link, *result, *errcode, *matcheddn, *errmsg, *referrals; + zval *link, *result, *errcode, *matcheddn = NULL, *errmsg = NULL, *referrals = NULL; ldap_linkdata *ld; LDAPMessage *ldap_result; char **lreferrals, **refp; diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 7f2209fb12fd3..0ad8cb046b6bf 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2252,7 +2252,7 @@ PHP_FUNCTION(mb_strlen) PHP_FUNCTION(mb_strpos) { int n, reverse = 0; - zend_long offset; + zend_long offset = 0; mbfl_string haystack, needle; char *enc_name = NULL; size_t enc_name_len; @@ -2322,7 +2322,7 @@ PHP_FUNCTION(mb_strrpos) zval *zoffset = NULL; long offset = 0, str_flg; char *enc_name2 = NULL; - int enc_name_len2; + size_t enc_name_len2; mbfl_string_init(&haystack); mbfl_string_init(&needle); @@ -2414,7 +2414,7 @@ PHP_FUNCTION(mb_strrpos) PHP_FUNCTION(mb_stripos) { int n; - zend_long offset; + zend_long offset = 0; mbfl_string haystack, needle; const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name; size_t from_encoding_len; @@ -2443,7 +2443,7 @@ PHP_FUNCTION(mb_stripos) PHP_FUNCTION(mb_strripos) { int n; - zend_long offset; + zend_long offset = 0; mbfl_string haystack, needle; const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name; size_t from_encoding_len; @@ -2757,15 +2757,14 @@ PHP_FUNCTION(mb_substr_count) Returns part of a string */ PHP_FUNCTION(mb_substr) { - size_t argc = ZEND_NUM_ARGS(); - char *str, *encoding; - zend_long from, len; + char *str, *encoding = NULL; + zend_long from, len = LONG_MAX; int mblen; size_t str_len, encoding_len; - zval *z_len = NULL; mbfl_string string, result, *ret; + zend_bool no_len = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|zs", &str, &str_len, &from, &z_len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!s", &str, &str_len, &from, &len, &no_len, &encoding, &encoding_len) == FAILURE) { return; } @@ -2773,7 +2772,7 @@ PHP_FUNCTION(mb_substr) string.no_language = MBSTRG(language); string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; - if (argc == 4) { + if (encoding != NULL) { string.no_encoding = mbfl_name2no_encoding(encoding); if (string.no_encoding == mbfl_no_encoding_invalid) { php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -2784,11 +2783,8 @@ PHP_FUNCTION(mb_substr) string.val = (unsigned char *)str; string.len = str_len; - if (argc < 3 || Z_TYPE_P(z_len) == IS_NULL) { + if (no_len || (len > 0 && (size_t)len > str_len)) { len = str_len; - } else { - convert_to_long_ex(z_len); - len = Z_LVAL_P(z_len); } /* measures length */ @@ -2837,22 +2833,21 @@ PHP_FUNCTION(mb_substr) Returns part of a string */ PHP_FUNCTION(mb_strcut) { - size_t argc = ZEND_NUM_ARGS(); - char *encoding; - zend_long from, len; + char *encoding = NULL; + long from, len = LONG_MAX; size_t encoding_len; - zval *z_len = NULL; mbfl_string string, result, *ret; + zend_bool no_len = 1; mbfl_string_init(&string); string.no_language = MBSTRG(language); string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|zs", (char **)&string.val, (int **)&string.len, &from, &z_len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!s", (char **)&string.val, (int **)&string.len, &from, &len, &no_len, &encoding, &encoding_len) == FAILURE) { return; } - if (argc == 4) { + if (encoding != NULL) { string.no_encoding = mbfl_name2no_encoding(encoding); if (string.no_encoding == mbfl_no_encoding_invalid) { php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -2860,11 +2855,8 @@ PHP_FUNCTION(mb_strcut) } } - if (argc < 3 || Z_TYPE_P(z_len) == IS_NULL) { + if (no_len || (len > 0 && (size_t)len > string.len)) { len = string.len; - } else { - convert_to_long_ex(z_len); - len = Z_LVAL_P(z_len); } /* if "from" position is negative, count start position from the end @@ -2941,7 +2933,7 @@ PHP_FUNCTION(mb_strwidth) Trim the string in terminal width */ PHP_FUNCTION(mb_strimwidth) { - char *str, *trimmarker, *encoding; + char *str, *trimmarker = NULL, *encoding = NULL; zend_long from, width; size_t str_len, trimmarker_len, encoding_len; mbfl_string string, result, marker, *ret; @@ -2959,7 +2951,7 @@ PHP_FUNCTION(mb_strimwidth) marker.val = NULL; marker.len = 0; - if (ZEND_NUM_ARGS() == 5) { + if (encoding != NULL) { string.no_encoding = marker.no_encoding = mbfl_name2no_encoding(encoding); if (string.no_encoding == mbfl_no_encoding_invalid) { php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -2980,7 +2972,7 @@ PHP_FUNCTION(mb_strimwidth) RETURN_FALSE; } - if (ZEND_NUM_ARGS() >= 4) { + if (trimmarker != NULL) { marker.val = (unsigned char *)trimmarker; marker.len = trimmarker_len; } @@ -3089,7 +3081,8 @@ PHP_FUNCTION(mb_convert_encoding) { char *arg_str, *arg_new; size_t str_len, new_len; - zval *arg_old; + zval *arg_old = NULL; + int i; size_t size, l, n; char *_from_encodings = NULL, *ret, *s_free = NULL; @@ -3100,7 +3093,7 @@ PHP_FUNCTION(mb_convert_encoding) return; } - if (ZEND_NUM_ARGS() == 3) { + if (arg_old != NULL) { switch (Z_TYPE_P(arg_old)) { case IS_ARRAY: target_hash = Z_ARRVAL_P(arg_old); @@ -3237,8 +3230,8 @@ PHP_FUNCTION(mb_detect_encoding) { char *str; size_t str_len; - zend_bool strict=0; - zval *encoding_list; + zend_bool strict = (zend_bool)MBSTRG(strict_detection); + zval *encoding_list = NULL; mbfl_string string; const mbfl_encoding *ret; @@ -3252,7 +3245,7 @@ PHP_FUNCTION(mb_detect_encoding) /* make encoding list */ list = NULL; size = 0; - if (ZEND_NUM_ARGS() >= 2 && !Z_ISNULL_P(encoding_list)) { + if (encoding_list != NULL && !ZVAL_IS_NULL(encoding_list)) { switch (Z_TYPE_P(encoding_list)) { case IS_ARRAY: if (FAILURE == php_mb_parse_encoding_array(encoding_list, &list, &size, 0)) { @@ -3279,10 +3272,6 @@ PHP_FUNCTION(mb_detect_encoding) } } - if (ZEND_NUM_ARGS() < 3) { - strict = (zend_bool)MBSTRG(strict_detection); - } - if (size > 0 && list != NULL) { elist = list; } else { @@ -3777,17 +3766,16 @@ PHP_FUNCTION(mb_convert_variables) static void php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type) { - char *str, *encoding; + char *str, *encoding = NULL; size_t str_len, encoding_len; zval *zconvmap, *hash_entry; HashTable *target_hash; - int argc = ZEND_NUM_ARGS(); int i, *convmap, *mapelm, mapsize=0; zend_bool is_hex = 0; mbfl_string string, result, *ret; enum mbfl_no_encoding no_encoding; - if (zend_parse_parameters(argc, "sz|sb", &str, &str_len, &zconvmap, &encoding, &encoding_len, &is_hex) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|sb", &str, &str_len, &zconvmap, &encoding, &encoding_len, &is_hex) == FAILURE) { return; } @@ -3798,7 +3786,7 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type) string.len = str_len; /* encoding */ - if ((argc == 3 || argc == 4) && encoding_len > 0) { + if (encoding != NULL && encoding_len > 0) { no_encoding = mbfl_name2no_encoding(encoding); if (no_encoding == mbfl_no_encoding_invalid) { php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -3808,10 +3796,8 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type) } } - if (argc == 4) { - if (type == 0 && is_hex) { - type = 2; /* output in hex format */ - } + if (type == 0 && is_hex) { + type = 2; /* output in hex format */ } /* conversion map */ diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 59238fda39e41..a2202e73ab885 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -653,8 +653,7 @@ _php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, O Returns the current encoding for regex as a string. */ PHP_FUNCTION(mb_regex_encoding) { - size_t argc = ZEND_NUM_ARGS(); - char *encoding; + char *encoding = NULL; size_t encoding_len; OnigEncoding mbctype; @@ -662,7 +661,7 @@ PHP_FUNCTION(mb_regex_encoding) return; } - if (argc == 0) { + if (encoding == NULL) { const char *retval = _php_mb_regex_mbctype2name(MBREX(current_mbctype)); if (retval == NULL) { @@ -670,7 +669,7 @@ PHP_FUNCTION(mb_regex_encoding) } RETURN_STRING((char *)retval); - } else if (argc == 1) { + } else { mbctype = _php_mb_regex_name2mbctype(encoding); if (mbctype == ONIG_ENCODING_UNDEF) { @@ -687,7 +686,7 @@ PHP_FUNCTION(mb_regex_encoding) /* {{{ _php_mb_regex_ereg_exec */ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) { - zval *arg_pattern, *array; + zval *arg_pattern, *array = NULL; char *string; size_t string_len; php_mb_regex_t *re; @@ -696,8 +695,6 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) OnigOptionType options; char *str; - array = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|z/", &arg_pattern, &string, &string_len, &array) == FAILURE) { RETURN_FALSE; } @@ -1178,26 +1175,25 @@ PHP_FUNCTION(mb_ereg_match) static void _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode) { - size_t argc = ZEND_NUM_ARGS(); - char *arg_pattern, *arg_options; + char *arg_pattern = NULL, *arg_options = NULL; size_t arg_pattern_len, arg_options_len; int n, i, err, pos, len, beg, end; OnigOptionType option; OnigUChar *str; OnigSyntaxType *syntax; - if (zend_parse_parameters(argc, "|ss", &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ss", &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) { return; } option = MBREX(regex_default_options); - if (argc == 2) { + if (arg_options != NULL) { option = 0; _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL); } - if (argc > 0) { + if (arg_pattern != NULL) { /* create regex pattern buffer */ if ((MBREX(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBREX(current_mbctype), MBREX(regex_default_syntax))) == NULL) { RETURN_FALSE; @@ -1308,18 +1304,17 @@ PHP_FUNCTION(mb_ereg_search_regs) Initialize string and regular expression for search. */ PHP_FUNCTION(mb_ereg_search_init) { - size_t argc = ZEND_NUM_ARGS(); zval *arg_str; char *arg_pattern = NULL, *arg_options = NULL; size_t arg_pattern_len = 0, arg_options_len = 0; OnigSyntaxType *syntax = NULL; OnigOptionType option; - if (zend_parse_parameters(argc, "z|ss", &arg_str, &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|ss", &arg_str, &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) { return; } - if (argc > 1 && arg_pattern_len == 0) { + if (arg_pattern != NULL && arg_pattern_len == 0) { php_error_docref(NULL, E_WARNING, "Empty pattern"); RETURN_FALSE; } @@ -1327,12 +1322,12 @@ PHP_FUNCTION(mb_ereg_search_init) option = MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); - if (argc == 3) { + if (arg_options != NULL) { option = 0; _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL); } - if (argc > 1) { + if (arg_pattern != NULL) { /* create regex pattern buffer */ if ((MBREX(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBREX(current_mbctype), syntax)) == NULL) { RETURN_FALSE; diff --git a/ext/mbstring/tests/mb_str_functions_opt-parameter2.phpt b/ext/mbstring/tests/mb_str_functions_opt-parameter2.phpt new file mode 100644 index 0000000000000..799b8fb294f7c --- /dev/null +++ b/ext/mbstring/tests/mb_str_functions_opt-parameter2.phpt @@ -0,0 +1,32 @@ +--TEST-- +Optional long parameter might be null +--SKIPIF-- + +--FILE-- + +==DONE== +--EXPECT-- +1 +2 +1 +2 +barbaz +baz +barbaz +baz +baz +baz +foo +==DONE== diff --git a/ext/mssql/php_mssql.c b/ext/mssql/php_mssql.c index 08e118d281c9a..7836931fec419 100644 --- a/ext/mssql/php_mssql.c +++ b/ext/mssql/php_mssql.c @@ -548,7 +548,7 @@ static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) mssql_link mssql, *mssql_ptr; char buffer[40]; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sssb", &host, &host_len, &user, &user_len, &passwd, &passwd_len, &new_link) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "|sssb", &host, &host_len, &user, &user_len, &passwd, &passwd_len, &new_link) == FAILURE) { return; } @@ -1324,27 +1324,22 @@ PHP_FUNCTION(mssql_query) zval *mssql_link_index = NULL; size_t query_len; int retvalue, batchsize, num_fields; - zend_long zbatchsize = 0; + zend_long zbatchsize = MS_SQL_G(batchsize); mssql_link *mssql_ptr; mssql_result *result; int id = -1; dbsettime(MS_SQL_G(timeout)); - batchsize = MS_SQL_G(batchsize); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|rl", &query, &query_len, &mssql_link_index, &zbatchsize) == FAILURE) { return; } - switch(ZEND_NUM_ARGS()) { - case 1: - id = php_mssql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); - CHECK_LINK(id); - break; - case 3: - batchsize = (int) zbatchsize; - break; + if(mssql_link_index == NULL) { + id = php_mssql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); + CHECK_LINK(id); } + batchsize = (int) zbatchsize; ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); @@ -2024,7 +2019,7 @@ PHP_FUNCTION(mssql_bind) return; } - if (ZEND_NUM_ARGS() == 7 && !is_output) { + if (!is_output) { maxlen = -1; } diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 2af92963f8f78..569e3beb9f66f 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -2083,7 +2083,7 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_ ZEND_PARSE_PARAMETERS_END(); #endif - if (ZEND_NUM_ARGS() < 2) { + if (class_name == NULL) { ce = zend_standard_class_def; } else { ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO); diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 2debf256e27dd..0c87763d10e82 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1050,36 +1050,19 @@ PHP_FUNCTION(mysqli_stmt_construct) zval *mysql_link; MY_STMT *stmt; MYSQLI_RESOURCE *mysqli_resource; - char *statement; - size_t statement_len; + char *statement = NULL; + size_t statement_len; - switch (ZEND_NUM_ARGS()) - { - case 1: /* mysql_stmt_init */ - if (zend_parse_parameters(1, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) { - return; - } - MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID); - - stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT)); - - stmt->stmt = mysql_stmt_init(mysql->mysql); - break; - case 2: - if (zend_parse_parameters(2, "Os", &mysql_link, mysqli_link_class_entry, &statement, &statement_len)==FAILURE) { - return; - } - MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &mysql_link, mysqli_link_class_entry, &statement, &statement_len)==FAILURE) { + return; + } + MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID); - stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT)); + stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT)); + stmt->stmt = mysql_stmt_init(mysql->mysql); - if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) { - mysql_stmt_prepare(stmt->stmt, (char *)statement, statement_len); - } - break; - default: - WRONG_PARAM_COUNT; - break; + if(statement != NULL && stmt->stmt) { + mysql_stmt_prepare(stmt->stmt, (char *)statement, statement_len); } if (!stmt->stmt) { @@ -1092,7 +1075,7 @@ PHP_FUNCTION(mysqli_stmt_construct) mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE)); mysqli_resource->ptr = (void *)stmt; - mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID; + mysqli_resource->status = (statement == NULL) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID; MYSQLI_REGISTER_RESOURCE_EX(mysqli_resource, getThis()); } @@ -1111,19 +1094,8 @@ PHP_FUNCTION(mysqli_result_construct) MYSQLI_RESOURCE *mysqli_resource; zend_long resmode = MYSQLI_STORE_RESULT; - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_parse_parameters(1, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) { - return; - } - break; - case 2: - if (zend_parse_parameters(2, "Ol", &mysql_link, mysqli_link_class_entry, &resmode)==FAILURE) { - return; - } - break; - default: - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &mysql_link, mysqli_link_class_entry, &resmode)==FAILURE) { + return; } MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID); diff --git a/ext/mysqli/mysqli_warning.c b/ext/mysqli/mysqli_warning.c index 396c6ed7ebd50..c79ff97a741fc 100644 --- a/ext/mysqli/mysqli_warning.c +++ b/ext/mysqli/mysqli_warning.c @@ -259,10 +259,7 @@ PHP_METHOD(mysqli_warning, __construct) MYSQLI_WARNING *w; MYSQLI_RESOURCE *mysqli_resource; - if (ZEND_NUM_ARGS() != 1) { - WRONG_PARAM_COUNT; - } - if (zend_parse_parameters(1, "o", &z)==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &z)==FAILURE) { return; } obj = Z_MYSQLI_P(z); diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index 80b847f5a513e..0e572447fc18c 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -2645,7 +2645,7 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg php_oci_out_column *column; ub4 nrows = 1; int i; - zend_long fetch_mode = 0; + zend_long fetch_mode = mode; if (expected_args > 2) { /* only for ocifetchinto BC */ @@ -2654,9 +2654,6 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg return; } - if (ZEND_NUM_ARGS() == 2) { - fetch_mode = mode; - } } else if (expected_args == 2) { /* only for oci_fetch_array() */ @@ -2664,9 +2661,6 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg return; } - if (ZEND_NUM_ARGS() == 1) { - fetch_mode = mode; - } } else { /* for all oci_fetch_*() */ @@ -2674,7 +2668,6 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg return; } - fetch_mode = mode; } if (!(fetch_mode & PHP_OCI_NUM) && !(fetch_mode & PHP_OCI_ASSOC)) { diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index a76f15a54d8c2..27bee12cb05fe 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -12,7 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Stig S�ther Bakken | + | Authors: Stig S�ther Bakken | | Thies C. Arntzen | | | | Collection support by Andy Sautins | @@ -105,7 +105,7 @@ PHP_FUNCTION(oci_bind_by_name) zval *z_statement; zval *bind_var = NULL; php_oci_statement *statement; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsz/|ll", &z_statement, &name, &name_len, &bind_var, &maxlen, &type) == FAILURE) { return; } @@ -113,7 +113,7 @@ PHP_FUNCTION(oci_bind_by_name) if (type) { bind_type = (ub2) type; } - + PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement); if (php_oci_bind_by_name(statement, name, name_len, bind_var, maxlen, bind_type)) { @@ -135,22 +135,22 @@ PHP_FUNCTION(oci_bind_array_by_name) zval *z_statement; zval *bind_var = NULL; php_oci_statement *statement; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsz/l|ll", &z_statement, &name, &name_len, &bind_var, &max_array_len, &max_item_len, &type) == FAILURE) { return; } PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement); - if (ZEND_NUM_ARGS() == 5 && max_item_len <= 0) { + if (max_item_len <= 0) { max_item_len = -1; } - + if (max_array_len <= 0) { php_error_docref(NULL, E_WARNING, "Maximum array length must be greater than zero"); RETURN_FALSE; } - + if (php_oci_bind_array_by_name(statement, name, name_len, bind_var, max_array_len, max_item_len, type)) { RETURN_FALSE; } @@ -249,7 +249,7 @@ PHP_FUNCTION(oci_lob_import) if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) { #endif return; - } + } } #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || (PHP_MAJOR_VERSION < 5) @@ -286,7 +286,7 @@ PHP_FUNCTION(oci_lob_load) if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -326,7 +326,7 @@ PHP_FUNCTION(oci_lob_read) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &z_descriptor, oci_lob_class_entry_ptr, &length) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -343,7 +343,7 @@ PHP_FUNCTION(oci_lob_read) if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len)) { RETURN_FALSE; - } + } if (buffer_len > 0) { RETURN_STRINGL(buffer, buffer_len); } @@ -360,11 +360,11 @@ PHP_FUNCTION(oci_lob_eof) zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; ub4 lob_length; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -389,11 +389,11 @@ PHP_FUNCTION(oci_lob_tell) { zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -413,11 +413,11 @@ PHP_FUNCTION(oci_lob_rewind) { zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -441,7 +441,7 @@ PHP_FUNCTION(oci_lob_seek) php_oci_descriptor *descriptor; zend_long offset, whence = PHP_OCI_SEEK_SET; ub4 lob_length; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &offset, &whence) == FAILURE) { return; @@ -450,7 +450,7 @@ PHP_FUNCTION(oci_lob_seek) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|l", &z_descriptor, oci_lob_class_entry_ptr, &offset, &whence) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -480,7 +480,7 @@ PHP_FUNCTION(oci_lob_seek) default: descriptor->lob_current_position = (offset > 0) ? offset : 0; break; - } + } RETURN_TRUE; } /* }}} */ @@ -492,11 +492,11 @@ PHP_FUNCTION(oci_lob_size) zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; ub4 lob_length; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -520,27 +520,23 @@ PHP_FUNCTION(oci_lob_write) zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; size_t data_len; - zend_long write_len = 0; + zend_long write_len = ZEND_LONG_MAX; ub4 bytes_written; char *data; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &data, &data_len, &write_len) == FAILURE) { return; } - - if (ZEND_NUM_ARGS() == 2) { - data_len = MIN(data_len, write_len); - } + + data_len = MIN(data_len, write_len); } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &write_len) == FAILURE) { return; } - if (ZEND_NUM_ARGS() == 3) { - data_len = MIN(data_len, write_len); - } + data_len = MIN(data_len, write_len); } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -567,7 +563,7 @@ PHP_FUNCTION(oci_lob_append) { zval *tmp_dest, *tmp_from, *z_descriptor_dest = getThis(), *z_descriptor_from; php_oci_descriptor *descriptor_dest, *descriptor_from; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) { return; @@ -576,7 +572,7 @@ PHP_FUNCTION(oci_lob_append) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"))) == NULL) { @@ -608,7 +604,7 @@ PHP_FUNCTION(oci_lob_truncate) php_oci_descriptor *descriptor; zend_long trim_length = 0; ub4 ub_trim_length; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &trim_length) == FAILURE) { return; @@ -617,7 +613,7 @@ PHP_FUNCTION(oci_lob_truncate) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &z_descriptor, oci_lob_class_entry_ptr, &trim_length) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -650,7 +646,7 @@ PHP_FUNCTION(oci_lob_erase) zend_long offset = -1, length = -1; if (getThis()) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &offset, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "|ll", &offset, &length) == FAILURE) { return; } @@ -665,7 +661,7 @@ PHP_FUNCTION(oci_lob_erase) } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) { return; } @@ -673,7 +669,7 @@ PHP_FUNCTION(oci_lob_erase) php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0"); RETURN_FALSE; } - + if (ZEND_NUM_ARGS() > 2 && length < 0) { php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0"); RETURN_FALSE; @@ -739,7 +735,7 @@ PHP_FUNCTION(ocisetbufferinglob) zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; zend_bool flag; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &flag) == FAILURE) { return; @@ -748,7 +744,7 @@ PHP_FUNCTION(ocisetbufferinglob) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &z_descriptor, oci_lob_class_entry_ptr, &flag) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -771,11 +767,11 @@ PHP_FUNCTION(ocigetbufferinglob) { zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -799,8 +795,8 @@ PHP_FUNCTION(oci_lob_copy) zval *tmp_dest, *tmp_from, *z_descriptor_dest, *z_descriptor_from; php_oci_descriptor *descriptor_dest, *descriptor_from; zend_long length = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO|l", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length) == FAILURE) { + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "OO|l", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length) == FAILURE) { return; } @@ -821,7 +817,7 @@ PHP_FUNCTION(oci_lob_copy) php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); RETURN_FALSE; } - + if (ZEND_NUM_ARGS() == 2) { /* indicate that we want to copy from the current position to the end of the LOB */ length = -1; @@ -862,7 +858,7 @@ PHP_FUNCTION(oci_lob_is_equal) if (php_oci_lob_is_equal(descriptor_first, descriptor_second, &is_equal)) { RETURN_FALSE; } - + if (is_equal == TRUE) { RETURN_TRUE; } @@ -879,7 +875,7 @@ PHP_FUNCTION(oci_lob_export) char *filename; char *buffer; size_t filename_len; - zend_long start = -1, length = -1, block_length; + zend_long start = 0, length = ZEND_LONG_MAX, block_length; php_stream *stream; ub4 lob_length; @@ -891,15 +887,6 @@ PHP_FUNCTION(oci_lob_export) #endif return; } - - if (ZEND_NUM_ARGS() > 1 && start < 0) { - php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0"); - RETURN_FALSE; - } - if (ZEND_NUM_ARGS() > 2 && length < 0) { - php_error_docref(NULL, E_WARNING, "Length parameter must be greater than or equal to 0"); - RETURN_FALSE; - } } else { #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3) || (PHP_MAJOR_VERSION > 5) @@ -909,15 +896,15 @@ PHP_FUNCTION(oci_lob_export) #endif return; } - - if (ZEND_NUM_ARGS() > 2 && start < 0) { - php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0"); - RETURN_FALSE; - } - if (ZEND_NUM_ARGS() > 3 && length < 0) { - php_error_docref(NULL, E_WARNING, "Length parameter must be greater than or equal to 0"); - RETURN_FALSE; - } + } + + if (start < 0) { + php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0"); + RETURN_FALSE; + } + if (length < 0) { + php_error_docref(NULL, E_WARNING, "Length parameter must be greater than or equal to 0"); + RETURN_FALSE; } #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || (PHP_MAJOR_VERSION < 5) @@ -937,16 +924,16 @@ PHP_FUNCTION(oci_lob_export) if (php_oci_lob_get_length(descriptor, &lob_length)) { RETURN_FALSE; - } - + } + if (start == -1) { start = 0; } - if (length == -1) { + if (length == ZEND_LONG_MAX) { length = lob_length - descriptor->lob_current_position; } - + if (length == 0) { /* nothing to write, fail silently */ RETURN_FALSE; @@ -988,7 +975,7 @@ PHP_FUNCTION(oci_lob_export) if (buffer) { efree(buffer); } - + length -= tmp_bytes_read; descriptor->lob_current_position += tmp_bytes_read; start += tmp_bytes_read; @@ -1021,7 +1008,7 @@ PHP_FUNCTION(oci_lob_write_temporary) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &type) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -1044,11 +1031,11 @@ PHP_FUNCTION(oci_lob_close) { zval *tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"))) == NULL) { @@ -1207,7 +1194,7 @@ PHP_FUNCTION(oci_field_type) if (!column) { RETURN_FALSE; } - + switch (column->data_type) { #ifdef SQLT_TIMESTAMP case SQLT_TIMESTAMP: @@ -1446,7 +1433,7 @@ PHP_FUNCTION(oci_fetch_all) } else { /* default to BY_COLUMN */ columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0); outarrs = safe_emalloc(statement->ncolumns, sizeof(zval*), 0); - + if (flags & PHP_OCI_NUM) { for (i = 0; i < statement->ncolumns; i++) { columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0); @@ -1476,7 +1463,7 @@ PHP_FUNCTION(oci_fetch_all) break; } } - + efree(columns); efree(outarrs); } @@ -1566,7 +1553,7 @@ PHP_FUNCTION(oci_close) zend_list_delete(connection->id); ZVAL_NULL(z_connection); - + RETURN_TRUE; } /* }}} */ @@ -1612,7 +1599,7 @@ PHP_FUNCTION(oci_error) return; } - if (ZEND_NUM_ARGS() > 0) { + if (arg) { statement = (php_oci_statement *) zend_fetch_resource(arg, -1, NULL, NULL, 1, le_statement); if (statement) { errh = statement->err; @@ -2037,7 +2024,7 @@ PHP_FUNCTION(oci_new_cursor) PHP_FUNCTION(oci_result) { php_oci_out_column *column; - + column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if(column) { php_oci_column_to_zval(column, return_value, 0); @@ -2167,7 +2154,7 @@ PHP_FUNCTION(oci_free_collection) if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2199,7 +2186,7 @@ PHP_FUNCTION(oci_collection_append) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_collection, oci_coll_class_entry_ptr, &value, &value_len) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2233,7 +2220,7 @@ PHP_FUNCTION(oci_collection_element_get) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &z_collection, oci_coll_class_entry_ptr, &element_index) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2266,7 +2253,7 @@ PHP_FUNCTION(oci_collection_assign) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &z_collection_dest, oci_coll_class_entry_ptr, &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_collection_dest), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2307,7 +2294,7 @@ PHP_FUNCTION(oci_collection_element_assign) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ols", &z_collection, oci_coll_class_entry_ptr, &element_index, &value, &value_len) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2331,11 +2318,11 @@ PHP_FUNCTION(oci_collection_size) zval *tmp, *z_collection = getThis(); php_oci_collection *collection; sb4 size = 0; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2363,7 +2350,7 @@ PHP_FUNCTION(oci_collection_max) if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2396,7 +2383,7 @@ PHP_FUNCTION(oci_collection_trim) else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &z_collection, oci_coll_class_entry_ptr, &trim_size) == FAILURE) { return; - } + } } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "descriptor", sizeof("descriptor"))) == NULL) { @@ -2409,7 +2396,7 @@ PHP_FUNCTION(oci_collection_trim) if (php_oci_collection_trim(collection, trim_size)) { RETURN_FALSE; } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -2426,7 +2413,7 @@ PHP_FUNCTION(oci_new_collection) if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) { return; } - + PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); if ( (collection = php_oci_collection_create(connection, tdo, tdo_len, schema, schema_len)) ) { diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index cd4964346fb02..78a35762a332f 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -12,7 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Stig S�ther Bakken | + | Authors: Stig S�ther Bakken | | Andreas Karajannis | | Frank M. Kromann Support for DB/2 CLI | | Kevin N. Shallow Birdstep Support| @@ -25,7 +25,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif - + #include "php.h" #include "php_globals.h" @@ -394,13 +394,13 @@ static PHP_GINIT_FUNCTION(odbc); */ zend_module_entry odbc_module_entry = { STANDARD_MODULE_HEADER, - "odbc", - odbc_functions, - PHP_MINIT(odbc), + "odbc", + odbc_functions, + PHP_MINIT(odbc), PHP_MSHUTDOWN(odbc), - PHP_RINIT(odbc), - PHP_RSHUTDOWN(odbc), - PHP_MINFO(odbc), + PHP_RINIT(odbc), + PHP_RSHUTDOWN(odbc), + PHP_MINFO(odbc), "1.0", PHP_MODULE_GLOBALS(odbc), PHP_GINIT(odbc), @@ -421,7 +421,7 @@ static void _free_odbc_result(zend_resource *rsrc) odbc_result *res = (odbc_result *)rsrc->ptr; int i; RETCODE rc; - + if (res) { if (res->values) { for(i = 0; i < res->numcols; i++) { @@ -667,7 +667,7 @@ static PHP_INI_DISP(display_cursortype) /* }}} */ -/* {{{ PHP_INI_BEGIN +/* {{{ PHP_INI_BEGIN */ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("odbc.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateLong, @@ -688,7 +688,7 @@ PHP_INI_BEGIN() defaultbinmode, zend_odbc_globals, odbc_globals, display_binmode) STD_PHP_INI_BOOLEAN("odbc.check_persistent", "1", PHP_INI_SYSTEM, OnUpdateLong, check_persistent, zend_odbc_globals, odbc_globals) - STD_PHP_INI_ENTRY_EX("odbc.default_cursortype", "3", PHP_INI_ALL, OnUpdateLong, + STD_PHP_INI_ENTRY_EX("odbc.default_cursortype", "3", PHP_INI_ALL, OnUpdateLong, default_cursortype, zend_odbc_globals, odbc_globals, display_cursortype) PHP_INI_END() /* }}} */ @@ -736,7 +736,7 @@ PHP_MINIT_FUNCTION(odbc) REGISTER_LONG_CONSTANT("SQL_CURSOR_KEYSET_DRIVEN", SQL_CURSOR_KEYSET_DRIVEN, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SQL_CURSOR_DYNAMIC", SQL_CURSOR_DYNAMIC, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("SQL_CURSOR_STATIC", SQL_CURSOR_STATIC, CONST_PERSISTENT | CONST_CS); - + REGISTER_LONG_CONSTANT("SQL_KEYSET_SIZE", SQL_KEYSET_SIZE, CONST_PERSISTENT | CONST_CS); /* these are for the Data Source type */ @@ -850,7 +850,7 @@ PHP_MINFO_FUNCTION(odbc) DISPLAY_INI_ENTRIES(); -} +} /* }}} */ /* {{{ odbc_sql_error */ @@ -872,7 +872,7 @@ void odbc_sql_error(ODBC_SQL_ERROR_PARAMS) conn = SQL_NULL_HDBC; } - /* This leads to an endless loop in many drivers! + /* This leads to an endless loop in many drivers! * while(henv != SQL_NULL_HENV){ do { @@ -893,7 +893,7 @@ void odbc_sql_error(ODBC_SQL_ERROR_PARAMS) } else { php_error_docref(NULL, E_WARNING, "SQL error: %s, SQL state %s", errormsg, state); } - /* + /* } while (SQL_SUCCEEDED(rc)); } */ @@ -910,7 +910,7 @@ void php_odbc_fetch_attribs(INTERNAL_FUNCTION_PARAMETERS, int mode) if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &pv_res, &flag) == FAILURE) { return; } - + if (Z_LVAL_P(pv_res)) { ZEND_FETCH_RESOURCE(result, odbc_result *, pv_res, -1, "ODBC result", le_result); if (mode) { @@ -950,13 +950,13 @@ int odbc_bindcols(odbc_result *result) rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_NAME, result->values[i].name, sizeof(result->values[i].name), &colnamelen, 0); - rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_TYPE, + rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_TYPE, NULL, 0, NULL, &result->values[i].coltype); - + /* Don't bind LONG / BINARY columns, so that fetch behaviour can * be controlled by odbc_binmode() / odbc_longreadlen() */ - + switch(result->values[i].coltype) { case SQL_BINARY: case SQL_VARBINARY: @@ -967,7 +967,7 @@ int odbc_bindcols(odbc_result *result) #endif result->values[i].value = NULL; break; - + #ifdef HAVE_ADABAS case SQL_TIMESTAMP: result->values[i].value = (char *)emalloc(27); @@ -1045,7 +1045,7 @@ void odbc_column_lengths(INTERNAL_FUNCTION_PARAMETERS, int type) { odbc_result *result; #if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) - /* this seems to be necessary for Solid2.3 ( tested by + /* this seems to be necessary for Solid2.3 ( tested by * tammy@synchronis.com) and Solid 3.0 (tested by eric@terra.telemediair.nl) * Solid does not seem to declare a SQLINTEGER, but it does declare a * SQL_INTEGER which does not work (despite being the same type as a SDWORD. @@ -1157,9 +1157,9 @@ PHP_FUNCTION(odbc_prepare) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + result->numparams = 0; - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -1200,7 +1200,7 @@ PHP_FUNCTION(odbc_prepare) odbc_sql_error(conn, result->stmt, "SQLPrepare"); RETURN_FALSE; } - + SQLNumParams(result->stmt, &(result->numparams)); SQLNumResultCols(result->stmt, &(result->numcols)); @@ -1215,7 +1215,7 @@ PHP_FUNCTION(odbc_prepare) Z_ADDREF_P(pv_conn); result->conn_ptr = conn; result->fetched = 0; - ZEND_REGISTER_RESOURCE(return_value, result, le_result); + ZEND_REGISTER_RESOURCE(return_value, result, le_result); } /* }}} */ @@ -1241,7 +1241,7 @@ PHP_FUNCTION(odbc_execute) odbc_result *result; int numArgs, i, ne; RETCODE rc; - + numArgs = ZEND_NUM_ARGS(); if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|a", &pv_res, &pv_param_arr) == FAILURE) { @@ -1267,7 +1267,7 @@ PHP_FUNCTION(odbc_execute) for(i = 0; i < result->numparams; i++) { params[i].fp = -1; } - + for(i = 1; i <= result->numparams; i++) { if ((tmp = zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr))) == NULL) { php_error_docref(NULL, E_WARNING,"Error getting parameter"); @@ -1294,12 +1294,12 @@ PHP_FUNCTION(odbc_execute) efree(params); RETURN_FALSE; } - + rc = SQLDescribeParam(result->stmt, (SQLUSMALLINT)i, &sqltype, &precision, &scale, &nullable); params[i-1].vallen = Z_STRLEN_P(tmp); params[i-1].fp = -1; if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter"); + odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter"); SQLFreeStmt(result->stmt, SQL_RESET_PARAMS); for (i = 0; i < result->numparams; i++) { if (params[i].fp != -1) { @@ -1374,7 +1374,7 @@ PHP_FUNCTION(odbc_execute) ¶ms[i-1].vallen); } if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLBindParameter"); + odbc_sql_error(result->conn_ptr, result->stmt, "SQLBindParameter"); SQLFreeStmt(result->stmt, SQL_RESET_PARAMS); for (i = 0; i < result->numparams; i++) { if (params[i].fp != -1) { @@ -1391,7 +1391,7 @@ PHP_FUNCTION(odbc_execute) rc = SQLFreeStmt(result->stmt, SQL_CLOSE); if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLFreeStmt"); + odbc_sql_error(result->conn_ptr, result->stmt, "SQLFreeStmt"); } rc = SQLExecute(result->stmt); @@ -1420,8 +1420,8 @@ PHP_FUNCTION(odbc_execute) odbc_sql_error(result->conn_ptr, result->stmt, "SQLExecute"); RETVAL_FALSE; } - } - + } + if (result->numparams > 0) { SQLFreeStmt(result->stmt, SQL_RESET_PARAMS); for(i = 0; i < result->numparams; i++) { @@ -1472,7 +1472,7 @@ PHP_FUNCTION(odbc_cursor) if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { RETURN_FALSE; } - + if (max_len > 0) { cursorname = emalloc(max_len + 1); rc = SQLGetCursorName(result->stmt,cursorname,(SQLSMALLINT)max_len,&len); @@ -1533,12 +1533,12 @@ PHP_FUNCTION(odbc_data_source) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, zv_conn, -1, "ODBC-Link", le_conn, le_pconn); /* now we have the "connection" lets call the DataSource object */ - rc = SQLDataSources(conn->henv, + rc = SQLDataSources(conn->henv, fetch_type, server_name, (SQLSMALLINT)sizeof(server_name), &len1, - desc, + desc, (SQLSMALLINT)sizeof(desc), &len2); @@ -1601,7 +1601,7 @@ PHP_FUNCTION(odbc_exec) efree(result); RETURN_FALSE; } - + #ifdef HAVE_SQL_EXTENDED_FETCH /* Solid doesn't have ExtendedFetch, if DriverManager is used, get Info, whether Driver supports ExtendedFetch */ @@ -1619,18 +1619,18 @@ PHP_FUNCTION(odbc_exec) #endif rc = SQLExecDirect(result->stmt, query, SQL_NTS); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA_FOUND) { + if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA_FOUND) { /* XXX FIXME we should really check out SQLSTATE with SQLError * in case rc is SQL_SUCCESS_WITH_INFO here. */ - odbc_sql_error(conn, result->stmt, "SQLExecDirect"); + odbc_sql_error(conn, result->stmt, "SQLExecDirect"); SQLFreeStmt(result->stmt, SQL_DROP); efree(result); RETURN_FALSE; } SQLNumResultCols(result->stmt, &(result->numcols)); - + /* For insert, update etc. cols == 0 */ if (result->numcols > 0) { if (!odbc_bindcols(result)) { @@ -1669,7 +1669,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &pv_res, &pv_row) == FAILURE) { return; } - + rownum = pv_row; #else zval *pv_res, tmp; @@ -1700,9 +1700,9 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { RETURN_FALSE; } - + array_init(return_value); - + #ifdef HAVE_SQL_EXTENDED_FETCH if (rownum > 0 && result->fetch_abs) result->fetched = rownum; @@ -1731,11 +1731,11 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) { ZVAL_EMPTY_STRING(&tmp); break; - } + } if (buf == NULL) { buf = emalloc(result->longreadlen + 1); } - + rc = SQLGetData(result->stmt, (SQLUSMALLINT)(i + 1), sql_c_type, buf, result->longreadlen + 1, &result->values[i].vallen); if (rc == SQL_ERROR) { @@ -1801,7 +1801,7 @@ PHP_FUNCTION(odbc_fetch_array) #endif /* {{{ proto int odbc_fetch_into(resource result_id, array &result_array, [, int rownumber]) - Fetch one result row into an array */ + Fetch one result row into an array */ PHP_FUNCTION(odbc_fetch_into) { int i; @@ -1821,7 +1821,7 @@ PHP_FUNCTION(odbc_fetch_into) if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/|l", &pv_res, &pv_res_arr, &pv_row) == FAILURE) { return; } - + rownum = pv_row; #else if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/", &pv_res, &pv_res_arr) == FAILURE) { @@ -1915,12 +1915,12 @@ PHP_FUNCTION(odbc_fetch_into) zend_hash_index_update(Z_ARRVAL_P(pv_res_arr), i, &tmp); } if (buf) efree(buf); - RETURN_LONG(result->numcols); + RETURN_LONG(result->numcols); } /* }}} */ /* {{{ proto bool solid_fetch_prev(resource result_id) - */ + */ #if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) || defined(HAVE_SOLID_35) PHP_FUNCTION(solid_fetch_prev) { @@ -1931,7 +1931,7 @@ PHP_FUNCTION(solid_fetch_prev) if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pv_res) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); if (result->numcols == 0) { php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); @@ -1966,10 +1966,10 @@ PHP_FUNCTION(odbc_fetch_row) SQLUSMALLINT RowStatus[1]; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &pv_res, &pv_row) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "r|l", &pv_res, &pv_row) == FAILURE) { return; } - + rownum = pv_row; ZEND_FETCH_RESOURCE(result, odbc_result *, pv_res, -1, "ODBC result", le_result); @@ -1993,19 +1993,19 @@ PHP_FUNCTION(odbc_fetch_row) if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { RETURN_FALSE; } - + if (ZEND_NUM_ARGS() > 1) { result->fetched = rownum; } else { result->fetched++; } - + RETURN_TRUE; -} +} /* }}} */ /* {{{ proto mixed odbc_result(resource result_id, mixed field) - Get result data */ + Get result data */ PHP_FUNCTION(odbc_result) { char *field; @@ -2041,7 +2041,7 @@ PHP_FUNCTION(odbc_result) php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - + /* get field index if the field parameter was a string */ if (field != NULL) { if (result->values == NULL) { @@ -2080,7 +2080,7 @@ PHP_FUNCTION(odbc_result) if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { RETURN_FALSE; } - + result->fetched++; } @@ -2092,7 +2092,7 @@ PHP_FUNCTION(odbc_result) sql_c_type = SQL_C_BINARY; } if (result->binmode <= 0) { - break; + break; } case SQL_LONGVARCHAR: #if defined(ODBCVER) && (ODBCVER >= 0x0300) @@ -2105,7 +2105,7 @@ PHP_FUNCTION(odbc_result) fieldsize = result->longreadlen; } } else { - SQLColAttributes(result->stmt, (SQLUSMALLINT)(field_ind + 1), + SQLColAttributes(result->stmt, (SQLUSMALLINT)(field_ind + 1), (SQLUSMALLINT)((sql_c_type == SQL_C_BINARY) ? SQL_COLUMN_LENGTH : SQL_COLUMN_DISPLAY_SIZE), NULL, 0, NULL, &fieldsize); @@ -2115,7 +2115,7 @@ PHP_FUNCTION(odbc_result) field = emalloc(fieldsize); /* SQLGetData will truncate CHAR data to fieldsize - 1 bytes and append \0. - * For binary data it is truncated to fieldsize bytes. + * For binary data it is truncated to fieldsize bytes. */ rc = SQLGetData(result->stmt, (SQLUSMALLINT)(field_ind + 1), sql_c_type, field, fieldsize, &result->values[field_ind].vallen); @@ -2133,7 +2133,7 @@ PHP_FUNCTION(odbc_result) efree(field); RETURN_FALSE; } - /* Reduce fieldlen by 1 if we have char data. One day we might + /* Reduce fieldlen by 1 if we have char data. One day we might have binary strings... */ if ((result->values[field_ind].coltype == SQL_LONGVARCHAR) #if defined(ODBCVER) && (ODBCVER >= 0x0300) @@ -2150,7 +2150,7 @@ PHP_FUNCTION(odbc_result) efree(field); return; break; - + default: if (result->values[field_ind].vallen == SQL_NULL_DATA) { RETURN_NULL(); @@ -2161,11 +2161,11 @@ PHP_FUNCTION(odbc_result) } /* If we come here, output unbound LONG and/or BINARY column data to the client */ - + /* We emalloc 1 byte more for SQL_C_CHAR (trailing \0) */ fieldsize = (sql_c_type == SQL_C_CHAR) ? 4096 : 4095; field = emalloc(fieldsize); - + /* Call SQLGetData() until SQL_SUCCESS is returned */ while(1) { rc = SQLGetData(result->stmt, (SQLUSMALLINT)(field_ind + 1),sql_c_type, field, fieldsize, &result->values[field_ind].vallen); @@ -2175,7 +2175,7 @@ PHP_FUNCTION(odbc_result) efree(field); RETURN_FALSE; } - + if (result->values[field_ind].vallen == SQL_NULL_DATA) { efree(field); RETURN_NULL(); @@ -2222,21 +2222,21 @@ PHP_FUNCTION(odbc_result_all) if (result->fetch_abs) rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); else -#endif +#endif rc = SQLFetch(result->stmt); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { php_printf("

No rows found

\n"); RETURN_LONG(0); } - + /* Start table tag */ - if (ZEND_NUM_ARGS() == 1) { + if (pv_format == NULL) { php_printf(""); } else { php_printf("
", pv_format); } - + for (i = 0; i < result->numcols; i++) { php_printf("", result->values[i].name); } @@ -2256,14 +2256,14 @@ PHP_FUNCTION(odbc_result_all) php_printf(""); break; } - if (result->binmode <= 1) sql_c_type = SQL_C_BINARY; + if (result->binmode <= 1) sql_c_type = SQL_C_BINARY; case SQL_LONGVARCHAR: #if defined(ODBCVER) && (ODBCVER >= 0x0300) case SQL_WLONGVARCHAR: #endif if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) { - php_printf(""); + php_printf(""); break; } @@ -2272,7 +2272,7 @@ PHP_FUNCTION(odbc_result_all) } rc = SQLGetData(result->stmt, (SQLUSMALLINT)(i + 1),sql_c_type, buf, result->longreadlen, &result->values[i].vallen); - + php_printf("
%sNot printableNot printableNot printable"); if (rc == SQL_ERROR) { @@ -2307,7 +2307,7 @@ PHP_FUNCTION(odbc_result_all) rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); else #endif - rc = SQLFetch(result->stmt); + rc = SQLFetch(result->stmt); } php_printf("
\n"); if (buf) efree(buf); @@ -2364,13 +2364,13 @@ PHP_FUNCTION(odbc_pconnect) int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int cur_opt, int persistent) { RETCODE rc; - + *conn = (odbc_connection *)pemalloc(sizeof(odbc_connection), persistent); (*conn)->persistent = persistent; SQLAllocEnv(&((*conn)->henv)); SQLAllocConnect((*conn)->henv, &((*conn)->hdbc)); - -#if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) + +#if defined(HAVE_SOLID) || defined(HAVE_SOLID_30) SQLSetConnectOption((*conn)->hdbc, SQL_TRANSLATE_OPTION, SQL_SOLID_XLATOPT_NOCNV); #endif @@ -2433,7 +2433,7 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int /* Possible fix for bug #10250 * Needs testing on UnixODBC < 2.0.5 though. */ #if defined(HAVE_EMPRESS) || defined(HAVE_UNIXODBC) || defined(PHP_WIN32) || defined (HAVE_IODBC) -/* * Uncomment the line above, and comment line below to fully test +/* * Uncomment the line above, and comment line below to fully test * #ifdef HAVE_EMPRESS */ { int direct = 0; @@ -2481,7 +2481,7 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int /* Persistent connections: two list-types le_pconn, le_conn and a plist * where hashed connection info is stored together with index pointer to - * the actual link of type le_pconn in the list. Only persistent + * the actual link of type le_pconn in the list. Only persistent * connections get hashed up. Normal connections use existing pconnections. * Maybe this has to change with regard to transactions on pconnections? * Possibly set autocommit to on on request shutdown. @@ -2508,18 +2508,16 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|l", &db, &db_len, &uid, &uid_len, &pwd, &pwd_len, &pv_opt) == FAILURE) { return; } - - cur_opt = pv_opt; - - if (ZEND_NUM_ARGS() > 3) { - /* Confirm the cur_opt range */ - if (! (cur_opt == SQL_CUR_USE_IF_NEEDED || - cur_opt == SQL_CUR_USE_ODBC || - cur_opt == SQL_CUR_USE_DRIVER || + + cur_opt = (int)pv_opt; + + /* Confirm the cur_opt range */ + if (! (cur_opt == SQL_CUR_USE_IF_NEEDED || + cur_opt == SQL_CUR_USE_ODBC || + cur_opt == SQL_CUR_USE_DRIVER || cur_opt == SQL_CUR_DEFAULT) ) { - php_error_docref(NULL, E_WARNING, "Invalid Cursor type (%d)", cur_opt); - RETURN_FALSE; - } + php_error_docref(NULL, E_WARNING, "Invalid Cursor type (%d)", cur_opt); + RETURN_FALSE; } if (ODBCG(allow_persistent) <= 0) { @@ -2589,8 +2587,8 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) UCHAR d_name[32]; SQLSMALLINT len; - ret = SQLGetInfo(db_conn->hdbc, - SQL_DATA_SOURCE_READ_ONLY, + ret = SQLGetInfo(db_conn->hdbc, + SQL_DATA_SOURCE_READ_ONLY, d_name, sizeof(d_name), &len); if(ret != SQL_SUCCESS || len == 0) { @@ -2792,12 +2790,12 @@ PHP_FUNCTION(odbc_field_name) php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - + if (pv_num > result->numcols) { php_error_docref(NULL, E_WARNING, "Field index larger than number of fields"); RETURN_FALSE; } - + if (pv_num < 1) { php_error_docref(NULL, E_WARNING, "Field numbering starts at 1"); RETURN_FALSE; @@ -2827,7 +2825,7 @@ PHP_FUNCTION(odbc_field_type) php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - + if (pv_num > result->numcols) { php_error_docref(NULL, E_WARNING, "Field index larger than number of fields"); RETURN_FALSE; @@ -2855,7 +2853,7 @@ PHP_FUNCTION(odbc_field_len) Get the scale of a column */ PHP_FUNCTION(odbc_field_scale) { - odbc_column_lengths(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + odbc_column_lengths(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ @@ -3076,7 +3074,7 @@ PHP_FUNCTION(odbc_tables) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3095,9 +3093,9 @@ PHP_FUNCTION(odbc_tables) schema = NULL; } - rc = SQLTables(result->stmt, - cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), + rc = SQLTables(result->stmt, + cat, SAFE_SQL_NTS(cat), + schema, SAFE_SQL_NTS(schema), table, SAFE_SQL_NTS(table), type, SAFE_SQL_NTS(type)); @@ -3143,7 +3141,7 @@ PHP_FUNCTION(odbc_columns) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3157,14 +3155,14 @@ PHP_FUNCTION(odbc_columns) RETURN_FALSE; } - /* + /* * Needed to make MS Access happy */ if (table && table_len && schema && schema_len == 0) { schema = NULL; } - rc = SQLColumns(result->stmt, + rc = SQLColumns(result->stmt, cat, (SQLSMALLINT) cat_len, schema, (SQLSMALLINT) schema_len, table, (SQLSMALLINT) table_len, @@ -3213,7 +3211,7 @@ PHP_FUNCTION(odbc_columnprivileges) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3227,7 +3225,7 @@ PHP_FUNCTION(odbc_columnprivileges) RETURN_FALSE; } - rc = SQLColumnPrivileges(result->stmt, + rc = SQLColumnPrivileges(result->stmt, cat, SAFE_SQL_NTS(cat), schema, SAFE_SQL_NTS(schema), table, SAFE_SQL_NTS(table), @@ -3289,7 +3287,7 @@ PHP_FUNCTION(odbc_foreignkeys) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3303,12 +3301,12 @@ PHP_FUNCTION(odbc_foreignkeys) RETURN_FALSE; } - rc = SQLForeignKeys(result->stmt, - pcat, SAFE_SQL_NTS(pcat), - pschema, SAFE_SQL_NTS(pschema), - ptable, SAFE_SQL_NTS(ptable), - fcat, SAFE_SQL_NTS(fcat), - fschema, SAFE_SQL_NTS(fschema), + rc = SQLForeignKeys(result->stmt, + pcat, SAFE_SQL_NTS(pcat), + pschema, SAFE_SQL_NTS(pschema), + ptable, SAFE_SQL_NTS(ptable), + fcat, SAFE_SQL_NTS(fcat), + fschema, SAFE_SQL_NTS(fschema), ftable, SAFE_SQL_NTS(ftable) ); if (rc == SQL_ERROR) { @@ -3349,13 +3347,13 @@ PHP_FUNCTION(odbc_gettypeinfo) if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &pv_conn, &pv_data_type) == FAILURE) { return; } - + data_type = (SQLSMALLINT) pv_data_type; ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3412,7 +3410,7 @@ PHP_FUNCTION(odbc_primarykeys) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3426,9 +3424,9 @@ PHP_FUNCTION(odbc_primarykeys) RETURN_FALSE; } - rc = SQLPrimaryKeys(result->stmt, - cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), + rc = SQLPrimaryKeys(result->stmt, + cat, SAFE_SQL_NTS(cat), + schema, SAFE_SQL_NTS(schema), table, SAFE_SQL_NTS(table) ); if (rc == SQL_ERROR) { @@ -3465,7 +3463,7 @@ PHP_FUNCTION(odbc_procedurecolumns) char *cat = NULL, *schema = NULL, *proc = NULL, *col = NULL; size_t cat_len = 0, schema_len = 0, proc_len = 0, col_len = 0; RETCODE rc; - + if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 5) { WRONG_PARAM_COUNT; } @@ -3478,7 +3476,7 @@ PHP_FUNCTION(odbc_procedurecolumns) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3492,10 +3490,10 @@ PHP_FUNCTION(odbc_procedurecolumns) RETURN_FALSE; } - rc = SQLProcedureColumns(result->stmt, - cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), - proc, SAFE_SQL_NTS(proc), + rc = SQLProcedureColumns(result->stmt, + cat, SAFE_SQL_NTS(cat), + schema, SAFE_SQL_NTS(schema), + proc, SAFE_SQL_NTS(proc), col, SAFE_SQL_NTS(col) ); if (rc == SQL_ERROR) { @@ -3545,7 +3543,7 @@ PHP_FUNCTION(odbc_procedures) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3559,9 +3557,9 @@ PHP_FUNCTION(odbc_procedures) RETURN_FALSE; } - rc = SQLProcedures(result->stmt, - cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), + rc = SQLProcedures(result->stmt, + cat, SAFE_SQL_NTS(cat), + schema, SAFE_SQL_NTS(schema), proc, SAFE_SQL_NTS(proc) ); if (rc == SQL_ERROR) { @@ -3605,7 +3603,7 @@ PHP_FUNCTION(odbc_specialcolumns) &name, &name_len, &vscope, &vnullable) == FAILURE) { return; } - + type = (SQLUSMALLINT) vtype; scope = (SQLUSMALLINT) vscope; nullable = (SQLUSMALLINT) vnullable; @@ -3613,7 +3611,7 @@ PHP_FUNCTION(odbc_specialcolumns) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3627,10 +3625,10 @@ PHP_FUNCTION(odbc_specialcolumns) RETURN_FALSE; } - rc = SQLSpecialColumns(result->stmt, + rc = SQLSpecialColumns(result->stmt, type, - cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), + cat, SAFE_SQL_NTS(cat), + schema, SAFE_SQL_NTS(schema), name, SAFE_SQL_NTS(name), scope, nullable); @@ -3675,14 +3673,14 @@ PHP_FUNCTION(odbc_statistics) &name, &name_len, &vunique, &vreserved) == FAILURE) { return; } - + unique = (SQLUSMALLINT) vunique; reserved = (SQLUSMALLINT) vreserved; ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3696,9 +3694,9 @@ PHP_FUNCTION(odbc_statistics) RETURN_FALSE; } - rc = SQLStatistics(result->stmt, + rc = SQLStatistics(result->stmt, cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), + schema, SAFE_SQL_NTS(schema), name, SAFE_SQL_NTS(name), unique, reserved); @@ -3745,7 +3743,7 @@ PHP_FUNCTION(odbc_tableprivileges) ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); result = (odbc_result *)ecalloc(1, sizeof(odbc_result)); - + rc = SQLAllocStmt(conn->hdbc, &(result->stmt)); if (rc == SQL_INVALID_HANDLE) { efree(result); @@ -3759,9 +3757,9 @@ PHP_FUNCTION(odbc_tableprivileges) RETURN_FALSE; } - rc = SQLTablePrivileges(result->stmt, - cat, SAFE_SQL_NTS(cat), - schema, SAFE_SQL_NTS(schema), + rc = SQLTablePrivileges(result->stmt, + cat, SAFE_SQL_NTS(cat), + schema, SAFE_SQL_NTS(schema), table, SAFE_SQL_NTS(table)); if (rc == SQL_ERROR) { diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 7d130aecefa45..74b25eacccd9f 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -757,7 +757,7 @@ PHP_FUNCTION(pcntl_exec) return; } - if (ZEND_NUM_ARGS() > 1) { + if (args != NULL) { /* Build argument list */ args_hash = HASH_OF(args); argc = zend_hash_num_elements(args_hash); @@ -779,7 +779,7 @@ PHP_FUNCTION(pcntl_exec) *(argv+1) = NULL; } - if ( ZEND_NUM_ARGS() == 3 ) { + if ( envs != NULL ) { /* Build environment pair list */ envs_hash = HASH_OF(envs); envc = zend_hash_num_elements(envs_hash); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 7ae888cfe1fa9..af2c3979d9d2e 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -1384,7 +1384,7 @@ static PHP_METHOD(PDOStatement, fetchAll) { zend_long how = PDO_FETCH_USE_DEFAULT; zval data, *return_all; - zval *arg2; + zval *arg2 = NULL; zend_class_entry *old_ce; zval old_ctor_args, *ctor_args = NULL; int error = 0, flags, old_arg_count; @@ -1406,27 +1406,23 @@ static PHP_METHOD(PDOStatement, fetchAll) switch(how & ~PDO_FETCH_FLAGS) { case PDO_FETCH_CLASS: - switch(ZEND_NUM_ARGS()) { - case 0: - case 1: - stmt->fetch.cls.ce = zend_standard_class_def; - break; - case 3: - if (Z_TYPE_P(ctor_args) != IS_NULL && Z_TYPE_P(ctor_args) != IS_ARRAY) { - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); - error = 1; - break; - } - if (Z_TYPE_P(ctor_args) != IS_ARRAY || !zend_hash_num_elements(Z_ARRVAL_P(ctor_args))) { - ctor_args = NULL; + if(arg2) { + if(ctor_args) { + if (Z_TYPE_P(ctor_args) != IS_NULL && Z_TYPE_P(ctor_args) != IS_ARRAY) { + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); + error = 1; + break; + } + if (Z_TYPE_P(ctor_args) != IS_ARRAY || !zend_hash_num_elements(Z_ARRVAL_P(ctor_args))) { + ctor_args = NULL; + } } - /* no break */ - case 2: - if (ctor_args) { + if(ctor_args) { ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */ } else { ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); } + if (Z_TYPE_P(arg2) != IS_STRING) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)"); error = 1; @@ -1439,42 +1435,38 @@ static PHP_METHOD(PDOStatement, fetchAll) break; } } + } else { + stmt->fetch.cls.ce = zend_standard_class_def; } + if (!error) { do_fetch_class_prepare(stmt); } break; case PDO_FETCH_FUNC: - switch (ZEND_NUM_ARGS()) { - case 0: - case 1: - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified"); + if(arg2) { + ZVAL_COPY_VALUE(&stmt->fetch.func.function, arg2); + if (do_fetch_func_prepare(stmt) == 0) { error = 1; - break; - case 3: - case 2: - ZVAL_COPY_VALUE(&stmt->fetch.func.function, arg2); - if (do_fetch_func_prepare(stmt) == 0) { - error = 1; - } - break; + } + } else { + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified"); + error = 1; } break; case PDO_FETCH_COLUMN: - switch(ZEND_NUM_ARGS()) { - case 0: - case 1: - stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; + if(ctor_args) { + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN"); + error = 1; break; - case 2: + } + if(arg2) { convert_to_long(arg2); stmt->fetch.column = Z_LVAL_P(arg2); - break; - case 3: - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN"); - error = 1; + } else { + stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; } break; @@ -1839,7 +1831,7 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in { zend_long mode = PDO_FETCH_BOTH; int flags = 0, argc = ZEND_NUM_ARGS() - skip; - zval *args; + zval *args = NULL; zend_class_entry *cep; int retval; @@ -1862,25 +1854,19 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in return SUCCESS; } - args = safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval), 0); - - retval = zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args); - - if (SUCCESS == retval) { - if (Z_TYPE(args[skip]) != IS_LONG) { - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "mode must be an integer"); - retval = FAILURE; - } else { - mode = Z_LVAL(args[skip]); - flags = mode & PDO_FETCH_FLAGS; - - retval = pdo_stmt_verify_mode(stmt, mode, 0); - } + argc = 0; + if(skip) { + zval *dummy; + retval = zend_parse_parameters(ZEND_NUM_ARGS(), "zl*", &dummy, &mode, &args, &argc); + } else { + retval = zend_parse_parameters(ZEND_NUM_ARGS(), "l*", &mode, &args, &argc); } - if (FAILURE == retval) { + if (SUCCESS == retval) { + flags = mode & PDO_FETCH_FLAGS; + retval = pdo_stmt_verify_mode(stmt, mode, 0); + } else { PDO_STMT_CLEAR_ERR(); - efree(args); return FAILURE; } @@ -1895,7 +1881,7 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in case PDO_FETCH_BOUND: case PDO_FETCH_NAMED: case PDO_FETCH_KEY_PAIR: - if (argc != 1) { + if (argc > 0) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode doesn't allow any extra arguments"); } else { retval = SUCCESS; @@ -1903,12 +1889,12 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in break; case PDO_FETCH_COLUMN: - if (argc != 2) { + if (argc != 1) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the colno argument"); - } else if (Z_TYPE(args[skip+1]) != IS_LONG) { + } else if (Z_TYPE(args[0]) != IS_LONG) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "colno must be an integer"); } else { - stmt->fetch.column = Z_LVAL(args[skip+1]); + stmt->fetch.column = Z_LVAL(args[0]); retval = SUCCESS; } break; @@ -1916,21 +1902,21 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in case PDO_FETCH_CLASS: /* Gets its class name from 1st column */ if ((flags & PDO_FETCH_CLASSTYPE) == PDO_FETCH_CLASSTYPE) { - if (argc != 1) { + if (argc > 0) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode doesn't allow any extra arguments"); } else { stmt->fetch.cls.ce = NULL; retval = SUCCESS; } } else { - if (argc < 2) { + if (argc < 1) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the classname argument"); - } else if (argc > 3) { + } else if (argc > 2) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "too many arguments"); - } else if (Z_TYPE(args[skip+1]) != IS_STRING) { + } else if (Z_TYPE(args[0]) != IS_STRING) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "classname must be a string"); } else { - cep = zend_lookup_class(Z_STR(args[skip+1])); + cep = zend_lookup_class(Z_STR(args[0])); if (cep) { retval = SUCCESS; stmt->fetch.cls.ce = cep; @@ -1945,12 +1931,12 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in php_error_docref(NULL, E_WARNING, "PHP might crash if you don't call $stmt->setFetchMode() to reset to defaults on this persistent statement. This will be fixed in a later release"); } #endif - if (argc == 3) { - if (Z_TYPE(args[skip+2]) != IS_NULL && Z_TYPE(args[skip+2]) != IS_ARRAY) { + if (argc == 2) { + if (Z_TYPE(args[1]) != IS_NULL && Z_TYPE(args[1]) != IS_ARRAY) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); retval = FAILURE; - } else if (Z_TYPE(args[skip+2]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL(args[skip+2]))) { - ZVAL_DUP(&stmt->fetch.cls.ctor_args, &args[skip+2]); + } else if (Z_TYPE(args[1]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL(args[1]))) { + ZVAL_DUP(&stmt->fetch.cls.ctor_args, &args[1]); } } @@ -1962,9 +1948,9 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in break; case PDO_FETCH_INTO: - if (argc != 2) { + if (argc != 1) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the object parameter"); - } else if (Z_TYPE(args[skip+1]) != IS_OBJECT) { + } else if (Z_TYPE(args[0]) != IS_OBJECT) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "object must be an object"); } else { retval = SUCCESS; @@ -1976,7 +1962,7 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in php_error_docref(NULL, E_WARNING, "PHP might crash if you don't call $stmt->setFetchMode() to reset to defaults on this persistent statement. This will be fixed in a later release"); } #endif - ZVAL_COPY(&stmt->fetch.into, &args[skip+1]); + ZVAL_COPY(&stmt->fetch.into, &args[0]); } break; @@ -1998,8 +1984,6 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in */ PDO_STMT_CLEAR_ERR(); - efree(args); - return retval; } diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 58dcabd060623..96c1ff97beac9 100644 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -341,7 +341,7 @@ typedef int (*pdo_stmt_describe_col_func)(pdo_stmt_t *stmt, int colno); * If the driver sets caller_frees, ptr should point to emalloc'd memory * and PDO will free it as soon as it is done using it. */ -typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees); +typedef int (*pdo_stmt_get_col_data_func)(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees); /* hook for bound params */ enum pdo_param_event { diff --git a/ext/pdo/tests/bug_44173.phpt b/ext/pdo/tests/bug_44173.phpt index f13abaa5d500a..cac0f20c1c04d 100644 --- a/ext/pdo/tests/bug_44173.phpt +++ b/ext/pdo/tests/bug_44173.phpt @@ -61,7 +61,7 @@ bool(false) Warning: PDO::query(): SQLSTATE[HY000]: General error: fetch mode doesn't allow any extra arguments in %s bool(false) -Warning: PDO::query(): SQLSTATE[HY000]: General error: mode must be an integer in %s +Warning: PDO::query() expects parameter 2 to be integer, string given in %s bool(false) Warning: PDO::query(): SQLSTATE[HY000]: General error: too many arguments in %s diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 225ff65c306a7..adc8a1f1c5fb8 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -93,6 +93,17 @@ #define PQfreemem free #endif +#define PGSQL_GET_LINK(pgsql_link) \ + if ((pgsql_link) == NULL) { \ + id = FETCH_DEFAULT_LINK(); \ + CHECK_DEFAULT_LINK(id); \ + } \ + if ((pgsql_link) == NULL && id == -1) { \ + RETURN_FALSE; \ + } \ + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + + ZEND_DECLARE_MODULE_GLOBALS(pgsql) static PHP_GINIT_FUNCTION(pgsql); @@ -1558,23 +1569,14 @@ PHP_FUNCTION(pg_pconnect) PHP_FUNCTION(pg_close) { zval *pgsql_link = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; PGconn *pgsql; - if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) { return; } - if (argc == 0) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); - } - - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (id==-1) { /* explicit resource number */ zend_list_close(Z_RES_P(pgsql_link)); @@ -1603,25 +1605,16 @@ PHP_FUNCTION(pg_close) static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) { zval *pgsql_link = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; PGconn *pgsql; char *msgbuf; char *result; - if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) { return; } - if (argc == 0) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); - } - - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); switch(entry_type) { case PHP_PG_DBNAME: @@ -1836,19 +1829,13 @@ PHP_FUNCTION(pg_query) if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &query, &query_len) == FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &pgsql_link, &query, &query_len) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (PQ_SETNONBLOCKING(pgsql, 0)) { php_error_docref(NULL, E_NOTICE,"Cannot set connection to blocking mode"); @@ -1939,19 +1926,13 @@ PHP_FUNCTION(pg_query_params) if (zend_parse_parameters(argc, "sa", &query, &query_len, &pv_param_arr) == FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc, "rsa", &pgsql_link, &query, &query_len, &pv_param_arr) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (PQ_SETNONBLOCKING(pgsql, 0)) { php_error_docref(NULL, E_NOTICE,"Cannot set connection to blocking mode"); @@ -2055,19 +2036,13 @@ PHP_FUNCTION(pg_prepare) if (zend_parse_parameters(argc, "ss", &stmtname, &stmtname_len, &query, &query_len) == FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc, "rss", &pgsql_link, &stmtname, &stmtname_len, &query, &query_len) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (PQ_SETNONBLOCKING(pgsql, 0)) { php_error_docref(NULL, E_NOTICE,"Cannot set connection to blocking mode"); @@ -2142,19 +2117,13 @@ PHP_FUNCTION(pg_execute) if (zend_parse_parameters(argc, "sa/", &stmtname, &stmtname_len, &pv_param_arr)==FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc, "rsa/", &pgsql_link, &stmtname, &stmtname_len, &pv_param_arr) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (PQ_SETNONBLOCKING(pgsql, 0)) { php_error_docref(NULL, E_NOTICE,"Cannot set connection to blocking mode"); @@ -2710,7 +2679,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_ RETURN_FALSE; } } - use_row = ZEND_NUM_ARGS() > 1 && row != -1; + use_row = zrow != NULL && row != -1; if (!(result_type & PGSQL_BOTH)) { php_error_docref(NULL, E_WARNING, "Invalid result type"); @@ -3102,25 +3071,17 @@ PHP_FUNCTION(pg_trace) char *z_filename, *mode = "w"; size_t z_filename_len, mode_len; zval *pgsql_link = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; PGconn *pgsql; FILE *fp = NULL; php_stream *stream; id = FETCH_DEFAULT_LINK(); - if (zend_parse_parameters(argc, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) { return; } - if (argc < 3) { - CHECK_DEFAULT_LINK(id); - } - - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); stream = php_stream_open_wrapper(z_filename, mode, REPORT_ERRORS, NULL); @@ -3143,23 +3104,15 @@ PHP_FUNCTION(pg_trace) PHP_FUNCTION(pg_untrace) { zval *pgsql_link = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; PGconn *pgsql; - if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) { return; } - if (argc == 0) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); - } - - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } + PGSQL_GET_LINK(pgsql_link); - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); PQuntrace(pgsql); RETURN_TRUE; } @@ -3169,29 +3122,21 @@ PHP_FUNCTION(pg_untrace) Create a large object */ PHP_FUNCTION(pg_lo_create) { - zval *pgsql_link = NULL, *oid = NULL; - PGconn *pgsql; - Oid pgsql_oid, wanted_oid = InvalidOid; - int id = -1, argc = ZEND_NUM_ARGS(); + zval *pgsql_link = NULL, *oid = NULL; + PGconn *pgsql; + Oid pgsql_oid, wanted_oid = InvalidOid; + int id = -1; - if (zend_parse_parameters(argc, "|zz", &pgsql_link, &oid) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zz", &pgsql_link, &oid) == FAILURE) { return; } - if ((argc == 1) && (Z_TYPE_P(pgsql_link) != IS_RESOURCE)) { + if ((oid == NULL) && (Z_TYPE_P(pgsql_link) != IS_RESOURCE)) { oid = pgsql_link; pgsql_link = NULL; } - if (pgsql_link == NULL) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); - if (id == -1) { - RETURN_FALSE; - } - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (oid) { #ifndef HAVE_PG_LO_CREATE @@ -3277,8 +3222,6 @@ PHP_FUNCTION(pg_lo_unlink) php_error_docref(NULL, E_NOTICE, "Wrong OID value passed"); RETURN_FALSE; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "l", &oid_long) == SUCCESS) { @@ -3287,18 +3230,13 @@ PHP_FUNCTION(pg_lo_unlink) RETURN_FALSE; } oid = (Oid)oid_long; - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { php_error_docref(NULL, E_WARNING, "Requires 1 or 2 arguments"); RETURN_FALSE; } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (lo_unlink(pgsql, oid) == -1) { php_error_docref(NULL, E_WARNING, "Unable to delete PostgreSQL large object %u", oid); @@ -3349,8 +3287,6 @@ PHP_FUNCTION(pg_lo_open) php_error_docref(NULL, E_NOTICE, "Wrong OID value passed"); RETURN_FALSE; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "ls", &oid_long, &mode_string, &mode_strlen) == SUCCESS) { @@ -3359,18 +3295,13 @@ PHP_FUNCTION(pg_lo_open) RETURN_FALSE; } oid = (Oid)oid_long; - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { php_error_docref(NULL, E_WARNING, "Requires 1 or 2 arguments"); RETURN_FALSE; } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); /* r/w/+ is little bit more PHP-like than INV_READ/INV_WRITE and a lot of faster to type. Unfortunately, doesn't behave the same way as fopen()... @@ -3460,21 +3391,19 @@ PHP_FUNCTION(pg_lo_close) PHP_FUNCTION(pg_lo_read) { zval *pgsql_id; - zend_long len; + zend_long len = PGSQL_LO_READ_BUF_SIZE; size_t buf_len = PGSQL_LO_READ_BUF_SIZE; - int nbytes, argc = ZEND_NUM_ARGS(); + int nbytes; zend_string *buf; pgLofp *pgsql; - if (zend_parse_parameters(argc, "r|l", &pgsql_id, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &pgsql_id, &len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(pgsql, pgLofp *, pgsql_id, -1, "PostgreSQL large object", le_lofp); - if (argc > 1) { - buf_len = len < 0 ? 0 : len; - } + buf_len = len; buf = zend_string_alloc(buf_len, 0); if ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf->val, buf->len))<0) { @@ -3500,7 +3429,7 @@ PHP_FUNCTION(pg_lo_write) pgLofp *pgsql; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rs|l", &pgsql_id, &str, &str_len, &z_len) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, argc TSRMLS_CC, "rs|l", &pgsql_id, &str, &str_len, &z_len) == FAILURE) { return; } @@ -3572,8 +3501,6 @@ PHP_FUNCTION(pg_lo_import) } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "p|z", &file_in, &name_len, &oid) == SUCCESS) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } /* old calling convention, deprecated since PHP 4.2 */ else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, @@ -3588,11 +3515,7 @@ PHP_FUNCTION(pg_lo_import) RETURN_FALSE; } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (oid) { #ifndef HAVE_PG_LO_IMPORT_WITH_OID @@ -3681,8 +3604,6 @@ PHP_FUNCTION(pg_lo_export) RETURN_FALSE; } oid = (Oid)oid_long; - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "sp", &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) { @@ -3692,8 +3613,6 @@ PHP_FUNCTION(pg_lo_export) php_error_docref(NULL, E_NOTICE, "Wrong OID value passed"); RETURN_FALSE; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "spr", &oid_string, &oid_strlen, &file_out, &name_len, &pgsql_link) == SUCCESS) { @@ -3718,16 +3637,12 @@ PHP_FUNCTION(pg_lo_export) RETURN_FALSE; } - if (php_check_open_basedir(file_out)) { - RETURN_FALSE; - } + PGSQL_GET_LINK(pgsql_link); - if (pgsql_link == NULL && id == -1) { + if (php_check_open_basedir(file_out)) { RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (lo_export(pgsql, oid, file_out) == -1) { RETURN_FALSE; } @@ -3742,9 +3657,8 @@ PHP_FUNCTION(pg_lo_seek) zval *pgsql_id = NULL; zend_long result, offset = 0, whence = SEEK_CUR; pgLofp *pgsql; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rl|l", &pgsql_id, &offset, &whence) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &pgsql_id, &offset, &whence) == FAILURE) { return; } if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { @@ -3778,9 +3692,8 @@ PHP_FUNCTION(pg_lo_tell) zval *pgsql_id = NULL; zend_long offset = 0; pgLofp *pgsql; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "r", &pgsql_id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pgsql_id) == FAILURE) { return; } @@ -3848,19 +3761,13 @@ PHP_FUNCTION(pg_set_error_verbosity) if (zend_parse_parameters(argc, "l", &verbosity) == FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc, "rl", &pgsql_link, &verbosity) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (verbosity & (PQERRORS_TERSE|PQERRORS_DEFAULT|PQERRORS_VERBOSE)) { RETURN_LONG(PQsetErrorVerbosity(pgsql, verbosity)); @@ -3886,19 +3793,13 @@ PHP_FUNCTION(pg_set_client_encoding) if (zend_parse_parameters(argc, "s", &encoding, &encoding_len) == FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc, "rs", &pgsql_link, &encoding, &encoding_len) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); RETURN_LONG(PQsetClientEncoding(pgsql, encoding)); } @@ -3909,23 +3810,14 @@ PHP_FUNCTION(pg_set_client_encoding) PHP_FUNCTION(pg_client_encoding) { zval *pgsql_link = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; PGconn *pgsql; - if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) { return; } - if (argc == 0) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); - } - - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); /* Just do the same as found in PostgreSQL sources... */ @@ -3943,24 +3835,15 @@ PHP_FUNCTION(pg_client_encoding) PHP_FUNCTION(pg_end_copy) { zval *pgsql_link = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; PGconn *pgsql; int result = 0; - if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) { return; } - if (argc == 0) { - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); - } - - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); result = PQendcopy(pgsql); @@ -3987,19 +3870,13 @@ PHP_FUNCTION(pg_put_line) if (zend_parse_parameters(argc, "s", &query, &query_len) == FAILURE) { return; } - id = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc, "rs", &pgsql_link, &query, &query_len) == FAILURE) { return; } } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); result = PQputline(pgsql, query); if (result==EOF) { @@ -4028,9 +3905,8 @@ PHP_FUNCTION(pg_copy_to) #endif char *csv = (char *)NULL; int ret; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rs|ss", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|ss", &pgsql_link, &table_name, &table_name_len, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) { return; @@ -4039,7 +3915,7 @@ PHP_FUNCTION(pg_copy_to) pg_delim = "\t"; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (!pg_null_as) { pg_null_as = estrdup("\\\\N"); @@ -4160,9 +4036,8 @@ PHP_FUNCTION(pg_copy_from) PGconn *pgsql; PGresult *pgsql_result; ExecStatusType status; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rsa|ss", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|ss", &pgsql_link, &table_name, &table_name_len, &pg_rows, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) { return; @@ -4175,7 +4050,7 @@ PHP_FUNCTION(pg_copy_from) pg_null_as_free = 1; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); spprintf(&query, 0, "COPY %s FROM STDIN DELIMITERS E'%c' WITH NULL AS E'%s'", table_name, *pg_delim, pg_null_as); while ((pgsql_result = PQgetResult(pgsql))) { @@ -4502,8 +4377,6 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &from, &from_len) == FAILURE) { return; } - pgsql_link = NULL; - id = FETCH_DEFAULT_LINK(); break; default: @@ -4513,12 +4386,8 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l break; } - if (pgsql_link == NULL && id == -1) { - php_error_docref(NULL, E_WARNING,"Cannot get default pgsql link"); - RETURN_FALSE; - } + PGSQL_GET_LINK(pgsql_link); - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); if (pgsql == NULL) { php_error_docref(NULL, E_WARNING,"Cannot get pgsql link"); RETURN_FALSE; @@ -4639,7 +4508,7 @@ PHP_FUNCTION(pg_connection_status) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); RETURN_LONG(PQstatus(pgsql)); } @@ -4660,7 +4529,7 @@ PHP_FUNCTION(pg_transaction_status) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); RETURN_LONG(PQtransactionStatus(pgsql)); } @@ -4672,7 +4541,7 @@ PHP_FUNCTION(pg_transaction_status) Reset connection (reconnect) */ PHP_FUNCTION(pg_connection_reset) { - zval *pgsql_link; + zval *pgsql_link = NULL; int id = -1; PGconn *pgsql; @@ -4681,7 +4550,7 @@ PHP_FUNCTION(pg_connection_reset) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); PQreset(pgsql); if (PQstatus(pgsql) == CONNECTION_BAD) { @@ -4718,7 +4587,7 @@ static int php_pgsql_flush_query(PGconn *pgsql) */ static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) { - zval *pgsql_link; + zval *pgsql_link = NULL; int id = -1; PGconn *pgsql; PGresult *pgsql_result; @@ -4728,7 +4597,7 @@ static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (PQ_SETNONBLOCKING(pgsql, 1)) { php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode"); @@ -4787,7 +4656,7 @@ static int _php_pgsql_link_has_results(PGconn *pgsql) /* {{{ */ Send asynchronous query */ PHP_FUNCTION(pg_send_query) { - zval *pgsql_link; + zval *pgsql_link = NULL; char *query; size_t len; int id = -1; @@ -4799,7 +4668,7 @@ PHP_FUNCTION(pg_send_query) return; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); is_non_blocking = PQisnonblocking(pgsql); @@ -4857,7 +4726,7 @@ PHP_FUNCTION(pg_send_query) Send asynchronous parameterized query */ PHP_FUNCTION(pg_send_query_params) { - zval *pgsql_link, *pv_param_arr, *tmp; + zval *pgsql_link = NULL, *pv_param_arr, **tmp; int num_params = 0; char **params = NULL; char *query; @@ -4871,11 +4740,7 @@ PHP_FUNCTION(pg_send_query_params) return; } - if (pgsql_link == NULL) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); is_non_blocking = PQisnonblocking(pgsql); @@ -4964,7 +4829,7 @@ PHP_FUNCTION(pg_send_query_params) Asynchronously prepare a query for future execution */ PHP_FUNCTION(pg_send_prepare) { - zval *pgsql_link; + zval *pgsql_link = NULL; char *query, *stmtname; size_t stmtname_len, query_len; int id = -1; @@ -4976,11 +4841,7 @@ PHP_FUNCTION(pg_send_prepare) return; } - if (pgsql_link == NULL) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); is_non_blocking = PQisnonblocking(pgsql); @@ -5039,8 +4900,8 @@ PHP_FUNCTION(pg_send_prepare) Executes prevriously prepared stmtname asynchronously */ PHP_FUNCTION(pg_send_execute) { - zval *pgsql_link; - zval *pv_param_arr, *tmp; + zval *pgsql_link = NULL; + zval *pv_param_arr, **tmp; int num_params = 0; char **params = NULL; char *stmtname; @@ -5054,11 +4915,7 @@ PHP_FUNCTION(pg_send_execute) return; } - if (pgsql_link == NULL) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); is_non_blocking = PQisnonblocking(pgsql); @@ -5145,7 +5002,7 @@ PHP_FUNCTION(pg_send_execute) Get asynchronous query result */ PHP_FUNCTION(pg_get_result) { - zval *pgsql_link; + zval *pgsql_link = NULL; int id = -1; PGconn *pgsql; PGresult *pgsql_result; @@ -5155,7 +5012,7 @@ PHP_FUNCTION(pg_get_result) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); pgsql_result = PQgetResult(pgsql); if (!pgsql_result) { @@ -5206,7 +5063,7 @@ PHP_FUNCTION(pg_result_status) Get asynchronous notification */ PHP_FUNCTION(pg_get_notify) { - zval *pgsql_link; + zval *pgsql_link = NULL; int id = -1; zend_long result_type = PGSQL_ASSOC; PGconn *pgsql; @@ -5217,7 +5074,7 @@ PHP_FUNCTION(pg_get_notify) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); if (!(result_type & PGSQL_BOTH)) { php_error_docref(NULL, E_WARNING, "Invalid result type"); @@ -5265,7 +5122,7 @@ PHP_FUNCTION(pg_get_notify) Get backend(server) pid */ PHP_FUNCTION(pg_get_pid) { - zval *pgsql_link; + zval *pgsql_link = NULL; int id = -1; PGconn *pgsql; @@ -5274,7 +5131,7 @@ PHP_FUNCTION(pg_get_pid) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); RETURN_LONG(PQbackendPID(pgsql)); } @@ -5535,7 +5392,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z Get meta_data */ PHP_FUNCTION(pg_meta_data) { - zval *pgsql_link; + zval *pgsql_link = NULL; char *table_name; size_t table_name_len; zend_bool extended=0; @@ -5547,7 +5404,7 @@ PHP_FUNCTION(pg_meta_data) return; } - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); array_init(return_value); if (php_pgsql_meta_data(pgsql, table_name, return_value, extended) == FAILURE) { @@ -6594,18 +6451,18 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var Insert values (filed=>value) to table */ PHP_FUNCTION(pg_insert) { - zval *pgsql_link, *values; + zval *pgsql_link = NULL, *values; char *table; size_t table_len; zend_ulong option = PGSQL_DML_EXEC, return_sql; - PGconn *pg_link; + PGconn *pgsql; PGresult *pg_result; ExecStatusType status; pgsql_result_handle *pgsql_handle; zend_string *sql = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; - if (zend_parse_parameters(argc, "rsa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l", &pgsql_link, &table, &table_len, &values, &option) == FAILURE) { return; } @@ -6614,30 +6471,30 @@ PHP_FUNCTION(pg_insert) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); - if (php_pgsql_flush_query(pg_link)) { + if (php_pgsql_flush_query(pgsql)) { php_error_docref(NULL, E_NOTICE, "Detected unhandled result(s) in connection"); } return_sql = option & PGSQL_DML_STRING; if (option & PGSQL_DML_EXEC) { /* return resource when executed */ option = option & ~PGSQL_DML_EXEC; - if (php_pgsql_insert(pg_link, table, values, option|PGSQL_DML_STRING, &sql) == FAILURE) { + if (php_pgsql_insert(pgsql, table, values, option|PGSQL_DML_STRING, &sql) == FAILURE) { RETURN_FALSE; } - pg_result = PQexec(pg_link, sql->val); - if ((PGG(auto_reset_persistent) & 2) && PQstatus(pg_link) != CONNECTION_OK) { + pg_result = PQexec(pgsql, sql->val); + if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) { PQclear(pg_result); - PQreset(pg_link); - pg_result = PQexec(pg_link, sql->val); + PQreset(pgsql); + pg_result = PQexec(pgsql, sql->val); } efree(sql); if (pg_result) { status = PQresultStatus(pg_result); } else { - status = (ExecStatusType) PQstatus(pg_link); + status = (ExecStatusType) PQstatus(pgsql); } switch (status) { @@ -6645,7 +6502,7 @@ PHP_FUNCTION(pg_insert) case PGRES_BAD_RESPONSE: case PGRES_NONFATAL_ERROR: case PGRES_FATAL_ERROR: - PHP_PQ_ERROR("Query failed: %s", pg_link); + PHP_PQ_ERROR("Query failed: %s", pgsql); PQclear(pg_result); RETURN_FALSE; break; @@ -6653,7 +6510,7 @@ PHP_FUNCTION(pg_insert) default: if (pg_result) { pgsql_handle = (pgsql_result_handle *) emalloc(sizeof(pgsql_result_handle)); - pgsql_handle->conn = pg_link; + pgsql_handle->conn = pgsql; pgsql_handle->result = pg_result; pgsql_handle->row = 0; ZEND_REGISTER_RESOURCE(return_value, pgsql_handle, le_result); @@ -6664,7 +6521,7 @@ PHP_FUNCTION(pg_insert) } break; } - } else if (php_pgsql_insert(pg_link, table, values, option, &sql) == FAILURE) { + } else if (php_pgsql_insert(pgsql, table, values, option, &sql) == FAILURE) { RETURN_FALSE; } if (return_sql) { @@ -6814,11 +6671,11 @@ PHP_FUNCTION(pg_update) char *table; size_t table_len; zend_ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; + PGconn * pgsql; zend_string *sql = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); + int id = -1; - if (zend_parse_parameters(argc, "rsaa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsaa|l", &pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) { return; } @@ -6827,12 +6684,12 @@ PHP_FUNCTION(pg_update) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); - if (php_pgsql_flush_query(pg_link)) { + if (php_pgsql_flush_query(pgsql)) { php_error_docref(NULL, E_NOTICE, "Detected unhandled result(s) in connection"); } - if (php_pgsql_update(pg_link, table, values, ids, option, &sql) == FAILURE) { + if (php_pgsql_update(pgsql, table, values, ids, option, &sql) == FAILURE) { RETURN_FALSE; } if (option & PGSQL_DML_STRING) { @@ -6904,11 +6761,11 @@ PHP_FUNCTION(pg_delete) char *table; size_t table_len; zend_ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; - zend_string *sql; - int id = -1, argc = ZEND_NUM_ARGS(); + PGconn * pgsql; + zend_string *sql = NULL; + int id = -1; - if (zend_parse_parameters(argc, "rsa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l", &pgsql_link, &table, &table_len, &ids, &option) == FAILURE) { return; } @@ -6916,13 +6773,12 @@ PHP_FUNCTION(pg_delete) php_error_docref(NULL, E_WARNING, "Invalid option is specified"); RETURN_FALSE; } + PGSQL_GET_LINK(pgsql_link); - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); - - if (php_pgsql_flush_query(pg_link)) { + if (php_pgsql_flush_query(pgsql)) { php_error_docref(NULL, E_NOTICE, "Detected unhandled result(s) in connection"); } - if (php_pgsql_delete(pg_link, table, ids, option, &sql) == FAILURE) { + if (php_pgsql_delete(pgsql, table, ids, option, &sql) == FAILURE) { RETURN_FALSE; } if (option & PGSQL_DML_STRING) { @@ -7034,11 +6890,10 @@ PHP_FUNCTION(pg_select) char *table; size_t table_len; zend_ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; + PGconn *pgsql; zend_string *sql = NULL; - int id = -1, argc = ZEND_NUM_ARGS(); - - if (zend_parse_parameters(argc, "rsa|l", + int id = -1; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l", &pgsql_link, &table, &table_len, &ids, &option) == FAILURE) { return; } @@ -7047,13 +6902,13 @@ PHP_FUNCTION(pg_select) RETURN_FALSE; } - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PGSQL_GET_LINK(pgsql_link); - if (php_pgsql_flush_query(pg_link)) { + if (php_pgsql_flush_query(pgsql)) { php_error_docref(NULL, E_NOTICE, "Detected unhandled result(s) in connection"); } array_init(return_value); - if (php_pgsql_select(pg_link, table, ids, return_value, option, &sql) == FAILURE) { + if (php_pgsql_select(pgsql, table, ids, return_value, option, &sql) == FAILURE) { zval_ptr_dtor(return_value); RETURN_FALSE; } diff --git a/ext/pspell/pspell.c b/ext/pspell/pspell.c index 0e9b5c437126c..05047d4b4f7fd 100644 --- a/ext/pspell/pspell.c +++ b/ext/pspell/pspell.c @@ -266,7 +266,6 @@ static PHP_FUNCTION(pspell_new) char *language, *spelling = NULL, *jargon = NULL, *encoding = NULL; size_t language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; zend_long mode = Z_L(0), speed = Z_L(0); - int argc = ZEND_NUM_ARGS(); zval *ind; #ifdef PHP_WIN32 @@ -281,7 +280,7 @@ static PHP_FUNCTION(pspell_new) PspellManager *manager; PspellConfig *config; - if (zend_parse_parameters(argc, "s|sssl", &language, &language_len, &spelling, &spelling_len, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|sssl", &language, &language_len, &spelling, &spelling_len, &jargon, &jargon_len, &encoding, &encoding_len, &mode) == FAILURE) { return; } @@ -323,7 +322,7 @@ static PHP_FUNCTION(pspell_new) pspell_config_replace(config, "encoding", encoding); } - if (argc > 4) { + if (mode) { speed = mode & PSPELL_SPEED_MASK_INTERNAL; /* First check what mode we want (how many suggestions) */ @@ -363,7 +362,6 @@ static PHP_FUNCTION(pspell_new_personal) char *personal, *language, *spelling = NULL, *jargon = NULL, *encoding = NULL; size_t personal_len, language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; zend_long mode = Z_L(0), speed = Z_L(0); - int argc = ZEND_NUM_ARGS(); zval *ind; #ifdef PHP_WIN32 @@ -378,7 +376,7 @@ static PHP_FUNCTION(pspell_new_personal) PspellManager *manager; PspellConfig *config; - if (zend_parse_parameters(argc, "ps|sssl", &personal, &personal_len, &language, &language_len, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps|sssl", &personal, &personal_len, &language, &language_len, &spelling, &spelling_len, &jargon, &jargon_len, &encoding, &encoding_len, &mode) == FAILURE) { return; } @@ -428,7 +426,7 @@ static PHP_FUNCTION(pspell_new_personal) pspell_config_replace(config, "encoding", encoding); } - if (argc > 5) { + if (mode) { speed = mode & PSPELL_SPEED_MASK_INTERNAL; /* First check what mode we want (how many suggestions) */ diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c95ec0d81e063..98527e15c2109 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3801,17 +3801,13 @@ ZEND_METHOD(reflection_class, getMethods) { reflection_object *intern; zend_class_entry *ce; - zend_long filter = 0; + /* If no parameters given, default to "return all" */ + zend_long filter = ZEND_ACC_PPP_MASK | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL | ZEND_ACC_STATIC; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); - if (argc) { - if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) { - return; - } - } else { - /* No parameters given, default to "return all" */ - filter = ZEND_ACC_PPP_MASK | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL | ZEND_ACC_STATIC; + if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { + return; } GET_REFLECTION_OBJECT_PTR(ce); @@ -3995,17 +3991,13 @@ ZEND_METHOD(reflection_class, getProperties) { reflection_object *intern; zend_class_entry *ce; - zend_long filter = 0; + /* If no parameters given, default to "return all" */ + zend_long filter = ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); - if (argc) { - if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) { - return; - } - } else { - /* No parameters given, default to "return all" */ - filter = ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC; + if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) { + return; } GET_REFLECTION_OBJECT_PTR(ce); @@ -4318,7 +4310,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) reflection_object *intern; zend_class_entry *ce, *old_scope; int ret, i, argc = 0; - HashTable *args; + HashTable *args = NULL; zend_function *constructor; @@ -4328,8 +4320,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (zend_parse_parameters(ZEND_NUM_ARGS(), "|h", &args) == FAILURE) { return; } - - if (ZEND_NUM_ARGS() > 0) { + if (args != NULL) { argc = args->nNumOfElements; } diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 96182816fc29a..d2c4a27aa8781 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1341,18 +1341,14 @@ SXE_METHOD(asXML) xmlOutputBufferPtr outbuf; xmlChar *strval; int strval_len; - char *filename; - size_t filename_len; + char *filename = NULL; + size_t filename_len; - if (ZEND_NUM_ARGS() > 1) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|p", &filename, &filename_len) == FAILURE) { RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - RETURN_FALSE; - } - + if(filename) { sxe = Z_SXEOBJ_P(getThis()); GET_NODE(sxe, node); node = php_sxe_get_first_node(sxe, node); diff --git a/ext/skeleton/create_stubs b/ext/skeleton/create_stubs index 1163908110362..14a037145b6e6 100755 --- a/ext/skeleton/create_stubs +++ b/ext/skeleton/create_stubs @@ -6,7 +6,7 @@ function gobble(s, x) match(line, "^" "(" s ")") x = substr(line, 1, RLENGTH) line = substr(line, RLENGTH+1) - return x + return x } function convert(i, j, t) @@ -64,7 +64,7 @@ BEGIN { } else { xmldoc = extname "/" extname ".xml" } - + xmlhead = "\n" \ "\n" \ @@ -195,7 +195,7 @@ END { if (maxargs[i]>0) { fetchargs = "\tif (zend_parse_parameters(" ints = ints "\tint argc = ZEND_NUM_ARGS();\n" - fetchargs = fetchargs "argc TSRMLS_CC, " specs[i] + fetchargs = fetchargs "ZEND_NUM_ARGS() TSRMLS_CC, " specs[i] } else { fetchargs = fetchargs "\tif (zend_parse_parameters_none() == FAILURE) {\n\t\treturn;\n\t}" xmlparams = xmlparams " \n" diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index ab8a25b9af1cf..3fcacbcee26b5 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1816,13 +1816,12 @@ PHP_METHOD(snmp, __construct) zend_long timeout = SNMP_DEFAULT_TIMEOUT; zend_long retries = SNMP_DEFAULT_RETRIES; zend_long version = SNMP_DEFAULT_VERSION; - int argc = ZEND_NUM_ARGS(); zend_error_handling error_handling; snmp_object = Z_SNMP_P(object); zend_replace_error_handling(EH_THROW, NULL, &error_handling); - if (zend_parse_parameters(argc, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) { zend_restore_error_handling(&error_handling); return; } @@ -1916,11 +1915,10 @@ PHP_METHOD(snmp, setSecurity) zval *object = getThis(); char *a1 = "", *a2 = "", *a3 = "", *a4 = "", *a5 = "", *a6 = "", *a7 = ""; size_t a1_len = 0, a2_len = 0, a3_len = 0, a4_len = 0, a5_len = 0, a6_len = 0, a7_len = 0; - int argc = ZEND_NUM_ARGS(); snmp_object = Z_SNMP_P(object); - if (zend_parse_parameters(argc, "s|ssssss", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ssssss", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len, &a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len) == FAILURE) { RETURN_FALSE; } diff --git a/ext/soap/soap.c b/ext/soap/soap.c index a993b2ef8c59f..b5a7bd9d9f2b3 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1564,7 +1564,7 @@ PHP_METHOD(SoapServer, handle) php_error_docref(NULL, E_ERROR,"ob_start failed"); } - if (ZEND_NUM_ARGS() == 0) { + if (!arg) { if (SG(request_info).request_body && 0 == php_stream_rewind(SG(request_info).request_body)) { zval *server_vars, *encoding; php_stream_filter *zf = NULL; diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index a1176ab85f746..62c542066ee7c 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1086,7 +1086,7 @@ PHP_FUNCTION(socket_write) php_socket *php_sock; int retval; size_t str_len; - zend_long length = 0; + zend_long length = ZEND_LONG_MAX; char *str; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &arg1, &str, &str_len, &length) == FAILURE) { @@ -1095,14 +1095,14 @@ PHP_FUNCTION(socket_write) ZEND_FETCH_RESOURCE(php_sock, php_socket *, arg1, -1, le_socket_name, le_socket); - if (ZEND_NUM_ARGS() < 3) { + if (length > str_len) { length = str_len; } #ifndef PHP_WIN32 - retval = write(php_sock->bsd_socket, str, MIN(length, str_len)); + retval = write(php_sock->bsd_socket, str, length); #else - retval = send(php_sock->bsd_socket, str, min(length, str_len), 0); + retval = send(php_sock->bsd_socket, str, length, 0); #endif if (retval < 0) { @@ -1384,10 +1384,10 @@ PHP_FUNCTION(socket_connect) char *addr; int retval; size_t addr_len; - zend_long port = 0; + zend_long port = 0; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, argc, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { return; } @@ -1775,7 +1775,7 @@ PHP_FUNCTION(socket_sendto) char *buf, *addr; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, argc, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) { return; } diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 38a4aaede225b..00fe18b81d3d9 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1238,7 +1238,7 @@ SPL_METHOD(Array, __construct) return; } - if (ZEND_NUM_ARGS() > 2) { + if (ce_get_iterator != NULL && ce_get_iterator != spl_ce_Iterator) { intern->ce_get_iterator = ce_get_iterator; } diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index faebd7a0f467b..0acdf4653a3ea 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -2582,41 +2582,39 @@ SPL_METHOD(SplFileObject, fgetcsv) char *delim = NULL, *enclo = NULL, *esc = NULL; size_t d_len = 0, e_len = 0, esc_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) { + return; + } - if(!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + if(!intern->u.file.stream) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + return; + } + + if(esc) { + if (esc_len != 1) { + php_error_docref(NULL, E_WARNING, "escape must be a character"); + RETURN_FALSE; } + escape = esc[0]; + } - switch(ZEND_NUM_ARGS()) - { - case 3: - if (esc_len != 1) { - php_error_docref(NULL, E_WARNING, "escape must be a character"); - RETURN_FALSE; - } - escape = esc[0]; - /* no break */ - case 2: - if (e_len != 1) { - php_error_docref(NULL, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 1: - if (d_len != 1) { - php_error_docref(NULL, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 0: - break; + if(enclo) { + if (e_len != 1) { + php_error_docref(NULL, E_WARNING, "enclosure must be a character"); + RETURN_FALSE; + } + enclosure = enclo[0]; + } + + if(delim) { + if (d_len != 1) { + php_error_docref(NULL, E_WARNING, "delimiter must be a character"); + RETURN_FALSE; } - spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value); + delimiter = delim[0]; } + spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value TSRMLS_CC); } /* }}} */ @@ -2631,37 +2629,27 @@ SPL_METHOD(SplFileObject, fputcsv) zend_long ret; zval *fields = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|sss", &fields, &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) { - switch(ZEND_NUM_ARGS()) - { - case 4: - if (esc_len != 1) { - php_error_docref(NULL, E_WARNING, "escape must be a character"); - RETURN_FALSE; - } - escape = esc[0]; - /* no break */ - case 3: - if (e_len != 1) { - php_error_docref(NULL, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 2: - if (d_len != 1) { - php_error_docref(NULL, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 1: - case 0: - break; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|sss", &fields, &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) { + return; + } + + if(enclo) { + if (e_len != 1) { + php_error_docref(NULL, E_WARNING, "enclosure must be a character"); + RETURN_FALSE; } - ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape); - RETURN_LONG(ret); + enclosure = enclo[0]; + } + + if(delim) { + if (d_len != 1) { + php_error_docref(NULL, E_WARNING, "delimiter must be a character"); + RETURN_FALSE; + } + delimiter = delim[0]; } + ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape); + RETURN_LONG(ret); } /* }}} */ @@ -2674,37 +2662,36 @@ SPL_METHOD(SplFileObject, setCsvControl) char *delim = NULL, *enclo = NULL, *esc = NULL; size_t d_len = 0, e_len = 0, esc_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) { - switch(ZEND_NUM_ARGS()) - { - case 3: - if (esc_len != 1) { - php_error_docref(NULL, E_WARNING, "escape must be a character"); - RETURN_FALSE; - } - escape = esc[0]; - /* no break */ - case 2: - if (e_len != 1) { - php_error_docref(NULL, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 1: - if (d_len != 1) { - php_error_docref(NULL, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 0: - break; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) { + return; + } + if(esc) { + if (esc_len != 1) { + php_error_docref(NULL, E_WARNING, "escape must be a character"); + RETURN_FALSE; + } + escape = esc[0]; + } + + if(enclo) { + if (e_len != 1) { + php_error_docref(NULL, E_WARNING, "enclosure must be a character"); + RETURN_FALSE; } - intern->u.file.delimiter = delimiter; - intern->u.file.enclosure = enclosure; - intern->u.file.escape = escape; + enclosure = enclo[0]; } + + if(delim) { + if (d_len != 1) { + php_error_docref(NULL, E_WARNING, "delimiter must be a character"); + RETURN_FALSE; + } + delimiter = delim[0]; + } + + intern->u.file.delimiter = delimiter; + intern->u.file.enclosure = enclosure; + intern->u.file.escape = escape; } /* }}} */ @@ -2880,7 +2867,7 @@ SPL_METHOD(SplFileObject, fwrite) spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis()); char *str; size_t str_len; - zend_long length = 0; + zend_long length = ZEND_LONG_MAX; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &str, &str_len, &length) == FAILURE) { return; @@ -2891,19 +2878,17 @@ SPL_METHOD(SplFileObject, fwrite) return; } - if (ZEND_NUM_ARGS() > 1) { - if (length >= 0) { - str_len = MAX(0, MIN((size_t)length, str_len)); - } else { - /* Negative length given, nothing to write */ - str_len = 0; - } + if(length > str_len) { + length = str_len; + } + if(length < 0) { + length = 0; } - if (!str_len) { + if (!length) { RETURN_LONG(0); } - RETURN_LONG(php_stream_write(intern->u.file.stream, str, str_len)); + RETURN_LONG(php_stream_write(intern->u.file.stream, str, length)); } /* }}} */ SPL_METHOD(SplFileObject, fread) diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index a974a2008f6e6..1657dcd355a90 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -363,7 +363,7 @@ static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, in if (intern->fptr_offset_get) { zval tmp, rv; if (!offset) { - ZVAL_UNDEF(&tmp); + ZVAL_NULL(&tmp); offset = &tmp; } else { SEPARATE_ARG_IF_REF(offset); diff --git a/ext/standard/array.c b/ext/standard/array.c index 966ea0f1f69de..0da54ed413627 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1600,7 +1600,7 @@ PHP_FUNCTION(compact) if (ZEND_NUM_ARGS() == 1 && Z_TYPE(args[0]) == IS_ARRAY) { array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL(args[0]))); } else { - array_init_size(return_value, ZEND_NUM_ARGS()); + array_init_size(return_value, num_args); } for (i=0; i 1) { - if (num_req <= 0 || num_req > num_avail) { - php_error_docref(NULL, E_WARNING, "Second argument has to be between 1 and the number of elements in the array"); - return; - } + if (num_req <= 0 || num_req > num_avail) { + php_error_docref(NULL, E_WARNING, "Second argument has to be between 1 and the number of elements in the array"); + return; } + /* Make the return value an array only if we need to pass back more than one result. */ if (num_req > 1) { array_init_size(return_value, (uint32_t)num_req); @@ -4583,7 +4599,7 @@ PHP_FUNCTION(array_reduce) } - if (ZEND_NUM_ARGS() > 2) { + if (initial != NULL) { ZVAL_DUP(&result, initial); } else { ZVAL_NULL(&result); @@ -4623,7 +4639,7 @@ PHP_FUNCTION(array_reduce) } /* }}} */ -/* {{{ proto array array_filter(array input [, mixed callback]) +/* {{{ proto array array_filter(array input [, mixed callback [, int flag ]]) Filters elements from the array via the callback. */ PHP_FUNCTION(array_filter) { @@ -4647,7 +4663,7 @@ PHP_FUNCTION(array_filter) return; } - if (ZEND_NUM_ARGS() > 1) { + if (fci.size > 0) { have_callback = 1; fci.no_separation = 0; fci.retval = &retval; @@ -4923,7 +4939,7 @@ PHP_FUNCTION(array_key_exists) Split array into chunks */ PHP_FUNCTION(array_chunk) { - int argc = ZEND_NUM_ARGS(), num_in; + int num_in; zend_long size, current = 0; zend_string *str_key; zend_ulong num_key; @@ -4932,7 +4948,7 @@ PHP_FUNCTION(array_chunk) zval chunk; zval *entry; - if (zend_parse_parameters(argc, "al|b", &input, &size, &preserve_keys) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "al|b", &input, &size, &preserve_keys) == FAILURE) { return; } /* Do bounds checking for size parameter. */ diff --git a/ext/standard/assert.c b/ext/standard/assert.c index 15803fa075d3b..b6f4eaf399dd1 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -259,17 +259,16 @@ PHP_FUNCTION(assert_options) zval *value = NULL; zend_long what; zend_bool oldint; - int ac = ZEND_NUM_ARGS(); zend_string *key; - if (zend_parse_parameters(ac, "l|z", &what, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|z", &what, &value) == FAILURE) { return; } switch (what) { case ASSERT_ACTIVE: oldint = ASSERTG(active); - if (ac == 2) { + if (value != NULL) { zend_string *value_str = zval_get_string(value); key = zend_string_init("assert.active", sizeof("assert.active")-1, 0); zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0); @@ -281,7 +280,7 @@ PHP_FUNCTION(assert_options) case ASSERT_BAIL: oldint = ASSERTG(bail); - if (ac == 2) { + if (value != NULL) { zend_string *value_str = zval_get_string(value); key = zend_string_init("assert.bail", sizeof("assert.bail")-1, 0); zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0); @@ -293,7 +292,7 @@ PHP_FUNCTION(assert_options) case ASSERT_QUIET_EVAL: oldint = ASSERTG(quiet_eval); - if (ac == 2) { + if (value != NULL) { zend_string *value_str = zval_get_string(value); key = zend_string_init("assert.quiet_eval", sizeof("assert.quiet_eval")-1, 0); zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0); @@ -305,7 +304,7 @@ PHP_FUNCTION(assert_options) case ASSERT_WARNING: oldint = ASSERTG(warning); - if (ac == 2) { + if (value != NULL) { zend_string *value_str = zval_get_string(value); key = zend_string_init("assert.warning", sizeof("assert.warning")-1, 0); zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0); @@ -323,7 +322,7 @@ PHP_FUNCTION(assert_options) } else { RETVAL_NULL(); } - if (ac == 2) { + if (value != NULL) { zval_ptr_dtor(&ASSERTG(callback)); ZVAL_COPY(&ASSERTG(callback), value); } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 940c9e4141750..6fb3cde8f9b61 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -685,7 +685,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_error_get_last, 0, 0, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_call_user_func, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_DEFAULT(arginfo_call_user_func, 0, 0, 1) ZEND_ARG_INFO(0, function_name) ZEND_ARG_VARIADIC_INFO(0, parameters) ZEND_END_ARG_INFO() @@ -695,7 +695,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_call_user_func_array, 0, 0, 2) ZEND_ARG_INFO(0, parameters) /* ARRAY_INFO(0, parameters, 1) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_forward_static_call, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_DEFAULT(arginfo_forward_static_call, 0, 0, 1) ZEND_ARG_INFO(0, function_name) ZEND_ARG_VARIADIC_INFO(0, parameters) ZEND_END_ARG_INFO() @@ -705,7 +705,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_forward_static_call_array, 0, 0, 2) ZEND_ARG_INFO(0, parameters) /* ARRAY_INFO(0, parameters, 1) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_register_shutdown_function, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_DEFAULT(arginfo_register_shutdown_function, 0, 0, 1) ZEND_ARG_INFO(0, function_name) ZEND_ARG_VARIADIC_INFO(0, parameters) ZEND_END_ARG_INFO() @@ -4607,16 +4607,14 @@ PHP_FUNCTION(error_log) { char *message, *opt = NULL, *headers = NULL; size_t message_len, opt_len = 0, headers_len = 0; - int opt_err = 0, argc = ZEND_NUM_ARGS(); + int opt_err = 0; zend_long erropt = 0; - if (zend_parse_parameters(argc, "s|lps", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lps", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) { return; } - if (argc > 1) { - opt_err = (int)erropt; - } + opt_err = (int)erropt; if (_php_error_log_ex(opt_err, message, message_len, opt, headers) == FAILURE) { RETURN_FALSE; @@ -4969,7 +4967,6 @@ PHP_FUNCTION(register_shutdown_function) int i; shutdown_function_entry.arg_count = ZEND_NUM_ARGS(); - if (shutdown_function_entry.arg_count < 1) { WRONG_PARAM_COUNT; } diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 9a26458321d34..3eb3141de7c4e 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -78,7 +78,7 @@ static zend_class_entry *dir_class_entry_ptr; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &id) == FAILURE) { \ return; \ } \ - if (ZEND_NUM_ARGS() == 0) { \ + if (id == NULL) { \ myself = getThis(); \ if (myself) { \ if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \ diff --git a/ext/standard/file.c b/ext/standard/file.c index 27053fe2716f6..f62d8a7b9ba7d 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1007,11 +1007,12 @@ PHPAPI PHP_FUNCTION(feof) PHPAPI PHP_FUNCTION(fgets) { zval *res; - zend_long len = 1024; + zend_long len = ZEND_LONG_MIN; char *buf = NULL; int argc = ZEND_NUM_ARGS(); size_t line_len = 0; php_stream *stream; + int alloc_buf = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &res, &len) == FAILURE) { RETURN_FALSE; @@ -1019,22 +1020,27 @@ PHPAPI PHP_FUNCTION(fgets) PHP_STREAM_TO_ZVAL(stream, res); - if (argc == 1) { - /* ask streams to give us a buffer of an appropriate size */ - buf = php_stream_get_line(stream, NULL, 0, &line_len); - if (buf == NULL) { - goto exit_failed; - } - } else if (argc > 1) { - if (len <= 0) { - php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); - RETURN_FALSE; - } + if(len == LONG_MIN) { + len = 1024; + alloc_buf = 0; + } + + if (len <= 0) { + php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); + RETURN_FALSE; + } + if(alloc_buf) { buf = ecalloc(len + 1, sizeof(char)); if (php_stream_get_line(stream, buf, len, &line_len) == NULL) { goto exit_failed; } + } else { + /* ask streams to give us a buffer of an appropriate size */ + buf = php_stream_get_line(stream, NULL, 0, &line_len); + if (buf == NULL) { + goto exit_failed; + } } /* resize buffer if it's much larger than the result. @@ -1091,7 +1097,7 @@ PHPAPI PHP_FUNCTION(fgetc) PHPAPI PHP_FUNCTION(fgetss) { zval *fd; - zend_long bytes = 0; + zend_long bytes = ZEND_LONG_MIN; size_t len = 0; size_t actual_len, retval_len; char *buf = NULL, *retval; @@ -1106,7 +1112,7 @@ PHPAPI PHP_FUNCTION(fgetss) PHP_STREAM_TO_ZVAL(stream, fd); - if (ZEND_NUM_ARGS() >= 2) { + if (bytes != LONG_MIN) { if (bytes <= 0) { php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); RETURN_FALSE; @@ -1198,14 +1204,14 @@ PHPAPI PHP_FUNCTION(fwrite) size_t inputlen; size_t ret; size_t num_bytes; - zend_long maxlen = 0; + zend_long maxlen = ZEND_LONG_MIN; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &res, &input, &inputlen, &maxlen) == FAILURE) { RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 2) { + if (maxlen == ZEND_LONG_MIN) { num_bytes = inputlen; } else if (maxlen <= 0) { num_bytes = 0; @@ -1413,6 +1419,7 @@ PHP_FUNCTION(umask) if (BG(umask) == -1) { BG(umask) = oldumask; } + mask = oldumask; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mask) == FAILURE) { RETURN_FALSE; diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 54bc5813e71c0..0b1a3d594bf70 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -714,13 +714,15 @@ PHP_FUNCTION(touch) { char *filename; size_t filename_len; - zend_long filetime = 0, fileatime = 0; + zend_long filetime, fileatime; int ret, argc = ZEND_NUM_ARGS(); FILE *file; struct utimbuf newtimebuf; struct utimbuf *newtime = &newtimebuf; php_stream_wrapper *wrapper; + filetime = fileatime = time(NULL); + if (zend_parse_parameters(argc, "p|ll", &filename, &filename_len, &filetime, &fileatime) == FAILURE) { return; } @@ -734,7 +736,7 @@ PHP_FUNCTION(touch) #ifdef HAVE_UTIME_NULL newtime = NULL; #else - newtime->modtime = newtime->actime = time(NULL); + newtime->modtime = newtime->actime = filetime; #endif break; case 2: diff --git a/ext/standard/image.c b/ext/standard/image.c index d5ab5290716d0..98d86aed7a586 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1394,15 +1394,14 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { php_stream *stream = NULL; char *input; size_t input_len; - const int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "s|z/", &input, &input_len, &info) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z/", &input, &input_len, &info) == FAILURE) { return; } - if (argc == 2) { - zval_dtor(info); - array_init(info); + if (info != NULL) { + zval_dtor(info); + array_init(info); } if (mode == FROM_PATH) { diff --git a/ext/standard/math.c b/ext/standard/math.c index 0125ae546a607..08c08a5bca719 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -374,9 +374,7 @@ PHP_FUNCTION(round) return; } - if (ZEND_NUM_ARGS() >= 2) { - places = (int) precision; - } + places = (int) precision; convert_scalar_to_number_ex(value); switch (Z_TYPE_P(value)) { diff --git a/ext/standard/rand.c b/ext/standard/rand.c index b80318c4b28b3..1cf9592aecbcb 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -231,7 +231,7 @@ PHP_FUNCTION(srand) { zend_long seed = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &seed) == FAILURE) + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "|l", &seed) == FAILURE) return; if (ZEND_NUM_ARGS() == 0) @@ -247,7 +247,7 @@ PHP_FUNCTION(mt_srand) { zend_long seed = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &seed) == FAILURE) + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "|l", &seed) == FAILURE) return; if (ZEND_NUM_ARGS() == 0) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index d5ee886ee9730..a30efae2d43e6 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1305,9 +1305,8 @@ PHP_FUNCTION(stream_set_timeout) zend_long seconds, microseconds = 0; struct timeval t; php_stream *stream; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "rl|l", &socket, &seconds, µseconds) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &socket, &seconds, µseconds) == FAILURE) { return; } @@ -1325,7 +1324,7 @@ PHP_FUNCTION(stream_set_timeout) #else t.tv_sec = seconds; - if (argc == 3) { + if (microseconds != 0) { t.tv_usec = microseconds % 1000000; t.tv_sec += microseconds / 1000000; } else { @@ -1438,10 +1437,10 @@ PHP_FUNCTION(stream_set_read_buffer) Enable or disable a specific kind of crypto on the stream */ PHP_FUNCTION(stream_socket_enable_crypto) { - zend_long cryptokind = 0; + zend_long cryptokind = -1; zval *zstream, *zsessstream = NULL; php_stream *stream, *sessstream = NULL; - zend_bool enable, cryptokindnull; + zend_bool enable, cryptokindnull = 0; int ret; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb|l!r", &zstream, &enable, &cryptokind, &cryptokindnull, &zsessstream) == FAILURE) { @@ -1451,7 +1450,7 @@ PHP_FUNCTION(stream_socket_enable_crypto) php_stream_from_zval(stream, zstream); if (enable) { - if (ZEND_NUM_ARGS() < 3 || cryptokindnull) { + if (cryptokind == -1 || cryptokindnull) { zval *val; if (!GET_CTX_OPT(stream, "ssl", "crypto_method", val)) { diff --git a/ext/standard/string.c b/ext/standard/string.c index e22dba3967fcd..3d76401c88926 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -294,7 +294,7 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / zend_string *s11, *s22; zend_long start = 0, len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|ll", &s11, + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS(), "SS|ll", &s11, &s22, &start, &len) == FAILURE) { return; } @@ -1325,7 +1325,7 @@ PHP_FUNCTION(strtok) ZEND_PARSE_PARAMETERS_END(); #endif - if (ZEND_NUM_ARGS() == 1) { + if (tok == NULL) { tok = str; } else { zval_ptr_dtor(&BG(strtok_zval)); @@ -2329,8 +2329,7 @@ PHP_FUNCTION(chunk_split) PHP_FUNCTION(substr) { zend_string *str; - zend_long l = 0, f; - int argc = ZEND_NUM_ARGS(); + zend_long l = ZEND_LONG_MAX, f; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l", &str, &f, &l) == FAILURE) { @@ -2345,13 +2344,9 @@ PHP_FUNCTION(substr) ZEND_PARSE_PARAMETERS_END(); #endif - if (argc > 2) { - if ((l < 0 && (size_t)(-l) > str->len)) { - RETURN_FALSE; - } else if (l > (zend_long)str->len) { - l = str->len; - } - } else { + if ((l < 0 && (size_t)(-l) > str->len)) { + RETURN_FALSE; + } else if (l > (zend_long)str->len) { l = str->len; } @@ -2407,7 +2402,6 @@ PHP_FUNCTION(substr_replace) zval *repl; zend_long l = 0; /* l and f should be size_t, however this needs much closer below logic investigation.*/ zend_long f; - int argc = ZEND_NUM_ARGS(); zend_string *result; HashPosition pos_from, pos_repl, pos_len; @@ -2427,7 +2421,7 @@ PHP_FUNCTION(substr_replace) convert_to_long_ex(from); } - if (argc > 3) { + if (len != NULL) { if (Z_TYPE_P(len) != IS_ARRAY) { l = zval_get_long(len); } @@ -2439,13 +2433,13 @@ PHP_FUNCTION(substr_replace) if (Z_TYPE_P(str) == IS_STRING) { if ( - (argc == 3 && Z_TYPE_P(from) == IS_ARRAY) || - (argc == 4 && Z_TYPE_P(from) != Z_TYPE_P(len)) + (len == NULL && Z_TYPE_P(from) == IS_ARRAY) || + (len != NULL && Z_TYPE_P(from) != Z_TYPE_P(len)) ) { php_error_docref(NULL, E_WARNING, "'from' and 'len' should be of same type - numerical or array "); RETURN_STR(zend_string_copy(Z_STR_P(str))); } - if (argc == 4 && Z_TYPE_P(from) == IS_ARRAY) { + if (len != NULL && Z_TYPE_P(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { php_error_docref(NULL, E_WARNING, "'from' and 'len' should have the same number of elements"); RETURN_STR(zend_string_copy(Z_STR_P(str))); @@ -2523,7 +2517,7 @@ PHP_FUNCTION(substr_replace) zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(from), &pos_from); } - if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) { + if (len != NULL && Z_TYPE_P(len) == IS_ARRAY) { zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(len), &pos_len); } @@ -2580,14 +2574,14 @@ PHP_FUNCTION(substr_replace) } } - if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) { + if (len != NULL && Z_TYPE_P(len) == IS_ARRAY) { if (NULL != (tmp_len = zend_hash_get_current_data_ex(Z_ARRVAL_P(len), &pos_len))) { l = zval_get_long(tmp_len); zend_hash_move_forward_ex(Z_ARRVAL_P(len), &pos_len); } else { l = Z_STRLEN_P(orig_str); } - } else if (argc > 3) { + } else if (len != NULL) { l = Z_LVAL_P(len); } else { l = Z_STRLEN_P(orig_str); @@ -2906,7 +2900,7 @@ PHPAPI char *php_strtr(char *str, size_t len, char *str_from, char *str_to, size for (i = 0; i < trlen; i++) { xlat[(size_t)(unsigned char) str_from[i]] = str_to[i]; } - + for (i = 0; i < len; i++) { str[i] = xlat[(size_t)(unsigned char) str[i]]; } @@ -3446,7 +3440,6 @@ PHP_FUNCTION(strtr) zend_string *str; char *to = NULL; size_t to_len = 0; - int ac = ZEND_NUM_ARGS(); #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|s", &str, &from, &to, &to_len) == FAILURE) { @@ -3461,7 +3454,7 @@ PHP_FUNCTION(strtr) ZEND_PARSE_PARAMETERS_END(); #endif - if (ac == 2 && Z_TYPE_P(from) != IS_ARRAY) { + if (to == NULL && Z_TYPE_P(from) != IS_ARRAY) { php_error_docref(NULL, E_WARNING, "The second argument is not an array"); RETURN_FALSE; } @@ -3471,7 +3464,7 @@ PHP_FUNCTION(strtr) RETURN_EMPTY_STRING(); } - if (ac == 2) { + if (to == NULL) { HashTable *pats = HASH_OF(from); if (zend_hash_num_elements(pats) < 1) { @@ -3487,7 +3480,7 @@ PHP_FUNCTION(strtr) ZVAL_LONG(&tmp, num_key); convert_to_string(&tmp); str_key = Z_STR(tmp); - } + } replace = zval_get_string(entry); if (str_key->len < 1) { RETVAL_STR(zend_string_copy(str)); @@ -3601,19 +3594,18 @@ PHP_FUNCTION(similar_text) { zend_string *t1, *t2; zval *percent = NULL; - int ac = ZEND_NUM_ARGS(); size_t sim; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|z/", &t1, &t2, &percent) == FAILURE) { return; } - if (ac > 2) { + if (percent != NULL) { convert_to_double_ex(percent); } if (t1->len + t2->len == 0) { - if (ac > 2) { + if (percent != NULL) { Z_DVAL_P(percent) = 0; } @@ -3622,7 +3614,7 @@ PHP_FUNCTION(similar_text) sim = php_similar_char(t1->val, t1->len, t2->val, t2->len); - if (ac > 2) { + if (percent != NULL) { Z_DVAL_P(percent) = sim * 200.0 / (t1->len + t2->len); } @@ -4048,7 +4040,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s zend_string_release(lc_subject_str); lc_subject_str = NULL; } - } + } } zend_string_release(Z_STR_P(result)); @@ -4104,7 +4096,6 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit zend_string *string_key; zend_ulong num_key; zend_long count = 0; - int argc = ZEND_NUM_ARGS(); #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz|z/", &search, &replace, &subject, &zcount) == FAILURE) { @@ -4152,7 +4143,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit } else { /* if subject is not an array */ count = php_str_replace_in_subject(search, replace, subject, return_value, case_sensitivity); } - if (argc > 3) { + if (zcount != NULL) { zval_ptr_dtor(zcount); ZVAL_LONG(zcount, count); } @@ -5696,7 +5687,7 @@ PHP_FUNCTION(strpbrk) PHP_FUNCTION(substr_compare) { zend_string *s1, *s2; - zend_long offset, len=0; + zend_long offset, len=ZEND_LONG_MAX; zend_bool cs=0; size_t cmp_len; @@ -5704,13 +5695,12 @@ PHP_FUNCTION(substr_compare) RETURN_FALSE; } - if (ZEND_NUM_ARGS() >= 4 && len <= 0) { - if (len == 0) { - RETURN_LONG(0L); - } else { - php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero"); - RETURN_FALSE; - } + if (len == 0) { + RETURN_LONG(0L); + } + if (len < 0) { + php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero"); + RETURN_FALSE; } if (offset < 0) { @@ -5723,7 +5713,7 @@ PHP_FUNCTION(substr_compare) RETURN_FALSE; } - cmp_len = (size_t) (len ? len : MAX(s2->len, (s1->len - offset))); + cmp_len = (size_t) MIN(len, MAX(s2->len, (s1->len - offset))); if (!cs) { RETURN_LONG(zend_binary_strncmp(s1->val + offset, (s1->len - offset), s2->val, s2->len, cmp_len)); diff --git a/ext/standard/tests/array/array_rand.phpt b/ext/standard/tests/array/array_rand.phpt index 1f495f4b129c0..27acb9d973d63 100644 --- a/ext/standard/tests/array/array_rand.phpt +++ b/ext/standard/tests/array/array_rand.phpt @@ -18,6 +18,8 @@ echo "Done\n"; --EXPECTF-- Warning: array_rand() expects at least 1 parameter, 0 given in %s on line %d NULL + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d NULL Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d diff --git a/ext/standard/tests/array/array_slice_variation1.phpt b/ext/standard/tests/array/array_slice_variation1.phpt index daed1d84fcfd0..804d90a34e722 100644 --- a/ext/standard/tests/array/array_slice_variation1.phpt +++ b/ext/standard/tests/array/array_slice_variation1.phpt @@ -54,8 +54,10 @@ array(1) { [2]=> int(3) } -array(0) { -} -array(0) { -} + +Warning: array_slice() expects parameter 3 to be integer, string given in %s/array_slice_variation1.php on line %d +NULL + +Warning: array_slice() expects parameter 3 to be integer, string given in %s/array_slice_variation1.php on line %d +NULL string(3) "foo" diff --git a/ext/standard/tests/array/array_slice_variation3.phpt b/ext/standard/tests/array/array_slice_variation3.phpt index bdcb7591a2990..4f16f303ef41d 100644 --- a/ext/standard/tests/array/array_slice_variation3.phpt +++ b/ext/standard/tests/array/array_slice_variation3.phpt @@ -5,7 +5,7 @@ Test array_slice() function : usage variations - Pass different data types as $l --FILE-- int(4) } -Done \ No newline at end of file +Done diff --git a/ext/standard/type.c b/ext/standard/type.c index d6ea5d58eca63..7fc50d2ffc3cd 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -140,9 +140,6 @@ PHP_FUNCTION(intval) zval *num; zend_long base = 10; - if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 2) { - WRONG_PARAM_COUNT; - } #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &num, &base) == FAILURE) { return; @@ -411,7 +408,7 @@ PHP_FUNCTION(is_callable) if (syntax_only) { check_flags |= IS_CALLABLE_CHECK_SYNTAX_ONLY; } - if (ZEND_NUM_ARGS() > 2) { + if (callable_name != NULL) { retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, &error); zval_dtor(callable_name); //??? is it necessary to be consistent with old PHP ("\0" support) diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index f47b3806b1bd5..576be18e5aabe 100644 --- a/ext/standard/versioning.c +++ b/ext/standard/versioning.c @@ -12,7 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Stig S�ther Bakken | + | Author: Stig S�ther Bakken | +----------------------------------------------------------------------+ */ @@ -212,15 +212,14 @@ PHP_FUNCTION(version_compare) { char *v1, *v2, *op = NULL; size_t v1_len, v2_len, op_len = 0; - int compare, argc; + int compare; - argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "ss|s", &v1, &v1_len, &v2, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|s", &v1, &v1_len, &v2, &v2_len, &op, &op_len) == FAILURE) { return; } compare = php_version_compare(v1, v2); - if (argc == 2) { + if (op == NULL) { RETURN_LONG(compare); } if (!strncmp(op, "<", op_len) || !strncmp(op, "lt", op_len)) { diff --git a/ext/sybase_ct/php_sybase_ct.c b/ext/sybase_ct/php_sybase_ct.c index 5ed1fb4dd7d0a..5b07e2fd4dc68 100644 --- a/ext/sybase_ct/php_sybase_ct.c +++ b/ext/sybase_ct/php_sybase_ct.c @@ -1977,7 +1977,7 @@ static char *php_sybase_get_field_name(CS_INT type) PHP_FUNCTION(sybase_fetch_field) { zval *sybase_result_index = NULL; - long field_offset = -1; + zend_long field_offset = -1; sybase_result *result; if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &sybase_result_index, &field_offset) == FAILURE) { diff --git a/ext/xmlrpc/xmlrpc-epi-php.c b/ext/xmlrpc/xmlrpc-epi-php.c index 914ec4989e26b..c270de4b889d1 100644 --- a/ext/xmlrpc/xmlrpc-epi-php.c +++ b/ext/xmlrpc/xmlrpc-epi-php.c @@ -1025,12 +1025,8 @@ PHP_FUNCTION(xmlrpc_server_call_method) if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsz|a", &handle, &rawxml, &rawxml_len, &caller_params, &output_opts) != SUCCESS) { return; } - /* user output options */ - if (argc == 3) { - set_output_options(&out, NULL); - } else { - set_output_options(&out, output_opts); - } + /* user output options, will set to NULL if omitted */ + set_output_options(&out, output_opts); ZEND_FETCH_RESOURCE(server, xmlrpc_server_data*, handle, -1, "xmlrpc server", le_xmlrpc_server); diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 8f976a8b93ea7..05e6a8655bd5d 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1489,9 +1489,9 @@ static PHP_MINFO_FUNCTION(cgi) PHP_FUNCTION(apache_child_terminate) /* {{{ */ { - if (ZEND_NUM_ARGS() > 0) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters_none() == FAILURE) { + RETURN_FALSE; + } if (fcgi_is_fastcgi()) { fcgi_terminate(); } @@ -1548,9 +1548,9 @@ static void add_request_header(char *var, unsigned int var_len, char *val, unsig PHP_FUNCTION(apache_request_headers) /* {{{ */ { - if (ZEND_NUM_ARGS() > 0) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters_none() == FAILURE) { + RETURN_FALSE; + } array_init(return_value); if (fcgi_is_fastcgi()) { fcgi_request *request = (fcgi_request*) SG(server_context);