diff --git a/Zend/tests/default_params01.phpt b/Zend/tests/default_params01.phpt new file mode 100644 index 0000000000000..0abadb3814809 --- /dev/null +++ b/Zend/tests/default_params01.phpt @@ -0,0 +1,72 @@ +--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(2) { + [1]=> + int(4) + [2]=> + int(5) +} +default,default,8 +int(1) +int(2) +int(8) +array(1) { + [2]=> + int(8) +} +3,default,5 +int(3) +int(2) +int(5) +array(2) { + [0]=> + int(3) + [2]=> + int(5) +} +3,default,7,default,6 +int(3) +int(2) +int(7) +array(3) { + [0]=> + int(3) + [2]=> + int(7) + [4]=> + int(6) +} +int(1) +Done diff --git a/Zend/tests/default_params02.phpt b/Zend/tests/default_params02.phpt new file mode 100644 index 0000000000000..cdb8825f4b27f --- /dev/null +++ b/Zend/tests/default_params02.phpt @@ -0,0 +1,59 @@ +--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(2) { + [0]=> + int(1) + [2]=> + int(3) +} + +Warning: Missing argument 1 for foo(), called in %s on line %d and defined in %s on line %d + +Notice: Undefined variable: a in %s on line %d +NULL +int(2) +int(3) +int(3) +int(3) +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +int(42) +int(42) +Done diff --git a/Zend/tests/default_params03.phpt b/Zend/tests/default_params03.phpt new file mode 100644 index 0000000000000..e15cb8e215966 --- /dev/null +++ b/Zend/tests/default_params03.phpt @@ -0,0 +1,19 @@ +--TEST-- +Default parameters - 3 +--FILE-- + +--EXPECTF-- +array(1) { + [0]=> + int(7) +} +bool(false) +Done diff --git a/Zend/tests/default_params04.phpt b/Zend/tests/default_params04.phpt new file mode 100644 index 0000000000000..fd30fbfb0b91b --- /dev/null +++ b/Zend/tests/default_params04.phpt @@ -0,0 +1,45 @@ +--TEST-- +Default parameters - 4 +--FILE-- +43, 4=>44)); +echo "Done\n"; +?> +--EXPECTF-- +int(1) +int(2) +int(3) +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +== +int(42) +int(1) +int(43) +int(3) +int(5) +array(3) { + [0]=> + int(42) + [2]=> + int(43) + [4]=> + int(44) +} +== +Done diff --git a/Zend/tests/default_params05.phpt b/Zend/tests/default_params05.phpt new file mode 100644 index 0000000000000..e2a90ca929cdb --- /dev/null +++ b/Zend/tests/default_params05.phpt @@ -0,0 +1,22 @@ +--TEST-- +Default parameters - 5 +--FILE-- + +--EXPECTF-- +#0 test(7) called at [%s:%d] +#0 test(, 4, 5) called at [%s.php:%d] +#0 test(, , 8) called at [%s:%d] +#0 test(3, , 5) called at [%s:%d] +#0 test(3, , 7, , 6) 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..34cdd84d38405 --- /dev/null +++ b/Zend/tests/default_params06.phpt @@ -0,0 +1,15 @@ +--TEST-- +Default parameters - 6, by-refs +--FILE-- + +--EXPECTF-- +Fatal error: Cannot pass parameter 2 by reference in %s on line %d diff --git a/Zend/tests/default_params07.phpt b/Zend/tests/default_params07.phpt new file mode 100644 index 0000000000000..a694bb640935c --- /dev/null +++ b/Zend/tests/default_params07.phpt @@ -0,0 +1,19 @@ +--TEST-- +Default parameters - 7, by-refs +--FILE-- + +--EXPECTF-- +int(7) +int(2) + +Fatal error: Cannot pass parameter 2 by reference in %s on line %d + diff --git a/Zend/tests/default_params08.phpt b/Zend/tests/default_params08.phpt new file mode 100644 index 0000000000000..866d74392080a --- /dev/null +++ b/Zend/tests/default_params08.phpt @@ -0,0 +1,11 @@ +--TEST-- +Default parameters - 8, by-refs +--FILE-- + +--EXPECTF-- +Fatal error: Cannot pass parameter 3 by reference in %s on line %d + diff --git a/Zend/tests/default_params09.phpt b/Zend/tests/default_params09.phpt new file mode 100644 index 0000000000000..8a4dc9ce49666 --- /dev/null +++ b/Zend/tests/default_params09.phpt @@ -0,0 +1,21 @@ +--TEST-- +Default parameters - 9, varargs with + +--FILE-- + +--EXPECTF-- +array(2) { + ["foo"]=> + string(4) "test" + ["bar"]=> + string(4) "test" +} + +Warning: compact() expects at least 1 parameter, 0 given in %s on line %d +NULL +Done + diff --git a/Zend/zend_API.c b/Zend/zend_API.c index b59faab28458d..533089f96cc4d 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -97,7 +97,7 @@ ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument while (param_count-->0) { param_ptr = *(p-arg_count); - if (!PZVAL_IS_REF(param_ptr) && Z_REFCOUNT_P(param_ptr) > 1) { + if (param_ptr != NULL && !PZVAL_IS_REF(param_ptr) && Z_REFCOUNT_P(param_ptr) > 1) { zval *new_tmp; ALLOC_ZVAL(new_tmp); @@ -167,6 +167,32 @@ ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_arr } /* }}} */ +ZEND_API int zend_get_parameters_array_nodefault(int param_count, zval ***argument_array TSRMLS_DC) /* {{{ */ +{ + void **p; + int arg_count; + + p = zend_vm_stack_top(TSRMLS_C) - 1; + arg_count = (int)(zend_uintptr_t) *p; + + if (param_count>arg_count) { + return FAILURE; + } + + while (param_count-->0) { + zval **value = (zval**)(p-arg_count); + if(*value == NULL) { + // defaults not allowed + return FAILURE; + } + *(argument_array++) = value; + arg_count--; + } + + return SUCCESS; +} +/* }}} */ + ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TSRMLS_DC) /* {{{ */ { void **p; @@ -739,6 +765,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, zend_bool have_varargs = 0; zval ****varargs = NULL; int *n_varargs = NULL; + int disallow_default = flags & ZEND_PARSE_PARAMS_NODEFAULT; for (spec_walk = type_spec; *spec_walk; spec_walk++) { c = *spec_walk; @@ -834,6 +861,8 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, i = 0; while (num_args-- > 0) { + int parse_failed; + if (*type_spec == '|') { type_spec++; } @@ -850,17 +879,40 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, int iv = 0; zval **p = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count - i)); - *n_varargs = num_varargs; + num_args -= num_varargs-1; /* adjust how many args we've left after varargs, -1 because we already subtracted 1 above */ + i += num_varargs; /* put loop counter after varargs */ /* allocate space for array and store args */ *varargs = safe_emalloc(num_varargs, sizeof(zval **), 0); - while (num_varargs-- > 0) { - (*varargs)[iv++] = p++; + for (;num_varargs-- > 0;p++) { + if(*p == NULL) { + /* skipped arg - not counting in varargs */ + continue; + } + (*varargs)[iv++] = p; + } + if(iv == 0) { + efree(*varargs); + *varargs = NULL; + + if(type_spec[-1] == '+') { + if (!quiet) { + zend_function *active_function = EG(current_execute_data)->function_state.function; + const char *class_name = active_function->common.scope ? active_function->common.scope->name : ""; + zend_error(E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given", + class_name, + class_name[0] ? "::" : "", + active_function->common.function_name, + min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most", + num_args < min_num_args ? min_num_args : max_num_args, + (num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s", + num_args); + } + return FAILURE; + } } - /* adjust how many args we have left and restart loop */ - num_args = num_args + 1 - iv; - i += iv; + *n_varargs = iv; continue; } else { *varargs = NULL; @@ -870,7 +922,36 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, arg = (zval **) (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count-i)); - if (zend_parse_arg(i+1, arg, va, &type_spec, quiet TSRMLS_CC) == FAILURE) { + parse_failed = 0; + if(*arg == NULL) { + /* we have skipped arg */ + if(i < min_num_args || disallow_default || type_spec[1] == '/') { + /* this is one of the required args or skipping is prohibited or we'd need to write there */ + if (!quiet) { + zend_function *active_function = EG(current_execute_data)->function_state.function; + const char *class_name = active_function->common.scope ? active_function->common.scope->name : ""; + zend_error(E_WARNING, "Parameter %d missing for %s%s%s()", + i+1, + class_name, + class_name[0] ? "::" : "", + active_function->common.function_name); + } + parse_failed = 1; + } else { + if(type_spec[1] == '!') { + /* for !, create a null */ + zval tmp = {0}; + zval *ptmp = &tmp; + ZVAL_NULL(ptmp); + arg = &ptmp; + } else { + /* optional arg - just skip it */ + continue; + } + } + } + + if (parse_failed || zend_parse_arg(i+1, arg, va, &type_spec, quiet TSRMLS_CC) == FAILURE) { /* clean up varargs array if it was used */ if (varargs && *varargs) { efree(*varargs); @@ -1054,7 +1135,7 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destro static int zval_update_class_constant(zval **pp, int is_static, int offset TSRMLS_DC) /* {{{ */ { if ((Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT || - (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT_ARRAY) { + (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT_ARRAY) { zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry); if ((*scope)->parent) { @@ -1075,10 +1156,10 @@ static int zval_update_class_constant(zval **pp, int is_static, int offset TSRML *scope = old_scope; return ret; } - } + } ce = ce->parent; } while (ce); - + } return zval_update_constant(pp, (void*)1 TSRMLS_CC); } @@ -1837,7 +1918,7 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */ module_post_deactivate_handlers = module_request_shutdown_handlers + shutdown_count + 1; module_post_deactivate_handlers[post_deactivate_count] = NULL; startup_count = 0; - + for (zend_hash_internal_pointer_reset_ex(&module_registry, &pos); zend_hash_get_current_data_ex(&module_registry, (void *) &module, &pos) == SUCCESS; zend_hash_move_forward_ex(&module_registry, &pos)) { @@ -2080,7 +2161,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio } if (ptr->arg_info) { zend_internal_function_info *info = (zend_internal_function_info*)ptr->arg_info; - + internal_function->arg_info = (zend_arg_info*)ptr->arg_info+1; internal_function->num_args = ptr->num_args; /* Currently you cannot denote that the function can accept less arguments than num_args */ @@ -2690,7 +2771,7 @@ static int zend_is_callable_check_class(const char *name, int name_len, zend_fca } ret = 1; } - } else if (name_len == sizeof("parent") - 1 && + } else if (name_len == sizeof("parent") - 1 && !memcmp(lcname, "parent", sizeof("parent") - 1)) { if (!EG(scope)) { if (error) *error = estrdup("cannot access parent:: when no class scope is active"); @@ -3019,7 +3100,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch if (error) { *error = NULL; } - + fcc->initialized = 0; fcc->calling_scope = NULL; fcc->called_scope = NULL; @@ -3031,7 +3112,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch object_ptr = NULL; } if (object_ptr && - (!EG(objects_store).object_buckets || + (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(object_ptr)].valid)) { return 0; } @@ -3112,7 +3193,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch } } else { - if (!EG(objects_store).object_buckets || + if (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_PP(obj)].valid) { return 0; } @@ -3181,7 +3262,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch *callable_name = emalloc(*callable_name_len + 1); memcpy(*callable_name, ce->name, ce->name_length); memcpy((*callable_name) + ce->name_length, "::__invoke", sizeof("::__invoke")); - } + } return 1; } /* break missing intentionally */ @@ -3284,11 +3365,51 @@ ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count } /* }}} */ -ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) /* {{{ */ +ZEND_API zval ***zend_fcall_create_args(HashTable *params_ar, zval ***args, unsigned int *param_count) /* {{{ */ { + int num_elems = zend_hash_num_elements(params_ar); + zval ***method_args; + int element = 0, i; HashPosition pos; - zval **arg, ***params; + if(args) { + method_args = (zval ***) safe_erealloc(args, sizeof(zval **), num_elems, 0); + for(i=0;i= num_elems) { + int last_elem = num_elems; + num_elems = index+1; + method_args = (zval ***) safe_erealloc(method_args, sizeof(zval **), num_elems, 0); + for(i=last_elem;iparam_count = zend_hash_num_elements(Z_ARRVAL_P(args)); - fci->params = params = (zval ***) erealloc(fci->params, fci->param_count * sizeof(zval **)); - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void *) &arg, &pos) == SUCCESS) { - *params++ = arg; - zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos); - } + fci->params = zend_fcall_create_args(HASH_OF(args), fci->params, &fci->param_count); return SUCCESS; } diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 16e766d8a51ea..d346e470009e4 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -237,6 +237,7 @@ ZEND_API int zend_get_parameters(int ht, int param_count, ...); ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument_array TSRMLS_DC); ZEND_API ZEND_ATTRIBUTE_DEPRECATED int zend_get_parameters_ex(int param_count, ...); ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_array TSRMLS_DC); +ZEND_API int zend_get_parameters_array_nodefault(int param_count, zval ***argument_array TSRMLS_DC); /* internal function to efficiently copy parameters when executing __call() */ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TSRMLS_DC); @@ -251,6 +252,7 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TS /* 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 TSRMLS_DC, const char *type_spec, ...); ZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, const char *type_spec, ...); ZEND_API char *zend_zval_type_name(const zval *arg); @@ -444,7 +446,7 @@ ZEND_API int add_property_zval_ex(zval *arg, const char *key, uint key_len, zval #define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key)+1, __d TSRMLS_CC) #define add_property_string(__arg, __key, __str, __duplicate) add_property_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate TSRMLS_CC) #define add_property_stringl(__arg, __key, __str, __length, __duplicate) add_property_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate TSRMLS_CC) -#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key)+1, __value TSRMLS_CC) +#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key)+1, __value TSRMLS_CC) ZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC); @@ -455,7 +457,7 @@ ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache; /** Build zend_call_info/cache from a zval* * - * Caller is responsible to provide a return value, otherwise the we will crash. + * Caller is responsible to provide a return value, otherwise the we will crash. * fci->retval_ptr_ptr = NULL; * In order to pass parameters the following members need to be set: * fci->param_count = 0; @@ -484,6 +486,11 @@ ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count */ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC); +/** + * Create arguments structure from zval + */ +ZEND_API zval ***zend_fcall_create_args(HashTable *params_ar, zval ***args, unsigned int *param_count); + /** Set arguments in the zend_fcall_info struct taking care of refcount. * If argc is 0 the arguments which are set will be cleared, else pass * a variable amount of zval** arguments. diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 1ad64e74eaf47..ccbf8be7efd64 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -435,6 +435,9 @@ ZEND_FUNCTION(func_get_arg) } arg = *(p-(arg_count-requested_offset)); + if(arg == NULL) { + RETURN_FALSE; + } *return_value = *arg; zval_copy_ctor(return_value); INIT_PZVAL(return_value); @@ -463,11 +466,12 @@ ZEND_FUNCTION(func_get_args) for (i=0; ivalue.ht, &element, sizeof(zval *), NULL); + zend_hash_index_update(return_value->value.ht, i, &element, sizeof(zval *), NULL); } } /* }}} */ @@ -495,7 +499,7 @@ ZEND_FUNCTION(strcmp) { char *s1, *s2; int s1_len, s2_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1_len, &s2, &s2_len) == FAILURE) { return; } @@ -533,7 +537,7 @@ ZEND_FUNCTION(strcasecmp) { char *s1, *s2; int s1_len, s2_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1_len, &s2, &s2_len) == FAILURE) { return; } @@ -699,7 +703,7 @@ ZEND_FUNCTION(define) } RETURN_FALSE; } - + c.value = *val; zval_copy_ctor(&c.value); if (val_free) { @@ -732,7 +736,7 @@ ZEND_FUNCTION(defined) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } - + if (zend_get_constant_ex(name, name_len, &c, NULL, ZEND_FETCH_CLASS_SILENT TSRMLS_CC)) { zval_dtor(&c); RETURN_TRUE; @@ -794,16 +798,16 @@ 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; const char *name; zend_uint name_length; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &arg) == FAILURE) { return; } - if (!ZEND_NUM_ARGS()) { + if (!ZEND_NUM_ARGS() || arg == NULL) { ce = EG(scope); if (ce && ce->parent) { RETURN_STRINGL(ce->parent->name, ce->parent->name_length, 1); @@ -821,7 +825,7 @@ ZEND_FUNCTION(get_parent_class) } } else if (Z_TYPE_P(arg) == IS_STRING) { zend_class_entry **pce; - + if (zend_lookup_class(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &pce TSRMLS_CC) == SUCCESS) { ce = *pce; } @@ -850,7 +854,7 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) return; } /* - * allow_string - is_a default is no, is_subclass_of is yes. + * allow_string - is_a default is no, is_subclass_of is yes. * if it's allowed, then the autoloader will be called if the class does not exist. * default behaviour is different, as 'is_a' used to be used to test mixed return values * and there is no easy way to deprecate this. @@ -1067,7 +1071,7 @@ ZEND_FUNCTION(get_class_methods) zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { - if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) + if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) || (EG(scope) && (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) && zend_check_protected(mptr->common.scope, EG(scope))) @@ -1111,7 +1115,7 @@ ZEND_FUNCTION(get_class_methods) Checks if the class method exists */ ZEND_FUNCTION(method_exists) { - zval *klass; + zval *klass; char *method_name; int method_len; char *lcname; @@ -1138,18 +1142,18 @@ ZEND_FUNCTION(method_exists) } else { union _zend_function *func = NULL; - if (Z_TYPE_P(klass) == IS_OBJECT + if (Z_TYPE_P(klass) == IS_OBJECT && Z_OBJ_HT_P(klass)->get_method != NULL && (func = Z_OBJ_HT_P(klass)->get_method(&klass, method_name, method_len, NULL TSRMLS_CC)) != NULL ) { - if (func->type == ZEND_INTERNAL_FUNCTION + if (func->type == ZEND_INTERNAL_FUNCTION && (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0 ) { /* Returns true to the fake Closure's __invoke */ RETVAL_BOOL((func->common.scope == zend_ce_closure && (method_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) ? 1 : 0); - + efree(lcname); efree((char*)((zend_internal_function*)func)->function_name); efree(func); @@ -1205,7 +1209,7 @@ ZEND_FUNCTION(property_exists) ZVAL_STRINGL(&property_z, property, property_len, 0); if (Z_TYPE_P(object) == IS_OBJECT && - Z_OBJ_HANDLER_P(object, has_property) && + Z_OBJ_HANDLER_P(object, has_property) && Z_OBJ_HANDLER_P(object, has_property)(object, &property_z, 2, 0 TSRMLS_CC)) { RETURN_TRUE; } @@ -1243,7 +1247,7 @@ ZEND_FUNCTION(class_exists) name = &lc_name[1]; len--; } - + found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce); free_alloca(lc_name, use_heap); RETURN_BOOL(found == SUCCESS && !(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)); @@ -1275,10 +1279,10 @@ ZEND_FUNCTION(interface_exists) if (!autoload) { char *name; int len; - + lc_name = do_alloca(iface_name_len + 1, use_heap); zend_str_tolower_copy(lc_name, iface_name, iface_name_len); - + /* Ignore leading "\" */ name = lc_name; len = iface_name_len; @@ -1310,18 +1314,18 @@ ZEND_FUNCTION(trait_exists) int found; zend_bool autoload = 1; ALLOCA_FLAG(use_heap) - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &trait_name, &trait_name_len, &autoload) == FAILURE) { return; } - + if (!autoload) { char *name; int len; - + lc_name = do_alloca(trait_name_len + 1, use_heap); zend_str_tolower_copy(lc_name, trait_name, trait_name_len); - + /* Ignore leading "\" */ name = lc_name; len = trait_name_len; @@ -1329,12 +1333,12 @@ ZEND_FUNCTION(trait_exists) name = &lc_name[1]; len--; } - + found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce); free_alloca(lc_name, use_heap); RETURN_BOOL(found == SUCCESS && (((*ce)->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)); } - + if (zend_lookup_class(trait_name, trait_name_len, &ce TSRMLS_CC) == SUCCESS) { RETURN_BOOL(((*ce)->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); } else { @@ -1344,7 +1348,7 @@ ZEND_FUNCTION(trait_exists) /* }}} */ -/* {{{ proto bool function_exists(string function_name) +/* {{{ proto bool function_exists(string function_name) Checks if the function exists */ ZEND_FUNCTION(function_exists) { @@ -1353,13 +1357,13 @@ ZEND_FUNCTION(function_exists) zend_function *func; char *lcname; zend_bool retval; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } lcname = zend_str_tolower_dup(name, name_len); - + /* Ignore leading "\" */ name = lcname; if (lcname[0] == '\\') { @@ -1368,7 +1372,7 @@ ZEND_FUNCTION(function_exists) } retval = (zend_hash_find(EG(function_table), name, name_len+1, (void **)&func) == SUCCESS); - + efree(lcname); /* @@ -1402,7 +1406,7 @@ ZEND_FUNCTION(class_alias) found = zend_lookup_class_ex(class_name, class_name_len, NULL, autoload, &ce TSRMLS_CC); if (found == SUCCESS) { - if ((*ce)->type == ZEND_USER_CLASS) { + if ((*ce)->type == ZEND_USER_CLASS) { if (zend_register_class_alias_ex(alias_name, alias_name_len, *ce TSRMLS_CC) == SUCCESS) { RETURN_TRUE; } else { @@ -1944,7 +1948,7 @@ ZEND_FUNCTION(get_loaded_extensions) ZEND_FUNCTION(get_defined_constants) { zend_bool categorize = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &categorize) == FAILURE) { return; } @@ -2084,7 +2088,7 @@ ZEND_FUNCTION(debug_print_backtrace) const char *free_class_name = NULL; frameno++; - class_name = call_type = NULL; + class_name = call_type = NULL; arg_array = NULL; skip = ptr; @@ -2169,9 +2173,9 @@ ZEND_FUNCTION(debug_print_backtrace) function_name = "require_once"; break; default: - /* this can actually happen if you use debug_backtrace() in your error_handler and + /* this can actually happen if you use debug_backtrace() in your error_handler and * you're in the top-scope */ - function_name = "unknown"; + function_name = "unknown"; build_filename_arg = 0; break; } @@ -2203,7 +2207,7 @@ ZEND_FUNCTION(debug_print_backtrace) prev->function_state.function->common.type != ZEND_USER_FUNCTION) { prev = NULL; break; - } + } if (prev->op_array) { zend_printf(") called at [%s:%d]\n", prev->op_array->filename, prev->opline->lineno); break; @@ -2272,7 +2276,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int add_assoc_long_ex(stack_frame, "line", sizeof("line"), lineno); /* try to fetch args only if an FCALL was just made - elsewise we're in the middle of a function - * and debug_baktrace() might have been called by the error_handler. in this case we don't + * and debug_baktrace() might have been called by the error_handler. in this case we don't * want to pop anything of the argument-stack */ } else { zend_execute_data *prev = skip->prev_execute_data; @@ -2283,7 +2287,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int !(prev->function_state.function->common.type == ZEND_INTERNAL_FUNCTION && (prev->function_state.function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER))) { break; - } + } if (prev->op_array) { add_assoc_string_ex(stack_frame, "file", sizeof("file"), (char*)prev->op_array->filename, 1); add_assoc_long_ex(stack_frame, "line", sizeof("line"), prev->opline->lineno); @@ -2315,7 +2319,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC); add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)class_name, dup); - + } if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) { add_assoc_zval_ex(stack_frame, "object", sizeof("object"), ptr->object); @@ -2328,7 +2332,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int add_assoc_string_ex(stack_frame, "type", sizeof("type"), "::", 1); } - if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 && + if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 && ((! ptr->opline) || ((ptr->opline->opcode == ZEND_DO_FCALL_BY_NAME) || (ptr->opline->opcode == ZEND_DO_FCALL)))) { if (ptr->function_state.arguments) { add_assoc_zval_ex(stack_frame, "args", sizeof("args"), debug_backtrace_get_args(ptr->function_state.arguments TSRMLS_CC)); @@ -2361,9 +2365,9 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int function_name = "require_once"; break; default: - /* this can actually happen if you use debug_backtrace() in your error_handler and + /* this can actually happen if you use debug_backtrace() in your error_handler and * you're in the top-scope */ - function_name = "unknown"; + function_name = "unknown"; build_filename_arg = 0; break; } @@ -2387,7 +2391,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int add_next_index_zval(return_value, stack_frame); - include_filename = filename; + include_filename = filename; ptr = skip->prev_execute_data; } @@ -2401,7 +2405,7 @@ ZEND_FUNCTION(debug_backtrace) { long options = DEBUG_BACKTRACE_PROVIDE_OBJECT; long limit = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &options, &limit) == FAILURE) { return; } diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f250b2be20879..c2756ed6caef0 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ +/* $Id: zend_compile.c 323898 2012-03-04 19:34:19Z gron $ */ #include #include "zend.h" @@ -2649,6 +2649,37 @@ void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC) /* {{ } /* }}} */ +void zend_do_empty_param(int offset TSRMLS_DC) /* {{{ */ +{ + zend_op *opline; + zend_function **function_ptr_ptr, *function_ptr; + int send_by_reference; + int send_function = 0; + + zend_stack_top(&CG(function_call_stack), (void **) &function_ptr_ptr); + function_ptr = *function_ptr_ptr; + + if (function_ptr) { + /* by-ref check to not allow send defaults by-ref */ + if (ARG_SHOULD_BE_SENT_BY_REF(function_ptr, (zend_uint) offset)) { + zend_error(E_COMPILE_ERROR, "Cannot pass parameter %d by reference", offset); + return; + } + } + + opline = get_next_op(CG(active_op_array) TSRMLS_CC); + opline->opcode = ZEND_SEND_VAL; + SET_UNUSED(opline->op1); + opline->op2.opline_num = offset; + SET_UNUSED(opline->op2); + if (function_ptr) { + opline->extended_value = ZEND_DO_FCALL; + } else { + opline->extended_value = ZEND_DO_FCALL_BY_NAME; + } +} +/* }}} */ + static int generate_free_switch_expr(const zend_switch_entry *switch_entry TSRMLS_DC) /* {{{ */ { zend_op *opline; diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 048c1fc18495d..4ec64f8219248 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1630,8 +1630,8 @@ static zend_always_inline zend_execute_data *i_create_execute_data_from_op_array /* copy arguments */ *EX(prev_execute_data)->function_state.arguments = (void*)(zend_uintptr_t)args_count; if (args_count > 0) { - zval **arg_src = (zval**)zend_vm_stack_get_arg_ex(EG(current_execute_data), 1); - zval **arg_dst = (zval**)zend_vm_stack_get_arg_ex(EX(prev_execute_data), 1); + zval **arg_src = zend_vm_stack_get_args(EG(current_execute_data)); + zval **arg_dst = zend_vm_stack_get_args(EX(prev_execute_data)); int i; for (i = 0; i < args_count; i++) { diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h index ff0758772e48b..02271279cb47e 100644 --- a/Zend/zend_execute.h +++ b/Zend/zend_execute.h @@ -295,6 +295,7 @@ static zend_always_inline void zend_vm_stack_clear_multiple(int nested TSRMLS_DC while (p != end) { zval *q = (zval *) *(--p); *p = NULL; + if(UNEXPECTED(q == NULL)) continue; i_zval_ptr_dtor(q ZEND_FILE_LINE_CC); } if (nested) { @@ -310,7 +311,7 @@ static zend_always_inline int zend_vm_stack_get_args_count_ex(zend_execute_data void **p = ex->function_state.arguments; return (int)(zend_uintptr_t) *p; } else { - return 0; + return 0; } } @@ -318,13 +319,27 @@ static zend_always_inline zval** zend_vm_stack_get_arg_ex(zend_execute_data *ex, { void **p = ex->function_state.arguments; int arg_count = (int)(zend_uintptr_t) *p; + zval **arg; if (UNEXPECTED(requested_arg > arg_count)) { return NULL; } - return (zval**)p - arg_count + requested_arg - 1; + arg = (zval**)p - arg_count + requested_arg - 1; + if(UNEXPECTED(*arg == NULL)) { + return NULL; + } + return arg; } +static zend_always_inline zval** zend_vm_stack_get_args(zend_execute_data *ex) +{ + void **p = ex->function_state.arguments; + int arg_count = (int)(zend_uintptr_t) *p; + + return (zval**)p - arg_count; +} + + static zend_always_inline int zend_vm_stack_get_args_count(TSRMLS_D) { return zend_vm_stack_get_args_count_ex(EG(current_execute_data)->prev_execute_data); diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 0b29086a0d5d0..9ee30576e2a50 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -830,6 +830,11 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS for (i=0; iparam_count; i++) { zval *param; + if(UNEXPECTED(fci->params[i] == NULL)) { + zend_vm_stack_push(NULL TSRMLS_CC); + continue; + } + if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) { if (!PZVAL_IS_REF(*fci->params[i]) && Z_REFCOUNT_PP(fci->params[i]) > 1) { zval *new_zval; diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 6a9a24a87ea72..42e68295b2f14 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ +/* $Id: zend_language_parser.y 322378 2012-01-17 08:09:13Z dmitry $ */ /* * LALR shift/reduce conflicts and how they are resolved: @@ -87,7 +87,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %left '?' ':' %left T_BOOLEAN_OR %token T_BOOLEAN_OR "|| (T_BOOLEAN_OR)" -%left T_BOOLEAN_AND +%left T_BOOLEAN_AND %token T_BOOLEAN_AND "&& (T_BOOLEAN_AND)" %left '|' %left '^' @@ -126,9 +126,9 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %token T_IF "if (T_IF)" %left T_ELSEIF %token T_ELSEIF "elseif (T_ELSEIF)" -%left T_ELSE +%left T_ELSE %token T_ELSE "else (T_ELSE)" -%left T_ENDIF +%left T_ENDIF %token T_ENDIF "endif (T_ENDIF)" %token T_LNUMBER "integer number (T_LNUMBER)" %token T_DNUMBER "floating-point number (T_DNUMBER)" @@ -550,13 +550,15 @@ function_call_parameter_list: non_empty_function_call_parameter_list: - expr_without_variable { Z_LVAL($$.u.constant) = 1; zend_do_pass_param(&$1, ZEND_SEND_VAL, Z_LVAL($$.u.constant) TSRMLS_CC); } + expr_without_variable { Z_LVAL($$.u.constant) = 1; zend_do_pass_param(&$1, ZEND_SEND_VAL, Z_LVAL($$.u.constant) TSRMLS_CC); } | variable { Z_LVAL($$.u.constant) = 1; zend_do_pass_param(&$1, ZEND_SEND_VAR, Z_LVAL($$.u.constant) TSRMLS_CC); } - | '&' w_variable { Z_LVAL($$.u.constant) = 1; zend_do_pass_param(&$2, ZEND_SEND_REF, Z_LVAL($$.u.constant) TSRMLS_CC); } + | '&' w_variable { Z_LVAL($$.u.constant) = 1; zend_do_pass_param(&$2, ZEND_SEND_REF, Z_LVAL($$.u.constant) TSRMLS_CC); } + | T_DEFAULT { Z_LVAL($$.u.constant) = 1; zend_do_empty_param(Z_LVAL($$.u.constant) TSRMLS_CC); } | non_empty_function_call_parameter_list ',' expr_without_variable { Z_LVAL($$.u.constant)=Z_LVAL($1.u.constant)+1; zend_do_pass_param(&$3, ZEND_SEND_VAL, Z_LVAL($$.u.constant) TSRMLS_CC); } | non_empty_function_call_parameter_list ',' variable { Z_LVAL($$.u.constant)=Z_LVAL($1.u.constant)+1; zend_do_pass_param(&$3, ZEND_SEND_VAR, Z_LVAL($$.u.constant) TSRMLS_CC); } | non_empty_function_call_parameter_list ',' '&' w_variable { Z_LVAL($$.u.constant)=Z_LVAL($1.u.constant)+1; zend_do_pass_param(&$4, ZEND_SEND_REF, Z_LVAL($$.u.constant) TSRMLS_CC); } -; + | non_empty_function_call_parameter_list ',' T_DEFAULT { Z_LVAL($$.u.constant)=Z_LVAL($1.u.constant)+1; zend_do_empty_param(Z_LVAL($$.u.constant) TSRMLS_CC); } + ; global_var_list: global_var_list ',' global_var { zend_do_fetch_global_variable(&$3, NULL, ZEND_FETCH_GLOBAL_LOCK TSRMLS_CC); } @@ -1232,7 +1234,7 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr) char buffer[120]; const unsigned char *end, *str, *tok1 = NULL, *tok2 = NULL; unsigned int len = 0, toklen = 0, yystr_len; - + CG(parse_error) = 1; if (LANG_SCNG(yy_text)[0] == 0 && @@ -1241,11 +1243,11 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr) yystpcpy(yyres, "end of file"); return sizeof("end of file")-1; } - + str = LANG_SCNG(yy_text); end = memchr(str, '\n', LANG_SCNG(yy_leng)); yystr_len = yystrlen(yystr); - + if ((tok1 = memchr(yystr, '(', yystr_len)) != NULL && (tok2 = zend_memrchr(yystr, ')', yystr_len)) != NULL) { toklen = (tok2 - tok1) + 1; @@ -1253,7 +1255,7 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr) tok1 = tok2 = NULL; toklen = 0; } - + if (end == NULL) { len = LANG_SCNG(yy_leng) > 30 ? 30 : LANG_SCNG(yy_leng); } else { @@ -1266,8 +1268,8 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr) } yystpcpy(yyres, buffer); return len + (toklen ? toklen + 1 : 0) + 2; - } - } + } + } if (*yystr == '"') { YYSIZE_T yyn = 0; const char *yyp = yystr; diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 2bc80faa4e841..f8150b9021cde 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3051,7 +3051,7 @@ 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 @@ -3060,7 +3060,9 @@ ZEND_VM_HANDLER(65, ZEND_SEND_VAL, CONST|TMP, ANY) && ARG_MUST_BE_SENT_BY_REF(EX(call)->fbc, opline->op2.opline_num)) { zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.opline_num); } - { + if(OP1_TYPE == IS_UNUSED) { + zend_vm_stack_push(NULL TSRMLS_CC); + } else { zval *valptr; zval *value; zend_free_op free_op1; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 08fb84738298d..e9088b70c6fdc 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2486,7 +2486,9 @@ static int ZEND_FASTCALL ZEND_SEND_VAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A && ARG_MUST_BE_SENT_BY_REF(EX(call)->fbc, opline->op2.opline_num)) { zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.opline_num); } - { + if(IS_CONST == IS_UNUSED) { + zend_vm_stack_push(NULL TSRMLS_CC); + } else { zval *valptr; zval *value; @@ -7814,7 +7816,9 @@ static int ZEND_FASTCALL ZEND_SEND_VAL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG && ARG_MUST_BE_SENT_BY_REF(EX(call)->fbc, opline->op2.opline_num)) { zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.opline_num); } - { + if(IS_TMP_VAR == IS_UNUSED) { + zend_vm_stack_push(NULL TSRMLS_CC); + } else { zval *valptr; zval *value; zend_free_op free_op1; @@ -24267,6 +24271,36 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ARG ZEND_VM_RETURN(); } +static int ZEND_FASTCALL ZEND_SEND_VAL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + + SAVE_OPLINE(); + if (opline->extended_value==ZEND_DO_FCALL_BY_NAME + && ARG_MUST_BE_SENT_BY_REF(EX(call)->fbc, opline->op2.opline_num)) { + zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.opline_num); + } + if(IS_UNUSED == IS_UNUSED) { + zend_vm_stack_push(NULL TSRMLS_CC); + } else { + zval *valptr; + zval *value; + + + value = NULL; + + ALLOC_ZVAL(valptr); + INIT_PZVAL_COPY(valptr, value); + if (!0) { + zval_copy_ctor(valptr); + } + zend_vm_stack_push(valptr TSRMLS_CC); + + } + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); +} + static int ZEND_FASTCALL ZEND_CLONE_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE @@ -42635,11 +42669,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, diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index c5fbce94dde5c..736d2255f2fc1 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -206,18 +206,15 @@ static void php_str2num(bc_num *num, char *str TSRMLS_DC) PHP_FUNCTION(bcadd) { char *left, *right; - long scale_param = 0; - bc_num first, second, result; int left_len, right_len; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + long scale_param = BCG(bc_precision); + bc_num first, second, result; + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); @@ -246,17 +243,14 @@ PHP_FUNCTION(bcsub) { char *left, *right; int left_len, right_len; - long scale_param = 0; + long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); @@ -285,17 +279,14 @@ PHP_FUNCTION(bcmul) { char *left, *right; int left_len, right_len; - long scale_param = 0; + long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); @@ -324,17 +315,14 @@ PHP_FUNCTION(bcdiv) { char *left, *right; int left_len, right_len; - long scale_param = 0; + long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); @@ -412,6 +400,7 @@ PHP_FUNCTION(bcpowmod) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); @@ -421,8 +410,6 @@ PHP_FUNCTION(bcpowmod) php_str2num(&second, right TSRMLS_CC); php_str2num(&mod, modulous TSRMLS_CC); - scale_int = (int) ((int)scale < 0) ? 0 : scale; - if (bc_raisemod(first, second, mod, &result, scale_int TSRMLS_CC) != -1) { if (result->n_scale > scale) { result->n_scale = scale; @@ -448,17 +435,14 @@ PHP_FUNCTION(bcpow) { char *left, *right; int left_len, right_len; - long scale_param = 0; + long scale_param = BCG(bc_precision); bc_num first, second, result; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); @@ -487,17 +471,14 @@ PHP_FUNCTION(bcsqrt) { char *left; int left_len; - long scale_param = 0; - bc_num result; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + long scale_param = BCG(bc_precision); + bc_num first, second, result; + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "s|l", &left, &left_len, &scale_param) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC); php_str2num(&result, left TSRMLS_CC); @@ -524,17 +505,14 @@ PHP_FUNCTION(bccomp) { char *left, *right; int left_len, right_len; - long scale_param = 0; - bc_num first, second; - int scale = BCG(bc_precision), argc = ZEND_NUM_ARGS(); + long scale_param = BCG(bc_precision); + bc_num first, second, result; + int scale; - if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC); bc_init_num(&second TSRMLS_CC); diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index 4adaa47fa9873..fe65fbc4707a6 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -15,7 +15,7 @@ | Author: Sterling Hughes | +----------------------------------------------------------------------+ */ - + /* $Id$ */ #ifdef HAVE_CONFIG_H @@ -138,7 +138,7 @@ static size_t php_bz2iop_read(php_stream *stream, char *buf, size_t count TSRMLS { struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract; size_t ret; - + ret = BZ2_bzread(self->bz_file, buf, count); if (ret == 0) { @@ -152,14 +152,14 @@ static size_t php_bz2iop_write(php_stream *stream, const char *buf, size_t count { struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract; - return BZ2_bzwrite(self->bz_file, (char*)buf, count); + return BZ2_bzwrite(self->bz_file, (char*)buf, count); } static int php_bz2iop_close(php_stream *stream, int close_handle TSRMLS_DC) { struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *)stream->abstract; int ret = EOF; - + if (close_handle) { BZ2_bzclose(self->bz_file); } @@ -195,7 +195,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, const char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC) { struct php_bz2_stream_data_t *self; - + self = emalloc(sizeof(*self)); self->stream = innerstream; @@ -226,12 +226,12 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, virtual_filepath_ex(path, &path_copy, NULL TSRMLS_CC); #else path_copy = path; -#endif +#endif if (php_check_open_basedir(path_copy TSRMLS_CC)) { return NULL; } - + /* try and open it directly first */ bz_file = BZ2_bzopen(path_copy, mode); @@ -239,11 +239,11 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, *opened_path = estrdup(path_copy); } path_copy = NULL; - + if (bz_file == NULL) { /* that didn't work, so try and get something from the network/wrapper */ stream = php_stream_open_wrapper(path, mode, options | STREAM_WILL_CAST, opened_path); - + if (stream) { int fd; if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) { @@ -258,7 +258,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, VCWD_UNLINK(*opened_path); } } - + if (bz_file) { retstream = _php_stream_bz2open_from_BZFILE(bz_file, mode, stream STREAMS_REL_CC TSRMLS_CC); if (retstream) { @@ -334,7 +334,7 @@ static PHP_FUNCTION(bzread) if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &bz, &len)) { RETURN_FALSE; } - + php_stream_from_zval(stream, &bz); if ((len + 1) < 1) { @@ -344,13 +344,13 @@ static PHP_FUNCTION(bzread) Z_STRVAL_P(return_value) = emalloc(len + 1); Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len); - + if (Z_STRLEN_P(return_value) < 0) { efree(Z_STRVAL_P(return_value)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read valid bz2 data from stream"); - RETURN_FALSE; + RETURN_FALSE; } - + Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; Z_TYPE_P(return_value) = IS_STRING; } @@ -366,7 +366,7 @@ static PHP_FUNCTION(bzopen) BZFILE *bz; /* The compressed file stream */ php_stream *stream = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &file, &mode, &mode_len) == FAILURE) { return; } @@ -382,15 +382,15 @@ static PHP_FUNCTION(bzopen) php_error_docref(NULL TSRMLS_CC, E_WARNING, "filename cannot be empty"); RETURN_FALSE; } - + if (CHECK_ZVAL_NULL_PATH(*file)) { RETURN_FALSE; } stream = php_stream_bz2open(NULL, - Z_STRVAL_PP(file), - mode, - REPORT_ERRORS, + Z_STRVAL_PP(file), + mode, + REPORT_ERRORS, NULL); } else if (Z_TYPE_PP(file) == IS_RESOURCE) { /* If it is a resource, than its a stream resource */ @@ -399,7 +399,7 @@ static PHP_FUNCTION(bzopen) php_stream_from_zval(stream, file); stream_mode_len = strlen(stream->mode); - + if (stream_mode_len != 1 && !(stream_mode_len == 2 && memchr(stream->mode, 'b', 2))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode); RETURN_FALSE; @@ -433,7 +433,7 @@ static PHP_FUNCTION(bzopen) if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_FD, (void *) &fd, REPORT_ERRORS)) { RETURN_FALSE; } - + bz = BZ2_bzdopen(fd, mode); stream = php_stream_bz2open_from_BZFILE(bz, mode, stream); @@ -479,39 +479,31 @@ static PHP_FUNCTION(bzerror) static PHP_FUNCTION(bzcompress) { char *source; /* Source data to compress */ - long zblock_size = 0; /* Optional block size to use */ + long zblock_size = 4; /* Optional block size to use */ long zwork_factor = 0;/* Optional work factor to use */ char *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 */ + work_factor = 0; /* Work factor for compression algorithm */ int source_len; /* Length of the source data */ - unsigned int dest_len; /* Length of the destination buffer */ - - argc = ZEND_NUM_ARGS(); + unsigned int dest_len; /* Length of the destination buffer */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &source, &source_len, &zblock_size, &zwork_factor) == FAILURE) { return; } /* Assign them to easy to use variables, dest_len is initially the length of the data - + .01 x length of data + 600 which is the largest size the results of the compression - could possibly be, at least that's what the libbz2 docs say (thanks to jeremy@nirvani.net + + .01 x length of data + 600 which is the largest size the results of the compression + could possibly be, at least that's what the libbz2 docs say (thanks to jeremy@nirvani.net for pointing this out). */ dest_len = (unsigned int) (source_len + (0.01 * source_len) + 600); - + /* Allocate the destination buffer */ dest = emalloc(dest_len + 1); - + /* 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, &dest_len, source, source_len, block_size, 0, work_factor); if (error != BZ_OK) { @@ -558,7 +550,7 @@ static PHP_FUNCTION(bzdecompress) /* in most cases bz2 offers at least 2:1 compression, so we use that as our base */ bzs.avail_out = source_len * 2; bzs.next_out = dest = emalloc(bzs.avail_out + 1); - + while ((error = BZ2_bzDecompress(&bzs)) == BZ_OK && bzs.avail_in > 0) { /* compression is better then 2:1, need to allocate more memory */ bzs.avail_out = source_len; @@ -584,13 +576,13 @@ static PHP_FUNCTION(bzdecompress) /* {{{ php_bz2_error() The central error handling interface, does the work for bzerrno, bzerrstr and bzerror */ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt) -{ +{ zval *bzp; /* BZip2 Resource Pointer */ php_stream *stream; const char *errstr; /* Error string */ int errnum; /* Error number */ struct php_bz2_stream_data_t *self; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &bzp) == FAILURE) { return; } @@ -602,10 +594,10 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt) } self = (struct php_bz2_stream_data_t *) stream->abstract; - + /* Fetch the error information */ errstr = BZ2_bzerror(self->bz_file, &errnum); - + /* Determine what to return */ switch (opt) { case PHP_BZ_ERRNO: @@ -616,7 +608,7 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt) break; case PHP_BZ_ERRBOTH: array_init(return_value); - + add_assoc_long (return_value, "errno", errnum); add_assoc_string(return_value, "errstr", (char*)errstr, 1); break; diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 95c68f1a78ca6..c373dd341ee7b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1203,12 +1203,10 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime) long ts; char *string; + ts = (long)time(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &format, &format_len, &ts) == FAILURE) { RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 1) { - ts = time(NULL); - } string = php_format_date(format, format_len, ts, localtime TSRMLS_CC); @@ -1362,6 +1360,7 @@ PHP_FUNCTION(idate) long ts = 0; int ret; + ts = (long)time(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &format, &format_len, &ts) == FAILURE) { RETURN_FALSE; } @@ -1371,10 +1370,6 @@ PHP_FUNCTION(idate) RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 1) { - ts = time(NULL); - } - ret = php_idate(format[0], ts, 0 TSRMLS_CC); if (ret == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unrecognized date format token."); @@ -1447,7 +1442,7 @@ PHP_FUNCTION(strtotime) timelib_unixtime2local(now, t->sse); timelib_time_dtor(t); efree(initial_ts); - } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", ×, &time_len, &preset_ts) != FAILURE) { + } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "s|l", ×, &time_len, &preset_ts) != FAILURE) { /* We have no initial timestamp */ now = timelib_time_ctor(); now->tz_info = tzi; @@ -1489,7 +1484,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) long ts, adjust_seconds = 0; int error; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lllllll", &hou, &min, &sec, &mon, &day, &yea, &dst) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "|lllllll", &hou, &min, &sec, &mon, &day, &yea, &dst) == FAILURE) { RETURN_FALSE; } /* Initialize structure with current time */ @@ -4606,40 +4601,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; - long time, retformat = 0; + long time, retformat = SUNFUNCS_RET_STRING; int rs; timelib_time *t; timelib_tzinfo *tzi; char *retstr; + if (calc_sunset) { + zenith = INI_FLT("date.sunset_zenith"); + } else { + zenith = INI_FLT("date.sunrise_zenith"); + } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC, 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 8005101de34b1..9b33463940219 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -28,12 +28,12 @@ #if HAVE_DBA #include "php_ini.h" -#include +#include #include #ifdef HAVE_SYS_FILE_H #include #endif - + #include "php_dba.h" #include "ext/standard/info.h" #include "ext/standard/php_string.h" @@ -157,7 +157,7 @@ PHP_MINFO_FUNCTION(dba); ZEND_BEGIN_MODULE_GLOBALS(dba) char *default_handler; dba_handler *default_hptr; -ZEND_END_MODULE_GLOBALS(dba) +ZEND_END_MODULE_GLOBALS(dba) ZEND_DECLARE_MODULE_GLOBALS(dba) @@ -165,15 +165,15 @@ ZEND_DECLARE_MODULE_GLOBALS(dba) #define DBA_G(v) TSRMG(dba_globals_id, zend_dba_globals *, v) #else #define DBA_G(v) (dba_globals.v) -#endif +#endif static PHP_GINIT_FUNCTION(dba); zend_module_entry dba_module_entry = { STANDARD_MODULE_HEADER, "dba", - dba_functions, - PHP_MINIT(dba), + dba_functions, + PHP_MINIT(dba), PHP_MSHUTDOWN(dba), NULL, NULL, @@ -206,7 +206,7 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS zval **group, **name; HashPosition pos; size_t len; - + if (zend_hash_num_elements(Z_ARRVAL_P(key)) != 2) { php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Key does not have exactly two elements: (key, name)"); return -1; @@ -393,8 +393,8 @@ PHPAPI dba_handler *dba_get_handler(const char* handler_name) */ /* }}} */ -/* {{{ dba_close - */ +/* {{{ dba_close + */ static void dba_close(dba_info *info TSRMLS_DC) { if (info->hnd) { @@ -428,7 +428,7 @@ static void dba_close(dba_info *info TSRMLS_DC) */ static void dba_close_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) { - dba_info *info = (dba_info *)rsrc->ptr; + dba_info *info = (dba_info *)rsrc->ptr; dba_close(info TSRMLS_CC); } @@ -444,7 +444,7 @@ int dba_close_pe_rsrc_deleter(zend_rsrc_list_entry *le, void *pDba TSRMLS_DC) /* {{{ dba_close_pe_rsrc */ static void dba_close_pe_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) { - dba_info *info = (dba_info *)rsrc->ptr; + dba_info *info = (dba_info *)rsrc->ptr; /* closes the resource by calling dba_close_rsrc() */ zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) dba_close_pe_rsrc_deleter, info TSRMLS_CC); @@ -476,7 +476,7 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("dba.default_handler", DBA_DEFAULT, PHP_INI_ALL, OnUpdateDefaultHandler, default_handler, zend_dba_globals, dba_globals) PHP_INI_END() /* }}} */ - + /* {{{ PHP_GINIT_FUNCTION */ static PHP_GINIT_FUNCTION(dba) @@ -541,13 +541,12 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) int 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 TSRMLS_CC, "zsr", &key, &val, &val_len, &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsr", &key, &val, &val_len, &id) == FAILURE) { return; } @@ -613,18 +612,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) char mode[4], *pmode, *lock_file_mode = NULL; int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0; char *opened_path, *lock_name; - + if(ac < 2) { WRONG_PARAM_COUNT; } - + /* we pass additional args to the respective handler */ args = safe_emalloc(ac, sizeof(zval *), 0); - if (zend_get_parameters_array_ex(ac, args) != SUCCESS) { + if (zend_get_parameters_array_nodefault(ac, args TSRMLS_CC) != SUCCESS) { FREENOW; WRONG_PARAM_COUNT; } - + /* we only take string arguments */ for (i = 0; i < ac; i++) { convert_to_string_ex(args[i]); @@ -633,12 +632,12 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (persistent) { zend_rsrc_list_entry *le; - + /* calculate hash */ key = safe_emalloc(keylen, 1, 1); key[keylen] = '\0'; keylen = 0; - + for(i = 0; i < ac; i++) { memcpy(key+keylen, Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i])); keylen += Z_STRLEN_PP(args[i]); @@ -647,18 +646,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* try to find if we already have this link in our persistent list */ if (zend_hash_find(&EG(persistent_list), key, keylen+1, (void **) &le) == SUCCESS) { FREENOW; - + if (Z_TYPE_P(le) != le_pdb) { RETURN_FALSE; } - + info = (dba_info *)le->ptr; ZEND_REGISTER_RESOURCE(return_value, info, le_pdb); return; } } - + if (ac==2) { hptr = DBA_G(default_hptr); if (!hptr) { @@ -720,18 +719,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) lock_dbf = 1; } switch (*pmode++) { - case 'r': - modenr = DBA_READER; + case 'r': + modenr = DBA_READER; lock_mode = (lock_flag & DBA_LOCK_READER) ? LOCK_SH : 0; file_mode = "r"; break; - case 'w': - modenr = DBA_WRITER; + case 'w': + modenr = DBA_WRITER; lock_mode = (lock_flag & DBA_LOCK_WRITER) ? LOCK_EX : 0; file_mode = "r+b"; break; - case 'c': - modenr = DBA_CREAT; + case 'c': + modenr = DBA_CREAT; lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0; if (lock_mode) { if (lock_dbf) { @@ -747,7 +746,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) } else { file_mode = "a+b"; } - /* In case of the 'a+b' append mode, the handler is responsible + /* In case of the 'a+b' append mode, the handler is responsible * to handle any rewind problems (see flatfile handler). */ break; @@ -793,7 +792,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) FREENOW; RETURN_FALSE; } - + info = pemalloc(sizeof(dba_info), persistent); memset(info, 0, sizeof(dba_info)); info->path = pestrdup(Z_STRVAL_PP(args[0]), persistent); @@ -902,7 +901,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) fcntl(info->fd, F_SETFL, flags & ~O_APPEND); #endif } - + } } @@ -999,11 +998,11 @@ PHP_FUNCTION(dba_fetch) skip = 0; } } else if (!strcmp(info->hnd->name, "inifile")) { - /* "-1" is compareable to 0 but allows a non restrictive + /* "-1" is compareable to 0 but allows a non restrictive * access which is fater. For example 'inifile' uses this * to allow faster access when the key was already found * using firstkey/nextkey. However explicitly setting the - * value to 0 ensures the first value. + * value to 0 ensures the first value. */ if (skip < -1) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s accepts only skip value -1 and greater, using skip=0", info->hnd->name); @@ -1011,15 +1010,15 @@ PHP_FUNCTION(dba_fetch) } } else { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s does not support optional skip parameter, the value will be ignored", info->hnd->name); - skip = 0; + skip = 0; } } else { - skip = 0; + skip = 0; } if((val = info->hnd->fetch(info, key_str, key_len, skip, &len TSRMLS_CC)) != NULL) { DBA_ID_DONE; RETURN_STRINGL(val, len, 0); - } + } DBA_ID_DONE; RETURN_FALSE; } @@ -1109,9 +1108,9 @@ PHP_FUNCTION(dba_nextkey) PHP_FUNCTION(dba_delete) { DBA_ID_GET2; - + DBA_WRITE_CHECK; - + if(info->hnd->delete(info, key_str, key_len TSRMLS_CC) == SUCCESS) { DBA_ID_DONE; @@ -1123,7 +1122,7 @@ PHP_FUNCTION(dba_delete) /* }}} */ /* {{{ proto bool dba_insert(string key, string value, resource handle) - If not inifile: Insert value as key, return false, if key exists already + If not inifile: Insert value as key, return false, if key exists already If inifile: Add vakue as key (next instance of key) */ PHP_FUNCTION(dba_insert) { diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c index 98b5c9fd87904..3b08be4358635 100644 --- a/ext/enchant/enchant.c +++ b/ext/enchant/enchant.c @@ -432,7 +432,7 @@ PHP_FUNCTION(enchant_broker_set_dict_path) if (!value_len) { RETURN_FALSE; } - + PHP_ENCHANT_GET_BROKER; switch (dict_type) { @@ -467,7 +467,7 @@ PHP_FUNCTION(enchant_broker_get_dict_path) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &broker, &dict_type) == FAILURE) { RETURN_FALSE; } - + PHP_ENCHANT_GET_BROKER; switch (dict_type) { @@ -542,7 +542,7 @@ PHP_FUNCTION(enchant_broker_request_dict) } PHP_ENCHANT_GET_BROKER; - + if (taglen == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tag cannot be empty"); RETURN_FALSE; @@ -740,7 +740,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 76f5c1b765866..1dc0fe7110ed0 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) @@ -204,7 +204,7 @@ static int _php_regcomp(regex_t *preg, const char *pattern, int cflags TSRMLS_DC } /* }}} */ -static void _free_ereg_cache(reg_cache *rc) +static void _free_ereg_cache(reg_cache *rc) { regfree(&rc->preg); } @@ -300,17 +300,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 TSRMLS_CC, "Zs|Z", ®ex, &findin, &findin_len, &array) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs|Z", ®ex, &findin, &findin_len, &array) == FAILURE) { return; } if (icase) { copts |= REG_ICASE; } - - if (argc == 2) { + + if (array == NULL) { copts |= REG_NOSUB; } @@ -337,7 +336,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) { @@ -455,7 +454,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 */ @@ -491,7 +490,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; @@ -556,7 +555,7 @@ static void php_do_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase) char *replace; char *ret; int arg_string_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZs", &arg_pattern, &arg_replace, &arg_string, &arg_string_len) == FAILURE) { return; } @@ -664,9 +663,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 TSRMLS_CC, E_WARNING, "Invalid Regular Expression"); - + zend_hash_destroy(Z_ARRVAL_P(return_value)); efree(Z_ARRVAL_P(return_value)); RETURN_FALSE; @@ -675,7 +674,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, 1); @@ -701,7 +700,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, 1); regfree(&re); @@ -738,9 +737,9 @@ PHP_EREG_API PHP_FUNCTION(sql_regcase) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 d8a90f5fb6a57..442e17f037d4a 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1737,7 +1737,7 @@ PHP_FUNCTION(imagefilledarc) long cx, cy, w, h, ST, E, col, style; gdImagePtr im; int e, st; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) { return; } @@ -1978,7 +1978,7 @@ PHP_FUNCTION(imagegrabwindow) if ( handle == 0 ) { goto clean; } - pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow"); + pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow"); if ( pPrintWindow ) { pPrintWindow(window, memDC, (UINT) client_area); @@ -2550,35 +2550,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; - long quality = 0, type = 0; + long quality = -1, type = 1; gdImagePtr im; char *fn = NULL; FILE *fp; - int file_len = 0, argc = ZEND_NUM_ARGS(); + int file_len = 0; 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 TSRMLS_CC, "r|pll", &imgind, &file, &file_len, &quality, &type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 +3264,7 @@ PHP_FUNCTION(imagecolorstotal) PHP_FUNCTION(imagecolortransparent) { zval *IM; - long COL = 0; + long COL = -1; gdImagePtr im; int argc = ZEND_NUM_ARGS(); @@ -3297,7 +3288,7 @@ PHP_FUNCTION(imageinterlace) { zval *IM; int argc = ZEND_NUM_ARGS(); - long INT = 0; + long INT = 1; gdImagePtr im; if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &INT) == FAILURE) { @@ -3835,7 +3826,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int if (zend_hash_get_current_data_ex(HASH_OF(EXT), (void **) &item, &pos) == FAILURE) { continue; } - + if (strcmp("linespacing", key) == 0) { convert_to_double_ex(item); strex.flags |= gdFTEX_LINESPACE; @@ -4254,11 +4245,11 @@ PHP_FUNCTION(imagepsbbox) if (argc != 3 && argc != 6) { ZEND_WRONG_PARAM_COUNT(); } - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) { + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) { return; } - + if (argc == 6) { space = sp; add_width = wd; @@ -4433,8 +4424,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type ) int int_threshold; int x, y; float x_ratio, y_ratio; - long ignore_warning; - + long ignore_warning; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pplll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) { return; } diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c index 2a0b500e9eec6..0ae8a0282de47 100644 --- a/ext/gd/gd_ctx.c +++ b/ext/gd/gd_ctx.c @@ -79,9 +79,8 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, zval *imgind; char *file = NULL; int file_len = 0; - long quality, basefilter; + long quality = -1, basefilter = -1; gdImagePtr im; - int argc = ZEND_NUM_ARGS(); int q = -1, i; int f = -1; gdIOCtx *ctx = NULL; @@ -109,15 +108,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 117221484e363..8f63e2bdcb89c 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -333,13 +333,13 @@ Initialize a hashing context */ PHP_FUNCTION(hash_init) { char *algo, *key = NULL; - int algo_len, key_len = 0, argc = ZEND_NUM_ARGS(); + int algo_len, key_len = 0; long options = 0; void *context; const php_hash_ops *ops; php_hash_data *hash; - if (zend_parse_parameters(argc TSRMLS_CC, "s|ls", &algo, &algo_len, &options, &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &algo, &algo_len, &options, &key, &key_len) == FAILURE) { return; } diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index ba893ea9e607a..0490fe3f256dd 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -1993,8 +1993,8 @@ PHP_FUNCTION(iconv_substr) char *charset = ICONVG(internal_encoding); int charset_len = 0; char *str; - int str_len; - long offset, length = 0; + int str_len; + long offset, length = LONG_MAX; php_iconv_err_t err; @@ -2011,8 +2011,8 @@ PHP_FUNCTION(iconv_substr) RETURN_FALSE; } - if (ZEND_NUM_ARGS() < 3) { - length = str_len; + if (length == LONG_MAX) { + length = str_len; } err = _php_iconv_substr(&retval, str, str_len, offset, length, charset); diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index d697fa79116b8..946458e2c3e7c 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -1721,7 +1721,7 @@ PHP_FUNCTION(imap_body) PHP_FUNCTION(imap_mail_copy) { zval *streamind; - long options = 0; + long options = NIL; char *seq, *folder; int seq_len, folder_len, argc = ZEND_NUM_ARGS(); pils *imap_le_struct; @@ -1994,10 +1994,9 @@ PHP_FUNCTION(imap_delete) { zval *streamind, **sequence; pils *imap_le_struct; - long flags = 0; - int argc = ZEND_NUM_ARGS(); + long flags = NIL; - if (zend_parse_parameters(argc TSRMLS_CC, "rZ|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ|l", &streamind, &sequence, &flags) == FAILURE) { return; } @@ -2005,7 +2004,7 @@ PHP_FUNCTION(imap_delete) convert_to_string_ex(sequence); - mail_setflag_full(imap_le_struct->imap_stream, Z_STRVAL_PP(sequence), "\\DELETED", (argc == 3 ? flags : NIL)); + mail_setflag_full(imap_le_struct->imap_stream, Z_STRVAL_PP(sequence), "\\DELETED", flags); RETVAL_TRUE; } /* }}} */ @@ -2015,11 +2014,10 @@ PHP_FUNCTION(imap_delete) PHP_FUNCTION(imap_undelete) { zval *streamind, **sequence; - long flags = 0; + long flags = NIL; pils *imap_le_struct; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rZ|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ|l", &streamind, &sequence, &flags) == FAILURE) { return; } @@ -2027,7 +2025,7 @@ PHP_FUNCTION(imap_undelete) convert_to_string_ex(sequence); - mail_clearflag_full(imap_le_struct->imap_stream, Z_STRVAL_PP(sequence), "\\DELETED", (argc == 3 ? flags : NIL)); + mail_clearflag_full(imap_le_struct->imap_stream, Z_STRVAL_PP(sequence), "\\DELETED", flags); RETVAL_TRUE; } /* }}} */ @@ -2039,7 +2037,7 @@ PHP_FUNCTION(imap_headerinfo) zval *streamind; char *defaulthost = NULL; int defaulthost_len = 0, argc = ZEND_NUM_ARGS(); - long msgno, fromlength, subjectlength; + long msgno, fromlength = 0, subjectlength = 0; pils *imap_le_struct; MESSAGECACHE *cache; ENVELOPE *en; @@ -2056,16 +2054,12 @@ PHP_FUNCTION(imap_headerinfo) php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "Subject length has to be between 0 and %d", MAILTMPLEN); RETURN_FALSE; } - } else { - subjectlength = 0x00; } PHP_IMAP_CHECK_MSGNO(msgno); @@ -2121,13 +2115,13 @@ PHP_FUNCTION(imap_rfc822_parse_headers) { char *headers, *defaulthost = NULL; ENVELOPE *en; - int headers_len, defaulthost_len = 0, argc = ZEND_NUM_ARGS(); + int headers_len, defaulthost_len = 0; - if (zend_parse_parameters(argc TSRMLS_CC, "s|s", &headers, &headers_len, &defaulthost, &defaulthost_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &headers, &headers_len, &defaulthost, &defaulthost_len) == FAILURE) { return; } - if (argc == 2) { + if (defaulthost != NULL) { rfc822_parse_msg(&en, NULL, headers, headers_len, NULL, defaulthost, NIL); } else { rfc822_parse_msg(&en, NULL, headers, headers_len, NULL, "UNKNOWN", NIL); @@ -3069,17 +3063,16 @@ PHP_FUNCTION(imap_clearflag_full) zval *streamind; char *sequence, *flag; int sequence_len, flag_len; - long flags = 0; + long flags = NIL; pils *imap_le_struct; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rss|l", &streamind, &sequence, &sequence_len, &flag, &flag_len, &flags) ==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|l", &streamind, &sequence, &sequence_len, &flag, &flag_len, &flags) ==FAILURE) { return; } ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap); - mail_clearflag_full(imap_le_struct->imap_stream, sequence, flag, (argc == 4 ? flags : NIL)); + mail_clearflag_full(imap_le_struct->imap_stream, sequence, flag, flags); RETURN_TRUE; } /* }}} */ @@ -3391,9 +3384,8 @@ PHP_FUNCTION(imap_fetch_overview) zval *myoverview; char *address; long status, flags = 0L; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rs|l", &streamind, &sequence, &sequence_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &streamind, &sequence, &sequence_len, &flags) == FAILURE) { return; } @@ -4046,9 +4038,9 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * PHP_FUNCTION(imap_mail) { char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *cc=NULL, *bcc=NULL, *rpath=NULL; - int to_len, message_len, headers_len, subject_len, cc_len, bcc_len, rpath_len, argc = ZEND_NUM_ARGS(); + int to_len, message_len, headers_len, subject_len, cc_len, bcc_len, rpath_len; - if (zend_parse_parameters(argc TSRMLS_CC, "sss|ssss", &to, &to_len, &subject, &subject_len, &message, &message_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|ssss", &to, &to_len, &subject, &subject_len, &message, &message_len, &headers, &headers_len, &cc, &cc_len, &bcc, &bcc_len, &rpath, &rpath_len) == FAILURE) { return; } @@ -4091,10 +4083,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 TSRMLS_CC, "rs|ls", &streamind, &criteria, &criteria_len, &flags, &charset, &charset_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ls", &streamind, &criteria, &criteria_len, &flags, &charset, &charset_len) == FAILURE) { return; } @@ -4105,7 +4096,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 : NIL), pgm, flags); + mail_search_full(imap_le_struct->imap_stream, (charset != NULL ? charset : NIL), pgm, flags); if (pgm && !(flags & SE_FREE)) { mail_free_searchpgm(&pgm); @@ -4712,10 +4703,9 @@ PHP_FUNCTION(imap_thread) long flags = SE_FREE; char criteria[] = "ALL"; THREADNODE *top; - int argc = ZEND_NUM_ARGS(); SEARCHPGM *pgm = NIL; - if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &streamind, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &streamind, &flags) == FAILURE) { return; } diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c index 9d9d2f807d176..a6f8f35cb5bf8 100644 --- a/ext/interbase/ibase_blobs.c +++ b/ext/interbase/ibase_blobs.c @@ -50,7 +50,7 @@ static void _php_ibase_free_blob(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ void php_ibase_blobs_minit(INIT_FUNC_ARGS) /* {{{ */ { - le_blob = zend_register_list_destructors_ex(_php_ibase_free_blob, NULL, + le_blob = zend_register_list_destructors_ex(_php_ibase_free_blob, NULL, "interbase blob", module_number); } /* }}} */ @@ -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 TSRMLS_DC) /* {{{ */ +int _php_ibase_blob_add(const char *str, int str_len, ibase_blob *ib_blob TSRMLS_DC) /* {{{ */ { unsigned long put_cnt = 0, rem_cnt; unsigned short chunk_size; - convert_to_string_ex(string_arg); - - for (rem_cnt = Z_STRLEN_PP(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_PP(string_arg)[put_cnt] )) { + if (isc_put_segment(IB_STATUS, &ib_blob->bl_handle, chunk_size, &str[put_cnt] )) { _php_ibase_error(TSRMLS_C); return FAILURE; } @@ -293,23 +291,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; + int 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" TSRMLS_CC); RETURN_FALSE; } - if (_php_ibase_blob_add(string_arg, ib_blob TSRMLS_CC) != SUCCESS) { + if (_php_ibase_blob_add(str, str_len, ib_blob TSRMLS_CC) != SUCCESS) { RETURN_FALSE; } } @@ -319,25 +319,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; + 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() TSRMLS_CC, "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" TSRMLS_CC); RETURN_FALSE; } - convert_to_long_ex(len_arg); - - if (_php_ibase_blob_get(return_value, ib_blob, Z_LVAL_PP(len_arg) TSRMLS_CC) != SUCCESS) { + if (_php_ibase_blob_get(return_value, ib_blob, len TSRMLS_CC) != SUCCESS) { RETURN_FALSE; } } @@ -345,16 +344,16 @@ 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_handle = NULL; + ibase_blob *ib_blob = NULL; RESET_ERRMSG; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &blob_arg) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &blob_handle) == 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 (bl_end == BLOB_CLOSE) { /* return id here */ @@ -375,7 +374,7 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{ ib_blob->bl_handle = NULL; RETVAL_TRUE; } - zend_list_delete(Z_LVAL_PP(blob_arg)); + zend_list_delete(Z_LVAL_P(blob_handle)); } /* }}} */ @@ -538,7 +537,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 }; @@ -549,7 +548,7 @@ PHP_FUNCTION(ibase_blob_import) RESET_ERRMSG; - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|r", + if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "r|r", (ZEND_NUM_ARGS()-1) ? &link : &file, &file)) { RETURN_FALSE; } diff --git a/ext/interbase/ibase_events.c b/ext/interbase/ibase_events.c index 3380defd4b912..066dd5aef9d8e 100644 --- a/ext/interbase/ibase_events.c +++ b/ext/interbase/ibase_events.c @@ -84,7 +84,7 @@ static void _php_ibase_free_event_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* void php_ibase_events_minit(INIT_FUNC_ARGS) /* {{{ */ { - le_event = zend_register_list_destructors_ex(_php_ibase_free_event_rsrc, NULL, + le_event = zend_register_list_destructors_ex(_php_ibase_free_event_rsrc, NULL, "interbase event", module_number); } /* }}} */ @@ -161,7 +161,7 @@ PHP_FUNCTION(ibase_wait_event) } } - for (; i < ZEND_NUM_ARGS(); ++i) { + for (; i < num_args; ++i) { convert_to_string_ex(args[i]); events[event_count++] = Z_STRVAL_PP(args[i]); } @@ -275,7 +275,7 @@ PHP_FUNCTION(ibase_set_event_handler) int link_res_id, num_args; RESET_ERRMSG; - + /* Minimum and maximum number of arguments allowed */ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 17) { WRONG_PARAM_COUNT; @@ -307,7 +307,7 @@ PHP_FUNCTION(ibase_set_event_handler) link_res_id = Z_LVAL_PP(args[0]); } else { - /* callback, event_1 [, ... event_15] + /* callback, event_1 [, ... event_15] * No more than 15 events */ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 16) { @@ -340,14 +340,14 @@ PHP_FUNCTION(ibase_set_event_handler) event->link = ib_link; event->event_count = 0; event->state = NEW; - event->events = (char **) safe_emalloc(sizeof(char *),ZEND_NUM_ARGS()-i,0); + event->events = (char **) safe_emalloc(sizeof(char *),num_args-i,0); ALLOC_ZVAL(event->callback); *event->callback = **cb_arg; INIT_PZVAL(event->callback); zval_copy_ctor(event->callback); - for (; i < ZEND_NUM_ARGS(); ++i) { + for (; i < num_args; ++i) { convert_to_string_ex(args[i]); event->events[event->event_count++] = estrdup(Z_STRVAL_PP(args[i])); } diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index b30d741a82ef4..f5ca597b70b51 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -77,7 +77,7 @@ typedef struct { char vary_string[1]; } IBVARY; -/* sql variables union +/* sql variables union * used for convert and binding input variables */ typedef struct { @@ -126,7 +126,7 @@ static void _php_ibase_free_stmt_handle(ibase_db_link *link, isc_stmt_handle stm char res_buf[8]; IBDEBUG("Dropping statement handle (free_stmt_handle)..."); /* Only free statement if db-connection is still open */ - if (SUCCESS == isc_database_info(IB_STATUS, &link->handle, + if (SUCCESS == isc_database_info(IB_STATUS, &link->handle, sizeof(info), info, sizeof(res_buf), res_buf)) { if (isc_dsql_free_statement(IB_STATUS, &stmt, DSQL_drop)) { _php_ibase_error(TSRMLS_C); @@ -196,9 +196,9 @@ static void php_ibase_free_query_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* { void php_ibase_query_minit(INIT_FUNC_ARGS) /* {{{ */ { - le_result = zend_register_list_destructors_ex(_php_ibase_free_result, NULL, + le_result = zend_register_list_destructors_ex(_php_ibase_free_result, NULL, "interbase result", module_number); - le_query = zend_register_list_destructors_ex(php_ibase_free_query_rsrc, NULL, + le_query = zend_register_list_destructors_ex(php_ibase_free_query_rsrc, NULL, "interbase query", module_number); } /* }}} */ @@ -277,7 +277,7 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{ case blr_varying2: /** * IB has a strange way of handling VARCHAR arrays. It doesn't store - * the length in the first short, as with VARCHAR fields. It does, + * the length in the first short, as with VARCHAR fields. It does, * however, expect the extra short to be allocated for each element. */ a->el_type = SQL_TEXT; @@ -288,7 +288,7 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{ case blr_cstring: case blr_cstring2: /** - * These types are mentioned as array types in the manual, but I + * These types are mentioned as array types in the manual, but I * wouldn't know how to create an array field with any of these * types. I assume these types are not applicable to arrays, and * were mentioned erroneously. @@ -355,12 +355,12 @@ static int _php_ibase_alloc_query(ibase_query *ib_query, ibase_db_link *link, /* } /* find out what kind of statement was prepared */ - if (isc_dsql_sql_info(IB_STATUS, &ib_query->stmt, sizeof(info_type), + if (isc_dsql_sql_info(IB_STATUS, &ib_query->stmt, sizeof(info_type), info_type, sizeof(result), result)) { _php_ibase_error(TSRMLS_C); goto _php_ibase_alloc_query_error; } - ib_query->statement_type = result[3]; + ib_query->statement_type = result[3]; /* not enough output variables ? */ if (ib_query->out_sqlda->sqld > ib_query->out_sqlda->sqln) { @@ -451,7 +451,7 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, / zend_hash_internal_pointer_reset(Z_ARRVAL_P(val)); } - for (i = 0; i < dim_len; ++i) { + for (i = 0; i < dim_len; ++i) { if (Z_TYPE_P(val) == IS_ARRAY && zend_hash_get_current_data(Z_ARRVAL_P(val), (void *) &subval) == FAILURE) @@ -519,15 +519,15 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, / } if (l > 0) { - *(ISC_INT64 *) buf = (ISC_INT64) (l * pow(10, + *(ISC_INT64 *) buf = (ISC_INT64) (l * pow(10, -array->ar_desc.array_desc_scale) + .5); } else { - *(ISC_INT64 *) buf = (ISC_INT64) (l * pow(10, + *(ISC_INT64 *) buf = (ISC_INT64) (l * pow(10, -array->ar_desc.array_desc_scale) - .5); } } break; - } + } } else { struct tm t = { 0, 0, 0, 0, 0, 0 }; @@ -581,7 +581,7 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, / #ifdef HAVE_STRPTIME strptime(Z_STRVAL_P(val), INI_STR("ibase.timestampformat"), &t); #else - n = sscanf(Z_STRVAL_P(val), "%d%*[/]%d%*[/]%d %d%*[:]%d%*[:]%d", + n = sscanf(Z_STRVAL_P(val), "%d%*[/]%d%*[/]%d %d%*[:]%d%*[:]%d", &t.tm_mon, &t.tm_mday, &t.tm_year, &t.tm_hour, &t.tm_min, &t.tm_sec); if (n != 3 && n != 6) { @@ -633,7 +633,7 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, / } } return SUCCESS; -} +} /* }}} */ static int _php_ibase_bind(XSQLDA *sqlda, zval ***b_vars, BIND_BUF *buf, /* {{{ */ @@ -776,7 +776,7 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval ***b_vars, BIND_BUF *buf, /* {{{ void *array_data = emalloc(ar->ar_size); ISC_QUAD array_id = { 0, 0 }; - if (FAILURE == _php_ibase_bind_array(b_var, array_data, ar->ar_size, + if (FAILURE == _php_ibase_bind_array(b_var, array_data, ar->ar_size, ar, 0 TSRMLS_CC)) { _php_ibase_module_error("Parameter %d: failed to bind array argument" TSRMLS_CC,i+1); @@ -785,7 +785,7 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval ***b_vars, BIND_BUF *buf, /* {{{ continue; } - if (isc_array_put_slice(IB_STATUS, &ib_query->link->handle, &ib_query->trans->handle, + if (isc_array_put_slice(IB_STATUS, &ib_query->link->handle, &ib_query->trans->handle, &array_id, &ar->ar_desc, array_data, &ar->ar_size)) { _php_ibase_error(TSRMLS_C); efree(array_data); @@ -793,7 +793,7 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval ***b_vars, BIND_BUF *buf, /* {{{ } buf[i].val.qval = array_id; efree(array_data); - } + } ++array_cnt; continue; } /* switch */ @@ -871,7 +871,7 @@ static int _php_ibase_exec(INTERNAL_FUNCTION_PARAMETERS, ibase_result **ib_resul char result[64]; ISC_STATUS isc_result; int argc = ib_query->in_sqlda ? ib_query->in_sqlda->sqld : 0; - + RESET_ERRMSG; for (i = 0; i < argc; ++i) { @@ -888,7 +888,7 @@ static int _php_ibase_exec(INTERNAL_FUNCTION_PARAMETERS, ibase_result **ib_resul /* a SET TRANSACTION statement should be executed with a NULL trans handle */ tr = NULL; - if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, &tr, 0, + if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, &tr, 0, ib_query->query, ib_query->dialect, NULL)) { _php_ibase_error(TSRMLS_C); goto _php_ibase_exec_error; @@ -919,14 +919,14 @@ static int _php_ibase_exec(INTERNAL_FUNCTION_PARAMETERS, ibase_result **ib_resul case isc_info_sql_stmt_commit: case isc_info_sql_stmt_rollback: - if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, + if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, &ib_query->trans->handle, 0, ib_query->query, ib_query->dialect, NULL)) { _php_ibase_error(TSRMLS_C); goto _php_ibase_exec_error; } if (ib_query->trans->handle == NULL && ib_query->trans_res_id != 0) { - /* transaction was released by the query and was a registered resource, + /* transaction was released by the query and was a registered resource, so we have to release it */ zend_list_delete(ib_query->trans_res_id); } @@ -1070,7 +1070,7 @@ PHP_FUNCTION(ibase_query) ibase_result *result = NULL; RESET_ERRMSG; - + RETVAL_FALSE; switch (ZEND_NUM_ARGS()) { @@ -1082,7 +1082,7 @@ PHP_FUNCTION(ibase_query) ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link*, &zlink, -1, LE_LINK, le_link, le_plink); ZEND_FETCH_RESOURCE(trans, ibase_trans*, &ztrans, -1, LE_TRANS, le_trans); - + trans_res_id = Z_LVAL_P(ztrans); bind_i = 3; break; @@ -1091,7 +1091,7 @@ PHP_FUNCTION(ibase_query) if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, 2 TSRMLS_CC, "rs", &zlink, &query, &query_len)) { _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, &zlink, &ib_link, &trans); - + if (trans != NULL) { trans_res_id = Z_LVAL_P(zlink); } @@ -1113,7 +1113,7 @@ PHP_FUNCTION(ibase_query) _php_ibase_module_error("CREATE DATABASE is not allowed: maximum link count " "(%ld) reached" TSRMLS_CC, l); - } else if (isc_dsql_execute_immediate(IB_STATUS, &db, &trans, (short)query_len, + } else if (isc_dsql_execute_immediate(IB_STATUS, &db, &trans, (short)query_len, query, SQL_DIALECT_CURRENT, NULL)) { _php_ibase_error(TSRMLS_C); @@ -1123,7 +1123,7 @@ PHP_FUNCTION(ibase_query) } else { - /* register the link as a resource; unfortunately, we cannot register + /* register the link as a resource; unfortunately, we cannot register it in the hash table, because we don't know the connection params */ ib_link = (ibase_db_link *) emalloc(sizeof(ibase_db_link)); ib_link->handle = db; @@ -1137,10 +1137,10 @@ PHP_FUNCTION(ibase_query) ++IBG(num_links); } return; - } + } case 1: case 0: - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() ? 1 : 0 TSRMLS_CC, "s", &query, + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() ? 1 : 0 TSRMLS_CC, "s", &query, &query_len)) { ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link), LE_LINK, le_link, le_plink); @@ -1152,7 +1152,7 @@ PHP_FUNCTION(ibase_query) } /* open default transaction */ - if (ib_link == NULL || FAILURE == _php_ibase_def_trans(ib_link, &trans TSRMLS_CC) + if (ib_link == NULL || FAILURE == _php_ibase_def_trans(ib_link, &trans TSRMLS_CC) || FAILURE == _php_ibase_alloc_query(&ib_query, ib_link, trans, query, ib_link->dialect, trans_res_id TSRMLS_CC)) { return; @@ -1161,26 +1161,33 @@ PHP_FUNCTION(ibase_query) do { int bind_n = ZEND_NUM_ARGS() - bind_i, expected_n = ib_query.in_sqlda ? ib_query.in_sqlda->sqld : 0; - + if (bind_n != expected_n) { php_error_docref(NULL TSRMLS_CC, (bind_n < expected_n) ? E_WARNING : E_NOTICE, "Statement expects %d arguments, %d given", expected_n, bind_n); if (bind_n < expected_n) { break; } - } else if (bind_n > 0) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &bind_args, &bind_num) == FAILURE) { + } else if (bind_n > 0) { + if (zend_parse_parameters_ex(ZEND_NUM_ARGS() TSRMLS_CC, "+", &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, + + if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, &ib_query, &bind_args[bind_i])) { break; } if (result != NULL) { /* statement returns a result */ - result->type = QUERY_RESULT; + result->type = QUERY_RESULT; /* EXECUTE PROCEDURE returns only one row => statement can be released immediately */ if (ib_query.statement_type != isc_info_sql_stmt_exec_procedure) { @@ -1205,9 +1212,9 @@ PHP_FUNCTION(ibase_affected_rows) ibase_trans *trans = NULL; ibase_db_link *ib_link; zval *arg = NULL; - + RESET_ERRMSG; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg) == FAILURE) { return; } @@ -1234,28 +1241,28 @@ PHP_FUNCTION(ibase_affected_rows) } /* }}} */ -/* {{{ proto int ibase_num_rows( resource result_identifier ) +/* {{{ proto int ibase_num_rows( resource result_identifier ) Return the number of rows that are available in a result */ #if abies_0 -PHP_FUNCTION(ibase_num_rows) +PHP_FUNCTION(ibase_num_rows) { /** * As this function relies on the InterBase API function isc_dsql_sql_info() - * which has a couple of limitations (which I hope will be fixed in future + * which has a couple of limitations (which I hope will be fixed in future * releases of Firebird), this function is fairly useless. I'm leaving it - * in place for people who can live with the limitations, which I only + * in place for people who can live with the limitations, which I only * found out about after I had implemented it anyway. * * Currently, there's no way to determine how many rows can be fetched from * a cursor. The only number that _can_ be determined is the number of rows - * that have already been pre-fetched by the client library. + * that have already been pre-fetched by the client library. * This implies the following: * - num_rows() always returns zero before the first fetch; * - num_rows() for SELECT ... FOR UPDATE is broken -> never returns a * higher number than the number of records fetched so far (no pre-fetch); - * - the result of num_rows() for other statements is merely a lower bound + * - the result of num_rows() for other statements is merely a lower bound * on the number of records => calling ibase_num_rows() again after a couple - * of fetches will most likely return a new (higher) figure for large result + * of fetches will most likely return a new (higher) figure for large result * sets. */ @@ -1287,7 +1294,7 @@ PHP_FUNCTION(ibase_num_rows) } i += len+3; } - } + } } #endif /* }}} */ @@ -1295,21 +1302,21 @@ PHP_FUNCTION(ibase_num_rows) static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{ */ int scale, int flag TSRMLS_DC) { - static ISC_INT64 const scales[] = { 1, 10, 100, 1000, - 10000, - 100000, - 1000000, + static ISC_INT64 const scales[] = { 1, 10, 100, 1000, + 10000, + 100000, + 1000000, 10000000, - 100000000, - 1000000000, - LL_LIT(10000000000), + 100000000, + 1000000000, + LL_LIT(10000000000), LL_LIT(100000000000), - LL_LIT(1000000000000), - LL_LIT(10000000000000), + LL_LIT(1000000000000), + LL_LIT(10000000000000), LL_LIT(100000000000000), LL_LIT(1000000000000000), - LL_LIT(10000000000000000), - LL_LIT(100000000000000000), + LL_LIT(10000000000000000), + LL_LIT(100000000000000000), LL_LIT(1000000000000000000) }; @@ -1344,7 +1351,7 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{ if (n >= 0) { l = slprintf(string_data, sizeof(string_data), "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, n % f); } else if (n <= -f) { - l = slprintf(string_data, sizeof(string_data), "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, -n % f); + l = slprintf(string_data, sizeof(string_data), "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, -n % f); } else { l = slprintf(string_data, sizeof(string_data), "-0.%0*" LL_MASK "d", -scale, -n % f); } @@ -1353,7 +1360,7 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{ break; #endif case SQL_LONG: - n = *(ISC_LONG *) data; + n = *(ISC_LONG *) data; _sql_long: if (scale == 0) { ZVAL_LONG(val,n); @@ -1405,7 +1412,7 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{ #else switch (type & ~1) { default: - l = slprintf(string_data, sizeof(string_data), "%02d/%02d/%4d %02d:%02d:%02d", t.tm_mon+1, t.tm_mday, + l = slprintf(string_data, sizeof(string_data), "%02d/%02d/%4d %02d:%02d:%02d", t.tm_mon+1, t.tm_mday, t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec); break; case SQL_TYPE_DATE: @@ -1430,7 +1437,7 @@ static int _php_ibase_arr_zval(zval *ar_zval, char *data, unsigned long data_siz /** * Create multidimension array - recursion function */ - int + int u_bound = ib_array->ar_desc.array_desc_bounds[dim].array_bound_upper, l_bound = ib_array->ar_desc.array_desc_bounds[dim].array_bound_lower, dim_len = 1 + u_bound - l_bound; @@ -1501,32 +1508,32 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) } } else { ib_result->has_more_rows = 0; - } + } array_init(return_value); for (i = 0; i < ib_result->out_sqlda->sqld; ++i) { XSQLVAR *var = &ib_result->out_sqlda->sqlvar[i]; char buf[METADATALENGTH+4], *alias = var->aliasname; - + if (! (fetch_type & FETCH_ROW)) { int i = 0; char const *base = "FIELD"; /* use 'FIELD' if name is empty */ - + /** - * Ensure no two columns have identical names: + * Ensure no two columns have identical names: * keep generating new names until we find one that is unique. */ switch (*alias) { void *p; - + default: i = 1; base = alias; - + while (SUCCESS == zend_symtable_find( Z_ARRVAL_P(return_value),alias,strlen(alias)+1,&p)) { - + case '\0': snprintf(alias = buf, sizeof(buf), "%s_%02d", base, i++); } @@ -1572,13 +1579,13 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) unsigned short item_len; char item = bl_info[i++]; - if (item == isc_info_end || item == isc_info_truncated || + if (item == isc_info_end || item == isc_info_truncated || item == isc_info_error || i >= sizeof(bl_info)) { _php_ibase_module_error("Could not determine BLOB size (internal error)" TSRMLS_CC); goto _php_ibase_fetch_error; - } + } item_len = (unsigned short) isc_vax_integer(&bl_info[i], 2); @@ -1591,7 +1598,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) if (max_len == 0) { ZVAL_STRING(result, "", 1); - } else if (SUCCESS != _php_ibase_blob_get(result, &blob_handle, + } else if (SUCCESS != _php_ibase_blob_get(result, &blob_handle, max_len TSRMLS_CC)) { goto _php_ibase_fetch_error; } @@ -1612,7 +1619,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) ibase_array *ib_array = &ib_result->out_array[array_cnt++]; void *ar_data = emalloc(ib_array->ar_size); - if (isc_array_get_slice(IB_STATUS, &ib_result->link->handle, + if (isc_array_get_slice(IB_STATUS, &ib_result->link->handle, &ib_result->trans->handle, &ar_qd, &ib_array->ar_desc, ar_data, &ib_array->ar_size)) { _php_ibase_error(TSRMLS_C); @@ -1740,7 +1747,7 @@ PHP_FUNCTION(ibase_prepare) char *query; RESET_ERRMSG; - + if (ZEND_NUM_ARGS() == 1) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &query, &query_len) == FAILURE) { return; @@ -1788,7 +1795,7 @@ PHP_FUNCTION(ibase_execute) ALLOCA_FLAG(use_heap) RESET_ERRMSG; - + RETVAL_FALSE; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() ? 1 : 0 TSRMLS_CC, "r", &query)) { @@ -1812,13 +1819,13 @@ PHP_FUNCTION(ibase_execute) /* have variables to bind */ args = (zval ***) do_alloca((expected_n + 1) * sizeof(zval **), use_heap); - + if (FAILURE == zend_get_parameters_array_ex((expected_n + 1), args)) { break; } /* Have we used this cursor before and it's still open (exec proc has no cursor) ? */ - if (ib_query->result_res_id != 0 + if (ib_query->result_res_id != 0 && ib_query->statement_type != isc_info_sql_stmt_exec_procedure) { IBDEBUG("Implicitly closing a cursor"); @@ -1827,10 +1834,10 @@ PHP_FUNCTION(ibase_execute) break; } /* invalidate previous results returned by this query (not necessary for exec proc) */ - zend_list_delete(ib_query->result_res_id); + zend_list_delete(ib_query->result_res_id); } - if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, ib_query, + if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, ib_query, &args[1])) { break; } @@ -1839,7 +1846,7 @@ PHP_FUNCTION(ibase_execute) if (ib_query->trans->handle == NULL) { zend_list_delete(Z_LVAL_P(query)); } - + if (result != NULL) { result->type = EXECUTE_RESULT; if (ib_query->statement_type == isc_info_sql_stmt_exec_procedure) { @@ -1952,36 +1959,36 @@ static void _php_ibase_field_info(zval *return_value, XSQLVAR *var) /* {{{ */ } else { switch (var->sqltype & ~1) { case SQL_TEXT: - s = "CHAR"; + s = "CHAR"; break; case SQL_VARYING: - s = "VARCHAR"; + s = "VARCHAR"; break; case SQL_SHORT: - s = "SMALLINT"; + s = "SMALLINT"; break; case SQL_LONG: - s = "INTEGER"; + s = "INTEGER"; break; case SQL_FLOAT: s = "FLOAT"; break; case SQL_DOUBLE: case SQL_D_FLOAT: s = "DOUBLE PRECISION"; break; - case SQL_INT64: - s = "BIGINT"; + case SQL_INT64: + s = "BIGINT"; break; - case SQL_TIMESTAMP: - s = "TIMESTAMP"; + case SQL_TIMESTAMP: + s = "TIMESTAMP"; break; case SQL_TYPE_DATE: s = "DATE"; break; case SQL_TYPE_TIME: - s = "TIME"; + s = "TIME"; break; case SQL_BLOB: - s = "BLOB"; + s = "BLOB"; break; case SQL_ARRAY: s = "ARRAY"; @@ -2025,7 +2032,7 @@ PHP_FUNCTION(ibase_field_info) ZEND_FETCH_RESOURCE(ib_result, ibase_result *, &result_arg, -1, LE_RESULT, le_result); sqlda = ib_result->out_sqlda; - } + } if (sqlda == NULL) { _php_ibase_module_error("Trying to get field info from a non-select query" TSRMLS_CC); diff --git a/ext/interbase/interbase.c b/ext/interbase/interbase.c index 132ad35fba0cf..9cdf5503405c8 100644 --- a/ext/interbase/interbase.c +++ b/ext/interbase/interbase.c @@ -472,7 +472,7 @@ int le_link, le_plink, le_trans; /* error handling ---------------------------- */ -/* {{{ proto string ibase_errmsg(void) +/* {{{ proto string ibase_errmsg(void) Return error message */ PHP_FUNCTION(ibase_errmsg) { @@ -488,7 +488,7 @@ PHP_FUNCTION(ibase_errmsg) } /* }}} */ -/* {{{ proto int ibase_errcode(void) +/* {{{ proto int ibase_errcode(void) Return error code */ PHP_FUNCTION(ibase_errcode) { @@ -510,7 +510,7 @@ void _php_ibase_error(TSRMLS_D) /* {{{ */ ISC_STATUS *statusp = IB_STATUS; IBG(sql_code) = isc_sqlcode(IB_STATUS); - + while ((s - IBG(errmsg)) < MAX_ERRMSG - (IBASE_MSGSIZE + 2) && isc_interprete(s, &statusp)) { strcat(IBG(errmsg), " "); s = IBG(errmsg) + strlen(IBG(errmsg)); @@ -559,7 +559,7 @@ void _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAMETERS, /* {{{ */ IBDEBUG("Transaction or database link?"); if (zend_list_find(Z_LVAL_PP(link_id), &type)) { if (type == le_trans) { - /* Transaction resource: make sure it refers to one link only, then + /* Transaction resource: make sure it refers to one link only, then fetch it; database link is stored in ib_trans->db_link[]. */ IBDEBUG("Type is le_trans"); ZEND_FETCH_RESOURCE(*trans, ibase_trans *, link_id, -1, LE_TRANS, le_trans); @@ -567,17 +567,17 @@ void _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAMETERS, /* {{{ */ _php_ibase_module_error("Link id is ambiguous: transaction spans multiple connections." TSRMLS_CC); return; - } + } *ib_link = (*trans)->db_link[0]; return; } - } + } IBDEBUG("Type is le_[p]link or id not found"); /* Database link resource, use default transaction. */ *trans = NULL; ZEND_FETCH_RESOURCE2(*ib_link, ibase_db_link *, link_id, -1, LE_LINK, le_link, le_plink); } -/* }}} */ +/* }}} */ /* destructors ---------------------- */ @@ -600,7 +600,7 @@ static void _php_ibase_commit_link(ibase_db_link *link TSRMLS_DC) /* {{{ */ } efree(p->trans); /* default transaction is not a registered resource: clean up */ } else { - if (p->trans->handle != NULL) { + if (p->trans->handle != NULL) { /* non-default trans might have been rolled back by other call of this dtor */ IBDEBUG("Rolling back other transactions..."); if (isc_rollback_transaction(IB_STATUS, &p->trans->handle)) { @@ -620,7 +620,7 @@ static void _php_ibase_commit_link(ibase_db_link *link TSRMLS_DC) /* {{{ */ efree(p); } link->tr_list = NULL; - + for (e = link->event_head; e; e = e->event_next) { _php_ibase_free_event(e TSRMLS_CC); e->link = NULL; @@ -670,7 +670,7 @@ static void _php_ibase_free_trans(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ * { ibase_trans *trans = (ibase_trans *)rsrc->ptr; unsigned short i; - + IBDEBUG("Cleaning up transaction resource..."); if (trans->handle != NULL) { IBDEBUG("Rolling back unhandled transaction..."); @@ -702,7 +702,7 @@ static PHP_INI_DISP(php_ibase_password_displayer_cb) { TSRMLS_FETCH(); - if ((type == PHP_INI_DISPLAY_ORIG && ini_entry->orig_value) + if ((type == PHP_INI_DISPLAY_ORIG && ini_entry->orig_value) || (type == PHP_INI_DISPLAY_ACTIVE && ini_entry->value)) { PUTS("********"); } else if (!sapi_module.phpinfo_as_text) { @@ -763,22 +763,22 @@ PHP_MINIT_FUNCTION(ibase) php_ibase_blobs_minit(INIT_FUNC_ARGS_PASSTHRU); php_ibase_events_minit(INIT_FUNC_ARGS_PASSTHRU); php_ibase_service_minit(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} - + + return SUCCESS; +} + PHP_MSHUTDOWN_FUNCTION(ibase) { #ifndef PHP_WIN32 /** - * When the Interbase client API library libgds.so is first loaded, it registers a call to + * When the Interbase client API library libgds.so is first loaded, it registers a call to * gds__cleanup() with atexit(), in order to clean up after itself when the process exits. * This means that the library is called at process shutdown, and cannot be unloaded beforehand. - * PHP tries to unload modules after every request [dl()'ed modules], and right before the + * PHP tries to unload modules after every request [dl()'ed modules], and right before the * process shuts down [modules loaded from php.ini]. This results in a segfault for this module. * By NULLing the dlopen() handle in the module entry, Zend omits the call to dlclose(), * ensuring that the module will remain present until the process exits. However, the functions - * and classes exported by the module will not be available until the module is 'reloaded'. + * and classes exported by the module will not be available until the module is 'reloaded'. * When reloaded, dlopen() will return the handle of the already loaded module. The module will * be unloaded automatically when the process exits. */ @@ -800,14 +800,14 @@ PHP_RSHUTDOWN_FUNCTION(ibase) RESET_ERRMSG; return SUCCESS; -} - +} + PHP_MINFO_FUNCTION(ibase) { char tmp[64], *s; php_info_print_table_start(); - php_info_print_table_row(2, "Firebird/InterBase Support", + php_info_print_table_row(2, "Firebird/InterBase Support", #ifdef COMPILE_DL_INTERBASE "dynamic"); #else @@ -845,7 +845,7 @@ PHP_MINFO_FUNCTION(ibase) } php_info_print_table_row(2, "Run-time Client Library Version", s); } while (0); -#endif +#endif php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -854,11 +854,11 @@ PHP_MINFO_FUNCTION(ibase) /* }}} */ enum connect_args { DB = 0, USER = 1, PASS = 2, CSET = 3, ROLE = 4, BUF = 0, DLECT = 1, SYNC = 2 }; - -static char const dpb_args[] = { + +static char const dpb_args[] = { 0, isc_dpb_user_name, isc_dpb_password, isc_dpb_lc_ctype, isc_dpb_sql_role_name, 0 }; - + int _php_ibase_attach_db(char **args, int *len, long *largs, isc_db_handle *db TSRMLS_DC) { short i, dpb_len, buf_len = 257-2; /* version byte at the front, and a null at the end */ @@ -874,7 +874,7 @@ int _php_ibase_attach_db(char **args, int *len, long *largs, isc_db_handle *db T } } if (largs[BUF] && buf_len > 0) { - dpb_len = slprintf(dpb, buf_len, "%c\2%c%c", isc_dpb_num_buffers, + dpb_len = slprintf(dpb, buf_len, "%c\2%c%c", isc_dpb_num_buffers, (char)(largs[BUF] >> 8), (char)(largs[BUF] & 0xff)); dpb += dpb_len; buf_len -= dpb_len; @@ -910,9 +910,9 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* &largs[SYNC])) { RETURN_FALSE; } - + /* restrict to the server/db in the .ini if in safe mode */ - if ((!len[DB] || PG(sql_safe_mode)) && (c = INI_STR("ibase.default_db"))) { + if ((!len[DB] || PG(sql_safe_mode)) && (c = INI_STR("ibase.default_db"))) { args[DB] = c; len[DB] = strlen(c); } @@ -928,7 +928,7 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* args[CSET] = c; len[CSET] = strlen(c); } - + /* don't want usernames and passwords floating around */ PHP_MD5Init(&hash_context); for (i = 0; i < sizeof(args)/sizeof(char*); ++i) { @@ -938,7 +938,7 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* PHP_MD5Update(&hash_context,(char*)&largs[i],sizeof(long)); } PHP_MD5Final(hash, &hash_context); - + /* try to reuse a connection */ if (SUCCESS == zend_hash_find(&EG(regular_list), hash, sizeof(hash), (void *) &le)) { long xlink; @@ -947,7 +947,7 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* if (Z_TYPE_P(le) != le_index_ptr) { RETURN_FALSE; } - + xlink = (long) le->ptr; if (zend_list_find(xlink, &type) && ((!persistent && type == le_link) || type == le_plink)) { zend_list_addref(xlink); @@ -955,12 +955,12 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* } else { zend_hash_del(&EG(regular_list), hash, sizeof(hash)); } - } + } /* ... or a persistent one */ switch (zend_hash_find(&EG(persistent_list), hash, sizeof(hash), (void *) &le)) { long l; - + static char info[] = { isc_info_base_level, isc_info_end }; char result[8]; ISC_STATUS status[20]; @@ -977,21 +977,21 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* break; } zend_hash_del(&EG(persistent_list), hash, sizeof(hash)); - + default: /* no link found, so we have to open one */ - + if ((l = INI_INT("ibase.max_links")) != -1 && IBG(num_links) >= l) { _php_ibase_module_error("Too many open links (%ld)" TSRMLS_CC, IBG(num_links)); RETURN_FALSE; } - + /* create the ib_link */ if (FAILURE == _php_ibase_attach_db(args, len, largs, &db_handle TSRMLS_CC)) { RETURN_FALSE; } - + /* use non-persistent if allowed number of persistent links is exceeded */ if (!persistent || ((l = INI_INT("ibase.max_persistent") != -1) && IBG(num_persistent) >= l)) { ib_link = (ibase_db_link *) emalloc(sizeof(ibase_db_link)); @@ -1019,7 +1019,7 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* ib_link->dialect = largs[DLECT] ? (unsigned short)largs[DLECT] : SQL_DIALECT_CURRENT; ib_link->tr_list = NULL; ib_link->event_head = NULL; - + ++IBG(num_links); } @@ -1059,12 +1059,12 @@ PHP_FUNCTION(ibase_close) int link_id; RESET_ERRMSG; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &link_arg) == FAILURE) { return; } - - if (ZEND_NUM_ARGS() == 0) { + + if (link_arg == NULL) { link_id = IBG(default_link); CHECK_LINK(link_id); IBG(default_link) = -1; @@ -1088,19 +1088,19 @@ PHP_FUNCTION(ibase_drop_db) int link_id; RESET_ERRMSG; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &link_arg) == FAILURE) { return; } - - if (ZEND_NUM_ARGS() == 0) { + + if (link_arg == NULL) { link_id = IBG(default_link); CHECK_LINK(link_id); IBG(default_link) = -1; } else { link_id = Z_RESVAL_P(link_arg); } - + ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, &link_arg, link_id, LE_LINK, le_link, le_plink); if (isc_drop_database(IB_STATUS, &ib_link->handle)) { @@ -1132,14 +1132,14 @@ PHP_FUNCTION(ibase_trans) ibase_trans *ib_trans; isc_tr_handle tr_handle = NULL; ISC_STATUS result; - + RESET_ERRMSG; argn = ZEND_NUM_ARGS(); /* (1+argn) is an upper bound for the number of links this trans connects to */ ib_link = (ibase_db_link **) safe_emalloc(sizeof(ibase_db_link *),1+argn,0); - + if (argn > 0) { long trans_argl = 0; char *tpb; @@ -1155,12 +1155,12 @@ PHP_FUNCTION(ibase_trans) teb = (ISC_TEB *) safe_emalloc(sizeof(ISC_TEB),argn,0); tpb = (char *) safe_emalloc(TPB_MAX_SIZE,argn,0); - /* enumerate all the arguments: assume every non-resource argument + /* enumerate all the arguments: assume every non-resource argument specifies modifiers for the link ids that follow it */ for (i = 0; i < argn; ++i) { - + if (Z_TYPE_PP(args[i]) == IS_RESOURCE) { - + if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link[link_cnt], ibase_db_link *, args[i], -1, LE_LINK, le_link, le_plink)) { efree(teb); efree(tpb); @@ -1168,7 +1168,7 @@ PHP_FUNCTION(ibase_trans) efree(args); RETURN_FALSE; } - + /* copy the most recent modifier string into tbp[] */ memcpy(&tpb[TPB_MAX_SIZE * link_cnt], last_tpb, TPB_MAX_SIZE); @@ -1176,11 +1176,11 @@ PHP_FUNCTION(ibase_trans) teb[link_cnt].db_ptr = &ib_link[link_cnt]->handle; teb[link_cnt].tpb_len = tpb_len; teb[link_cnt].tpb_ptr = &tpb[TPB_MAX_SIZE * link_cnt]; - + ++link_cnt; - + } else { - + tpb_len = 0; convert_to_long_ex(args[i]); @@ -1202,14 +1202,14 @@ PHP_FUNCTION(ibase_trans) if (PHP_IBASE_REC_VERSION == (trans_argl & PHP_IBASE_REC_VERSION)) { last_tpb[tpb_len++] = isc_tpb_rec_version; } else if (PHP_IBASE_REC_NO_VERSION == (trans_argl & PHP_IBASE_REC_NO_VERSION)) { - last_tpb[tpb_len++] = isc_tpb_no_rec_version; - } + last_tpb[tpb_len++] = isc_tpb_no_rec_version; + } } else if (PHP_IBASE_CONSISTENCY == (trans_argl & PHP_IBASE_CONSISTENCY)) { last_tpb[tpb_len++] = isc_tpb_consistency; } else if (PHP_IBASE_CONCURRENCY == (trans_argl & PHP_IBASE_CONCURRENCY)) { last_tpb[tpb_len++] = isc_tpb_concurrency; } - + /* lock resolution */ if (PHP_IBASE_NOWAIT == (trans_argl & PHP_IBASE_NOWAIT)) { last_tpb[tpb_len++] = isc_tpb_nowait; @@ -1218,8 +1218,8 @@ PHP_FUNCTION(ibase_trans) } } } - } - + } + if (link_cnt > 0) { result = isc_start_multiple(IB_STATUS, &tr_handle, link_cnt, teb); } @@ -1237,7 +1237,7 @@ PHP_FUNCTION(ibase_trans) } result = isc_start_transaction(IB_STATUS, &tr_handle, 1, &ib_link[0]->handle, tpb_len, last_tpb); } - + /* start the transaction */ if (result) { _php_ibase_error(TSRMLS_C); @@ -1253,7 +1253,7 @@ PHP_FUNCTION(ibase_trans) for (i = 0; i < link_cnt; ++i) { ibase_tr_list **l; ib_trans->db_link[i] = ib_link[i]; - + /* the first item in the connection-transaction list is reserved for the default transaction */ if (ib_link[i]->tr_list == NULL) { ib_link[i]->tr_list = (ibase_tr_list *) emalloc(sizeof(ibase_tr_list)); @@ -1319,12 +1319,12 @@ static void _php_ibase_trans_end(INTERNAL_FUNCTION_PARAMETERS, int commit) /* {{ int type; RESET_ERRMSG; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg) == FAILURE) { 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 */ @@ -1363,7 +1363,7 @@ static void _php_ibase_trans_end(INTERNAL_FUNCTION_PARAMETERS, int commit) /* {{ result = isc_commit_retaining(IB_STATUS, &trans->handle); break; } - + if (result) { _php_ibase_error(TSRMLS_C); RETURN_FALSE; @@ -1428,20 +1428,20 @@ PHP_FUNCTION(ibase_gen_id) &inc, &link)) { RETURN_FALSE; } - + if (gen_len > 31) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid generator name"); RETURN_FALSE; } PHP_IBASE_LINK_TRANS(link, ib_link, trans); - + snprintf(query, sizeof(query), "SELECT GEN_ID(%s,%ld) FROM rdb$database", generator, inc); /* allocate a minimal descriptor area */ out_sqlda.sqln = out_sqlda.sqld = 1; out_sqlda.version = SQLDA_CURRENT_VERSION; - + /* allocate the field for the result */ out_sqlda.sqlvar[0].sqltype = SQL_INT64; out_sqlda.sqlvar[0].sqlscale = 0; @@ -1469,7 +1469,7 @@ PHP_FUNCTION(ibase_gen_id) } /* }}} */ - + #endif /* HAVE_IBASE */ /* diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 8a094e015e433..f83630064653a 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -409,14 +409,22 @@ PHP_FUNCTION(grapheme_substr) UBreakIterator* bi = NULL; int sub_str_start_pos, sub_str_end_pos; int32_t (*iter_func)(UBreakIterator *); + int no_length = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", (char **)&str, &str_len, &lstart, &length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l!", (char **)&str, &str_len, &lstart, &length, &no_length) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: unable to parse input param", 0 TSRMLS_CC ); 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) ) { @@ -431,7 +439,7 @@ PHP_FUNCTION(grapheme_substr) /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if ( grapheme_ascii_check(str, str_len) >= 0 ) { - grapheme_substr_ascii((char *)str, str_len, start, length, ZEND_NUM_ARGS(), (char **) &sub_str, &sub_str_len); + grapheme_substr_ascii((char *)str, str_len, start, (int32_t)length, (char **) &sub_str, &sub_str_len); if ( NULL == sub_str ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: invalid parameters", 1 TSRMLS_CC ); @@ -499,9 +507,9 @@ PHP_FUNCTION(grapheme_substr) RETURN_FALSE; } - if (ZEND_NUM_ARGS() <= 2) { + if (length >= str_len) { - /* no length supplied, return the rest of the string */ + /* no length supplied or length too big, return the rest of the string */ sub_str = NULL; sub_str_len = 0; @@ -537,7 +545,7 @@ PHP_FUNCTION(grapheme_substr) efree(ustr); } ubrk_close(bi); - RETURN_EMPTY_STRING(); + RETURN_EMPTY_STRING(); } /* find the end point of the string to return */ @@ -576,7 +584,7 @@ PHP_FUNCTION(grapheme_substr) sub_str_end_pos = ustr_len; } } - + if(sub_str_start_pos > sub_str_end_pos) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: length is beyond start", 1 TSRMLS_CC ); diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c index c752b02372e2c..74d72c73eb7ae 100644 --- a/ext/intl/grapheme/grapheme_util.c +++ b/ext/intl/grapheme/grapheme_util.c @@ -49,17 +49,13 @@ grapheme_close_global_iterator( TSRMLS_D ) /* }}} */ /* {{{ grapheme_substr_ascii f='from' - starting point, l='length' */ -void grapheme_substr_ascii(char *str, int str_len, int f, int l, int argc, char **sub_str, int *sub_str_len) +void grapheme_substr_ascii(char *str, int32_t str_len, int32_t f, int32_t l, char **sub_str, int *sub_str_len) { *sub_str = NULL; - if (argc > 2) { - if ((l < 0 && -l > str_len)) { - return; - } else if (l > str_len) { - l = str_len; - } - } else { + if ((l < 0 && -l > str_len)) { + return; + } else if (l > str_len) { l = str_len; } @@ -175,10 +171,10 @@ int grapheme_strpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigne offset_pos = grapheme_get_haystack_offset(bi, offset); if(offset_pos == -1) { status = U_ILLEGAL_ARGUMENT_ERROR; - STRPOS_CHECK_STATUS(status, "Invalid search offset"); + STRPOS_CHECK_STATUS(status, "Invalid search offset"); } status = U_ZERO_ERROR; - usearch_setOffset(src, offset_pos, &status); + usearch_setOffset(src, offset_pos, &status); STRPOS_CHECK_STATUS(status, "Invalid search offset"); } @@ -243,17 +239,17 @@ int grapheme_split_string(const UChar *text, int32_t text_length, int boundary_a if( U_FAILURE(status) ) { return -1; } - + ubrk_setText(bi, text, text_length, &status); pos = 0; - + for ( ret_len = 0; pos != UBRK_DONE; ) { - + pos = ubrk_next(bi); - + if ( pos != UBRK_DONE ) { - + if ( NULL != boundary_array && ret_len < boundary_array_len ) { boundary_array[ret_len] = pos; } @@ -261,9 +257,9 @@ int grapheme_split_string(const UChar *text, int32_t text_length, int boundary_a ret_len++; } } - + ubrk_close(bi); - + return ret_len; } /* }}} */ @@ -274,19 +270,19 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri int ret_len = 0; int pos = 0; UErrorCode status = U_ZERO_ERROR; - + ubrk_setText(bi, string, string_len, &status); do { - + pos = ubrk_next(bi); - + if ( UBRK_DONE != pos ) { ret_len++; } - + } while ( UBRK_DONE != pos ); - + return ret_len; } /* }}} */ @@ -302,7 +298,7 @@ int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) if ( 0 == offset ) { return 0; } - + if ( offset < 0 ) { iter_op = ubrk_previous; ubrk_last(bi); /* one past the end */ @@ -312,13 +308,13 @@ int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) iter_op = ubrk_next; iter_incr = -1; } - + pos = 0; - + while ( pos != UBRK_DONE && offset != 0 ) { - + pos = iter_op(bi); - + if ( UBRK_DONE != pos ) { offset += iter_incr; } @@ -327,7 +323,7 @@ int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset) if ( offset != 0 ) { return -1; } - + return pos; } /* }}} */ @@ -382,7 +378,7 @@ UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *stat if ( NULL == global_break_iterator ) { - global_break_iterator = ubrk_open(UBRK_CHARACTER, + global_break_iterator = ubrk_open(UBRK_CHARACTER, NULL, /* icu default locale - locale has no effect on this iterator */ NULL, /* text not set in global iterator */ 0, /* text length = 0 */ diff --git a/ext/intl/grapheme/grapheme_util.h b/ext/intl/grapheme/grapheme_util.h index 14f3f22c456b4..095995f24dd3e 100644 --- a/ext/intl/grapheme/grapheme_util.h +++ b/ext/intl/grapheme/grapheme_util.h @@ -23,7 +23,8 @@ /* get_break_interator: get a break iterator from the global structure */ UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status TSRMLS_DC ); -void grapheme_substr_ascii(char *str, int32_t str_len, int32_t f, int32_t l, int argc, char **sub_str, int *sub_str_len); +void +grapheme_substr_ascii(char *str, int32_t str_len, int32_t f, int32_t l, char **sub_str, int *sub_str_len); int grapheme_strrpos_utf16(unsigned char *haystack, int32_t haystack_len, unsigned char*needle, int32_t needle_len, int32_t offset, int f_ignore_case TSRMLS_DC); @@ -41,7 +42,8 @@ int grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset); int32_t grapheme_strrpos_ascii(unsigned char *haystack, int32_t haystack_len, unsigned char *needle, int32_t needle_len, int32_t offset); -UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status TSRMLS_DC ); +UBreakIterator* +grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status TSRMLS_DC ); /* OUTSIDE_STRING: check if (possibly negative) long offset is outside the string with int32_t length */ #define OUTSIDE_STRING(offset, max_len) ( offset <= INT32_MIN || offset > INT32_MAX || (offset < 0 ? -offset > (long) max_len : offset >= (long) max_len) ) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 3cfa2092e776e..fc5709a268741 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -22,7 +22,7 @@ | PHP 4.0 updates: Zeev Suraski | +----------------------------------------------------------------------+ */ - + /* $Id$ */ #define IS_EXT_MODULE @@ -122,7 +122,7 @@ static void _free_ldap_result_entry(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ } zend_list_delete(entry->id); efree(entry); -} +} /* }}} */ /* {{{ PHP_INI_BEGIN @@ -321,7 +321,7 @@ PHP_FUNCTION(ldap_connect) #ifdef LDAP_API_FEATURE_X_OPENLDAP if (host != NULL && strchr(host, '/')) { int rc; - + rc = ldap_initialize(&ldap, host); if (rc != LDAP_SUCCESS) { efree(ld); @@ -334,7 +334,7 @@ PHP_FUNCTION(ldap_connect) #else ldap = ldap_open(host, port); #endif - + if (ldap == NULL) { efree(ld); RETURN_FALSE; @@ -346,7 +346,7 @@ PHP_FUNCTION(ldap_connect) php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL init failed"); RETURN_FALSE; } - } + } #endif LDAPG(num_links)++; ld->link = ldap; @@ -416,7 +416,7 @@ static php_ldap_bictx *_php_sasl_setdefs(LDAP *ld, char *sasl_mech, char *sasl_r { php_ldap_bictx *ctx; - ctx = ber_memalloc(sizeof(php_ldap_bictx)); + ctx = ber_memalloc(sizeof(php_ldap_bictx)); ctx->mech = (sasl_mech) ? ber_strdup(sasl_mech) : NULL; ctx->realm = (sasl_realm) ? ber_strdup(sasl_realm) : NULL; ctx->authcid = (sasl_authc_id) ? ber_strdup(sasl_authc_id) : NULL; @@ -554,8 +554,8 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_sizelimit); ldap_set_option(ldap, LDAP_OPT_SIZELIMIT, &sizelimit); #else - *old_sizelimit = ldap->ld_sizelimit; - ldap->ld_sizelimit = sizelimit; + *old_sizelimit = ldap->ld_sizelimit; + ldap->ld_sizelimit = sizelimit; #endif } @@ -565,8 +565,8 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_timelimit); ldap_set_option(ldap, LDAP_OPT_TIMELIMIT, &timelimit); #else - *old_timelimit = ldap->ld_timelimit; - ldap->ld_timelimit = timelimit; + *old_timelimit = ldap->ld_timelimit; + ldap->ld_timelimit = timelimit; #endif } @@ -576,8 +576,8 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in ldap_get_option(ldap, LDAP_OPT_SIZELIMIT, old_deref); ldap_set_option(ldap, LDAP_OPT_DEREF, &deref); #else - *old_deref = ldap->ld_deref; - ldap->ld_deref = deref; + *old_deref = ldap->ld_deref; + ldap->ld_deref = deref; #endif } } @@ -588,12 +588,12 @@ 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; - long attrsonly, sizelimit, timelimit, deref; - char *ldap_base_dn = NULL, *ldap_filter = NULL, **ldap_attrs = NULL; + 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; - int ldap_attrsonly = 0, ldap_sizelimit = -1, ldap_timelimit = -1, ldap_deref = -1; - int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1; + int ldap_attrsonly = 0, ldap_sizelimit = -1, ldap_timelimit = -1, ldap_deref = -1; + int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1; int num_attribs = 0, ret = 1, i, errno, argcount = ZEND_NUM_ARGS(); if (zend_parse_parameters(argcount TSRMLS_CC, "zzZ|allll", &link, &base_dn, &filter, &attrs, &attrsonly, @@ -612,6 +612,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); @@ -636,7 +638,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) int i, nlinks, nbases, nfilters, *rcs; ldap_linkdata **lds; zval **entry, *resource; - + nlinks = zend_hash_num_elements(Z_ARRVAL_P(link)); if (nlinks == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No links in link array"); @@ -678,7 +680,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) lds = safe_emalloc(nlinks, sizeof(ldap_linkdata), 0); rcs = safe_emalloc(nlinks, sizeof(*rcs), 0); - + zend_hash_internal_pointer_reset(Z_ARRVAL_P(link)); for (i=0; ilink, ldap_sizelimit, ldap_timelimit, ldap_deref, &old_ldap_sizelimit, &old_ldap_timelimit, &old_ldap_deref); - /* Run the actual search */ + /* Run the actual search */ rcs[i] = ldap_search(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly); lds[i] = ld; zend_hash_move_forward(Z_ARRVAL_P(link)); } - + array_init(return_value); /* Collect results from the searches */ @@ -750,9 +752,9 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref, &old_ldap_sizelimit, &old_ldap_timelimit, &old_ldap_deref); - /* Run the actual search */ + /* Run the actual search */ errno = ldap_search_s(ld->link, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res); - + if (errno != LDAP_SUCCESS && errno != LDAP_SIZELIMIT_EXCEEDED #ifdef LDAP_ADMINLIMIT_EXCEEDED @@ -773,7 +775,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial search results returned: Adminlimit exceeded"); } #endif - + ZEND_REGISTER_RESOURCE(return_value, ldap_res, le_result); } } @@ -858,7 +860,7 @@ PHP_FUNCTION(ldap_count_entries) PHP_FUNCTION(ldap_first_entry) { zval *link, *result; - ldap_linkdata *ld; + ldap_linkdata *ld; ldap_resultentry *resultentry; LDAPMessage *ldap_result, *entry; @@ -943,7 +945,7 @@ PHP_FUNCTION(ldap_get_entries) if (num_entries == 0) { return; } - + ldap_result_entry = ldap_first_entry(ldap, ldap_result); if (ldap_result_entry == NULL) { zval_dtor(return_value); @@ -967,7 +969,7 @@ PHP_FUNCTION(ldap_get_entries) add_assoc_long(tmp2, "count", num_values); for (i = 0; i < num_values; i++) { add_index_stringl(tmp2, i, ldap_value[i]->bv_val, ldap_value[i]->bv_len, 1); - } + } ldap_value_free_len(ldap_value); attr_len = strlen(attribute); @@ -996,7 +998,7 @@ PHP_FUNCTION(ldap_get_entries) #endif zend_hash_index_update(Z_ARRVAL_P(return_value), num_entries, (void *) &tmp1, sizeof(zval *), NULL); - + num_entries++; ldap_result_entry = ldap_next_entry(ldap, ldap_result_entry); } @@ -1095,7 +1097,7 @@ PHP_FUNCTION(ldap_get_attributes) array_init(return_value); num_attrib = 0; - + attribute = ldap_first_attribute(ld->link, resultentry->data, &ber); while (attribute != NULL) { ldap_value = ldap_get_values_len(ld->link, resultentry->data, attribute); @@ -1123,7 +1125,7 @@ PHP_FUNCTION(ldap_get_attributes) ber_free(ber, 0); } #endif - + add_assoc_long(return_value, "count", num_attrib); } /* }}} */ @@ -1138,11 +1140,11 @@ PHP_FUNCTION(ldap_get_values_len) char *attr; struct berval **ldap_value_len; int i, num_values, attr_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &link, &result_entry, &attr, &attr_len) != SUCCESS) { return; } - + ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link); ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry); @@ -1150,14 +1152,14 @@ PHP_FUNCTION(ldap_get_values_len) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot get the value(s) of attribute %s", ldap_err2string(_get_lderrno(ld->link))); RETURN_FALSE; } - + num_values = ldap_count_values_len(ldap_value_len); array_init(return_value); - + for (i=0; ibv_val, ldap_value_len[i]->bv_len, 1); } - + add_assoc_long(return_value, "count", num_values); ldap_value_free_len(ldap_value_len); @@ -1166,7 +1168,7 @@ PHP_FUNCTION(ldap_get_values_len) /* {{{ proto string ldap_get_dn(resource link, resource result_entry) Get the DN of a result entry */ -PHP_FUNCTION(ldap_get_dn) +PHP_FUNCTION(ldap_get_dn) { zval *link, *result_entry; ldap_linkdata *ld; @@ -1176,7 +1178,7 @@ PHP_FUNCTION(ldap_get_dn) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &link, &result_entry) != SUCCESS) { return; } - + ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link); ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, &result_entry, -1, "ldap result entry", le_result_entry); @@ -1236,9 +1238,9 @@ PHP_FUNCTION(ldap_dn2ufn) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dn, &dn_len) != SUCCESS) { return; } - + ufn = ldap_dn2ufn(dn); - + if (ufn != NULL) { RETVAL_STRING(ufn, 1); #if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 || WINDOWS @@ -1269,7 +1271,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa", &link, &dn, &dn_len, &entry) != SUCCESS) { return; - } + } ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link); @@ -1303,7 +1305,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) i--; } efree(num_berval); - efree(ldap_mods); + efree(ldap_mods); RETURN_FALSE; } @@ -1314,7 +1316,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) } else { num_values = zend_hash_num_elements(Z_ARRVAL_PP(value)); } - + num_berval[i] = num_values; ldap_mods[i]->mod_bvalues = safe_emalloc((num_values + 1), sizeof(struct berval *), 0); @@ -1324,7 +1326,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) ldap_mods[i]->mod_bvalues[0] = (struct berval *) emalloc (sizeof(struct berval)); ldap_mods[i]->mod_bvalues[0]->bv_len = Z_STRLEN_PP(value); ldap_mods[i]->mod_bvalues[0]->bv_val = Z_STRVAL_PP(value); - } else { + } else { for (j = 0; j < num_values; j++) { if (zend_hash_index_find(Z_ARRVAL_PP(value), j, (void **) &ivalue) != SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value array must have consecutive indices 0, 1, ..."); @@ -1354,7 +1356,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) if ((i = ldap_modify_ext_s(ld->link, dn, ldap_mods, NULL, NULL)) != LDAP_SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Modify: %s", ldap_err2string(i)); RETVAL_FALSE; - } else RETVAL_TRUE; + } else RETVAL_TRUE; } errexit: @@ -1367,7 +1369,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) efree(ldap_mods[i]); } efree(num_berval); - efree(ldap_mods); + efree(ldap_mods); return; } @@ -1465,7 +1467,7 @@ PHP_FUNCTION(ldap_err2str) /* {{{ proto string ldap_error(resource link) Get the current ldap error string */ -PHP_FUNCTION(ldap_error) +PHP_FUNCTION(ldap_error) { zval *link; ldap_linkdata *ld; @@ -1485,7 +1487,7 @@ PHP_FUNCTION(ldap_error) /* {{{ proto bool ldap_compare(resource link, string dn, string attr, string value) Determine if an entry has a specific value for one of its attributes */ -PHP_FUNCTION(ldap_compare) +PHP_FUNCTION(ldap_compare) { zval *link; char *dn, *attr, *value; @@ -1510,7 +1512,7 @@ PHP_FUNCTION(ldap_compare) RETURN_FALSE; break; } - + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Compare: %s", ldap_err2string(errno)); RETURN_LONG(-1); } @@ -1549,12 +1551,12 @@ PHP_FUNCTION(ldap_sort) #if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 /* {{{ proto bool ldap_get_option(resource link, int option, mixed retval) Get the current value of various session-wide parameters */ -PHP_FUNCTION(ldap_get_option) +PHP_FUNCTION(ldap_get_option) { zval *link, *retval; ldap_linkdata *ld; long option; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &link, &option, &retval) != SUCCESS) { return; } @@ -1591,7 +1593,7 @@ PHP_FUNCTION(ldap_get_option) ldap_memfree(timeout); } RETURN_FALSE; - } + } if (!timeout) { RETURN_FALSE; } @@ -1606,7 +1608,7 @@ PHP_FUNCTION(ldap_get_option) if (ldap_get_option(ld->link, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) { RETURN_FALSE; - } + } zval_dtor(retval); ZVAL_LONG(retval, (timeout / 1000)); } break; @@ -1617,7 +1619,7 @@ PHP_FUNCTION(ldap_get_option) case LDAP_OPT_HOST_NAME: #endif #ifdef HAVE_LDAP_SASL - case LDAP_OPT_X_SASL_MECH: + case LDAP_OPT_X_SASL_MECH: case LDAP_OPT_X_SASL_REALM: case LDAP_OPT_X_SASL_AUTHCID: case LDAP_OPT_X_SASL_AUTHZID: @@ -1653,13 +1655,13 @@ PHP_FUNCTION(ldap_get_option) /* {{{ proto bool ldap_set_option(resource link, int option, mixed newval) Set the value of various session-wide parameters */ -PHP_FUNCTION(ldap_set_option) +PHP_FUNCTION(ldap_set_option) { zval *link, **newval; ldap_linkdata *ld; LDAP *ldap; long option; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlZ", &link, &option, &newval) != SUCCESS) { return; } @@ -1700,7 +1702,7 @@ PHP_FUNCTION(ldap_set_option) timeout.tv_usec = 0; if (ldap_set_option(ldap, LDAP_OPT_NETWORK_TIMEOUT, (void *) &timeout)) { RETURN_FALSE; - } + } } break; #elif defined(LDAP_X_OPT_CONNECT_TIMEOUT) case LDAP_X_OPT_CONNECT_TIMEOUT: @@ -1711,7 +1713,7 @@ PHP_FUNCTION(ldap_set_option) timeout = 1000 * Z_LVAL_PP(newval); /* Convert to milliseconds */ if (ldap_set_option(ldap, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) { RETURN_FALSE; - } + } } break; #endif /* options with string value */ @@ -1720,7 +1722,7 @@ PHP_FUNCTION(ldap_set_option) case LDAP_OPT_HOST_NAME: #endif #ifdef HAVE_LDAP_SASL - case LDAP_OPT_X_SASL_MECH: + case LDAP_OPT_X_SASL_MECH: case LDAP_OPT_X_SASL_REALM: case LDAP_OPT_X_SASL_AUTHCID: case LDAP_OPT_X_SASL_AUTHZID: @@ -1795,7 +1797,7 @@ PHP_FUNCTION(ldap_set_option) } else { ctrl->ldctl_iscritical = 0; } - + ++ctrlp; *ctrlp = NULL; zend_hash_move_forward(Z_ARRVAL_PP(newval)); @@ -1823,9 +1825,9 @@ PHP_FUNCTION(ldap_set_option) #ifdef HAVE_LDAP_PARSE_RESULT /* {{{ proto bool ldap_parse_result(resource link, resource result, int errcode, string matcheddn, string errmsg, array referrals) Extract information from result */ -PHP_FUNCTION(ldap_parse_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; @@ -1833,7 +1835,7 @@ PHP_FUNCTION(ldap_parse_result) int rc, lerrcode, myargcount = ZEND_NUM_ARGS(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrz|zzz", &link, &result, &errcode, &matcheddn, &errmsg, &referrals) != SUCCESS) { - return; + return; } ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link); @@ -1874,7 +1876,7 @@ PHP_FUNCTION(ldap_parse_result) ZVAL_STRING(errmsg, lerrmsg, 1); ldap_memfree(lerrmsg); } - case 4: + case 4: zval_dtor(matcheddn); if (lmatcheddn == NULL) { ZVAL_EMPTY_STRING(matcheddn); @@ -1992,7 +1994,7 @@ PHP_FUNCTION(ldap_rename) char *dn, *newrdn, *newparent; int dn_len, newrdn_len, newparent_len; zend_bool deleteoldrdn; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsssb", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn) != SUCCESS) { return; } @@ -2139,11 +2141,11 @@ PHP_FUNCTION(ldap_set_rebind_proc) #ifdef STR_TRANSLATION /* {{{ php_ldap_do_translate */ -static void php_ldap_do_translate(INTERNAL_FUNCTION_PARAMETERS, int way) +static void php_ldap_do_translate(INTERNAL_FUNCTION_PARAMETERS, int way) { char *value; int result, ldap_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) != SUCCESS) { return; } @@ -2188,7 +2190,7 @@ PHP_FUNCTION(ldap_8859_to_t61) #ifdef LDAP_CONTROL_PAGEDRESULTS /* {{{ proto mixed ldap_control_paged_result(resource link, int pagesize [, bool iscritical [, string cookie]]) Inject paged results control*/ -PHP_FUNCTION(ldap_control_paged_result) +PHP_FUNCTION(ldap_control_paged_result) { long pagesize; zend_bool iscritical; @@ -2280,7 +2282,7 @@ PHP_FUNCTION(ldap_control_paged_result) /* {{{ proto bool ldap_control_paged_result_response(resource link, resource result [, string &cookie [, int &estimated]]) Extract paged results control response */ -PHP_FUNCTION(ldap_control_paged_result_response) +PHP_FUNCTION(ldap_control_paged_result_response) { zval *link, *result, *cookie, *estimated; struct berval lcookie; @@ -2635,9 +2637,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_8859_to_t61, 0, 0, 1) ZEND_END_ARG_INFO() #endif /* }}} */ - + /* - This is just a small subset of the functionality provided by the LDAP library. All the + This is just a small subset of the functionality provided by the LDAP library. All the operations are synchronous. Referrals are not handled automatically. */ /* {{{ ldap_functions[] @@ -2718,13 +2720,13 @@ const zend_function_entry ldap_functions[] = { zend_module_entry ldap_module_entry = { /* {{{ */ STANDARD_MODULE_HEADER, - "ldap", - ldap_functions, - PHP_MINIT(ldap), - PHP_MSHUTDOWN(ldap), - NULL, + "ldap", + ldap_functions, + PHP_MINIT(ldap), + PHP_MSHUTDOWN(ldap), + NULL, NULL, - PHP_MINFO(ldap), + PHP_MINFO(ldap), NO_VERSION_YET, PHP_MODULE_GLOBALS(ldap), PHP_GINIT(ldap), diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 4e430b6ea2364..ba2fa64cb2dc6 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -213,7 +213,7 @@ static const struct mb_overload_def mb_ovld[] = { {MB_OVERLOAD_REGEX, "split", "mb_split", "mb_orig_split"}, #endif {0, NULL, NULL, NULL} -}; +}; /* }}} */ /* {{{ arginfo */ @@ -620,7 +620,7 @@ static void *_php_mb_allocators_calloc(unsigned int nelems, unsigned int szelem) static void _php_mb_allocators_free(void *ptr) { efree(ptr); -} +} static void *_php_mb_allocators_pmalloc(unsigned int sz) { @@ -635,7 +635,7 @@ static void *_php_mb_allocators_prealloc(void *ptr, unsigned int sz) static void _php_mb_allocators_pfree(void *ptr) { pefree(ptr, 1); -} +} static mbfl_allocators _php_mb_allocators = { _php_mb_allocators_malloc, @@ -658,7 +658,7 @@ static sapi_post_entry mbstr_post_entries[] = { /* {{{ static int php_mb_parse_encoding_list() * Return 0 if input contains any illegal encoding, otherwise 1. - * Even if any illegal encoding is detected the result may contain a list + * Even if any illegal encoding is detected the result may contain a list * of parsed encodings. */ static int @@ -693,7 +693,7 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en endp = tmpstr + value_length; n = 1; p1 = tmpstr; - while ((p2 = php_memnstr(p1, ",", 1, endp)) != NULL) { + while ((p2 = (char *)php_memnstr(p1, ",", 1, endp)) != NULL) { p1 = p2 + 1; n++; } @@ -706,7 +706,7 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en bauto = 0; p1 = tmpstr; do { - p2 = p = php_memnstr(p1, ",", 1, endp); + p2 = p = (char *)php_memnstr(p1, ",", 1, endp); if (p == NULL) { p = endp; } @@ -777,7 +777,7 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en /* {{{ static int php_mb_parse_encoding_array() * Return 0 if input contains any illegal encoding, otherwise 1. - * Even if any illegal encoding is detected the result may contain a list + * Even if any illegal encoding is detected the result may contain a list * of parsed encodings. */ static int @@ -932,7 +932,7 @@ static size_t php_mb_zend_encoding_converter(unsigned char **to, size_t *to_leng if (!mbfl_buffer_converter_result(convd, &result)) { mbfl_buffer_converter_delete(convd); return (size_t)-1; - } + } *to = result.val; *to_length = result.len; @@ -1164,7 +1164,7 @@ static char *php_mb_rfc1867_basename(const zend_encoding *encoding, char *filena * to nill or problem is fixed this code must remain enabled for all systems. */ s = php_mb_safe_strrchr_ex(filename, '\\', filename_len, (const mbfl_encoding *)encoding); s2 = php_mb_safe_strrchr_ex(filename, '/', filename_len, (const mbfl_encoding *)encoding); - + if (s && s2) { if (s > s2) { return ++s; @@ -1454,13 +1454,13 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("mbstring.http_output", "pass", PHP_INI_ALL, OnUpdate_mbstring_http_output) STD_PHP_INI_ENTRY("mbstring.internal_encoding", NULL, PHP_INI_ALL, OnUpdate_mbstring_internal_encoding, internal_encoding_name, zend_mbstring_globals, mbstring_globals) PHP_INI_ENTRY("mbstring.substitute_character", NULL, PHP_INI_ALL, OnUpdate_mbstring_substitute_character) - STD_PHP_INI_ENTRY("mbstring.func_overload", "0", + STD_PHP_INI_ENTRY("mbstring.func_overload", "0", PHP_INI_SYSTEM, OnUpdateLong, func_overload, zend_mbstring_globals, mbstring_globals) STD_PHP_INI_BOOLEAN("mbstring.encoding_translation", "0", PHP_INI_SYSTEM | PHP_INI_PERDIR, - OnUpdate_mbstring_encoding_translation, - encoding_translation, zend_mbstring_globals, mbstring_globals) + OnUpdate_mbstring_encoding_translation, + encoding_translation, zend_mbstring_globals, mbstring_globals) PHP_INI_ENTRY("mbstring.http_output_conv_mimetypes", "^(text/|application/xhtml\\+xml)", PHP_INI_ALL, @@ -1602,21 +1602,21 @@ PHP_RINIT_FUNCTION(mbstring) /* override original function. */ if (MBSTRG(func_overload)){ p = &(mb_ovld[0]); - + while (p->type > 0) { - if ((MBSTRG(func_overload) & p->type) == p->type && + if ((MBSTRG(func_overload) & p->type) == p->type && zend_hash_find(EG(function_table), p->save_func, strlen(p->save_func)+1, (void **)&orig) != SUCCESS) { zend_hash_find(EG(function_table), p->ovld_func, strlen(p->ovld_func)+1 , (void **)&func); - + if (zend_hash_find(EG(function_table), p->orig_func, strlen(p->orig_func)+1, (void **)&orig) != SUCCESS) { php_error_docref("ref.mbstring" TSRMLS_CC, E_WARNING, "mbstring couldn't find function %s.", p->orig_func); return FAILURE; } else { zend_hash_add(EG(function_table), p->save_func, strlen(p->save_func)+1, orig, sizeof(zend_function), NULL); - if (zend_hash_update(EG(function_table), p->orig_func, strlen(p->orig_func)+1, func, sizeof(zend_function), + if (zend_hash_update(EG(function_table), p->orig_func, strlen(p->orig_func)+1, func, sizeof(zend_function), NULL) == FAILURE) { php_error_docref("ref.mbstring" TSRMLS_CC, E_WARNING, "mbstring couldn't replace function %s.", p->orig_func); return FAILURE; @@ -1663,10 +1663,10 @@ PHP_RSHUTDOWN_FUNCTION(mbstring) if (MBSTRG(func_overload)){ p = &(mb_ovld[0]); while (p->type > 0) { - if ((MBSTRG(func_overload) & p->type) == p->type && + if ((MBSTRG(func_overload) & p->type) == p->type && zend_hash_find(EG(function_table), p->save_func, strlen(p->save_func)+1, (void **)&orig) == SUCCESS) { - + zend_hash_update(EG(function_table), p->orig_func, strlen(p->orig_func)+1, orig, sizeof(zend_function), NULL); zend_hash_del(EG(function_table), p->save_func, strlen(p->save_func)+1); } @@ -1688,7 +1688,7 @@ PHP_MINFO_FUNCTION(mbstring) php_info_print_table_start(); php_info_print_table_row(2, "Multibyte Support", "enabled"); php_info_print_table_row(2, "Multibyte string engine", "libmbfl"); - php_info_print_table_row(2, "HTTP input encoding translation", MBSTRG(encoding_translation) ? "enabled": "disabled"); + php_info_print_table_row(2, "HTTP input encoding translation", MBSTRG(encoding_translation) ? "enabled": "disabled"); { char tmp[256]; snprintf(tmp, sizeof(tmp), "%d.%d.%d", MBFL_VERSION_MAJOR, MBFL_VERSION_MINOR, MBFL_VERSION_TEENY); @@ -1824,7 +1824,7 @@ PHP_FUNCTION(mb_http_input) temp = list; spprintf(&list, 0, "%s,%s", temp, (*entry)->name); efree(temp); - if (!list) { + if (!list) { break; } } else { @@ -2056,12 +2056,12 @@ PHP_FUNCTION(mb_parse_str) encstr = estrndup(encstr, encstr_len); info.data_type = PARSE_STRING; - info.separator = PG(arg_separator).input; + info.separator = PG(arg_separator).input; info.report_errors = 1; info.to_encoding = MBSTRG(current_internal_encoding); info.to_language = MBSTRG(language); info.from_encodings = MBSTRG(http_input_list); - info.num_from_encodings = MBSTRG(http_input_list_size); + info.num_from_encodings = MBSTRG(http_input_list_size); info.from_language = MBSTRG(language); if (track_vars_array != NULL) { @@ -2071,8 +2071,8 @@ PHP_FUNCTION(mb_parse_str) if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); } - Z_ARRVAL(tmp) = EG(active_symbol_table); - detected = _php_mb_encoding_handler_ex(&info, &tmp, encstr TSRMLS_CC); + Z_ARRVAL(tmp) = EG(active_symbol_table); + detected = _php_mb_encoding_handler_ex(&info, &tmp, encstr TSRMLS_CC); } MBSTRG(http_input_identify) = detected; @@ -2136,7 +2136,7 @@ PHP_FUNCTION(mb_output_handler) if (SG(sapi_headers).send_default_content_type || send_text_mimetype) { charset = encoding->mime_name; if (charset) { - len = spprintf( &p, 0, "Content-Type: %s; charset=%s", mimetype, charset ); + len = spprintf( &p, 0, "Content-Type: %s; charset=%s", mimetype, charset ); if (sapi_add_header(p, len, 0) != FAILURE) { SG(sapi_headers).send_default_content_type = 0; } @@ -2159,7 +2159,7 @@ PHP_FUNCTION(mb_output_handler) /* mode */ mbfl_buffer_converter_illegal_mode(MBSTRG(outconv), MBSTRG(current_filter_illegal_mode)); mbfl_buffer_converter_illegal_substchar(MBSTRG(outconv), MBSTRG(current_filter_illegal_substchar)); - + /* feed the string */ mbfl_string_init(&string); string.no_language = MBSTRG(language); @@ -2169,11 +2169,11 @@ PHP_FUNCTION(mb_output_handler) mbfl_buffer_converter_feed(MBSTRG(outconv), &string); if (last_feed) { mbfl_buffer_converter_flush(MBSTRG(outconv)); - } + } /* get the converter output, and return it */ mbfl_buffer_converter_result(MBSTRG(outconv), &result); RETVAL_STRINGL((char *)result.val, result.len, 0); /* the string is already strdup()'ed */ - + /* delete the converter if it is the last feed. */ if (last_feed) { MBSTRG(illegalchars) += mbfl_buffer_illegalchars(MBSTRG(outconv)); @@ -2223,7 +2223,7 @@ PHP_FUNCTION(mb_strlen) PHP_FUNCTION(mb_strpos) { int n, reverse = 0; - long offset; + long offset = 0; mbfl_string haystack, needle; char *enc_name = NULL; int enc_name_len; @@ -2385,7 +2385,7 @@ PHP_FUNCTION(mb_strrpos) PHP_FUNCTION(mb_stripos) { int n; - long offset; + long offset = 0; mbfl_string haystack, needle; const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name; int from_encoding_len; @@ -2414,7 +2414,7 @@ PHP_FUNCTION(mb_stripos) PHP_FUNCTION(mb_strripos) { int n; - long offset; + long offset = 0; mbfl_string haystack, needle; const char *from_encoding = MBSTRG(current_internal_encoding)->mime_name; int from_encoding_len; @@ -2711,14 +2711,13 @@ PHP_FUNCTION(mb_substr_count) Returns part of a string */ PHP_FUNCTION(mb_substr) { - size_t argc = ZEND_NUM_ARGS(); - char *str, *encoding; - long from, len; + char *str, *encoding = NULL; + long from, len = LONG_MAX; int mblen, 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() TSRMLS_CC, "sl|Zs", &str, &str_len, &from, &z_len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l!s", &str, &str_len, &from, &len, &no_len, &encoding, &encoding_len) == FAILURE) { return; } @@ -2726,7 +2725,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 TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -2737,11 +2736,8 @@ PHP_FUNCTION(mb_substr) string.val = (unsigned char *)str; string.len = str_len; - if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) { + if (no_len || len > str_len) { len = str_len; - } else { - convert_to_long_ex(z_len); - len = Z_LVAL_PP(z_len); } /* measures length */ @@ -2788,22 +2784,21 @@ PHP_FUNCTION(mb_substr) Returns part of a string */ PHP_FUNCTION(mb_strcut) { - size_t argc = ZEND_NUM_ARGS(); - char *encoding; - long from, len; + char *encoding = NULL; + long from, len = LONG_MAX; int 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() TSRMLS_CC, "sl|Zs", (char **)&string.val, (int **)&string.len, &from, &z_len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -2811,11 +2806,8 @@ PHP_FUNCTION(mb_strcut) } } - if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) { + if (no_len || len > string.len) { len = string.len; - } else { - convert_to_long_ex(z_len); - len = Z_LVAL_PP(z_len); } /* if "from" position is negative, count start position from the end @@ -2890,7 +2882,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; long from, width; int str_len, trimmarker_len, encoding_len; mbfl_string string, result, marker, *ret; @@ -2908,7 +2900,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 TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -2929,7 +2921,7 @@ PHP_FUNCTION(mb_strimwidth) RETURN_FALSE; } - if (ZEND_NUM_ARGS() >= 4) { + if (trimmarker != NULL) { marker.val = (unsigned char *)trimmarker; marker.len = trimmarker_len; } @@ -3037,7 +3029,7 @@ PHP_FUNCTION(mb_convert_encoding) { char *arg_str, *arg_new; int 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; @@ -3049,7 +3041,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); @@ -3125,7 +3117,7 @@ PHP_FUNCTION(mb_convert_case) if (newstr) { RETVAL_STRINGL(newstr, ret_len, 0); - } + } } /* }}} */ @@ -3183,8 +3175,8 @@ PHP_FUNCTION(mb_detect_encoding) { char *str; int 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; @@ -3198,7 +3190,7 @@ PHP_FUNCTION(mb_detect_encoding) /* make encoding list */ list = NULL; size = 0; - if (ZEND_NUM_ARGS() >= 2 && !ZVAL_IS_NULL(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 TSRMLS_CC)) { @@ -3225,10 +3217,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 { @@ -3499,7 +3487,7 @@ PHP_FUNCTION(mb_convert_variables) size_t elistsz; const mbfl_encoding **elist; char *to_enc; - void *ptmp; + void *ptmp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sZ+", &to_enc, &to_enc_len, &zfrom_enc, &args, &argc) == FAILURE) { return; @@ -3706,17 +3694,16 @@ PHP_FUNCTION(mb_convert_variables) static void php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type) { - char *str, *encoding; + char *str, *encoding = NULL; int str_len, encoding_len; zval *zconvmap, **hash_entry; HashTable *target_hash; - size_t 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 TSRMLS_CC, "sz|sb", &str, &str_len, &zconvmap, &encoding, &encoding_len, &is_hex) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|sb", &str, &str_len, &zconvmap, &encoding, &encoding_len, &is_hex) == FAILURE) { return; } @@ -3727,7 +3714,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 TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", encoding); @@ -3737,10 +3724,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 */ @@ -3860,12 +3845,12 @@ static int _php_mbstr_parse_mail_headers(HashTable *ht, const char *str, size_t /* * C o n t e n t - T y p e : t e x t / h t m l \r\n - * ^ ^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^ ^^^^ - * state 0 1 2 3 + * ^ ^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^ ^^^^ + * state 0 1 2 3 * * C o n t e n t - T y p e : t e x t / h t m l \r\n - * ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ - * crlf_state -1 0 1 -1 + * ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ + * crlf_state -1 0 1 -1 * */ @@ -3931,7 +3916,7 @@ static int _php_mbstr_parse_mail_headers(HashTable *ht, const char *str, size_t token.a = 0; state = 1; break; - + case 2: if (crlf_state != -1) { token.c = (char *)ps; @@ -4108,14 +4093,14 @@ PHP_FUNCTION(mb_send_mail) if ((param_name = php_strtok_r(p, "= ", &tmp)) != NULL) { if (strcasecmp(param_name, "charset") == 0) { enum mbfl_no_encoding _tran_cs = tran_cs; - + charset = php_strtok_r(NULL, "= \"", &tmp); if (charset != NULL) { _tran_cs = mbfl_name2no_encoding(charset); } if (_tran_cs == mbfl_no_encoding_invalid) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported charset \"%s\" - will be regarded as ascii", charset); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported charset \"%s\" - will be regarded as ascii", charset); _tran_cs = mbfl_no_encoding_ascii; } tran_cs = _tran_cs; @@ -4140,7 +4125,7 @@ PHP_FUNCTION(mb_send_mail) break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported transfer encoding \"%s\" - will be regarded as 8bit", s->c); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported transfer encoding \"%s\" - will be regarded as 8bit", s->c); body_enc = mbfl_no_encoding_8bit; break; } @@ -4273,7 +4258,7 @@ PHP_FUNCTION(mb_send_mail) extra_cmd = php_escape_shell_cmd(force_extra_parameters); } else if (extra_cmd) { extra_cmd = php_escape_shell_cmd(extra_cmd); - } + } if (!err && php_mail(to_r, subject, message, headers, extra_cmd TSRMLS_CC)) { RETVAL_TRUE; @@ -4372,7 +4357,7 @@ PHP_FUNCTION(mb_get_info) } if ((name = (char *)mbfl_no_language2name(MBSTRG(language))) != NULL) { add_assoc_string(return_value, "language", name, 1); - } + } n = MBSTRG(current_detect_order_list_size); entry = MBSTRG(current_detect_order_list); if (n > 0) { @@ -4402,15 +4387,15 @@ PHP_FUNCTION(mb_get_info) } else if (!strcasecmp("internal_encoding", typ)) { if (MBSTRG(current_internal_encoding)) { RETVAL_STRING((char *)MBSTRG(current_internal_encoding)->name, 1); - } + } } else if (!strcasecmp("http_input", typ)) { if (MBSTRG(http_input_identify)) { RETVAL_STRING((char *)MBSTRG(http_input_identify)->name, 1); - } + } } else if (!strcasecmp("http_output", typ)) { if (MBSTRG(current_http_output_encoding)) { RETVAL_STRING((char *)MBSTRG(current_http_output_encoding)->name, 1); - } + } } else if (!strcasecmp("http_output_conv_mimetypes", typ)) { if ((name = (char *)zend_ini_string("mbstring.http_output_conv_mimetypes", sizeof("mbstring.http_output_conv_mimetypes"), 0)) != NULL) { RETVAL_STRING(name, 1); @@ -4453,7 +4438,7 @@ PHP_FUNCTION(mb_get_info) } else if (!strcasecmp("language", typ)) { if ((name = (char *)mbfl_no_language2name(MBSTRG(language))) != NULL) { RETVAL_STRING(name, 1); - } + } } else if (!strcasecmp("detect_order", typ)) { n = MBSTRG(current_detect_order_list_size); entry = MBSTRG(current_detect_order_list); @@ -4520,9 +4505,9 @@ PHP_FUNCTION(mb_check_encoding) if (convd == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create converter"); RETURN_FALSE; - } + } mbfl_buffer_converter_illegal_mode(convd, MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE); - mbfl_buffer_converter_illegal_substchar(convd, 0); + mbfl_buffer_converter_illegal_substchar(convd, 0); /* initialize string */ mbfl_string_init_set(&string, mbfl_no_language_neutral, encoding->no_encoding); @@ -4573,7 +4558,7 @@ static void php_mb_populate_current_detect_order_list(TSRMLS_D) } /* {{{ static int php_mb_encoding_translation() */ -static int php_mb_encoding_translation(TSRMLS_D) +static int php_mb_encoding_translation(TSRMLS_D) { return MBSTRG(encoding_translation); } @@ -4699,7 +4684,7 @@ MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned int { int haystack_char_len = mbfl_strlen(&haystack); - + if (mode) { if ((offset > 0 && offset > haystack_char_len) || (offset < 0 && -offset > haystack_char_len)) { diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 607921ebb6b8f..940231daf47f7 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -32,7 +32,7 @@ #include "ext/standard/info.h" #include "php_mbregex.h" #include "mbstring.h" - + #include "php_onig_compat.h" /* must come prior to the oniguruma header */ #include #undef UChar @@ -55,7 +55,7 @@ struct _zend_mb_regex_globals { #define MBREX(g) (MBSTRG(mb_regex_globals)->g) /* {{{ static void php_mb_regex_free_cache() */ -static void php_mb_regex_free_cache(php_mb_regex_t **pre) +static void php_mb_regex_free_cache(php_mb_regex_t **pre) { onig_free(*pre); } @@ -78,7 +78,7 @@ static int _php_mb_regex_globals_ctor(zend_mb_regex_globals *pglobals TSRMLS_DC) /* }}} */ /* {{{ _php_mb_regex_globals_dtor */ -static void _php_mb_regex_globals_dtor(zend_mb_regex_globals *pglobals TSRMLS_DC) +static void _php_mb_regex_globals_dtor(zend_mb_regex_globals *pglobals TSRMLS_DC) { zend_hash_destroy(&pglobals->ht_rc); } @@ -466,7 +466,7 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, int patl retval = *rc; } out: - return retval; + return retval; } /* }}} */ @@ -483,7 +483,7 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT --len_left; *(p++) = 'i'; } - ++len_req; + ++len_req; } if ((option & ONIG_OPTION_EXTEND) != 0) { @@ -491,7 +491,7 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT --len_left; *(p++) = 'x'; } - ++len_req; + ++len_req; } if ((option & (ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE)) == @@ -500,14 +500,14 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT --len_left; *(p++) = 'p'; } - ++len_req; + ++len_req; } else { if ((option & ONIG_OPTION_MULTILINE) != 0) { if (len_left > 0) { --len_left; *(p++) = 'm'; } - ++len_req; + ++len_req; } if ((option & ONIG_OPTION_SINGLELINE) != 0) { @@ -515,22 +515,22 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT --len_left; *(p++) = 's'; } - ++len_req; + ++len_req; } - } + } if ((option & ONIG_OPTION_FIND_LONGEST) != 0) { if (len_left > 0) { --len_left; *(p++) = 'l'; } - ++len_req; + ++len_req; } if ((option & ONIG_OPTION_FIND_NOT_EMPTY) != 0) { if (len_left > 0) { --len_left; *(p++) = 'n'; } - ++len_req; + ++len_req; } c = 0; @@ -566,7 +566,7 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT --len_left; *(p++) = '\0'; } - ++len_req; + ++len_req; if (len < len_req) { return len_req; } @@ -577,11 +577,11 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT /* {{{ _php_mb_regex_init_options */ static void -_php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, OnigSyntaxType **syntax, int *eval) +_php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, OnigSyntaxType **syntax, int *eval) { int n; char c; - int optm = 0; + int optm = 0; *syntax = ONIG_SYNTAX_RUBY; @@ -636,13 +636,13 @@ _php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, O *syntax = ONIG_SYNTAX_POSIX_EXTENDED; break; case 'e': - if (eval != NULL) *eval = 1; + if (eval != NULL) *eval = 1; break; default: break; } } - if (option != NULL) *option|=optm; + if (option != NULL) *option|=optm; } } /* }}} */ @@ -655,8 +655,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; int encoding_len; OnigEncoding mbctype; @@ -664,7 +663,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) { @@ -672,7 +671,7 @@ PHP_FUNCTION(mb_regex_encoding) } RETURN_STRING((char *)retval, 1); - } else if (argc == 1) { + } else { mbctype = _php_mb_regex_name2mbctype(encoding); if (mbctype == ONIG_ENCODING_UNDEF) { @@ -689,7 +688,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; int string_len; php_mb_regex_t *re; @@ -698,8 +697,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() TSRMLS_CC, "Zs|z", &arg_pattern, &string, &string_len, &array) == FAILURE) { RETURN_FALSE; } @@ -860,11 +857,11 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp } else { /* FIXME: this code is not multibyte aware! */ convert_to_long_ex(arg_pattern_zval); - pat_buf[0] = (char)Z_LVAL_PP(arg_pattern_zval); + pat_buf[0] = (char)Z_LVAL_PP(arg_pattern_zval); pat_buf[1] = '\0'; arg_pattern = pat_buf; - arg_pattern_len = 1; + arg_pattern_len = 1; } /* create regex pattern buffer */ re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax TSRMLS_CC); @@ -934,7 +931,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp } } } - + if (eval) { zval v; /* null terminate buffer */ @@ -957,18 +954,18 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp zval **args[1]; zval *subpats; int i; - + MAKE_STD_ZVAL(subpats); array_init(subpats); - + for (i = 0; i < regs->num_regs; i++) { add_next_index_stringl(subpats, string + regs->beg[i], regs->end[i] - regs->beg[i], 1); - } - + } + args[0] = &subpats; /* null terminate buffer */ smart_str_0(&eval_buf); - + arg_replace_fci.param_count = 1; arg_replace_fci.params = args; arg_replace_fci.retval_ptr_ptr = &retval_ptr; @@ -991,7 +988,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp pos = (OnigUChar *)string + n; } else { if (pos < string_lim) { - smart_str_appendl(&out_buf, pos, 1); + smart_str_appendl(&out_buf, pos, 1); } pos++; } @@ -1013,7 +1010,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp smart_str_free(&eval_buf); if (err <= -2) { - smart_str_free(&out_buf); + smart_str_free(&out_buf); RETVAL_FALSE; } else { smart_str_appendc(&out_buf, '\0'); @@ -1063,7 +1060,7 @@ PHP_FUNCTION(mb_split) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &arg_pattern, &arg_pattern_len, &string, &string_len, &count) == FAILURE) { RETURN_FALSE; - } + } if (count > 0) { count--; @@ -1177,26 +1174,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; int 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 TSRMLS_CC, "|ss", &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|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) TSRMLS_CC)) == NULL) { RETURN_FALSE; @@ -1307,18 +1303,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; int arg_pattern_len = 0, arg_options_len = 0; OnigSyntaxType *syntax = NULL; OnigOptionType option; - if (zend_parse_parameters(argc TSRMLS_CC, "z|ss", &arg_str, &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC, E_WARNING, "Empty pattern"); RETURN_FALSE; } @@ -1326,12 +1321,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 TSRMLS_CC)) == NULL) { RETURN_FALSE; @@ -1416,7 +1411,7 @@ PHP_FUNCTION(mb_ereg_search_setpos) /* }}} */ /* {{{ php_mb_regex_set_options */ -static void _php_mb_regex_set_options(OnigOptionType options, OnigSyntaxType *syntax, OnigOptionType *prev_options, OnigSyntaxType **prev_syntax TSRMLS_DC) +static void _php_mb_regex_set_options(OnigOptionType options, OnigSyntaxType *syntax, OnigOptionType *prev_options, OnigSyntaxType **prev_syntax TSRMLS_DC) { if (prev_options != NULL) { *prev_options = MBREX(regex_default_options); 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 d74f0829d91e1..ca758868312e7 100644 --- a/ext/mssql/php_mssql.c +++ b/ext/mssql/php_mssql.c @@ -187,16 +187,16 @@ static PHP_GINIT_FUNCTION(mssql); /* {{{ mssql_module_entry */ -zend_module_entry mssql_module_entry = +zend_module_entry mssql_module_entry = { STANDARD_MODULE_HEADER, - "mssql", - mssql_functions, - PHP_MINIT(mssql), - PHP_MSHUTDOWN(mssql), - PHP_RINIT(mssql), - PHP_RSHUTDOWN(mssql), - PHP_MINFO(mssql), + "mssql", + mssql_functions, + PHP_MINIT(mssql), + PHP_MSHUTDOWN(mssql), + PHP_RINIT(mssql), + PHP_RSHUTDOWN(mssql), + PHP_MINFO(mssql), NO_VERSION_YET, PHP_MODULE_GLOBALS(mssql), PHP_GINIT(mssql), @@ -218,7 +218,7 @@ static PHP_INI_DISP(display_text_size) { char *value; TSRMLS_FETCH(); - + if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) { value = ini_entry->orig_value; } else if (ini_entry->value) { @@ -271,7 +271,7 @@ static int php_mssql_error_handler(DBPROCESS *dbproc, int severity, int dberr, i if (severity >= MS_SQL_G(min_error_severity)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (severity %d)", dberrstr, severity); } - return INT_CANCEL; + return INT_CANCEL; } /* {{{ php_mssql_message_handler @@ -299,7 +299,7 @@ static int _clean_invalid_results(zend_rsrc_list_entry *le TSRMLS_DC) { if (Z_TYPE_P(le) == le_result) { mssql_link *mssql_ptr = ((mssql_result *) le->ptr)->mssql_ptr; - + if (!mssql_ptr->valid) { return 1; } @@ -310,7 +310,7 @@ static int _clean_invalid_results(zend_rsrc_list_entry *le TSRMLS_DC) /* {{{ _free_result */ -static void _free_result(mssql_result *result, int free_fields) +static void _free_result(mssql_result *result, int free_fields) { int i,j; @@ -327,7 +327,7 @@ static void _free_result(mssql_result *result, int free_fields) result->data = NULL; result->blocks_initialized = 0; } - + if (free_fields && result->fields) { for (i=0; inum_fields; i++) { STR_FREE(result->fields[i].name); @@ -348,7 +348,7 @@ static void _free_mssql_statement(zend_rsrc_list_entry *rsrc TSRMLS_DC) zend_hash_destroy(statement->binds); efree(statement->binds); } - + efree(statement); } /* }}} */ @@ -551,7 +551,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() TSRMLS_CC, "|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() TSRMLS_CC, "|sssb", &host, &host_len, &user, &user_len, &passwd, &passwd_len, &new_link) == FAILURE) { return; } @@ -594,12 +594,12 @@ static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) dbsetlogintime(MS_SQL_G(connect_timeout)); dbsettime(MS_SQL_G(timeout)); - /* set a DBLOGIN record */ + /* set a DBLOGIN record */ if ((mssql.login = dblogin()) == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate login record"); RETURN_FALSE; } - + DBERRHANDLE(mssql.login, (EHANDLEFUNC) php_mssql_error_handler); DBMSGHANDLE(mssql.login, (MHANDLEFUNC) php_mssql_message_handler); @@ -718,7 +718,7 @@ static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) efree(hashed_details); RETURN_FALSE; } - + mssql_ptr = (mssql_link *) le->ptr; /* test that the link hasn't died */ if (DBDEAD(mssql_ptr->link) == TRUE) { @@ -754,7 +754,7 @@ static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) ZEND_REGISTER_RESOURCE(return_value, mssql_ptr, le_plink); } else { /* non persistent */ zend_rsrc_list_entry *index_ptr, new_index_ptr; - + /* first we check the hash for the hashed_details key. if it exists, * it should point us to the right offset where the actual mssql link sits. * if it doesn't, open a new mssql link, add it to the resource list, @@ -789,7 +789,7 @@ static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) dbfreelogin(mssql.login); RETURN_FALSE; } - + if ((mssql.link=dbopen(mssql.login, host))==NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to connect to server: %s", (host == NULL ? "" : host)); efree(hashed_details); @@ -826,7 +826,7 @@ static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) mssql_ptr = (mssql_link *) emalloc(sizeof(mssql_link)); memcpy(mssql_ptr, &mssql, sizeof(mssql_link)); ZEND_REGISTER_RESOURCE(return_value, mssql_ptr, le_link); - + /* add it to the hash */ new_index_ptr.ptr = (void *) Z_LVAL_P(return_value); Z_TYPE(new_index_ptr) = le_index_ptr; @@ -876,7 +876,7 @@ PHP_FUNCTION(mssql_close) zval *mssql_link_index = NULL; int id = -1; mssql_link *mssql_ptr; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mssql_link_index) == FAILURE) { return; } @@ -918,7 +918,7 @@ PHP_FUNCTION(mssql_select_db) } ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); - + if (dbuse(mssql_ptr->link, db)==FAIL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to select database: %s", db); RETURN_FALSE; @@ -943,10 +943,10 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off case SQLINT1: case SQLINT2: case SQLINT4: - case SQLINTN: { + case SQLINTN: { ZVAL_LONG(result, (long) anyintcol(offset)); break; - } + } case SQLCHAR: case SQLVARCHAR: case SQLTEXT: { @@ -959,7 +959,7 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off length--; } #endif - ZVAL_STRINGL(result, data, length, 1); + ZVAL_STRINGL(result, data, length, 1); break; } case SQLFLT4: @@ -1003,7 +1003,7 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off default: { if (dbwillconvert(column_type,SQLCHAR)) { char *res_buf; - DBDATEREC dateinfo; + DBDATEREC dateinfo; int res_length = dbdatlen(mssql_ptr->link,offset); if (res_length == -1) { @@ -1040,11 +1040,11 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off } else { dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset)); } - + res_length = 19; spprintf(&res_buf, 0, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second); } - + ZVAL_STRINGL(result, res_buf, res_length, 0); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "column %d has unknown data type (%d)", offset, coltype(offset)); @@ -1087,7 +1087,7 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int } else if (dbwillconvert(coltype(offset),SQLCHAR)) { unsigned char *res_buf; - DBDATEREC dateinfo; + DBDATEREC dateinfo; int res_length = dbdatlen(mssql_ptr->link,offset); if ((column_type != SQLDATETIME && column_type != SQLDATETIM4) || MS_SQL_G(datetimeconvert)) { @@ -1107,7 +1107,7 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int res_length += 20; break; } - + res_buf = (unsigned char *) emalloc(res_length+1); res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR, res_buf, -1); res_buf[res_length] = '\0'; @@ -1120,7 +1120,7 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int } else { dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset)); } - + res_length = 19; spprintf(&res_buf, 0, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second); } @@ -1135,7 +1135,7 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int /* {{{ _mssql_get_sp_result */ -static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *statement TSRMLS_DC) +static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *statement TSRMLS_DC) { int i, num_rets, type; char *parameter; @@ -1148,7 +1148,7 @@ static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *stateme for (i = 1; i <= num_rets; i++) { parameter = (char*)dbretname(mssql_ptr->link, i); type = dbrettype(mssql_ptr->link, i); - + if (statement->binds != NULL) { /* Maybe a non-parameter sp */ if (zend_hash_find(statement->binds, parameter, strlen(parameter), (void**)&bind)==SUCCESS) { if (!dbretlen(mssql_ptr->link,i)) { @@ -1164,7 +1164,7 @@ static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *stateme /* FIXME this works only on little endian machine !!! */ Z_LVAL_P(bind->zval) = *((int *)(dbretdata(mssql_ptr->link,i))); break; - + case SQLFLT4: case SQLFLT8: case SQLFLTN: @@ -1174,7 +1174,7 @@ static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *stateme convert_to_double_ex(&bind->zval); Z_DVAL_P(bind->zval) = *((double *)(dbretdata(mssql_ptr->link,i))); break; - + case SQLCHAR: case SQLVARCHAR: case SQLTEXT: @@ -1208,7 +1208,7 @@ static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *stateme /* {{{ _mssql_fetch_batch */ -static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int retvalue TSRMLS_DC) +static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int retvalue TSRMLS_DC) { int i, j = 0; char computed_buf[16]; @@ -1217,7 +1217,7 @@ static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int r for (i=0; inum_fields; i++) { char *source = NULL; char *fname = (char *)dbcolname(mssql_ptr->link,i+1); - + if (*fname) { result->fields[i].name = estrdup(fname); } else { @@ -1237,7 +1237,7 @@ static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int r else { result->fields[i].column_source = STR_EMPTY_ALLOC(); } - + result->fields[i].type = coltype(i+1); /* set numeric flag */ switch (result->fields[i].type) { @@ -1278,7 +1278,7 @@ static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int r } if (ibatchsize || result->batchsize==0) { i++; - dbclrbuf(mssql_ptr->link,DBLASTROW(mssql_ptr->link)); + dbclrbuf(mssql_ptr->link,DBLASTROW(mssql_ptr->link)); retvalue=dbnextrow(mssql_ptr->link); } else @@ -1303,7 +1303,7 @@ PHP_FUNCTION(mssql_fetch_batch) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mssql_result_index) == FAILURE) { return; } - + if (Z_RESVAL_P(mssql_result_index) == 0) { RETURN_FALSE; } @@ -1326,30 +1326,25 @@ PHP_FUNCTION(mssql_query) char *query; zval *mssql_link_index = NULL; int query_len, retvalue, batchsize, num_fields; - long zbatchsize = 0; + 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() TSRMLS_CC, "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); - + if (dbcmd(mssql_ptr->link, query)==FAIL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set query"); RETURN_FALSE; @@ -1359,7 +1354,7 @@ PHP_FUNCTION(mssql_query) dbcancel(mssql_ptr->link); RETURN_FALSE; } - + /* Skip results not returning any columns */ while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue == SUCCEED) { retvalue = dbresults(mssql_ptr->link); @@ -1369,7 +1364,7 @@ PHP_FUNCTION(mssql_query) RETURN_TRUE; } - retvalue=dbnextrow(mssql_ptr->link); + retvalue=dbnextrow(mssql_ptr->link); if (retvalue==FAIL) { dbcancel(mssql_ptr->link); RETURN_FALSE; @@ -1379,7 +1374,7 @@ PHP_FUNCTION(mssql_query) result->statement = NULL; result->num_fields = num_fields; result->blocks_initialized = 1; - + result->batchsize = batchsize; result->data = NULL; result->blocks_initialized = 0; @@ -1389,7 +1384,7 @@ PHP_FUNCTION(mssql_query) result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), result->num_fields, 0); result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue TSRMLS_CC); - + ZEND_REGISTER_RESOURCE(return_value, result, le_result); } /* }}} */ @@ -1404,7 +1399,7 @@ PHP_FUNCTION(mssql_rows_affected) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mssql_link_index) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, -1, "MS SQL-Link", le_link, le_plink); RETURN_LONG(DBCOUNT(mssql_ptr->link)); @@ -1418,16 +1413,16 @@ PHP_FUNCTION(mssql_free_result) zval *mssql_result_index; mssql_result *result; int retvalue; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mssql_result_index) == FAILURE) { return; } - + if (Z_RESVAL_P(mssql_result_index) == 0) { RETURN_FALSE; } - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); /* Release remaining results */ do { dbcanquery(result->mssql_ptr->link); @@ -1466,7 +1461,7 @@ PHP_FUNCTION(mssql_num_rows) return; } - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); RETURN_LONG(result->num_rows); } @@ -1478,12 +1473,12 @@ PHP_FUNCTION(mssql_num_fields) { zval *mssql_result_index; mssql_result *result; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mssql_result_index) == FAILURE) { return; } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); RETURN_LONG(result->num_fields); } @@ -1515,7 +1510,7 @@ static void php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) return; } - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); if (MS_SQL_G(server_message)) { STR_FREE(MS_SQL_G(server_message)); @@ -1525,9 +1520,9 @@ static void php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (result->cur_row >= result->num_rows) { RETURN_FALSE; } - + array_init(return_value); - + for (i=0; inum_fields; i++) { if (Z_TYPE(result->data[result->cur_row][i]) != IS_NULL) { char *data; @@ -1540,7 +1535,7 @@ static void php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (result_type & MSSQL_NUM) { add_index_stringl(return_value, i, data, data_len, 1); } - + if (result_type & MSSQL_ASSOC) { add_assoc_stringl(return_value, result->fields[i].name, data, data_len, 1); } @@ -1548,14 +1543,14 @@ static void php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) else if (Z_TYPE(result->data[result->cur_row][i]) == IS_LONG) { if (result_type & MSSQL_NUM) add_index_long(return_value, i, Z_LVAL(result->data[result->cur_row][i])); - + if (result_type & MSSQL_ASSOC) add_assoc_long(return_value, result->fields[i].name, Z_LVAL(result->data[result->cur_row][i])); } else if (Z_TYPE(result->data[result->cur_row][i]) == IS_DOUBLE) { if (result_type & MSSQL_NUM) add_index_double(return_value, i, Z_DVAL(result->data[result->cur_row][i])); - + if (result_type & MSSQL_ASSOC) add_assoc_double(return_value, result->fields[i].name, Z_DVAL(result->data[result->cur_row][i])); } @@ -1618,14 +1613,14 @@ PHP_FUNCTION(mssql_data_seek) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &mssql_result_index, &offset) == FAILURE) { return; } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); if (offset < 0 || offset >= result->num_rows) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad row offset"); RETURN_FALSE; } - + result->cur_row = offset; RETURN_TRUE; } @@ -1702,13 +1697,13 @@ PHP_FUNCTION(mssql_fetch_field) return; } - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + if (field_offset==-1) { field_offset = result->cur_field; result->cur_field++; } - + if (field_offset<0 || field_offset >= result->num_fields) { if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset"); @@ -1737,14 +1732,14 @@ PHP_FUNCTION(mssql_field_length) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &mssql_result_index, &field_offset) == FAILURE) { return; } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - + + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + if (field_offset==-1) { field_offset = result->cur_field; result->cur_field++; } - + if (field_offset<0 || field_offset >= result->num_fields) { if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset"); @@ -1767,14 +1762,14 @@ PHP_FUNCTION(mssql_field_name) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &mssql_result_index, &field_offset) == FAILURE) { return; } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - + + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + if (field_offset==-1) { field_offset = result->cur_field; result->cur_field++; } - + if (field_offset<0 || field_offset >= result->num_fields) { if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset"); @@ -1797,14 +1792,14 @@ PHP_FUNCTION(mssql_field_type) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &mssql_result_index, &field_offset) == FAILURE) { return; } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - + + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + if (field_offset==-1) { field_offset = result->cur_field; result->cur_field++; } - + if (field_offset<0 || field_offset >= result->num_fields) { if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset"); @@ -1827,9 +1822,9 @@ PHP_FUNCTION(mssql_field_seek) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &mssql_result_index, &field_offset) == FAILURE) { return; } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - + + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + if (field_offset<0 || field_offset >= result->num_fields) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset"); RETURN_FALSE; @@ -1853,7 +1848,7 @@ PHP_FUNCTION(mssql_result) return; } - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); if (row < 0 || row >= result->num_rows) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad row offset (%ld)", row); @@ -1904,7 +1899,7 @@ PHP_FUNCTION(mssql_next_result) return; } - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); + ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); mssql_ptr = result->mssql_ptr; retvalue = dbresults(mssql_ptr->link); @@ -1959,7 +1954,7 @@ PHP_FUNCTION(mssql_min_error_severity) PHP_FUNCTION(mssql_min_message_severity) { long severity; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &severity) == FAILURE) { return; } @@ -1978,7 +1973,7 @@ PHP_FUNCTION(mssql_init) mssql_link *mssql_ptr; mssql_statement *statement; int id = -1; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &sp_name, &sp_name_len, &mssql_link_index) == FAILURE) { return; } @@ -1989,7 +1984,7 @@ PHP_FUNCTION(mssql_init) } ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); - + if (dbrpcinit(mssql_ptr->link, sp_name,0)==FAIL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to init stored procedure"); RETURN_FALSE; @@ -2001,7 +1996,7 @@ PHP_FUNCTION(mssql_init) statement->executed=FALSE; statement->id = zend_list_insert(statement,le_statement TSRMLS_CC); - + RETURN_RESOURCE(statement->id); } /* }}} */ @@ -2025,10 +2020,10 @@ PHP_FUNCTION(mssql_bind) return; } - if (ZEND_NUM_ARGS() == 7 && !is_output) { + if (!is_output) { maxlen = -1; } - + ZEND_FETCH_RESOURCE(statement, mssql_statement *, &stmt, -1, "MS SQL-Statement", le_statement); if (statement==NULL) { @@ -2077,11 +2072,11 @@ PHP_FUNCTION(mssql_bind) break; } } - + if (is_output) { status=DBRPCRETURN; } - + /* hashtable of binds */ if (! statement->binds) { ALLOC_HASHTABLE(statement->binds); @@ -2097,9 +2092,9 @@ PHP_FUNCTION(mssql_bind) if( NULL == bindp ) RETURN_FALSE; bindp->zval=*var; zval_add_ref(var); - + /* no call to dbrpcparam if RETVAL */ - if ( strcmp("RETVAL", param_name)!=0 ) { + if ( strcmp("RETVAL", param_name)!=0 ) { if (dbrpcparam(mssql_ptr->link, param_name, (BYTE)status, type, maxlen, datalen, (LPBYTE)value)==FAIL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set parameter"); RETURN_FALSE; @@ -2154,8 +2149,8 @@ PHP_FUNCTION(mssql_execute) RETURN_FALSE; } - /* The following is just like mssql_query, fetch all rows from the first result - * set into the row buffer. + /* The following is just like mssql_query, fetch all rows from the first result + * set into the row buffer. */ result=NULL; if (retval_results == SUCCEED) { @@ -2190,7 +2185,7 @@ PHP_FUNCTION(mssql_execute) if (retval_results == NO_MORE_RESULTS || retval_results == NO_MORE_RPC_RESULTS) { _mssql_get_sp_result(mssql_ptr, statement TSRMLS_CC); } - + if (result==NULL) { RETURN_TRUE; /* no recordset returned ...*/ } @@ -2211,12 +2206,12 @@ PHP_FUNCTION(mssql_free_statement) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mssql_statement_index) == FAILURE) { return; } - + if (Z_RESVAL_P(mssql_statement_index) == 0) { RETURN_FALSE; } - ZEND_FETCH_RESOURCE(statement, mssql_statement *, &mssql_statement_index, -1, "MS SQL-statement", le_statement); + ZEND_FETCH_RESOURCE(statement, mssql_statement *, &mssql_statement_index, -1, "MS SQL-statement", le_statement); /* Release remaining results */ do { dbcanquery(statement->link->link); diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 88bb9ab21ef9f..cc2804bb8bb97 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -775,13 +775,13 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } else { /* mysql_pconnect does not support new_link parameter */ if (persistent) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!l", &host_and_port, &host_len, + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!l", &host_and_port, &host_len, &user, &user_len, &passwd, &passwd_len, &client_flags)==FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!bl", &host_and_port, &host_len, + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!bl", &host_and_port, &host_len, &user, &user_len, &passwd, &passwd_len, &new_link, &client_flags)==FAILURE) { return; @@ -1250,7 +1250,7 @@ PHP_FUNCTION(mysql_info) return; } - if (ZEND_NUM_ARGS() == 0) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -1277,7 +1277,7 @@ PHP_FUNCTION(mysql_thread_id) return; } - if (ZEND_NUM_ARGS() == 0) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -1303,7 +1303,7 @@ PHP_FUNCTION(mysql_stat) return; } - if (ZEND_NUM_ARGS() == 0) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -1335,7 +1335,7 @@ PHP_FUNCTION(mysql_client_encoding) return; } - if (ZEND_NUM_ARGS() == 0) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -1360,7 +1360,7 @@ PHP_FUNCTION(mysql_set_charset) return; } - if (ZEND_NUM_ARGS() == 1) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -1718,7 +1718,7 @@ PHP_FUNCTION(mysql_list_processes) return; } - if (ZEND_NUM_ARGS() == 0) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -1866,7 +1866,7 @@ PHP_FUNCTION(mysql_real_escape_string) return; } - if (ZEND_NUM_ARGS() == 1) { + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); } @@ -2073,7 +2073,7 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, return; } - if (ZEND_NUM_ARGS() < 2) { + if (class_name == NULL) { ce = zend_standard_class_def; } else { ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -2668,11 +2668,12 @@ PHP_FUNCTION(mysql_ping) int id = -1; php_mysql_conn *mysql; - if (0 == ZEND_NUM_ARGS()) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link)==FAILURE) { + return; + } + if (mysql_link == NULL) { id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); CHECK_LINK(id); - } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mysql_link)==FAILURE) { - return; } ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink); diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index ad4e25c66f322..5313e7b7e708c 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1033,36 +1033,19 @@ PHP_FUNCTION(mysqli_stmt_construct) zval *mysql_link; MY_STMT *stmt; MYSQLI_RESOURCE *mysqli_resource; - char *statement; + char *statement = NULL; int statement_len; - switch (ZEND_NUM_ARGS()) - { - case 1: /* mysql_stmt_init */ - if (zend_parse_parameters(1 TSRMLS_CC, "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 TSRMLS_CC, "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() TSRMLS_CC, "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) { @@ -1072,7 +1055,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_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource; } @@ -1091,19 +1074,8 @@ PHP_FUNCTION(mysqli_result_construct) MYSQLI_RESOURCE *mysqli_resource; long resmode = MYSQLI_STORE_RESULT; - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_parse_parameters(1 TSRMLS_CC, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) { - return; - } - break; - case 2: - if (zend_parse_parameters(2 TSRMLS_CC, "Ol", &mysql_link, mysqli_link_class_entry, &resmode)==FAILURE) { - return; - } - break; - default: - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &mysql_link, mysqli_link_class_entry, &resmode)==FAILURE) { + return; } MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID); @@ -1142,7 +1114,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long unsigned int i; MYSQL_FIELD *fields; unsigned long *field_len; - + if (!(row = mysql_fetch_row(result))) { RETURN_NULL(); } @@ -1233,13 +1205,13 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags zend_class_entry *ce = NULL; if (into_object) { - char *class_name; + char *class_name = NULL; int class_name_len; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sz", &mysql_result, mysqli_result_class_entry, &class_name, &class_name_len, &ctor_params) == FAILURE) { return; } - if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) { + if (class_name == NULL) { ce = zend_standard_class_def; } else { ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 3ee5c803a5508..e535ebf0401cc 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -80,8 +80,7 @@ PHP_FUNCTION(mysqli_autocommit) /* {{{ mysqli_stmt_bind_param_do_bind */ #ifndef MYSQLI_USE_MYSQLND static -int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars, - zval ***args, unsigned int start, const char * const types TSRMLS_DC) +int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int offset, unsigned int num_vars, zval ***args, const char * const types TSRMLS_DC) { int i, ofs; MYSQL_BIND *bind; @@ -95,9 +94,8 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in stmt->param.is_null = ecalloc(num_vars, sizeof(char)); bind = (MYSQL_BIND *) ecalloc(num_vars, sizeof(MYSQL_BIND)); - ofs = 0; - for (i = start; i < argc; i++) { - + for (i = 0; i < num_vars; i++) { + ofs = i; /* set specified type */ switch (types[ofs]) { case 'd': /* Double */ @@ -128,11 +126,10 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1+offset); rc = 1; goto end_1; } - ofs++; } rc = mysql_stmt_bind_param(stmt->stmt, bind); @@ -144,8 +141,8 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in stmt->param.vars = (zval **)safe_emalloc(num_vars, sizeof(zval), 0); for (i = 0; i < num_vars; i++) { if (bind[i].buffer_type != MYSQL_TYPE_LONG_BLOB) { - Z_ADDREF_P(*args[i+start]); - stmt->param.vars[i] = *args[i+start]; + Z_ADDREF_P(*args[i]); + stmt->param.vars[i] = *args[i]; } else { stmt->param.vars[i] = NULL; } @@ -157,22 +154,21 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in } #else static -int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars, - zval ***args, unsigned int start, const char * const types TSRMLS_DC) +int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int offset, unsigned int num_vars, zval ***args, const char * const types TSRMLS_DC) { unsigned int i; MYSQLND_PARAM_BIND *params; enum_func_status ret = FAIL; /* If no params -> skip binding and return directly */ - if (argc == start) { + if (args == NULL || num_vars == 0) { return PASS; } params = mysqlnd_stmt_alloc_param_bind(stmt->stmt); if (!params) { goto end; } - for (i = 0; i < (argc - start); i++) { + for (i = 0; i < num_vars; i++) { zend_uchar type; switch (types[i]) { case 'd': /* Double */ @@ -193,12 +189,12 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in break; default: /* We count parameters from 1 */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[i], i + start + 1); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[i], i + 1 + offset); ret = FAIL; mysqlnd_stmt_free_param_bind(stmt->stmt, params); goto end; } - params[i].zv = *(args[i + start]); + params[i].zv = *(args[i]); params[i].type = type; } ret = mysqlnd_stmt_bind_param(stmt->stmt, params); @@ -213,42 +209,27 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in Bind variables to a prepared statement as parameters */ PHP_FUNCTION(mysqli_stmt_bind_param) { - zval ***args; - int argc = ZEND_NUM_ARGS(); - int num_vars; - int start = 2; + zval ***args = NULL; + int num_vars = 0; MY_STMT *stmt; zval *mysql_stmt; - char *types; + char *types = NULL; int types_len; unsigned long rc; - /* calculate and check number of parameters */ - if (argc < 2) { - /* there has to be at least one pair */ - WRONG_PARAM_COUNT; - } - - if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, - &types, &types_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os*", &mysql_stmt, mysqli_stmt_class_entry, + &types, &types_len, &args, &num_vars) == FAILURE) { return; } MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID); - num_vars = argc - 1; - if (getThis()) { - start = 1; - } else { - /* ignore handle parameter in procedural interface*/ - --num_vars; - } if (!types_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type or no types specified"); RETURN_FALSE; } - if (types_len != argc - start) { + if (types_len != num_vars) { /* number of bind variables doesn't match number of elements in type definition string */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables"); RETURN_FALSE; @@ -259,18 +240,13 @@ PHP_FUNCTION(mysqli_stmt_bind_param) RETURN_FALSE; } - args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0); + rc = mysqli_stmt_bind_param_do_bind(stmt, 2, num_vars, args, types TSRMLS_CC); + MYSQLI_REPORT_STMT_ERROR(stmt->stmt); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - zend_wrong_param_count(TSRMLS_C); - rc = 1; - } else { - rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types TSRMLS_CC); - MYSQLI_REPORT_STMT_ERROR(stmt->stmt); + if(args) { + efree(args); } - efree(args); - RETURN_BOOL(!rc); } /* }}} */ @@ -281,11 +257,10 @@ PHP_FUNCTION(mysqli_stmt_bind_param) do_alloca, free_alloca */ static int -mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC) +mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int var_cnt TSRMLS_DC) { MYSQL_BIND *bind; int i, ofs; - int var_cnt = argc - start; long col_type; ulong rc; @@ -303,8 +278,8 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, memset(p, 0, size); } - for (i=start; i < var_cnt + start ; i++) { - ofs = i - start; + for (i=0; i < var_cnt; i++) { + ofs = i; col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING; switch (col_type) { @@ -442,10 +417,9 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, } else { stmt->result.var_cnt = var_cnt; stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0); - for (i = start; i < var_cnt+start; i++) { - ofs = i-start; + for (i = 0; i < var_cnt; i++) { Z_ADDREF_PP(args[i]); - stmt->result.vars[ofs] = *args[i]; + stmt->result.vars[i] = *args[i]; } } efree(bind); @@ -454,13 +428,13 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, } #else static int -mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC) +mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc TSRMLS_DC) { unsigned int i; MYSQLND_RESULT_BIND * params = mysqlnd_stmt_alloc_result_bind(stmt->stmt); if (params) { - for (i = 0; i < (argc - start); i++) { - params[i].zv = *(args[i + start]); + for (i = 0; i < argc; i++) { + params[i].zv = *(args[i]); } return mysqlnd_stmt_bind_result(stmt->stmt, params); } @@ -473,41 +447,24 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, Bind variables to a prepared statement for result storage */ PHP_FUNCTION(mysqli_stmt_bind_result) { - zval ***args; - int argc = ZEND_NUM_ARGS(); - int start = 1; + zval ***args = NULL; + int num_args; ulong rc; MY_STMT *stmt; zval *mysql_stmt; - if (getThis()) { - start = 0; - } - - if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O+", &mysql_stmt, mysqli_stmt_class_entry, &args, &num_args) == FAILURE) { return; } MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID); - if (argc < (getThis() ? 1 : 2)) { - WRONG_PARAM_COUNT; - } - - if ((argc - start) != mysql_stmt_field_count(stmt->stmt)) { + if (num_args != mysql_stmt_field_count(stmt->stmt)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement"); RETURN_FALSE; } - args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0); - - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc, start TSRMLS_CC); - + rc = mysqli_stmt_bind_result_do_bind(stmt, args, num_args TSRMLS_CC); efree(args); RETURN_BOOL(!rc); diff --git a/ext/mysqli/mysqli_warning.c b/ext/mysqli/mysqli_warning.c index 25653e3358593..ca26276aa39ab 100644 --- a/ext/mysqli/mysqli_warning.c +++ b/ext/mysqli/mysqli_warning.c @@ -273,10 +273,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 TSRMLS_CC, "o", &z)==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &z)==FAILURE) { return; } obj = (mysqli_object *)zend_object_store_get_object(z TSRMLS_CC);\ diff --git a/ext/mysqli/tests/mysqli_stmt_bind_result.phpt b/ext/mysqli/tests/mysqli_stmt_bind_result.phpt index 553e71ab6b5fc..6b4c0138b9144 100644 --- a/ext/mysqli/tests/mysqli_stmt_bind_result.phpt +++ b/ext/mysqli/tests/mysqli_stmt_bind_result.phpt @@ -320,12 +320,11 @@ require_once('skipifconnectfailure.inc'); require_once("clean_table.inc"); ?> --EXPECTF-- -Warning: mysqli_stmt_bind_result(): invalid object or resource mysqli_stmt - in %s on line %d +Warning: mysqli_stmt_bind_result() expects at least 2 parameters, 1 given in %s on line %d Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in %s on line %d Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in %s on line %d int(1) %s(1) "a" -done! \ No newline at end of file +done! diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index b183e480af358..2df308de70f10 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -113,7 +113,7 @@ zend_class_entry *oci_coll_class_entry_ptr; #define PHP_OCI_ERRBUF_LEN OCI_ERROR_MAXMSG_SIZE2 #else #define PHP_OCI_ERRBUF_LEN OCI_ERROR_MAXMSG_SIZE -#endif +#endif #if ZEND_MODULE_API_NO > 20020429 #define ONUPDATELONGFUNC OnUpdateLong @@ -1096,7 +1096,7 @@ static void php_oci_init_global_handles(TSRMLS_D) && *tmp_buf) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tmp_buf); } - + OCI_G(env) = NULL; OCI_G(err) = NULL; return; @@ -1125,18 +1125,18 @@ static void php_oci_init_global_handles(TSRMLS_D) if (ora_error_code) { int tmp_buf_len = strlen((char *)tmp_buf); - + if (tmp_buf_len > 0 && tmp_buf[tmp_buf_len - 1] == '\n') { tmp_buf[tmp_buf_len - 1] = '\0'; } - + if (errstatus == OCI_SUCCESS_WITH_INFO) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Initialization error: OCI_SUCCESS_WITH_INFO: %s", tmp_buf); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Initialization error: OCI_ERROR: %s", tmp_buf); - + OCIHandleFree((dvoid *) OCI_G(env), OCI_HTYPE_ENV); - + OCI_G(env) = NULL; OCI_G(err) = NULL; } @@ -2483,7 +2483,7 @@ void php_oci_client_get_version(char **version TSRMLS_DC) char version_buff[256]; #if ((OCI_MAJOR_VERSION > 10) || ((OCI_MAJOR_VERSION == 10) && (OCI_MINOR_VERSION >= 2))) /* OCIClientVersion only available 10.2 onwards */ sword major_version = 0; - sword minor_version = 0; + sword minor_version = 0; sword update_num = 0; sword patch_num = 0; sword port_update_num = 0; @@ -2616,7 +2616,7 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg php_oci_out_column *column; ub4 nrows = 1; int i; - long fetch_mode = 0; + long fetch_mode = mode; if (expected_args > 2) { /* only for ocifetchinto BC */ @@ -2625,9 +2625,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() */ @@ -2635,9 +2632,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_*() */ @@ -2645,7 +2639,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)) { @@ -3029,7 +3022,7 @@ static OCIEnv *php_oci_create_env(ub2 charsetid TSRMLS_DC) && *ora_msg_buf) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ora_msg_buf); } - + return NULL; } return retenv; diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index aee876d736954..49c06ef08b3c6 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 | @@ -104,7 +104,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() TSRMLS_CC, "rsz/|ll", &z_statement, &name, &name_len, &bind_var, &maxlen, &type) == FAILURE) { return; } @@ -112,7 +112,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 TSRMLS_CC)) { @@ -134,22 +134,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() TSRMLS_CC, "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 TSRMLS_CC, 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 TSRMLS_CC)) { RETURN_FALSE; } @@ -169,7 +169,7 @@ PHP_FUNCTION(oci_free_descriptor) return; } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; @@ -203,7 +203,7 @@ PHP_FUNCTION(oci_lob_save) return; } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; @@ -215,7 +215,7 @@ PHP_FUNCTION(oci_lob_save) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset parameter must be greater than or equal to 0"); RETURN_FALSE; } - + if (php_oci_lob_write(descriptor, offset, data, data_len, &bytes_written TSRMLS_CC)) { RETURN_FALSE; } @@ -248,14 +248,14 @@ PHP_FUNCTION(oci_lob_import) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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) /* The "p" parsing parameter handles this case in PHP 5.4+ */ if (strlen(filename) != filename_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename cannot contain null bytes"); - RETURN_FALSE; + RETURN_FALSE; } #endif @@ -285,14 +285,14 @@ PHP_FUNCTION(oci_lob_load) if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); if (php_oci_lob_read(descriptor, -1, 0, &buffer, &buffer_len TSRMLS_CC)) { @@ -325,24 +325,24 @@ PHP_FUNCTION(oci_lob_read) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_descriptor, oci_lob_class_entry_ptr, &length) == FAILURE) { return; - } + } } if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); if (length <= 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0"); RETURN_FALSE; } - + if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len TSRMLS_CC)) { RETURN_FALSE; - } + } if (buffer_len > 0) { RETURN_STRINGL(buffer, buffer_len, 0); } @@ -359,20 +359,20 @@ 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() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (!php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC) && lob_length >= 0) { if (lob_length == descriptor->lob_current_position) { RETURN_TRUE; @@ -388,21 +388,21 @@ PHP_FUNCTION(oci_lob_tell) { zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - - RETURN_LONG(descriptor->lob_current_position); + + RETURN_LONG(descriptor->lob_current_position); } /* }}} */ @@ -412,20 +412,20 @@ PHP_FUNCTION(oci_lob_rewind) { zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + descriptor->lob_current_position = 0; RETURN_TRUE; @@ -440,7 +440,7 @@ PHP_FUNCTION(oci_lob_seek) php_oci_descriptor *descriptor; long offset, whence = PHP_OCI_SEEK_SET; ub4 lob_length; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &offset, &whence) == FAILURE) { return; @@ -449,14 +449,14 @@ PHP_FUNCTION(oci_lob_seek) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol|l", &z_descriptor, oci_lob_class_entry_ptr, &offset, &whence) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) { @@ -479,7 +479,7 @@ PHP_FUNCTION(oci_lob_seek) default: descriptor->lob_current_position = (offset > 0) ? offset : 0; break; - } + } RETURN_TRUE; } /* }}} */ @@ -491,20 +491,20 @@ 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() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) { RETURN_FALSE; } @@ -519,40 +519,36 @@ PHP_FUNCTION(oci_lob_write) zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; int data_len; - long write_len = 0; + long write_len = LONG_MAX; ub4 bytes_written; char *data; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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() TSRMLS_CC, "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 (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (data_len <= 0) { RETURN_LONG(0); } - + if (php_oci_lob_write(descriptor, descriptor->lob_current_position, data, data_len, &bytes_written TSRMLS_CC)) { RETURN_FALSE; } @@ -566,7 +562,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() TSRMLS_CC, "O", &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) { return; @@ -575,22 +571,22 @@ PHP_FUNCTION(oci_lob_append) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"), (void **)&tmp_dest) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object"); RETURN_FALSE; } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor"), (void **)&tmp_from) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_dest, descriptor_dest); PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_from, descriptor_from); - + if (php_oci_lob_append(descriptor_dest, descriptor_from TSRMLS_CC)) { RETURN_FALSE; } @@ -607,7 +603,7 @@ PHP_FUNCTION(oci_lob_truncate) php_oci_descriptor *descriptor; long trim_length = 0; ub4 ub_trim_length; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &trim_length) == FAILURE) { return; @@ -616,9 +612,9 @@ PHP_FUNCTION(oci_lob_truncate) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &z_descriptor, oci_lob_class_entry_ptr, &trim_length) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; @@ -631,7 +627,7 @@ PHP_FUNCTION(oci_lob_truncate) ub_trim_length = (ub4) trim_length; PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (php_oci_lob_truncate(descriptor, ub_trim_length TSRMLS_CC)) { RETURN_FALSE; } @@ -647,9 +643,9 @@ PHP_FUNCTION(oci_lob_erase) php_oci_descriptor *descriptor; ub4 bytes_erased; long offset = -1, length = -1; - + if (getThis()) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &offset, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &offset, &length) == FAILURE) { return; } @@ -664,7 +660,7 @@ PHP_FUNCTION(oci_lob_erase) } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) { return; } @@ -672,7 +668,7 @@ PHP_FUNCTION(oci_lob_erase) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset must be greater than or equal to 0"); RETURN_FALSE; } - + if (ZEND_NUM_ARGS() > 2 && length < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to 0"); RETURN_FALSE; @@ -700,7 +696,7 @@ PHP_FUNCTION(oci_lob_flush) zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; long flush_flag = 0; - + if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flush_flag) == FAILURE) { return; @@ -711,14 +707,14 @@ PHP_FUNCTION(oci_lob_flush) return; } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (descriptor->buffering == PHP_OCI_LOB_BUFFER_DISABLED) { /* buffering wasn't enabled, there is nothing to flush */ RETURN_FALSE; @@ -738,7 +734,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() TSRMLS_CC, "b", &flag) == FAILURE) { return; @@ -747,16 +743,16 @@ PHP_FUNCTION(ocisetbufferinglob) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ob", &z_descriptor, oci_lob_class_entry_ptr, &flag) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (php_oci_lob_set_buffering(descriptor, flag TSRMLS_CC)) { RETURN_FALSE; } @@ -770,20 +766,20 @@ PHP_FUNCTION(ocigetbufferinglob) { zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (descriptor->buffering != PHP_OCI_LOB_BUFFER_DISABLED) { RETURN_TRUE; } @@ -798,29 +794,29 @@ PHP_FUNCTION(oci_lob_copy) zval **tmp_dest, **tmp_from, *z_descriptor_dest, *z_descriptor_from; php_oci_descriptor *descriptor_dest, *descriptor_from; long length = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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() TSRMLS_CC, "OO|l", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length) == FAILURE) { return; } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"), (void **)&tmp_dest) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object"); RETURN_FALSE; } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor"), (void **)&tmp_from) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_dest, descriptor_dest); PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_from, descriptor_from); - + if (ZEND_NUM_ARGS() == 3 && length < 0) { php_error_docref(NULL TSRMLS_CC, 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; @@ -840,28 +836,28 @@ PHP_FUNCTION(oci_lob_is_equal) zval **tmp_first, **tmp_second, *z_descriptor_first, *z_descriptor_second; php_oci_descriptor *descriptor_first, *descriptor_second; boolean is_equal; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &z_descriptor_first, oci_lob_class_entry_ptr, &z_descriptor_second, oci_lob_class_entry_ptr) == FAILURE) { return; } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor_first), "descriptor", sizeof("descriptor"), (void **)&tmp_first) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object"); RETURN_FALSE; } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor_second), "descriptor", sizeof("descriptor"), (void **)&tmp_second) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_first, descriptor_first); PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_second, descriptor_second); if (php_oci_lob_is_equal(descriptor_first, descriptor_second, &is_equal TSRMLS_CC)) { RETURN_FALSE; } - + if (is_equal == TRUE) { RETURN_TRUE; } @@ -872,7 +868,7 @@ PHP_FUNCTION(oci_lob_is_equal) /* {{{ proto bool oci_lob_export([string filename [, int start [, int length]]]) Writes a large object into a file */ PHP_FUNCTION(oci_lob_export) -{ +{ zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; char *filename; @@ -884,13 +880,13 @@ PHP_FUNCTION(oci_lob_export) if (getThis()) { #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3) || (PHP_MAJOR_VERSION > 5) - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|ll", &filename, &filename_len, &start, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "p|ll", &filename, &filename_len, &start, &length) == FAILURE) { #else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &filename, &filename_len, &start, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &filename, &filename_len, &start, &length) == FAILURE) { #endif return; } - + if (ZEND_NUM_ARGS() > 1 && start < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start parameter must be greater than or equal to 0"); RETURN_FALSE; @@ -902,13 +898,13 @@ PHP_FUNCTION(oci_lob_export) } else { #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3) || (PHP_MAJOR_VERSION > 5) - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Op|ll", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "Op|ll", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) { #else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|ll", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "Os|ll", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) { #endif return; } - + if (ZEND_NUM_ARGS() > 2 && start < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start parameter must be greater than or equal to 0"); RETURN_FALSE; @@ -923,7 +919,7 @@ PHP_FUNCTION(oci_lob_export) /* The "p" parsing parameter handles this case in PHP 5.4+ */ if (strlen(filename) != filename_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename cannot contain null bytes"); - RETURN_FALSE; + RETURN_FALSE; } #endif @@ -931,13 +927,13 @@ PHP_FUNCTION(oci_lob_export) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - + if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) { RETURN_FALSE; - } - + } + if (start == -1) { start = 0; } @@ -945,7 +941,7 @@ PHP_FUNCTION(oci_lob_export) if (length == -1) { length = lob_length - descriptor->lob_current_position; } - + if (length == 0) { /* nothing to write, fail silently */ RETURN_FALSE; @@ -987,7 +983,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; @@ -1020,14 +1016,14 @@ PHP_FUNCTION(oci_lob_write_temporary) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &type) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); if (php_oci_lob_write_tmp(descriptor, type, data, data_len TSRMLS_CC)) { @@ -1043,18 +1039,18 @@ PHP_FUNCTION(oci_lob_close) { zval **tmp, *z_descriptor = getThis(); php_oci_descriptor *descriptor; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); if (php_oci_lob_close(descriptor TSRMLS_CC)) { @@ -1080,8 +1076,8 @@ PHP_FUNCTION(oci_new_descriptor) PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); /* php_oci_lob_create() checks type */ - descriptor = php_oci_lob_create(connection, type TSRMLS_CC); - + descriptor = php_oci_lob_create(connection, type TSRMLS_CC); + if (!descriptor) { RETURN_NULL(); } @@ -1131,7 +1127,7 @@ PHP_FUNCTION(oci_commit) if (connection->descriptors) { php_oci_connection_descriptors_free(connection TSRMLS_CC); } - + if (php_oci_connection_commit(connection TSRMLS_CC)) { RETURN_FALSE; } @@ -1206,7 +1202,7 @@ PHP_FUNCTION(oci_field_type) if (!column) { RETURN_FALSE; } - + switch (column->data_type) { #ifdef SQLT_TIMESTAMP case SQLT_TIMESTAMP: @@ -1423,7 +1419,7 @@ PHP_FUNCTION(oci_fetch_all) while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) { zval *row; - + MAKE_STD_ZVAL(row); array_init(row); @@ -1457,11 +1453,11 @@ 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 TSRMLS_CC); - + MAKE_STD_ZVAL(tmp); array_init(tmp); zend_hash_next_index_insert(Z_ARRVAL_P(array), &tmp, sizeof(zval*), (void **) &(outarrs[ i ])); @@ -1469,7 +1465,7 @@ PHP_FUNCTION(oci_fetch_all) } else { /* default to ASSOC */ for (i = 0; i < statement->ncolumns; i++) { columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); - + MAKE_STD_ZVAL(tmp); array_init(tmp); #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5) @@ -1496,7 +1492,7 @@ PHP_FUNCTION(oci_fetch_all) break; } } - + efree(columns); efree(outarrs); } @@ -1577,7 +1573,7 @@ PHP_FUNCTION(oci_close) /* do nothing to keep BC */ return; } - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) { return; } @@ -1586,7 +1582,7 @@ PHP_FUNCTION(oci_close) zend_list_delete(connection->id); ZVAL_NULL(z_connection); - + RETURN_TRUE; } /* }}} */ @@ -1633,9 +1629,9 @@ PHP_FUNCTION(oci_error) return; } - if (ZEND_NUM_ARGS() > 0) { + if (arg) { statement = (php_oci_statement *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_statement); - + if (statement) { errh = statement->err; error = statement->errcode; @@ -1983,7 +1979,7 @@ PHP_FUNCTION(oci_new_cursor) PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection); statement = php_oci_statement_create(connection, NULL, 0 TSRMLS_CC); - + if (statement) { RETURN_RESOURCE(statement->id); } @@ -1996,7 +1992,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 TSRMLS_CC); @@ -2035,7 +2031,7 @@ PHP_FUNCTION(oci_server_version) if (php_oci_server_get_version(connection, &version TSRMLS_CC)) { RETURN_FALSE; } - + RETURN_STRING(version, 0); } /* }}} */ @@ -2126,14 +2122,14 @@ PHP_FUNCTION(oci_free_collection) if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); zend_list_delete(collection->id); @@ -2158,14 +2154,14 @@ PHP_FUNCTION(oci_collection_append) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &z_collection, oci_coll_class_entry_ptr, &value, &value_len) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); if (php_oci_collection_append(collection, value, value_len TSRMLS_CC)) { @@ -2192,20 +2188,20 @@ PHP_FUNCTION(oci_collection_element_get) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_collection, oci_coll_class_entry_ptr, &element_index) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); if (php_oci_collection_element_get(collection, element_index, &value TSRMLS_CC)) { RETURN_FALSE; } - + *return_value = *value; zval_copy_ctor(return_value); zval_ptr_dtor(&value); @@ -2227,9 +2223,9 @@ PHP_FUNCTION(oci_collection_assign) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &z_collection_dest, oci_coll_class_entry_ptr, &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection_dest), "collection", sizeof("collection"), (void **)&tmp_dest) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property. The first argument should be valid collection object"); RETURN_FALSE; @@ -2268,14 +2264,14 @@ PHP_FUNCTION(oci_collection_element_assign) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ols", &z_collection, oci_coll_class_entry_ptr, &element_index, &value, &value_len) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); if (php_oci_collection_element_set(collection, element_index, value, value_len TSRMLS_CC)) { @@ -2292,18 +2288,18 @@ 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() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); if (php_oci_collection_size(collection, &size TSRMLS_CC)) { @@ -2320,18 +2316,18 @@ PHP_FUNCTION(oci_collection_max) zval **tmp, *z_collection = getThis(); php_oci_collection *collection; long max; - + if (!getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); if (php_oci_collection_max(collection, &max TSRMLS_CC)) { @@ -2357,20 +2353,20 @@ PHP_FUNCTION(oci_collection_trim) else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_collection, oci_coll_class_entry_ptr, &trim_size) == FAILURE) { return; - } + } } - + if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property"); RETURN_FALSE; } - + PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection); if (php_oci_collection_trim(collection, trim_size TSRMLS_CC)) { RETURN_FALSE; } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -2383,13 +2379,13 @@ PHP_FUNCTION(oci_new_collection) php_oci_collection *collection; char *tdo, *schema = NULL; int tdo_len, schema_len = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC)) ) { object_init_ex(return_value, oci_coll_class_entry_ptr); add_property_resource(return_value, "collection", collection->id); diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index c84a4ecc60913..93abe40090e2f 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_rsrc_list_entry *rsrc TSRMLS_DC) odbc_result *res = (odbc_result *)rsrc->ptr; int i; RETCODE rc; - + if (res) { if (res->values) { for(i = 0; i < res->numcols; i++) { @@ -511,7 +511,7 @@ static void _close_odbc_pconn(zend_rsrc_list_entry *rsrc TSRMLS_DC) } } } - + safe_odbc_disconnect(conn->hdbc); SQLFreeConnect(conn->hdbc); SQLFreeEnv(conn->henv); @@ -584,7 +584,7 @@ static PHP_INI_DISP(display_binmode) { char *value; TSRMLS_FETCH(); - + if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) { value = ini_entry->orig_value; } else if (ini_entry->value) { @@ -678,7 +678,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, @@ -699,7 +699,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() /* }}} */ @@ -722,7 +722,7 @@ PHP_MINIT_FUNCTION(odbc) le_conn = zend_register_list_destructors_ex(_close_odbc_conn, NULL, "odbc link", module_number); le_pconn = zend_register_list_destructors_ex(NULL, _close_odbc_pconn, "odbc link persistent", module_number); Z_TYPE(odbc_module_entry) = type; - + REGISTER_STRING_CONSTANT("ODBC_TYPE", PHP_ODBC_TYPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ODBC_BINMODE_PASSTHRU", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ODBC_BINMODE_RETURN", 1, CONST_CS | CONST_PERSISTENT); @@ -747,7 +747,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 */ @@ -858,7 +858,7 @@ PHP_MINFO_FUNCTION(odbc) DISPLAY_INI_ENTRIES(); -} +} /* }}} */ /* {{{ odbc_sql_error */ @@ -881,7 +881,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 { @@ -902,7 +902,7 @@ void odbc_sql_error(ODBC_SQL_ERROR_PARAMS) } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "SQL error: %s, SQL state %s", errormsg, state); } - /* + /* } while (SQL_SUCCEEDED(rc)); } */ @@ -919,7 +919,7 @@ void php_odbc_fetch_attribs(INTERNAL_FUNCTION_PARAMETERS, int mode) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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) { @@ -952,15 +952,15 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC) result->binmode = ODBCG(defaultbinmode); for(i = 0; i < result->numcols; i++) { - rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_NAME, + 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: @@ -968,7 +968,7 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC) case SQL_LONGVARCHAR: result->values[i].value = NULL; break; - + #ifdef HAVE_ADABAS case SQL_TIMESTAMP: result->values[i].value = (char *)emalloc(27); @@ -979,7 +979,7 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC) default: rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE, NULL, 0, NULL, &displaysize); - displaysize = displaysize <= result->longreadlen ? displaysize : + displaysize = displaysize <= result->longreadlen ? displaysize : result->longreadlen; /* Workaround for Oracle ODBC Driver bug (#50162) when fetching TIMESTAMP column */ if (result->values[i].coltype == SQL_TIMESTAMP) { @@ -1001,13 +1001,13 @@ void odbc_transact(INTERNAL_FUNCTION_PARAMETERS, int type) odbc_connection *conn; RETCODE rc; zval *pv_conn; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pv_conn) == FAILURE) { return; } ZEND_FETCH_RESOURCE2(conn, odbc_connection *, &pv_conn, -1, "ODBC-Link", le_conn, le_pconn); - + rc = SQLTransact(conn->henv, conn->hdbc, (SQLUSMALLINT)((type)?SQL_COMMIT:SQL_ROLLBACK)); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLTransact"); @@ -1034,7 +1034,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. @@ -1090,7 +1090,7 @@ PHP_FUNCTION(odbc_close_all) } nument = zend_hash_next_free_element(&EG(regular_list)); - + /* Loop through list and close all statements */ for(i = 1; i < nument; i++) { ptr = zend_list_find(i, &type); @@ -1101,7 +1101,7 @@ PHP_FUNCTION(odbc_close_all) /* Second loop through list, now close all connections */ nument = zend_hash_next_free_element(&EG(regular_list)); - + for(i = 1; i < nument; i++) { ptr = zend_list_find(i, &type); if (ptr){ @@ -1110,7 +1110,7 @@ PHP_FUNCTION(odbc_close_all) }else if(type == le_pconn){ zend_list_delete(i); /* Delete the persistent connection */ - zend_hash_apply_with_argument(&EG(persistent_list), + zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _close_pconn_with_id, (void *) &i TSRMLS_CC); } } @@ -1155,9 +1155,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); @@ -1198,7 +1198,7 @@ PHP_FUNCTION(odbc_prepare) odbc_sql_error(conn, result->stmt, "SQLPrepare"); RETURN_FALSE; } - + SQLNumParams(result->stmt, &(result->numparams)); SQLNumResultCols(result->stmt, &(result->numcols)); @@ -1213,7 +1213,7 @@ PHP_FUNCTION(odbc_prepare) zend_list_addref(conn->id); result->conn_ptr = conn; result->fetched = 0; - ZEND_REGISTER_RESOURCE(return_value, result, le_result); + ZEND_REGISTER_RESOURCE(return_value, result, le_result); } /* }}} */ @@ -1224,7 +1224,7 @@ PHP_FUNCTION(odbc_prepare) /* {{{ proto bool odbc_execute(resource result_id [, array parameters_array]) Execute a prepared statement */ PHP_FUNCTION(odbc_execute) -{ +{ zval *pv_res, *pv_param_arr, **tmp; typedef struct params_t { SQLLEN vallen; @@ -1239,15 +1239,15 @@ PHP_FUNCTION(odbc_execute) odbc_result *result; int numArgs, i, ne; RETCODE rc; - + numArgs = ZEND_NUM_ARGS(); - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|a", &pv_res, &pv_param_arr) == FAILURE) { return; } ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + /* XXX check for already bound parameters*/ if (result->numparams > 0 && numArgs == 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No parameters to SQL statement given"); @@ -1265,7 +1265,7 @@ PHP_FUNCTION(odbc_execute) for(i = 0; i < result->numparams; i++) { params[i].fp = -1; } - + for(i = 1; i <= result->numparams; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); @@ -1292,12 +1292,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_PP(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) { @@ -1317,7 +1317,7 @@ PHP_FUNCTION(odbc_execute) if (Z_STRLEN_PP(tmp) > 2 && Z_STRVAL_PP(tmp)[0] == '\'' && Z_STRVAL_PP(tmp)[Z_STRLEN_PP(tmp) - 1] == '\'') { - + if (CHECK_ZVAL_NULL_PATH(*tmp)) { RETURN_FALSE; } @@ -1372,7 +1372,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) { @@ -1389,7 +1389,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); @@ -1418,8 +1418,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++) { @@ -1459,7 +1459,7 @@ PHP_FUNCTION(odbc_cursor) char *cursorname; odbc_result *result; RETCODE rc; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pv_res) == FAILURE) { return; } @@ -1470,7 +1470,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); @@ -1531,12 +1531,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); @@ -1577,13 +1577,13 @@ PHP_FUNCTION(odbc_exec) #endif numArgs = ZEND_NUM_ARGS(); - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &pv_conn, &query, &query_len, &pv_flags) == FAILURE) { return; } 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)); @@ -1598,7 +1598,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 */ @@ -1616,18 +1616,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 TSRMLS_CC)) { @@ -1666,7 +1666,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &pv_res, &pv_row) == FAILURE) { return; } - + rownum = pv_row; #else zval *pv_res, *tmp; @@ -1697,9 +1697,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; @@ -1728,11 +1728,11 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) { Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC(); 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) { @@ -1800,7 +1800,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; @@ -1820,7 +1820,7 @@ PHP_FUNCTION(odbc_fetch_into) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ|l", &pv_res, &pv_res_arr, &pv_row) == FAILURE) { return; } - + rownum = pv_row; #else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pv_res, &pv_res_arr) == FAILURE) { @@ -1829,12 +1829,12 @@ PHP_FUNCTION(odbc_fetch_into) #endif /* HAVE_SQL_EXTENDED_FETCH */ ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + if (result->numcols == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - + if (Z_TYPE_PP(pv_res_arr) != IS_ARRAY) { array_init(*pv_res_arr); } @@ -1875,7 +1875,7 @@ PHP_FUNCTION(odbc_fetch_into) Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC(); 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 (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) { Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC(); @@ -1915,23 +1915,23 @@ PHP_FUNCTION(odbc_fetch_into) zend_hash_index_update(Z_ARRVAL_PP(pv_res_arr), i, &tmp, sizeof(zval *), NULL); } 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) { odbc_result *result; RETCODE rc; zval *pv_res; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC, E_WARNING, "No tuples available at this result index"); @@ -1966,14 +1966,14 @@ PHP_FUNCTION(odbc_fetch_row) SQLUSMALLINT RowStatus[1]; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &pv_res, &pv_row) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &pv_res, &pv_row) == FAILURE) { return; } - + rownum = pv_row; - + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + if (result->numcols == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; @@ -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; @@ -2027,21 +2027,21 @@ PHP_FUNCTION(odbc_result) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rZ", &pv_res, &pv_field) == FAILURE) { return; } - + if (Z_TYPE_PP(pv_field) == IS_STRING) { field = Z_STRVAL_PP(pv_field); } else { convert_to_long_ex(pv_field); field_ind = Z_LVAL_PP(pv_field) - 1; } - + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + if ((result->numcols == 0)) { php_error_docref(NULL TSRMLS_CC, 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 (IS_SQL_LONG(result->values[field_ind].coltype)) { @@ -2102,7 +2102,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); @@ -2112,7 +2112,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); @@ -2130,7 +2130,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) { fieldsize -= 1; @@ -2140,7 +2140,7 @@ PHP_FUNCTION(odbc_result) */ RETURN_STRINGL(field, (rc == SQL_SUCCESS_WITH_INFO) ? fieldsize : result->values[field_ind].vallen, 0); break; - + default: if (result->values[field_ind].vallen == SQL_NULL_DATA) { RETURN_NULL(); @@ -2151,11 +2151,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); @@ -2165,7 +2165,7 @@ PHP_FUNCTION(odbc_result) efree(field); RETURN_FALSE; } - + if (result->values[field_ind].vallen == SQL_NULL_DATA) { efree(field); RETURN_NULL(); @@ -2201,9 +2201,9 @@ PHP_FUNCTION(odbc_result_all) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s", &pv_res, &pv_format, &pv_format_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + if (result->numcols == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; @@ -2212,21 +2212,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); } @@ -2246,11 +2246,11 @@ 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 (IS_SQL_LONG(result->values[i].coltype) && + if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) { - php_printf(""); + php_printf(""); break; } @@ -2259,7 +2259,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) { @@ -2294,7 +2294,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); @@ -2324,9 +2324,9 @@ PHP_FUNCTION(odbc_free_result) efree(result->values); result->values = NULL; } - + zend_list_delete(Z_LVAL_P(pv_res)); - + RETURN_TRUE; } /* }}} */ @@ -2351,13 +2351,13 @@ PHP_FUNCTION(odbc_pconnect) int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int cur_opt, int persistent TSRMLS_DC) { 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 @@ -2420,7 +2420,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; @@ -2468,7 +2468,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. @@ -2495,18 +2495,16 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 || + + /* 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 TSRMLS_CC, E_WARNING, "Invalid Cursor type (%d)", cur_opt); - RETURN_FALSE; - } + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Cursor type (%d)", cur_opt); + RETURN_FALSE; } if (ODBCG(allow_persistent) <= 0) { @@ -2526,11 +2524,11 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (persistent) { zend_rsrc_list_entry *le; - + /* the link is not in the persistent list */ if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_len + 1, (void **) &le) == FAILURE) { zend_rsrc_list_entry new_le; - + if (ODBCG(max_links) != -1 && ODBCG(num_links) >= ODBCG(max_links)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", ODBCG(num_links)); efree(hashed_details); @@ -2541,12 +2539,12 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) efree(hashed_details); RETURN_FALSE; } - + if (!odbc_sqlconnect(&db_conn, db, uid, pwd, cur_opt, 1 TSRMLS_CC)) { efree(hashed_details); RETURN_FALSE; } - + Z_TYPE(new_le) = le_pconn; new_le.ptr = db_conn; if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_len + 1, &new_le, @@ -2575,13 +2573,13 @@ 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) { zend_hash_del(&EG(persistent_list), hashed_details, hashed_len + 1); - /* Commented out to fix a possible double closure error + /* Commented out to fix a possible double closure error * when working with persistent connections as submitted by * bug #15758 * @@ -2595,7 +2593,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) db_conn->id = ZEND_REGISTER_RESOURCE(return_value, db_conn, le_pconn); } else { /* non persistent */ zend_rsrc_list_entry *index_ptr, new_index_ptr; - + if (zend_hash_find(&EG(regular_list), hashed_details, hashed_len + 1, (void **) &index_ptr) == SUCCESS) { int type, conn_id; void *ptr; @@ -2676,11 +2674,11 @@ PHP_FUNCTION(odbc_close) } } } - + zend_list_delete(Z_LVAL_P(pv_conn)); - + if(is_pconn){ - zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _close_pconn_with_id, (void *) &(Z_LVAL_P(pv_conn)) TSRMLS_CC); + zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _close_pconn_with_id, (void *) &(Z_LVAL_P(pv_conn)) TSRMLS_CC); } } /* }}} */ @@ -2692,7 +2690,7 @@ PHP_FUNCTION(odbc_num_rows) odbc_result *result; SQLLEN rows; zval *pv_res; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pv_res) == FAILURE) { return; } @@ -2714,7 +2712,7 @@ PHP_FUNCTION(odbc_next_result) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pv_res) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); if (result->values) { for(i = 0; i < result->numcols; i++) { @@ -2774,28 +2772,28 @@ PHP_FUNCTION(odbc_field_name) odbc_result *result; zval *pv_res; long pv_num; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &pv_res, &pv_num) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + if (result->numcols == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - + if (pv_num > result->numcols) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field index larger than number of fields"); RETURN_FALSE; } - + if (pv_num < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field numbering starts at 1"); RETURN_FALSE; } - + RETURN_STRING(result->values[pv_num - 1].name, 1); } /* }}} */ @@ -2820,7 +2818,7 @@ PHP_FUNCTION(odbc_field_type) php_error_docref(NULL TSRMLS_CC, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - + if (pv_num > result->numcols) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field index larger than number of fields"); RETURN_FALSE; @@ -2848,7 +2846,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); } /* }}} */ @@ -2864,9 +2862,9 @@ PHP_FUNCTION(odbc_field_num) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pv_res, &fname, &fname_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_res, -1, "ODBC result", le_result); - + if (result->numcols == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; @@ -2901,7 +2899,7 @@ PHP_FUNCTION(odbc_autocommit) } ZEND_FETCH_RESOURCE2(conn, odbc_connection *, &pv_conn, -1, "ODBC-Link", le_conn, le_pconn); - + if (ZEND_NUM_ARGS() > 1) { rc = SQLSetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, (pv_onoff) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { @@ -2956,7 +2954,7 @@ static void php_odbc_lasterror(INTERNAL_FUNCTION_PARAMETERS, int mode) len = SQL_MAX_MESSAGE_LENGTH; } - if (ZEND_NUM_ARGS() == 1) { + if (pv_handle) { ZEND_FETCH_RESOURCE2(conn, odbc_connection *, &pv_handle, -1, "ODBC-Link", le_conn, le_pconn); ptr = ecalloc(len + 1, 1); if (mode == 0) { @@ -3028,7 +3026,7 @@ PHP_FUNCTION(odbc_setoption) break; case 2: /* SQLSetStmtOption */ ZEND_FETCH_RESOURCE(result, odbc_result *, &pv_handle, -1, "ODBC result", le_result); - + rc = SQLSetStmtOption(result->stmt, (unsigned short) pv_opt, pv_val); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { @@ -3061,7 +3059,7 @@ PHP_FUNCTION(odbc_tables) int cat_len = 0, schema_len = 0, table_len = 0, type_len = 0; RETCODE rc; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, &table, &table_len, &type, &type_len) == FAILURE) { return; } @@ -3069,7 +3067,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); @@ -3088,9 +3086,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)); @@ -3136,7 +3134,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); @@ -3150,14 +3148,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, @@ -3197,7 +3195,7 @@ PHP_FUNCTION(odbc_columnprivileges) char *cat = NULL, *schema, *table, *column; int cat_len = 0, schema_len, table_len, column_len; RETCODE rc; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, &table, &table_len, &column, &column_len) == FAILURE) { return; @@ -3206,7 +3204,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); @@ -3220,7 +3218,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), @@ -3262,7 +3260,7 @@ PHP_FUNCTION(odbc_foreignkeys) int pcat_len = 0, pschema_len, ptable_len, fcat_len, fschema_len, ftable_len; RETCODE rc; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!sssss", &pv_conn, &pcat, &pcat_len, &pschema, &pschema_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!sssss", &pv_conn, &pcat, &pcat_len, &pschema, &pschema_len, &ptable, &ptable_len, &fcat, &fcat_len, &fschema, &fschema_len, &ftable, &ftable_len) == FAILURE) { return; } @@ -3282,7 +3280,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); @@ -3296,12 +3294,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) { @@ -3342,13 +3340,13 @@ PHP_FUNCTION(odbc_gettypeinfo) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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); @@ -3405,7 +3403,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); @@ -3419,9 +3417,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) { @@ -3458,12 +3456,12 @@ PHP_FUNCTION(odbc_procedurecolumns) char *cat = NULL, *schema = NULL, *proc = NULL, *col = NULL; int 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; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, &proc, &proc_len, &col, &col_len) == FAILURE) { return; } @@ -3471,7 +3469,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); @@ -3485,10 +3483,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) { @@ -3530,7 +3528,7 @@ PHP_FUNCTION(odbc_procedures) if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 4) { WRONG_PARAM_COUNT; } - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!ss", &pv_conn, &cat, &cat_len, &schema, &schema_len, &proc, &proc_len) == FAILURE) { return; } @@ -3538,7 +3536,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); @@ -3552,9 +3550,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) { @@ -3598,7 +3596,7 @@ PHP_FUNCTION(odbc_specialcolumns) &name, &name_len, &vscope, &vnullable) == FAILURE) { return; } - + type = (SQLUSMALLINT) vtype; scope = (SQLUSMALLINT) vscope; nullable = (SQLUSMALLINT) vnullable; @@ -3606,7 +3604,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); @@ -3620,10 +3618,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); @@ -3668,14 +3666,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); @@ -3689,9 +3687,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); @@ -3738,7 +3736,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); @@ -3752,9 +3750,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 b66f4722e8108..708fa1b27eb3f 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -198,7 +198,7 @@ ZEND_GET_MODULE(pcntl) static void pcntl_signal_handler(int); static void pcntl_signal_dispatch(); - + void php_register_signal_constants(INIT_FUNC_ARGS) { @@ -234,7 +234,7 @@ void php_register_signal_constants(INIT_FUNC_ARGS) REGISTER_LONG_CONSTANT("SIGTERM", (long) SIGTERM, CONST_CS | CONST_PERSISTENT); #ifdef SIGSTKFLT REGISTER_LONG_CONSTANT("SIGSTKFLT",(long) SIGSTKFLT, CONST_CS | CONST_PERSISTENT); -#endif +#endif #ifdef SIGCLD REGISTER_LONG_CONSTANT("SIGCLD", (long) SIGCLD, CONST_CS | CONST_PERSISTENT); #endif @@ -484,7 +484,7 @@ static void php_pcntl_register_errno_constants(INIT_FUNC_ARGS) } static PHP_GINIT_FUNCTION(pcntl) -{ +{ memset(pcntl_globals, 0, sizeof(*pcntl_globals)); } @@ -547,7 +547,7 @@ PHP_FUNCTION(pcntl_fork) PCNTL_G(last_error) = errno; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error %d", errno); } - + RETURN_LONG((long) id); } /* }}} */ @@ -560,7 +560,7 @@ PHP_FUNCTION(pcntl_alarm) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &seconds) == FAILURE) return; - + RETURN_LONG ((long) alarm(seconds)); } /* }}} */ @@ -576,7 +576,7 @@ PHP_FUNCTION(pcntl_waitpid) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|l", &pid, &z_status, &options) == FAILURE) return; - + convert_to_long_ex(&z_status); status = Z_LVAL_P(z_status); @@ -604,7 +604,7 @@ PHP_FUNCTION(pcntl_wait) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &z_status, &options) == FAILURE) return; - + convert_to_long_ex(&z_status); status = Z_LVAL_P(z_status); @@ -628,7 +628,7 @@ PHP_FUNCTION(pcntl_wait) } /* }}} */ -/* {{{ proto bool pcntl_wifexited(int status) +/* {{{ proto bool pcntl_wifexited(int status) Returns true if the child status code represents a successful exit */ PHP_FUNCTION(pcntl_wifexited) { @@ -646,7 +646,7 @@ PHP_FUNCTION(pcntl_wifexited) } /* }}} */ -/* {{{ proto bool pcntl_wifstopped(int status) +/* {{{ proto bool pcntl_wifstopped(int status) Returns true if the child status code represents a stopped process (WUNTRACED must have been used with waitpid) */ PHP_FUNCTION(pcntl_wifstopped) { @@ -664,7 +664,7 @@ PHP_FUNCTION(pcntl_wifstopped) } /* }}} */ -/* {{{ proto bool pcntl_wifsignaled(int status) +/* {{{ proto bool pcntl_wifsignaled(int status) Returns true if the child status code represents a process that was terminated due to a signal */ PHP_FUNCTION(pcntl_wifsignaled) { @@ -682,7 +682,7 @@ PHP_FUNCTION(pcntl_wifsignaled) } /* }}} */ -/* {{{ proto int pcntl_wexitstatus(int status) +/* {{{ proto int pcntl_wexitstatus(int status) Returns the status code of a child's exit */ PHP_FUNCTION(pcntl_wexitstatus) { @@ -700,7 +700,7 @@ PHP_FUNCTION(pcntl_wexitstatus) } /* }}} */ -/* {{{ proto int pcntl_wtermsig(int status) +/* {{{ proto int pcntl_wtermsig(int status) Returns the number of the signal that terminated the process who's status code is passed */ PHP_FUNCTION(pcntl_wtermsig) { @@ -718,7 +718,7 @@ PHP_FUNCTION(pcntl_wtermsig) } /* }}} */ -/* {{{ proto int pcntl_wstopsig(int status) +/* {{{ proto int pcntl_wstopsig(int status) Returns the number of the signal that caused the process to stop who's status code is passed */ PHP_FUNCTION(pcntl_wstopsig) { @@ -754,19 +754,19 @@ PHP_FUNCTION(pcntl_exec) char *path; int path_len; ulong key_num; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|aa", &path, &path_len, &args, &envs) == FAILURE) { return; } - - if (ZEND_NUM_ARGS() > 1) { + + if (args != NULL) { /* Build argument list */ args_hash = HASH_OF(args); argc = zend_hash_num_elements(args_hash); - + argv = safe_emalloc((argc + 2), sizeof(char *), 0); *argv = path; - for ( zend_hash_internal_pointer_reset(args_hash), current_arg = argv+1; + for ( zend_hash_internal_pointer_reset(args_hash), current_arg = argv+1; (argi < argc && (zend_hash_get_current_data(args_hash, (void **) &element) == SUCCESS)); (argi++, current_arg++, zend_hash_move_forward(args_hash)) ) { @@ -780,13 +780,13 @@ 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); - + envp = safe_emalloc((envc + 1), sizeof(char *), 0); - for ( zend_hash_internal_pointer_reset(envs_hash), pair = envp; + for ( zend_hash_internal_pointer_reset(envs_hash), pair = envp; (envi < envc && (zend_hash_get_current_data(envs_hash, (void **) &element) == SUCCESS)); (envi++, pair++, zend_hash_move_forward(envs_hash)) ) { switch (return_val = zend_hash_get_current_key_ex(envs_hash, &key, &key_length, &key_num, 0, NULL)) { @@ -802,13 +802,13 @@ PHP_FUNCTION(pcntl_exec) convert_to_string_ex(element); - /* Length of element + equal sign + length of key + null */ + /* Length of element + equal sign + length of key + null */ pair_length = Z_STRLEN_PP(element) + key_length + 2; *pair = emalloc(pair_length); - strlcpy(*pair, key, key_length); + strlcpy(*pair, key, key_length); strlcat(*pair, "=", pair_length); strlcat(*pair, Z_STRVAL_PP(element), pair_length); - + /* Cleanup */ if (return_val == HASH_KEY_IS_LONG) efree(key); } @@ -818,7 +818,7 @@ PHP_FUNCTION(pcntl_exec) PCNTL_G(last_error) = errno; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error has occurred: (errno %d) %s", errno, strerror(errno)); } - + /* Cleanup */ for (pair = envp; *pair != NULL; pair++) efree(*pair); efree(envp); @@ -831,7 +831,7 @@ PHP_FUNCTION(pcntl_exec) } efree(argv); - + RETURN_FALSE; } /* }}} */ @@ -880,7 +880,7 @@ PHP_FUNCTION(pcntl_signal) } RETURN_TRUE; } - + if (!zend_is_callable(handle, 0, &func_name TSRMLS_CC)) { PCNTL_G(last_error) = EINVAL; php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not a callable function name error", func_name); @@ -888,11 +888,11 @@ PHP_FUNCTION(pcntl_signal) RETURN_FALSE; } efree(func_name); - + /* Add the function name to our signal table */ zend_hash_index_update(&PCNTL_G(php_signal_table), signo, (void **) &handle, sizeof(zval *), (void **) &dest_handle); if (dest_handle) zval_add_ref(dest_handle); - + if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == SIG_ERR) { PCNTL_G(last_error) = errno; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error assigning signal"); @@ -1029,7 +1029,7 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{ } /* - * sigtimedwait and sigwaitinfo can return 0 on success on some + * sigtimedwait and sigwaitinfo can return 0 on success on some * platforms, e.g. NetBSD */ if (!signo && siginfo.si_signo) { @@ -1077,7 +1077,7 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{ EMPTY_SWITCH_DEFAULT_CASE(); } } - + RETURN_LONG(signo); } /* }}} */ @@ -1107,12 +1107,12 @@ PHP_FUNCTION(pcntl_getpriority) long who = PRIO_PROCESS; long pid = getpid(); int pri; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &pid, &who) == FAILURE) { RETURN_FALSE; } - /* needs to be cleared, since any returned value is valid */ + /* needs to be cleared, since any returned value is valid */ errno = 0; pri = getpriority(who, pid); @@ -1172,7 +1172,7 @@ PHP_FUNCTION(pcntl_setpriority) } RETURN_FALSE; } - + RETURN_TRUE; } /* }}} */ @@ -1205,7 +1205,7 @@ static void pcntl_signal_handler(int signo) { struct php_pcntl_pending_signal *psig; TSRMLS_FETCH(); - + psig = PCNTL_G(spares); if (!psig) { /* oops, too many signals for us to track, so we'll forget about this one */ @@ -1233,7 +1233,7 @@ void pcntl_signal_dispatch() sigset_t mask; sigset_t old_mask; TSRMLS_FETCH(); - + /* Mask all signals */ sigfillset(&mask); sigprocmask(SIG_BLOCK, &mask, &old_mask); @@ -1249,7 +1249,7 @@ void pcntl_signal_dispatch() queue = PCNTL_G(head); PCNTL_G(head) = NULL; /* simple stores are atomic */ - + /* Allocate */ while (queue) { @@ -1274,7 +1274,7 @@ void pcntl_signal_dispatch() /* Re-enable queue */ PCNTL_G(processing_signal_queue) = 0; - + /* return signal mask to previous state */ sigprocmask(SIG_SETMASK, &old_mask, NULL); } diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 7d34d9feb15a8..7c0668453cb74 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -136,7 +136,7 @@ static PHP_MINFO_FUNCTION(pcre) static PHP_MINIT_FUNCTION(pcre) { REGISTER_INI_ENTRIES(); - + REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); @@ -276,9 +276,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le #endif } } - + p = regex; - + /* Parse through the leading whitespace, and display a warning if we get to the end without encountering a delimiter. */ while (isspace((int)*(unsigned char *)p)) p++; @@ -287,7 +287,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le p < regex + regex_len ? "Null byte in regex" : "Empty regular expression"); return NULL; } - + /* Get the delimiter and display a warning if it is alphanumeric or a backslash. */ delimiter = *p++; @@ -340,7 +340,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le } return NULL; } - + /* Make a copy of the actual pattern. */ pattern = estrndup(p, pp-p); @@ -356,7 +356,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le case 'm': coptions |= PCRE_MULTILINE; break; case 's': coptions |= PCRE_DOTALL; break; case 'x': coptions |= PCRE_EXTENDED; break; - + /* PCRE specific options */ case 'A': coptions |= PCRE_ANCHORED; break; case 'D': coptions |= PCRE_DOLLAR_ENDONLY;break; @@ -369,12 +369,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le the PCRE_UCP option. */ #ifdef PCRE_UCP coptions |= PCRE_UCP; -#endif +#endif break; /* Custom preg options */ case 'e': poptions |= PREG_REPLACE_EVAL; break; - + case ' ': case '\n': break; @@ -482,7 +482,7 @@ PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_ if (preg_options) { *preg_options = pce ? pce->preg_options : 0; } - + return pce ? pce->re : NULL; } /* }}} */ @@ -492,7 +492,7 @@ PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC) { pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex) TSRMLS_CC); - + if (extra) { *extra = pce ? pce->extra : NULL; } @@ -502,7 +502,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr if (compile_options) { *compile_options = pce ? pce->compile_options : 0; } - + return pce ? pce->re : NULL; } /* }}} */ @@ -519,7 +519,7 @@ static inline void add_offset_pair(zval *result, char *str, int len, int offset, /* Add (match, offset) to the return value */ add_next_index_stringl(match_pair, str, len, 1); add_next_index_long(match_pair, offset); - + if (name) { zval_add_ref(&match_pair); zend_hash_update(Z_ARRVAL_P(result), name, strlen(name)+1, &match_pair, sizeof(zval *), NULL); @@ -544,13 +544,13 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * &subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) { RETURN_FALSE; } - + /* Compile regex or get it from cache. */ if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - php_pcre_match_impl(pce, subject, subject_len, return_value, subpats, + php_pcre_match_impl(pce, subject, subject_len, return_value, subpats, global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC); } /* }}} */ @@ -653,7 +653,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec matched = 0; PCRE_G(error_code) = PHP_PCRE_NO_ERROR; - + do { /* Execute the regular expression. */ count = pcre_exec(pce->re, extra, subject, subject_len, start_offset, @@ -710,7 +710,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec ALLOC_ZVAL(result_set); array_init(result_set); INIT_PZVAL(result_set); - + /* Add all the subpatterns to it */ for (i = 0; i < count; i++) { if (offset_capture) { @@ -762,13 +762,13 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec pcre_handle_exec_error(count TSRMLS_CC); break; } - + /* If we have matched an empty string, mimic what Perl's /g options does. This turns out to be rather cunning. First we set PCRE_NOTEMPTY and try the match again at the same point. If this fails (picked up above) we advance to the next character. */ g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0; - + /* Advance to the position right after the last full match */ start_offset = offsets[1]; } while (global); @@ -785,7 +785,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec } efree(match_sets); } - + efree(offsets); efree(subpat_names); @@ -835,7 +835,7 @@ static int preg_get_backref(char **str, int *backref) walk++; } else return 0; - + if (*walk && *walk >= '0' && *walk <= '9') { *backref = *backref * 10 + *walk - '0'; walk++; @@ -847,9 +847,9 @@ static int preg_get_backref(char **str, int *backref) else walk++; } - + *str = walk; - return 1; + return 1; } /* }}} */ @@ -859,7 +859,7 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char * { zval *retval_ptr; /* Function return value */ zval **args[1]; /* Argument to pass to function */ - zval *subpats; /* Captured subpatterns */ + zval *subpats; /* Captured subpatterns */ int result_len; /* Return value length */ int i; @@ -910,11 +910,11 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, int backref; /* Current backref */ char *compiled_string_description; smart_str code = {0}; - + eval_str_end = eval_str + eval_str_len; walk = segment = eval_str; walk_last = 0; - + while (walk < eval_str_end) { /* If found a backreference.. */ if ('\\' == *walk || '$' == *walk) { @@ -967,15 +967,15 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, } efree(compiled_string_description); convert_to_string(&retval); - + /* Save the return value and its length */ *result = estrndup(Z_STRVAL(retval), Z_STRLEN(retval)); result_len = Z_STRLEN(retval); - + /* Clean up */ zval_dtor(&retval); smart_str_free(&code); - + return result_len; } /* }}} */ @@ -994,13 +994,13 @@ PHPAPI char *php_pcre_replace(char *regex, int regex_len, return NULL; } - return php_pcre_replace_impl(pce, subject, subject_len, replace_val, + return php_pcre_replace_impl(pce, subject, subject_len, replace_val, is_callable_replace, result_len, limit, replace_count TSRMLS_CC); } /* }}} */ /* {{{ php_pcre_replace_impl() */ -PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, +PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_extra *extra = pce->extra;/* Holds results of studying */ @@ -1076,7 +1076,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub } offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0); - + alloc_len = 2 * subject_len + 1; result = safe_emalloc(alloc_len, sizeof(char), 0); @@ -1085,7 +1085,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub *result_len = 0; start_offset = 0; PCRE_G(error_code) = PHP_PCRE_NO_ERROR; - + while (1) { /* Execute the regular expression. */ count = pcre_exec(pce->re, extra, subject, subject_len, start_offset, @@ -1110,7 +1110,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub match = subject + offsets[0]; new_len = *result_len + offsets[0] - start_offset; /* part before the match */ - + /* If evaluating, do it and add the return string's length */ if (eval) { eval_result_len = preg_do_eval(replace, replace_len, subject, @@ -1155,7 +1155,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub /* copy replacement and backrefs */ walkbuf = result + *result_len; - + /* If evaluating or using custom function, copy result to the buffer * and clean up. */ if (eval || is_callable_replace) { @@ -1223,13 +1223,13 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub result = NULL; break; } - + /* If we have matched an empty string, mimic what Perl's /g options does. This turns out to be rather cunning. First we set PCRE_NOTEMPTY and try the match again at the same point. If this fails (picked up above) we advance to the next character. */ g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0; - + /* Advance to the next piece. */ start_offset = offsets[1]; } @@ -1253,18 +1253,18 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, *result; int subject_len; - /* Make sure we're dealing with strings. */ + /* Make sure we're dealing with strings. */ convert_to_string_ex(subject); /* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */ ZVAL_STRINGL(&empty_replace, "", 0, 0); - + /* If regex is an array */ if (Z_TYPE_P(regex) == IS_ARRAY) { /* Duplicate subject string for repeated replacement */ subject_value = estrndup(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject)); subject_len = Z_STRLEN_PP(subject); *result_len = subject_len; - + zend_hash_internal_pointer_reset(Z_ARRVAL_P(regex)); replace_value = replace; @@ -1273,9 +1273,9 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, /* For each entry in the regex array, get the entry */ while (zend_hash_get_current_data(Z_ARRVAL_P(regex), (void **)®ex_entry) == SUCCESS) { - /* Make sure we're dealing with strings. */ + /* Make sure we're dealing with strings. */ convert_to_string_ex(regex_entry); - + /* If replace is an array and not a callable construct */ if (Z_TYPE_P(replace) == IS_ARRAY && !is_callable_replace) { /* Get current entry */ @@ -1290,7 +1290,7 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, replace_value = &empty_replace; } } - + /* Do the actual replacement and put the result back into subject_value for further replacements. */ if ((result = php_pcre_replace(Z_STRVAL_PP(regex_entry), @@ -1346,12 +1346,12 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl ulong num_key; char *callback_name; int replace_count=0, old_replace_count; - + /* Get function parameters and do error-checking. */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZZ|lZ", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { return; } - + if (!is_callable_replace && Z_TYPE_PP(replace) == IS_ARRAY && Z_TYPE_PP(regex) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter mismatch, pattern is a string while replacement is an array"); RETURN_FALSE; @@ -1374,13 +1374,11 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl SEPARATE_ZVAL(regex); SEPARATE_ZVAL(subject); - if (ZEND_NUM_ARGS() > 3) { - limit_val = limit; - } - + limit_val = limit; + if (Z_TYPE_PP(regex) != IS_ARRAY) convert_to_string_ex(regex); - + /* if subject is an array */ if (Z_TYPE_PP(subject) == IS_ARRAY) { array_init(return_value); @@ -1408,7 +1406,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl efree(result); } } - + zend_hash_move_forward(Z_ARRVAL_PP(subject)); } } else { /* if subject is not an array */ @@ -1421,11 +1419,11 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl } } } - if (ZEND_NUM_ARGS() > 4) { + if (zcount) { zval_dtor(*zcount); ZVAL_LONG(*zcount, replace_count); } - + } /* }}} */ @@ -1453,7 +1451,7 @@ static PHP_FUNCTION(preg_filter) } /* }}} */ -/* {{{ proto array preg_split(string pattern, string subject [, int limit [, int flags]]) +/* {{{ proto array preg_split(string pattern, string subject [, int limit [, int flags]]) Split string into an array using a perl-style regular expression as a delimiter */ static PHP_FUNCTION(preg_split) { @@ -1465,12 +1463,12 @@ static PHP_FUNCTION(preg_split) long flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ - /* Get function parameters and do error checking */ + /* Get function parameters and do error checking */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", ®ex, ®ex_len, &subject, &subject_len, &limit_val, &flags) == FAILURE) { RETURN_FALSE; } - + /* Compile regex or get it from cache. */ if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; @@ -1505,7 +1503,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec no_empty = flags & PREG_SPLIT_NO_EMPTY; delim_capture = flags & PREG_SPLIT_DELIM_CAPTURE; offset_capture = flags & PREG_SPLIT_OFFSET_CAPTURE; - + if (limit_val == 0) { limit_val = -1; } @@ -1516,7 +1514,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec } extra->match_limit = PCRE_G(backtrack_limit); extra->match_limit_recursion = PCRE_G(recursion_limit); - + /* Initialize return value */ array_init(return_value); @@ -1528,13 +1526,13 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec } size_offsets = (size_offsets + 1) * 3; offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0); - + /* Start at the beginning of the string */ start_offset = 0; next_offset = 0; last_match = subject; PCRE_G(error_code) = PHP_PCRE_NO_ERROR; - + /* Get next piece if no limit or limit not yet reached and something matched*/ while ((limit_val == -1 || limit_val > 1)) { count = pcre_exec(pce->re, extra, subject, @@ -1549,7 +1547,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec php_error_docref(NULL TSRMLS_CC,E_NOTICE, "Matched, but too many substrings"); count = size_offsets/3; } - + /* If something matched */ if (count > 0) { if (!no_empty || &subject[offsets[0]] != last_match) { @@ -1567,7 +1565,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec if (limit_val != -1) limit_val--; } - + last_match = &subject[offsets[1]]; next_offset = offsets[1]; @@ -1624,7 +1622,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec the match again at the same point. If this fails (picked up above) we advance to the next character. */ g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0; - + /* Advance to the position right after the last full match */ start_offset = offsets[1]; } @@ -1643,7 +1641,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec } } - + /* Clean up */ efree(offsets); } @@ -1664,13 +1662,13 @@ static PHP_FUNCTION(preg_quote) delim_char=0, /* Delimiter character to be quoted */ c; /* Current character */ zend_bool quote_delim = 0; /* Whether to quote additional delim char */ - + /* Get the arguments and check for errors */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &in_str, &in_str_len, &delim, &delim_len) == FAILURE) { return; } - + in_str_end = in_str + in_str_len; /* Nothing to do if we got an empty string */ @@ -1682,11 +1680,11 @@ static PHP_FUNCTION(preg_quote) delim_char = delim[0]; quote_delim = 1; } - + /* Allocate enough memory so that even if each character is quoted, we won't run out of room */ out_str = safe_emalloc(4, in_str_len, 1); - + /* Go through the string and quote necessary characters */ for(p = in_str, q = out_str; p != in_str_end; p++) { c = *p; @@ -1730,7 +1728,7 @@ static PHP_FUNCTION(preg_quote) } } *q = '\0'; - + /* Reallocate string and return it */ RETVAL_STRINGL(erealloc(out_str, q - out_str + 1), q - out_str, 0); } @@ -1751,12 +1749,12 @@ static PHP_FUNCTION(preg_grep) &input, &flags) == FAILURE) { return; } - + /* Compile regex or get it from cache. */ if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - + php_pcre_grep_impl(pce, input, return_value, flags TSRMLS_CC); } /* }}} */ @@ -1774,9 +1772,9 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return zend_bool invert; /* Whether to return non-matching entries */ int rc; - + invert = flags & PREG_GREP_INVERT ? 1 : 0; - + if (extra == NULL) { extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION; extra = &extra_data; @@ -1792,7 +1790,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return } size_offsets = (size_offsets + 1) * 3; offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0); - + /* Initialize return array */ array_init(return_value); @@ -1905,7 +1903,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_split, 0, 0, 2) ZEND_ARG_INFO(0, pattern) ZEND_ARG_INFO(0, subject) ZEND_ARG_INFO(0, limit) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_quote, 0, 0, 1) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index aec388c03f5d9..dcd0311d45249 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -52,7 +52,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate return; #endif } - + if (stmt) { pdo_err = &stmt->error_code; } @@ -82,7 +82,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate zend_update_property_string(def_ex, ex, "message", sizeof("message")-1, message TSRMLS_CC); zend_update_property_string(def_ex, ex, "code", sizeof("code")-1, *pdo_err TSRMLS_CC); - + MAKE_STD_ZVAL(info); array_init(info); @@ -94,7 +94,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate zend_throw_exception_object(ex TSRMLS_CC); } - + if (message) { efree(message); } @@ -113,7 +113,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{ if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) { return; } - + if (stmt) { pdo_err = &stmt->error_code; } @@ -129,14 +129,14 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{ array_init(info); add_next_index_string(info, *pdo_err, 1); - + if (dbh->methods->fetch_err(dbh, stmt, info TSRMLS_CC)) { zval **item; if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(info), 1, (void**)&item)) { native_code = Z_LVAL_PP(item); } - + if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(info), 2, (void**)&item)) { supp = estrndup(Z_STRVAL_PP(item), Z_STRLEN_PP(item)); } @@ -160,7 +160,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{ zend_update_property_string(def_ex, ex, "message", sizeof("message")-1, message TSRMLS_CC); zend_update_property_string(def_ex, ex, "code", sizeof("code")-1, *pdo_err TSRMLS_CC); - + if (info) { zend_update_property(pdo_ex, ex, "errorInfo", sizeof("errorInfo")-1, info TSRMLS_CC); } @@ -236,7 +236,7 @@ static PHP_METHOD(PDO, dbh_constructor) data_source = ini_dsn; colon = strchr(data_source, ':'); - + if (!colon) { zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "invalid data source name (via INI: %s)", alt_dsn); ZVAL_NULL(object); @@ -269,7 +269,7 @@ static PHP_METHOD(PDO, dbh_constructor) ZVAL_NULL(object); return; } - + dbh = (pdo_dbh_t *) zend_object_store_get_object(object TSRMLS_CC); /* is this supposed to be a persistent connection ? */ @@ -336,7 +336,7 @@ static PHP_METHOD(PDO, dbh_constructor) if (pdbh) { /* let's copy the emalloc bits over from the other handle */ if (pdbh->std.properties) { - zend_hash_destroy(dbh->std.properties); + zend_hash_destroy(dbh->std.properties); efree(dbh->std.properties); if (dbh->std.properties_table) { efree(dbh->std.properties_table); @@ -360,14 +360,14 @@ static PHP_METHOD(PDO, dbh_constructor) efree(hashkey); } } - + if (call_factory) { dbh->data_source_len = strlen(colon + 1); dbh->data_source = (const char*)pestrdup(colon + 1, is_persistent); dbh->username = username ? pestrdup(username, is_persistent) : NULL; dbh->password = password ? pestrdup(password, is_persistent) : NULL; dbh->default_fetch_type = PDO_FETCH_BOTH; - } + } dbh->auto_commit = pdo_attr_lval(options, PDO_ATTR_AUTOCOMMIT, 1 TSRMLS_CC); @@ -406,11 +406,11 @@ static PHP_METHOD(PDO, dbh_constructor) zval **attr_value; char *str_key; ulong long_key; - + zend_hash_internal_pointer_reset(Z_ARRVAL_P(options)); - while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(options), (void**)&attr_value) + while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(options), (void**)&attr_value) && HASH_KEY_IS_LONG == zend_hash_get_current_key(Z_ARRVAL_P(options), &str_key, &long_key, 0)) { - + pdo_dbh_attribute_set(dbh, long_key, *attr_value TSRMLS_CC); zend_hash_move_forward(Z_ARRVAL_P(options)); } @@ -442,12 +442,12 @@ static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry object_init_ex(object, dbstmt_ce); Z_SET_REFCOUNT_P(object, 1); Z_SET_ISREF_P(object); - + return object; } /* }}} */ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry *dbstmt_ce, zval *ctor_args TSRMLS_DC) /* {{{ */ -{ +{ zval *query_string; zval z_key; @@ -498,7 +498,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry } else { zval_ptr_dtor(&retval); } - + if (fci.params) { efree(fci.params); } @@ -521,16 +521,16 @@ static PHP_METHOD(PDO, prepare) &statement_len, &options)) { RETURN_FALSE; } - + PDO_DBH_CLEAR_ERR(); PDO_CONSTRUCT_CHECK; - if (ZEND_NUM_ARGS() > 1 && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), PDO_ATTR_STATEMENT_CLASS, (void**)&opt)) { + if (options != NULL && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), PDO_ATTR_STATEMENT_CLASS, (void**)&opt)) { if (Z_TYPE_PP(opt) != IS_ARRAY || zend_hash_index_find(Z_ARRVAL_PP(opt), 0, (void**)&item) == FAILURE || Z_TYPE_PP(item) != IS_STRING || zend_lookup_class(Z_STRVAL_PP(item), Z_STRLEN_PP(item), &pce TSRMLS_CC) == FAILURE ) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " "the classname must be a string specifying an existing class" TSRMLS_CC); @@ -539,20 +539,20 @@ static PHP_METHOD(PDO, prepare) } dbstmt_ce = *pce; if (!instanceof_function(dbstmt_ce, pdo_dbstmt_ce TSRMLS_CC)) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement class must be derived from PDOStatement" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } if (dbstmt_ce->constructor && !(dbstmt_ce->constructor->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement class cannot have a public constructor" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } if (zend_hash_index_find(Z_ARRVAL_PP(opt), 1, (void**)&item) == SUCCESS) { if (Z_TYPE_PP(item) != IS_ARRAY) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "PDO::ATTR_STATEMENT_CLASS requires format array(classname, ctor_args); " "ctor_args must be an array" TSRMLS_CC); @@ -569,14 +569,14 @@ static PHP_METHOD(PDO, prepare) } if (!pdo_stmt_instantiate(dbh, return_value, dbstmt_ce, ctor_args TSRMLS_CC)) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "failed to instantiate user-supplied statement class" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } stmt = (pdo_stmt_t*)zend_object_store_get_object(return_value TSRMLS_CC); - + /* unconditionally keep this for later reference */ stmt->query_string = estrndup(statement, statement_len); stmt->query_stringlen = statement_len; @@ -618,7 +618,7 @@ static PHP_METHOD(PDO, beginTransaction) zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "There is already an active transaction"); RETURN_FALSE; } - + if (!dbh->methods->begin) { /* TODO: this should be an exception; see the auto-commit mode * comments below */ @@ -656,7 +656,7 @@ static PHP_METHOD(PDO, commit) dbh->in_txn = 0; RETURN_TRUE; } - + PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } @@ -682,7 +682,7 @@ static PHP_METHOD(PDO, rollBack) dbh->in_txn = 0; RETURN_TRUE; } - + PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } @@ -701,7 +701,7 @@ static PHP_METHOD(PDO, inTransaction) if (!dbh->methods->in_transaction) { RETURN_BOOL(dbh->in_txn); - } + } RETURN_BOOL(dbh->methods->in_transaction(dbh TSRMLS_CC)); } @@ -781,14 +781,14 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D convert_to_long(value); dbh->stringify = Z_LVAL_P(value) ? 1 : 0; return SUCCESS; - + case PDO_ATTR_STATEMENT_CLASS: { /* array(string classname, array(mixed ctor_args)) */ zend_class_entry **pce; zval **item; if (dbh->is_persistent) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); @@ -799,7 +799,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D || Z_TYPE_PP(item) != IS_STRING || zend_lookup_class(Z_STRVAL_PP(item), Z_STRLEN_PP(item), &pce TSRMLS_CC) == FAILURE ) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " "the classname must be a string specifying an existing class" TSRMLS_CC); @@ -807,13 +807,13 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D return FAILURE; } if (!instanceof_function(*pce, pdo_dbstmt_ce TSRMLS_CC)) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement class must be derived from PDOStatement" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); return FAILURE; } if ((*pce)->constructor && !((*pce)->constructor->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement class cannot have a public constructor" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); return FAILURE; @@ -825,7 +825,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D } if (zend_hash_index_find(Z_ARRVAL_P(value), 1, (void**)&item) == SUCCESS) { if (Z_TYPE_PP(item) != IS_ARRAY) { - pdo_raise_impl_error(dbh, NULL, "HY000", + pdo_raise_impl_error(dbh, NULL, "HY000", "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " "ctor_args must be an array" TSRMLS_CC); @@ -837,7 +837,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D } return SUCCESS; } - + default: ; } @@ -862,7 +862,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D return FAILURE; } /* }}} */ - + /* {{{ proto bool PDO::setAttribute(long attribute, mixed value) Set an attribute */ static PHP_METHOD(PDO, setAttribute) @@ -903,7 +903,7 @@ static PHP_METHOD(PDO, getAttribute) switch (attr) { case PDO_ATTR_PERSISTENT: RETURN_BOOL(dbh->is_persistent); - + case PDO_ATTR_CASE: RETURN_LONG(dbh->desired_case); @@ -928,7 +928,7 @@ static PHP_METHOD(PDO, getAttribute) RETURN_LONG(dbh->default_fetch_type); } - + if (!dbh->methods->get_attribute) { pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support getting attributes" TSRMLS_CC); RETURN_FALSE; @@ -1022,7 +1022,7 @@ static PHP_METHOD(PDO, errorCode) if (dbh->query_stmt) { RETURN_STRING(dbh->query_stmt->error_code, 1); } - + if (dbh->error_code[0] == '\0') { RETURN_NULL(); } @@ -1062,7 +1062,7 @@ static PHP_METHOD(PDO, errorInfo) if (dbh->methods->fetch_err) { dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value TSRMLS_CC); } - + /** * In order to be consistent, we have to make sure we add the good amount * of nulls depending on the current number of elements. We make a simple @@ -1095,12 +1095,12 @@ static PHP_METHOD(PDO, query) zend_parse_parameters(0 TSRMLS_CC, "z|z", NULL, NULL); RETURN_FALSE; } - + if (FAILURE == zend_parse_parameters(1 TSRMLS_CC, "s", &statement, &statement_len)) { RETURN_FALSE; } - + PDO_DBH_CLEAR_ERR(); PDO_CONSTRUCT_CHECK; @@ -1109,7 +1109,7 @@ static PHP_METHOD(PDO, query) return; } stmt = (pdo_stmt_t*)zend_object_store_get_object(return_value TSRMLS_CC); - + /* unconditionally keep this for later reference */ stmt->query_string = estrndup(statement, statement_len); stmt->query_stringlen = statement_len; @@ -1172,7 +1172,7 @@ static PHP_METHOD(PDO, quote) if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, ¶mtype)) { RETURN_FALSE; } - + PDO_DBH_CLEAR_ERR(); PDO_CONSTRUCT_CHECK; if (!dbh->methods->quoter) { @@ -1214,7 +1214,7 @@ static PHP_METHOD(PDO, getAvailableDrivers) if (zend_parse_parameters_none() == FAILURE) { return; } - + array_init(return_value); zend_hash_internal_pointer_reset_ex(&pdo_driver_hash, &pos); @@ -1414,7 +1414,7 @@ void pdo_dbh_init(TSRMLS_D) memcpy(&pdo_dbh_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); pdo_dbh_object_handlers.get_method = dbh_method_get; pdo_dbh_object_handlers.compare_objects = dbh_compare; - + REGISTER_PDO_CLASS_CONST_LONG("PARAM_BOOL", (long)PDO_PARAM_BOOL); REGISTER_PDO_CLASS_CONST_LONG("PARAM_NULL", (long)PDO_PARAM_NULL); REGISTER_PDO_CLASS_CONST_LONG("PARAM_INT", (long)PDO_PARAM_INT); @@ -1472,7 +1472,7 @@ void pdo_dbh_init(TSRMLS_D) REGISTER_PDO_CLASS_CONST_LONG("ATTR_MAX_COLUMN_LEN",(long)PDO_ATTR_MAX_COLUMN_LEN); REGISTER_PDO_CLASS_CONST_LONG("ATTR_EMULATE_PREPARES",(long)PDO_ATTR_EMULATE_PREPARES); REGISTER_PDO_CLASS_CONST_LONG("ATTR_DEFAULT_FETCH_MODE",(long)PDO_ATTR_DEFAULT_FETCH_MODE); - + REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_SILENT", (long)PDO_ERRMODE_SILENT); REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_WARNING", (long)PDO_ERRMODE_WARNING); REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_EXCEPTION", (long)PDO_ERRMODE_EXCEPTION); @@ -1484,7 +1484,7 @@ void pdo_dbh_init(TSRMLS_D) REGISTER_PDO_CLASS_CONST_LONG("NULL_NATURAL", (long)PDO_NULL_NATURAL); REGISTER_PDO_CLASS_CONST_LONG("NULL_EMPTY_STRING", (long)PDO_NULL_EMPTY_STRING); REGISTER_PDO_CLASS_CONST_LONG("NULL_TO_STRING", (long)PDO_NULL_TO_STRING); - + REGISTER_PDO_CLASS_CONST_STRING("ERR_NONE", PDO_ERR_NONE); REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_NEXT", (long)PDO_FETCH_ORI_NEXT); @@ -1493,7 +1493,7 @@ void pdo_dbh_init(TSRMLS_D) REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_LAST", (long)PDO_FETCH_ORI_LAST); REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_ABS", (long)PDO_FETCH_ORI_ABS); REGISTER_PDO_CLASS_CONST_LONG("FETCH_ORI_REL", (long)PDO_FETCH_ORI_REL); - + REGISTER_PDO_CLASS_CONST_LONG("CURSOR_FWDONLY", (long)PDO_CURSOR_FWDONLY); REGISTER_PDO_CLASS_CONST_LONG("CURSOR_SCROLL", (long)PDO_CURSOR_SCROLL); @@ -1537,7 +1537,7 @@ static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC) if (dbh->password) { pefree(dbh->password, dbh->is_persistent); } - + if (dbh->persistent_id) { pefree((char *)dbh->persistent_id, dbh->is_persistent); } @@ -1545,7 +1545,7 @@ static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC) if (dbh->def_stmt_ctor_args) { zval_ptr_dtor(&dbh->def_stmt_ctor_args); } - + for (i = 0; i < PDO_DBH_DRIVER_METHOD_KIND__MAX; i++) { if (dbh->cls_methods[i]) { zend_hash_destroy(dbh->cls_methods[i]); @@ -1572,7 +1572,7 @@ static void pdo_dbh_free_storage(pdo_dbh_t *dbh TSRMLS_DC) dbh->methods->rollback(dbh TSRMLS_CC); dbh->in_txn = 0; } - + if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) { dbh->methods->persistent_shutdown(dbh TSRMLS_CC); } @@ -1594,10 +1594,10 @@ zend_object_value pdo_dbh_new(zend_class_entry *ce TSRMLS_DC) rebuild_object_properties(&dbh->std); dbh->refcount = 1; dbh->def_stmt_ce = pdo_dbstmt_ce; - + retval.handle = zend_objects_store_put(dbh, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbh_free_storage, NULL TSRMLS_CC); retval.handlers = &pdo_dbh_object_handlers; - + return retval; } diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 04e71823b9ded..82b17d16a1ac4 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -145,7 +145,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC); return 0; } - + zend_hash_internal_pointer_reset(stmt->bound_param_map); while (SUCCESS == zend_hash_get_current_data(stmt->bound_param_map, (void**)&name)) { if (strcmp(name, param->name)) { @@ -163,7 +163,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC); return 0; } - return 1; + return 1; } /* }}} */ @@ -188,7 +188,7 @@ static int dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_typ ret = 0; break; } - + zend_hash_move_forward(ht); } } @@ -442,14 +442,14 @@ static PHP_METHOD(PDOStatement, execute) } PDO_STMT_CLEAR_ERR(); - + if (input_params) { struct pdo_bound_param_data param; zval **tmp; uint str_length; ulong num_index; - - if (stmt->bound_params) { + + if (stmt->bound_params) { zend_hash_destroy(stmt->bound_params); FREE_HASHTABLE(stmt->bound_params); stmt->bound_params = NULL; @@ -466,7 +466,7 @@ static PHP_METHOD(PDOStatement, execute) param.paramno = -1; } else { /* we're okay to be zero based here */ - if (num_index < 0) { + if ((long)num_index < 0) { pdo_raise_impl_error(stmt->dbh, stmt, "HY093", NULL TSRMLS_CC); RETURN_FALSE; } @@ -490,7 +490,7 @@ static PHP_METHOD(PDOStatement, execute) if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { /* handle the emulated parameter binding, - * stmt->active_query_string holds the query with binds expanded and + * stmt->active_query_string holds the query with binds expanded and * quoted. */ @@ -531,7 +531,7 @@ static PHP_METHOD(PDOStatement, execute) if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST TSRMLS_CC)) { RETURN_FALSE; } - + RETURN_BOOL(ret); } if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { @@ -569,12 +569,12 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ } else { ZVAL_NULL(dest); } - + if (Z_TYPE_P(dest) == IS_NULL) { type = new_type; } break; - + case PDO_PARAM_INT: if (value && value_len == sizeof(long)) { ZVAL_LONG(dest, *(long*)value); @@ -635,7 +635,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ } } break; - + case PDO_PARAM_STR: if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) { ZVAL_STRINGL(dest, value, value_len, !caller_frees); @@ -666,7 +666,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ ; } } - + if (caller_frees && value) { efree(value); } @@ -705,7 +705,7 @@ static int do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, if (!stmt->columns && !pdo_stmt_describe_columns(stmt TSRMLS_CC)) { return 0; } - + if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_POST TSRMLS_CC)) { return 0; } @@ -751,7 +751,7 @@ static int do_fetch_class_prepare(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; ce = ZEND_STANDARD_CLASS_DEF_PTR; } - + if (ce->constructor) { fci->function_table = &ce->function_table; fci->function_name = NULL; @@ -792,7 +792,7 @@ static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info * { char *is_callable_error = NULL; - if (zend_fcall_info_init(callable, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) { + if (zend_fcall_info_init(callable, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) { if (is_callable_error) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", is_callable_error TSRMLS_CC); efree(is_callable_error); @@ -805,10 +805,10 @@ static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info * /* Possible E_STRICT error message */ efree(is_callable_error); } - + fci->param_count = num_args; /* probably less */ fci->params = safe_emalloc(sizeof(zval**), num_args, 0); - + return 1; } /* }}} */ @@ -921,7 +921,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, } else if (flags == PDO_FETCH_GROUP && colno) { fetch_value(stmt, return_value, 0, NULL TSRMLS_CC); } else { - fetch_value(stmt, return_value, colno, NULL TSRMLS_CC); + fetch_value(stmt, return_value, colno, NULL TSRMLS_CC); } if (!return_all) { return 1; @@ -988,7 +988,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, } } break; - + case PDO_FETCH_INTO: if (!stmt->fetch.into) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified." TSRMLS_CC); @@ -1018,13 +1018,13 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, } } break; - + default: /* shouldn't happen */ return 0; } - + if (return_all && how != PDO_FETCH_KEY_PAIR) { INIT_PZVAL(&grp_val); if (flags == PDO_FETCH_GROUP && how == PDO_FETCH_COLUMN && stmt->fetch.column > 0) { @@ -1049,7 +1049,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, case PDO_FETCH_ASSOC: add_assoc_zval(return_value, stmt->columns[i].name, val); break; - + case PDO_FETCH_KEY_PAIR: { zval *tmp; @@ -1158,12 +1158,12 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, #endif } break; - + case PDO_FETCH_FUNC: stmt->fetch.func.values[idx] = val; stmt->fetch.cls.fci.params[idx] = &stmt->fetch.func.values[idx]; break; - + default: zval_ptr_dtor(&val); pdo_raise_impl_error(stmt->dbh, stmt, "22003", "mode is out of range" TSRMLS_CC); @@ -1171,7 +1171,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, break; } } - + switch (how) { case PDO_FETCH_CLASS: if (ce->constructor && !(flags & (PDO_FETCH_PROPS_LATE | PDO_FETCH_SERIALIZE))) { @@ -1213,7 +1213,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, zval_ptr_dtor(&stmt->fetch.func.values[idx]); } break; - + default: break; } @@ -1250,7 +1250,7 @@ static int pdo_stmt_verify_mode(pdo_stmt_t *stmt, long mode, int fetch_all TSRML pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode" TSRMLS_CC); return 0; } - + if (mode == PDO_FETCH_USE_DEFAULT) { flags = stmt->default_fetch_type & PDO_FETCH_FLAGS; mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS; @@ -1277,7 +1277,7 @@ static int pdo_stmt_verify_mode(pdo_stmt_t *stmt, long mode, int fetch_all TSRML return 0; } /* fall through */ - + default: if ((flags & PDO_FETCH_SERIALIZE) == PDO_FETCH_SERIALIZE) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together with PDO::FETCH_CLASS" TSRMLS_CC); @@ -1354,7 +1354,7 @@ static PHP_METHOD(PDOStatement, fetchObject) old_ce = stmt->fetch.cls.ce; old_ctor_args = stmt->fetch.cls.ctor_args; old_arg_count = stmt->fetch.cls.fci.param_count; - + do_fetch_opt_finish(stmt, 0 TSRMLS_CC); if (ctor_args) { @@ -1422,11 +1422,11 @@ static PHP_METHOD(PDOStatement, fetchAll) { 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; - PHP_STMT_GET_OBJ; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lzz", &how, &arg2, &ctor_args)) { RETURN_FALSE; @@ -1444,22 +1444,18 @@ 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" TSRMLS_CC); - 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" TSRMLS_CC); + 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: + stmt->fetch.cls.ctor_args = ctor_args; /* we're not going to free these */ if (Z_TYPE_P(arg2) != IS_STRING) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)" TSRMLS_CC); @@ -1473,42 +1469,38 @@ static PHP_METHOD(PDOStatement, fetchAll) break; } } + } else { + stmt->fetch.cls.ce = zend_standard_class_def; } + if (!error) { do_fetch_class_prepare(stmt TSRMLS_CC); } 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" TSRMLS_CC); - error = 1; - break; - case 3: - case 2: + if(arg2) { stmt->fetch.func.function = arg2; if (do_fetch_func_prepare(stmt TSRMLS_CC) == 0) { error = 1; } - break; + } else { + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified" TSRMLS_CC); + 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" TSRMLS_CC); + 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" TSRMLS_CC); - error = 1; + } else { + stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; } break; @@ -1520,7 +1512,7 @@ static PHP_METHOD(PDOStatement, fetchAll) } flags = how & PDO_FETCH_FLAGS; - + if ((how & ~PDO_FETCH_FLAGS) == PDO_FETCH_USE_DEFAULT) { flags |= stmt->default_fetch_type & PDO_FETCH_FLAGS; how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS; @@ -1529,7 +1521,7 @@ static PHP_METHOD(PDOStatement, fetchAll) if (!error) { PDO_STMT_CLEAR_ERR(); MAKE_STD_ZVAL(data); - if ( (how & PDO_FETCH_GROUP) || how == PDO_FETCH_KEY_PAIR || + if ( (how & PDO_FETCH_GROUP) || how == PDO_FETCH_KEY_PAIR || (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type == PDO_FETCH_KEY_PAIR) ) { array_init(return_value); @@ -1558,13 +1550,13 @@ static PHP_METHOD(PDOStatement, fetchAll) } FREE_ZVAL(data); } - + do_fetch_opt_finish(stmt, 0 TSRMLS_CC); stmt->fetch.cls.ce = old_ce; stmt->fetch.cls.ctor_args = old_ctor_args; stmt->fetch.cls.fci.param_count = old_arg_count; - + if (error) { PDO_HANDLE_STMT_ERR(); if (error != 2) { @@ -1590,14 +1582,14 @@ static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, "lz|llz!", ¶m.paramno, ¶m.parameter, ¶m_type, ¶m.max_value_len, ¶m.driver_params)) { if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|llz!", ¶m.name, - ¶m.namelen, ¶m.parameter, ¶m_type, ¶m.max_value_len, + ¶m.namelen, ¶m.parameter, ¶m_type, ¶m.max_value_len, ¶m.driver_params)) { return 0; - } + } } - + param.param_type = (int) param_type; - + if (param.paramno > 0) { --param.paramno; /* make it zero-based internally */ } else if (!param.name) { @@ -1625,7 +1617,7 @@ static PHP_METHOD(PDOStatement, bindValue) PHP_STMT_GET_OBJ; param.paramno = -1; - + if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "lz/|l", ¶m.paramno, ¶m.parameter, ¶m_type)) { if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|l", ¶m.name, @@ -1635,14 +1627,14 @@ static PHP_METHOD(PDOStatement, bindValue) } param.param_type = (int) param_type; - + if (param.paramno > 0) { --param.paramno; /* make it zero-based internally */ } else if (!param.name) { pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based" TSRMLS_CC); RETURN_FALSE; } - + Z_ADDREF_P(param.parameter); if (!really_register_bound_param(¶m, stmt, TRUE TSRMLS_CC)) { if (param.parameter) { @@ -1779,7 +1771,7 @@ static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, long attr } return 0; } - + static PHP_METHOD(PDOStatement, getAttribute) { long attr; @@ -1877,10 +1869,10 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in { long mode = PDO_FETCH_BOTH; int flags = 0, argc = ZEND_NUM_ARGS() - skip; - zval ***args; + zval ***args = NULL; zend_class_entry **cep; int retval; - + do_fetch_opt_finish(stmt, 1 TSRMLS_CC); switch (stmt->default_fetch_type) { @@ -1893,32 +1885,31 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in default: ; } - + stmt->default_fetch_type = PDO_FETCH_BOTH; if (argc == 0) { return SUCCESS; } - args = safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval*), 0); + argc = 0; + if(skip) { + zval *dummy; + retval = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl*", &dummy, &mode, &args, &argc); + } else { + retval = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l*", &mode, &args, &argc); + } - retval = zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args); - if (SUCCESS == retval) { - if (Z_TYPE_PP(args[skip]) != IS_LONG) { - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "mode must be an integer" TSRMLS_CC); - retval = FAILURE; - } else { - mode = Z_LVAL_PP(args[skip]); - flags = mode & PDO_FETCH_FLAGS; - - retval = pdo_stmt_verify_mode(stmt, mode, 0 TSRMLS_CC); - } + flags = mode & PDO_FETCH_FLAGS; + retval = pdo_stmt_verify_mode(stmt, mode, 0 TSRMLS_CC); } - + if (FAILURE == retval) { PDO_STMT_CLEAR_ERR(); - efree(args); + if(args) { + efree(args); + } return FAILURE; } @@ -1933,7 +1924,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" TSRMLS_CC); } else { retval = SUCCESS; @@ -1941,12 +1932,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" TSRMLS_CC); - } else if (Z_TYPE_PP(args[skip+1]) != IS_LONG) { + } else if (Z_TYPE_PP(args[0]) != IS_LONG) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "colno must be an integer" TSRMLS_CC); } else { - stmt->fetch.column = Z_LVAL_PP(args[skip+1]); + stmt->fetch.column = Z_LVAL_PP(args[0]); retval = SUCCESS; } break; @@ -1954,22 +1945,22 @@ 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" TSRMLS_CC); } 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" TSRMLS_CC); - } else if (argc > 3) { + } else if (argc > 2) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "too many arguments" TSRMLS_CC); - } else if (Z_TYPE_PP(args[skip+1]) != IS_STRING) { + } else if (Z_TYPE_PP(args[0]) != IS_STRING) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "classname must be a string" TSRMLS_CC); } else { - retval = zend_lookup_class(Z_STRVAL_PP(args[skip+1]), - Z_STRLEN_PP(args[skip+1]), &cep TSRMLS_CC); + retval = zend_lookup_class(Z_STRVAL_PP(args[0]), + Z_STRLEN_PP(args[0]), &cep TSRMLS_CC); if (SUCCESS == retval && cep && *cep) { stmt->fetch.cls.ce = *cep; @@ -1984,13 +1975,13 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in php_error_docref(NULL TSRMLS_CC, 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_PP(args[skip+2]) != IS_NULL && Z_TYPE_PP(args[skip+2]) != IS_ARRAY) { + if (argc == 2) { + if (Z_TYPE_PP(args[1]) != IS_NULL && Z_TYPE_PP(args[1]) != IS_ARRAY) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array" TSRMLS_CC); retval = FAILURE; - } else if (Z_TYPE_PP(args[skip+2]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_PP(args[skip+2]))) { + } else if (Z_TYPE_PP(args[1]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_PP(args[1]))) { ALLOC_ZVAL(stmt->fetch.cls.ctor_args); - *stmt->fetch.cls.ctor_args = **args[skip+2]; + *stmt->fetch.cls.ctor_args = **args[1]; zval_copy_ctor(stmt->fetch.cls.ctor_args); } } @@ -1999,34 +1990,34 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in do_fetch_class_prepare(stmt TSRMLS_CC); } } - + 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" TSRMLS_CC); - } else if (Z_TYPE_PP(args[skip+1]) != IS_OBJECT) { + } else if (Z_TYPE_PP(args[0]) != IS_OBJECT) { pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "object must be an object" TSRMLS_CC); } else { retval = SUCCESS; } - + if (SUCCESS == retval) { #ifdef ilia_0 /* we'll only need this when we have persistent statements, if ever */ if (stmt->dbh->is_persistent) { php_error_docref(NULL TSRMLS_CC, 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 +#endif MAKE_STD_ZVAL(stmt->fetch.into); Z_TYPE_P(stmt->fetch.into) = IS_OBJECT; - Z_OBJ_HANDLE_P(stmt->fetch.into) = Z_OBJ_HANDLE_PP(args[skip+1]); - Z_OBJ_HT_P(stmt->fetch.into) = Z_OBJ_HT_PP(args[skip+1]); + Z_OBJ_HANDLE_P(stmt->fetch.into) = Z_OBJ_HANDLE_PP(args[0]); + Z_OBJ_HT_P(stmt->fetch.into) = Z_OBJ_HT_PP(args[0]); zend_objects_store_add_ref(stmt->fetch.into TSRMLS_CC); } - + break; - + default: pdo_raise_impl_error(stmt->dbh, stmt, "22003", "Invalid fetch mode specified" TSRMLS_CC); } @@ -2043,12 +2034,13 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, in * */ PDO_STMT_CLEAR_ERR(); + if(args) { + efree(args); + } - efree(args); - return retval; } - + static PHP_METHOD(PDOStatement, setFetchMode) { PHP_STMT_GET_OBJ; @@ -2069,7 +2061,7 @@ static int pdo_stmt_do_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) if (stmt->columns) { int i; struct pdo_column_data *cols = stmt->columns; - + for (i = 0; i < stmt->column_count; i++) { efree(cols[i].name); } @@ -2099,7 +2091,7 @@ static PHP_METHOD(PDOStatement, nextRowset) } PDO_STMT_CLEAR_ERR(); - + if (!pdo_stmt_do_next_rowset(stmt TSRMLS_CC)) { PDO_HANDLE_STMT_ERR(); RETURN_FALSE; @@ -2127,7 +2119,7 @@ static PHP_METHOD(PDOStatement, closeCursor) if (!pdo_stmt_do_next_rowset(stmt TSRMLS_CC)) { break; } - + } while (1); stmt->executed = 0; RETURN_TRUE; @@ -2156,14 +2148,14 @@ static PHP_METHOD(PDOStatement, debugDumpParams) if (out == NULL) { RETURN_FALSE; } - + php_stream_printf(out TSRMLS_CC, "SQL: [%d] %.*s\n", stmt->query_stringlen, stmt->query_stringlen, stmt->query_string); php_stream_printf(out TSRMLS_CC, "Params: %d\n", stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0); - + if (stmt->bound_params) { zend_hash_internal_pointer_reset_ex(stmt->bound_params, &pos); while (SUCCESS == zend_hash_get_current_data_ex(stmt->bound_params, @@ -2184,7 +2176,7 @@ static PHP_METHOD(PDOStatement, debugDumpParams) param->paramno, param->namelen, param->namelen, param->name ? param->name : "", param->is_param, param->param_type); - + zend_hash_move_forward_ex(stmt->bound_params, &pos); } } @@ -2278,7 +2270,7 @@ static union _zend_function *dbstmt_method_get( lc_method_name = emalloc(method_len + 1); zend_str_tolower_copy(lc_method_name, method_name, method_len); - if (zend_hash_find(&Z_OBJCE_P(object)->function_table, lc_method_name, + if (zend_hash_find(&Z_OBJCE_P(object)->function_table, lc_method_name, method_len+1, (void**)&fbc) == FAILURE) { pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(object TSRMLS_CC); /* instance not created by PDO object */ @@ -2288,7 +2280,7 @@ static union _zend_function *dbstmt_method_get( /* not a pre-defined method, nor a user-defined method; check * the driver specific methods */ if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { - if (!pdo_hash_methods(stmt->dbh, + if (!pdo_hash_methods(stmt->dbh, PDO_DBH_DRIVER_METHOD_KIND_STMT TSRMLS_CC) || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { goto out; @@ -2302,7 +2294,7 @@ static union _zend_function *dbstmt_method_get( } /* got it */ } - + out: efree(lc_method_name); return fbc; @@ -2326,15 +2318,15 @@ static zend_object_value dbstmt_clone_obj(zval *zobject TSRMLS_DC) stmt->refcount = 1; old_stmt = (pdo_stmt_t *)zend_object_store_get_object(zobject TSRMLS_CC); - + retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC); retval.handlers = Z_OBJ_HT_P(zobject); zend_objects_clone_members((zend_object *)stmt, retval, (zend_object *)old_stmt, handle TSRMLS_CC); - + zend_objects_store_add_ref(&old_stmt->database_object_handle TSRMLS_CC); stmt->database_object_handle = old_stmt->database_object_handle; - + return retval; } @@ -2349,7 +2341,7 @@ void pdo_stmt_init(TSRMLS_D) pdo_dbstmt_ce = zend_register_internal_class(&ce TSRMLS_CC); pdo_dbstmt_ce->get_iterator = pdo_stmt_iter_get; pdo_dbstmt_ce->create_object = pdo_dbstmt_new; - zend_class_implements(pdo_dbstmt_ce TSRMLS_CC, 1, zend_ce_traversable); + zend_class_implements(pdo_dbstmt_ce TSRMLS_CC, 1, zend_ce_traversable); zend_declare_property_null(pdo_dbstmt_ce, "queryString", sizeof("queryString")-1, ZEND_ACC_PUBLIC TSRMLS_CC); memcpy(&pdo_dbstmt_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); @@ -2409,7 +2401,7 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC) FREE_ZVAL(stmt->fetch.into); stmt->fetch.into = NULL; } - + do_fetch_opt_finish(stmt, 1 TSRMLS_CC); zend_objects_store_del_ref(&stmt->database_object_handle TSRMLS_CC); @@ -2471,7 +2463,7 @@ static void pdo_stmt_iter_dtor(zend_object_iterator *iter TSRMLS_DC) if (--I->stmt->refcount == 0) { free_statement(I->stmt TSRMLS_CC); } - + if (I->fetch_ahead) { zval_ptr_dtor(&I->fetch_ahead); } @@ -2615,7 +2607,7 @@ static zval *row_prop_read(zval *object, zval *member, int type, const zend_lite Z_SET_REFCOUNT_P(return_value, 0); Z_UNSET_ISREF_P(return_value); - + return return_value; } @@ -2681,7 +2673,7 @@ static HashTable *row_get_properties(zval *object TSRMLS_DC) if (stmt == NULL) { return NULL; } - + if (!stmt->std.properties) { rebuild_object_properties(&stmt->std); } @@ -2714,7 +2706,7 @@ static union _zend_function *row_method_get( efree(lc_method_name); return NULL; } - + efree(lc_method_name); return fbc; } @@ -2788,7 +2780,7 @@ void pdo_row_free_storage(pdo_stmt_t *stmt TSRMLS_DC) { if (stmt) { ZVAL_NULL(&stmt->lazy_object_ref); - + if (--stmt->refcount == 0) { free_statement(stmt TSRMLS_CC); } diff --git a/ext/pdo/tests/bug_44173.phpt b/ext/pdo/tests/bug_44173.phpt index f13abaa5d500a..3d310e0cd5016 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 long, 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 35eb09e58466e..bee22dd17505e 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -15,11 +15,11 @@ | Authors: Zeev Suraski | | Jouni Ahto | | Yasuo Ohgaki | - | Youichi Iwakiri (pg_copy_*) | - | Chris Kings-Lynne (v3 protocol) | + | Youichi Iwakiri (pg_copy_*) | + | Chris Kings-Lynne (v3 protocol) | +----------------------------------------------------------------------+ */ - + /* $Id$ */ #include @@ -89,6 +89,17 @@ #define PQfreemem free #endif +#define PGSQL_GET_LINK(pgsql_link) \ + if ((pgsql_link) == NULL) { \ + id = PGG(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); @@ -780,7 +791,7 @@ static inline char * _php_pgsql_trim_result(PGconn * pgsql, char **buf) /* {{{ php_pgsql_set_default_link */ static void php_pgsql_set_default_link(int id TSRMLS_DC) -{ +{ zend_list_addref(id); if (PGG(default_link) != -1) { @@ -827,7 +838,7 @@ static void _close_pgsql_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC) static void _php_pgsql_notice_handler(void *resource_id, const char *message) { php_pgsql_notice *notice; - + TSRMLS_FETCH(); if (! PGG(ignore_notices)) { notice = (php_pgsql_notice *)emalloc(sizeof(php_pgsql_notice)); @@ -844,7 +855,7 @@ static void _php_pgsql_notice_handler(void *resource_id, const char *message) /* {{{ _php_pgsql_notice_dtor */ -static void _php_pgsql_notice_ptr_dtor(void **ptr) +static void _php_pgsql_notice_ptr_dtor(void **ptr) { php_pgsql_notice *notice = (php_pgsql_notice *)*ptr; if (notice) { @@ -863,7 +874,7 @@ static int _rollback_transactions(zend_rsrc_list_entry *rsrc TSRMLS_DC) PGresult *res; int orig; - if (Z_TYPE_P(rsrc) != le_plink) + if (Z_TYPE_P(rsrc) != le_plink) return 0; link = (PGconn *) rsrc->ptr; @@ -872,7 +883,7 @@ static int _rollback_transactions(zend_rsrc_list_entry *rsrc TSRMLS_DC) php_error_docref("ref.pgsql" TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode"); return -1; } - + while ((res = PQgetResult(link))) { PQclear(res); } @@ -1011,7 +1022,7 @@ static PHP_GINIT_FUNCTION(pgsql) { memset(pgsql_globals, 0, sizeof(zend_pgsql_globals)); /* Initilize notice message hash at MINIT only */ - zend_hash_init_ex(&pgsql_globals->notices, 0, NULL, PHP_PGSQL_NOTICE_PTR_DTOR, 1, 0); + zend_hash_init_ex(&pgsql_globals->notices, 0, NULL, PHP_PGSQL_NOTICE_PTR_DTOR, 1, 0); } /* }}} */ @@ -1020,7 +1031,7 @@ static PHP_GINIT_FUNCTION(pgsql) PHP_MINIT_FUNCTION(pgsql) { REGISTER_INI_ENTRIES(); - + le_link = zend_register_list_destructors_ex(_close_pgsql_link, NULL, "pgsql link", module_number); le_plink = zend_register_list_destructors_ex(NULL, _close_pgsql_plink, "pgsql link persistent", module_number); le_result = zend_register_list_destructors_ex(_free_result, NULL, "pgsql result", module_number); @@ -1156,7 +1167,7 @@ PHP_MINFO_FUNCTION(pgsql) #else php_info_print_table_row(2, "SSL support", "disabled"); #endif -#endif /* HAVE_PG_CONFIG_H */ +#endif /* HAVE_PG_CONFIG_H */ snprintf(buf, sizeof(buf), "%ld", PGG(num_persistent)); php_info_print_table_row(2, "Active Persistent Links", buf); snprintf(buf, sizeof(buf), "%ld", PGG(num_links)); @@ -1180,16 +1191,16 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) PGresult *pg_result; if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 5 - || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { + || zend_get_parameters_array_nodefault(ZEND_NUM_ARGS(), args) == FAILURE) { WRONG_PARAM_COUNT; } smart_str_appends(&str, "pgsql"); - + for (i = 0; i < ZEND_NUM_ARGS(); i++) { /* make sure that the PGSQL_CONNECT_FORCE_NEW bit is not part of the hash so that subsequent connections * can re-use this connection. Bug #39979 - */ + */ if (i == 1 && ZEND_NUM_ARGS() == 2 && Z_TYPE_PP(args[i]) == IS_LONG) { if (Z_LVAL_PP(args[1]) == PGSQL_CONNECT_FORCE_NEW) { continue; @@ -1224,14 +1235,14 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) break; } } - + if (persistent && PGG(allow_persistent)) { zend_rsrc_list_entry *le; - + /* try to find if we already have this link in our persistent list */ if (zend_hash_find(&EG(persistent_list), str.c, str.len+1, (void **) &le)==FAILURE) { /* we don't */ zend_rsrc_list_entry new_le; - + if (PGG(max_links)!=-1 && PGG(num_links)>=PGG(max_links)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create new link. Too many open links (%ld)", PGG(num_links)); @@ -1307,7 +1318,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink); } else { /* Non persistent connection */ zend_rsrc_list_entry *index_ptr,new_index_ptr; - + /* first we check the hash for the hashed_details key. if it exists, * it should point us to the right offset where the actual pgsql link sits. * if it doesn't, open a new pgsql link, add it to the resource list, @@ -1367,11 +1378,11 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) PQsetNoticeProcessor(pgsql, _php_pgsql_notice_handler, (void*)Z_RESVAL_P(return_value)); } php_pgsql_set_default_link(Z_LVAL_P(return_value) TSRMLS_CC); - + cleanup: smart_str_free(&str); return; - + err: smart_str_free(&str); RETURN_FALSE; @@ -1409,33 +1420,24 @@ PHP_FUNCTION(pg_pconnect) /* }}} */ /* {{{ proto bool pg_close([resource connection]) - Close a PostgreSQL connection */ + Close a PostgreSQL connection */ 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 TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { return; } - - if (argc == 0) { - id = PGG(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_delete(Z_RESVAL_P(pgsql_link)); } - if (id!=-1 + if (id!=-1 || (pgsql_link && Z_RESVAL_P(pgsql_link)==PGG(default_link))) { zend_list_delete(PGG(default_link)); PGG(default_link) = -1; @@ -1459,24 +1461,15 @@ 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; - if (zend_parse_parameters(argc TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { return; } - - if (argc == 0) { - id = PGG(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: @@ -1524,7 +1517,7 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type /* }}} */ /* {{{ proto string pg_dbname([resource connection]) - Get the database name */ + Get the database name */ PHP_FUNCTION(pg_dbname) { php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_DBNAME); @@ -1600,7 +1593,7 @@ PHP_FUNCTION(pg_parameter_status) } if (pgsql_link == NULL && id == -1) { RETURN_FALSE; - } + } ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); @@ -1631,7 +1624,7 @@ PHP_FUNCTION(pg_ping) } if (pgsql_link == NULL && id == -1) { RETURN_FALSE; - } + } ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); @@ -1669,19 +1662,13 @@ PHP_FUNCTION(pg_query) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &query, &query_len) == FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC, E_NOTICE,"Cannot set connection to blocking mode"); @@ -1706,7 +1693,7 @@ PHP_FUNCTION(pg_query) } else { status = (ExecStatusType) PQstatus(pgsql); } - + switch (status) { case PGRES_EMPTY_QUERY: case PGRES_BAD_RESPONSE: @@ -1766,24 +1753,18 @@ PHP_FUNCTION(pg_query_params) PGresult *pgsql_result; ExecStatusType status; pgsql_result_handle *pg_result; - + if (argc == 2) { if (zend_parse_parameters(argc TSRMLS_CC, "sa", &query, &query_len, &pv_param_arr) == FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC, E_NOTICE,"Cannot set connection to blocking mode"); @@ -1802,7 +1783,7 @@ PHP_FUNCTION(pg_query_params) if (num_params > 0) { int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - + for(i = 0; i < num_params; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); @@ -1830,12 +1811,12 @@ PHP_FUNCTION(pg_query_params) } } - pgsql_result = PQexecParams(pgsql, query, num_params, + pgsql_result = PQexecParams(pgsql, query, num_params, NULL, (const char * const *)params, NULL, NULL, 0); if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) { PQclear(pgsql_result); PQreset(pgsql); - pgsql_result = PQexecParams(pgsql, query, num_params, + pgsql_result = PQexecParams(pgsql, query, num_params, NULL, (const char * const *)params, NULL, NULL, 0); } @@ -1844,7 +1825,7 @@ PHP_FUNCTION(pg_query_params) } else { status = (ExecStatusType) PQstatus(pgsql); } - + _php_pgsql_free_params(params, num_params); switch (status) { @@ -1892,19 +1873,13 @@ PHP_FUNCTION(pg_prepare) if (zend_parse_parameters(argc TSRMLS_CC, "ss", &stmtname, &stmtname_len, &query, &query_len) == FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC, E_NOTICE,"Cannot set connection to blocking mode"); @@ -1929,7 +1904,7 @@ PHP_FUNCTION(pg_prepare) } else { status = (ExecStatusType) PQstatus(pgsql); } - + switch (status) { case PGRES_EMPTY_QUERY: case PGRES_BAD_RESPONSE: @@ -1978,19 +1953,13 @@ PHP_FUNCTION(pg_execute) if (zend_parse_parameters(argc TSRMLS_CC, "sa/", &stmtname, &stmtname_len, &pv_param_arr)==FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc TSRMLS_CC, "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 TSRMLS_CC, E_NOTICE,"Cannot set connection to blocking mode"); @@ -2009,7 +1978,7 @@ PHP_FUNCTION(pg_execute) if (num_params > 0) { int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - + for(i = 0; i < num_params; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); @@ -2037,12 +2006,12 @@ PHP_FUNCTION(pg_execute) } } - pgsql_result = PQexecPrepared(pgsql, stmtname, num_params, + pgsql_result = PQexecPrepared(pgsql, stmtname, num_params, (const char * const *)params, NULL, NULL, 0); if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) { PQclear(pgsql_result); PQreset(pgsql); - pgsql_result = PQexecPrepared(pgsql, stmtname, num_params, + pgsql_result = PQexecPrepared(pgsql, stmtname, num_params, (const char * const *)params, NULL, NULL, 0); } @@ -2051,7 +2020,7 @@ PHP_FUNCTION(pg_execute) } else { status = (ExecStatusType) PQstatus(pgsql); } - + _php_pgsql_free_params(params, num_params); switch (status) { @@ -2096,7 +2065,7 @@ static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_ty if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; @@ -2151,13 +2120,13 @@ PHP_FUNCTION(pg_affected_rows) /* {{{ proto string pg_last_notice(resource connection) Returns the last notice set by the backend */ -PHP_FUNCTION(pg_last_notice) +PHP_FUNCTION(pg_last_notice) { zval *pgsql_link; PGconn *pg_link; int id = -1; php_pgsql_notice **notice; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pgsql_link) == FAILURE) { return; } @@ -2203,17 +2172,17 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC) num_rows = PQntuples(result); oid_offset = PQfnumber(result,"oid"); name_offset = PQfnumber(result,"typname"); - + for (i=0; iresult; - + if (field < 0 || field >= PQnfields(pgsql_result)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset specified"); RETURN_FALSE; } - + switch (entry_type) { case PHP_PG_FIELD_NAME: Z_STRVAL_P(return_value) = PQfname(pgsql_result, field); @@ -2369,7 +2338,7 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ Z_TYPE_P(return_value) = IS_STRING; break; case PHP_PG_FIELD_TYPE_OID: - + oid = PQftype(pgsql_result, field); #if UINT_MAX > LONG_MAX if (oid > LONG_MAX) { @@ -2401,7 +2370,7 @@ PHP_FUNCTION(pg_field_name) /* }}} */ /* {{{ proto int pg_field_size(resource result, int field_number) - Returns the internal size of the field */ + Returns the internal size of the field */ PHP_FUNCTION(pg_field_size) { php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_FIELD_SIZE); @@ -2438,11 +2407,11 @@ PHP_FUNCTION(pg_field_num) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &result, &field, &field_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; - + Z_LVAL_P(return_value) = PQfnumber(pgsql_result, field); Z_TYPE_P(return_value) = IS_LONG; } @@ -2457,7 +2426,7 @@ PHP_FUNCTION(pg_fetch_result) PGresult *pgsql_result; pgsql_result_handle *pg_result; int field_offset, pgsql_row, argc = ZEND_NUM_ARGS(); - + if (argc == 2) { if (zend_parse_parameters(argc TSRMLS_CC, "rZ", &result, &field) == FAILURE) { return; @@ -2467,7 +2436,7 @@ PHP_FUNCTION(pg_fetch_result) return; } } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; @@ -2500,7 +2469,7 @@ PHP_FUNCTION(pg_fetch_result) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified"); RETURN_FALSE; } - + if (PQgetisnull(pgsql_result, pgsql_row, field_offset)) { Z_TYPE_P(return_value) = IS_NULL; } else { @@ -2555,18 +2524,18 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, 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 TSRMLS_CC, E_WARNING, "Invalid result type"); RETURN_FALSE; } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; - if (use_row) { + if (use_row) { pgsql_row = row; pg_result->row = pgsql_row; if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) { @@ -2603,12 +2572,12 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, data = safe_estrndup(element, element_len); data_len = element_len; - + if (result_type & PGSQL_NUM) { add_index_stringl(return_value, i, data, data_len, should_copy); should_copy=1; } - + if (result_type & PGSQL_ASSOC) { field_name = PQfname(pgsql_result, i); add_assoc_stringl(return_value, field_name, data, data_len, should_copy); @@ -2621,11 +2590,11 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, zval dataset = *return_value; zend_fcall_info fci; zend_fcall_info_cache fcc; - zval *retval_ptr; - + zval *retval_ptr; + object_and_properties_init(return_value, ce, NULL); zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC); - + if (ce->constructor) { fci.size = sizeof(fci); fci.function_table = &ce->function_table; @@ -2637,7 +2606,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, if (Z_TYPE_P(ctor_params) == IS_ARRAY) { HashTable *ht = Z_ARRVAL_P(ctor_params); Bucket *p; - + fci.param_count = 0; fci.params = safe_emalloc(sizeof(zval*), ht->nNumOfElements, 0); p = ht->pListHead; @@ -2648,7 +2617,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, } else { /* Two problems why we throw exceptions here: PHP is typeless * and hence passing one argument that's not an array could be - * by mistake and the other way round is possible, too. The + * by mistake and the other way round is possible, too. The * single value is an array. Also we'd have to make that one * argument passed by reference. */ @@ -2666,7 +2635,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object_ptr = return_value; - + if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name); } else { @@ -2685,7 +2654,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, /* }}} */ /* {{{ proto array pg_fetch_row(resource result [, int row [, int result_type]]) - Get a row as an enumerated array */ + Get a row as an enumerated array */ PHP_FUNCTION(pg_fetch_row) { php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, PGSQL_NUM, 0); @@ -2780,8 +2749,8 @@ PHP_FUNCTION(pg_fetch_all_columns) if (PQgetisnull(pgsql_result, pg_row, colno)) { add_next_index_null(return_value); } else { - add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); - } + add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); + } } } /* }}} */ @@ -2803,7 +2772,7 @@ PHP_FUNCTION(pg_result_seek) if (row < 0 || row >= PQntuples(pg_result->result)) { RETURN_FALSE; } - + /* seek to offset */ pg_result->row = row; RETURN_TRUE; @@ -2833,7 +2802,7 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) return; } } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; @@ -2853,7 +2822,7 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) RETURN_FALSE; } } - + switch(Z_TYPE_PP(field)) { case IS_STRING: convert_to_string_ex(field); @@ -2868,7 +2837,7 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified"); RETURN_FALSE; } - + switch (entry_type) { case PHP_PG_DATA_LENGTH: Z_LVAL_P(return_value) = PQgetlength(pgsql_result, pgsql_row, field_offset); @@ -2903,7 +2872,7 @@ PHP_FUNCTION(pg_free_result) { zval *result; pgsql_result_handle *pg_result; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { return; } @@ -2931,7 +2900,7 @@ PHP_FUNCTION(pg_last_oid) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; #ifdef HAVE_PQOIDVALUE @@ -2957,25 +2926,17 @@ PHP_FUNCTION(pg_trace) char *z_filename, *mode = "w"; int 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 = PGG(default_link); - - if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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); @@ -2998,23 +2959,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 TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { - return; - } - if (argc == 0) { - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { + return; } - 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; } @@ -3027,34 +2980,26 @@ 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(); + int id = -1; - if (zend_parse_parameters(argc TSRMLS_CC, "|zz", &pgsql_link, &oid) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|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 = PGG(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 +#ifndef HAVE_PG_LO_CREATE php_error_docref(NULL TSRMLS_CC, E_NOTICE, "OID value passing not supported"); #else switch (Z_TYPE_P(oid)) { case IS_STRING: - { + { char *end_ptr; wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10); if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) { @@ -3080,7 +3025,7 @@ PHP_FUNCTION(pg_lo_create) RETURN_FALSE; } - PGSQL_RETURN_OID(pgsql_oid); + PGSQL_RETURN_OID(pgsql_oid); #endif } @@ -3089,7 +3034,7 @@ PHP_FUNCTION(pg_lo_create) RETURN_FALSE; } - PGSQL_RETURN_OID(pgsql_oid); + PGSQL_RETURN_OID(pgsql_oid); } /* }}} */ @@ -3132,8 +3077,6 @@ PHP_FUNCTION(pg_lo_unlink) php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); RETURN_FALSE; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "l", &oid_long) == SUCCESS) { @@ -3142,18 +3085,13 @@ PHP_FUNCTION(pg_lo_unlink) RETURN_FALSE; } oid = (Oid)oid_long; - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "Unable to delete PostgreSQL large object %u", oid); @@ -3204,8 +3142,6 @@ PHP_FUNCTION(pg_lo_open) php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); RETURN_FALSE; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "ls", &oid_long, &mode_string, &mode_strlen) == SUCCESS) { @@ -3214,19 +3150,14 @@ PHP_FUNCTION(pg_lo_open) RETURN_FALSE; } oid = (Oid)oid_long; - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { php_error_docref(NULL TSRMLS_CC, 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()... (Jouni) @@ -3296,7 +3227,7 @@ PHP_FUNCTION(pg_lo_close) } ZEND_FETCH_RESOURCE(pgsql, pgLofp *, &pgsql_lofp, -1, "PostgreSQL large object", le_lofp); - + if (lo_close((PGconn *)pgsql->conn, pgsql->lofd) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to close PostgreSQL large object descriptor %d", pgsql->lofd); RETVAL_FALSE; @@ -3316,21 +3247,19 @@ PHP_FUNCTION(pg_lo_close) PHP_FUNCTION(pg_lo_read) { zval *pgsql_id; - long len; - int buf_len = PGSQL_LO_READ_BUF_SIZE, nbytes, argc = ZEND_NUM_ARGS(); + long len = PGSQL_LO_READ_BUF_SIZE; + int buf_len = PGSQL_LO_READ_BUF_SIZE, nbytes; char *buf; pgLofp *pgsql; - if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &pgsql_id, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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; - } - + buf_len = len; + buf = (char *) safe_emalloc(sizeof(char), (buf_len+1), 0); if ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, buf_len))<0) { efree(buf); @@ -3354,7 +3283,7 @@ PHP_FUNCTION(pg_lo_write) pgLofp *pgsql; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "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; } @@ -3392,7 +3321,7 @@ PHP_FUNCTION(pg_lo_read_all) volatile int nbytes; char buf[PGSQL_LO_READ_BUF_SIZE]; pgLofp *pgsql; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pgsql_id) == FAILURE) { return; } @@ -3425,8 +3354,6 @@ PHP_FUNCTION(pg_lo_import) } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "p|z", &file_in, &name_len, &oid) == SUCCESS) { - id = PGG(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 TSRMLS_CC, @@ -3436,16 +3363,12 @@ PHP_FUNCTION(pg_lo_import) else { WRONG_PARAM_COUNT; } - + if (php_check_open_basedir(file_in TSRMLS_CC)) { 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 @@ -3454,7 +3377,7 @@ PHP_FUNCTION(pg_lo_import) Oid wanted_oid; switch (Z_TYPE_P(oid)) { case IS_STRING: - { + { char *end_ptr; wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10); if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) { @@ -3533,8 +3456,6 @@ PHP_FUNCTION(pg_lo_export) RETURN_FALSE; } oid = (Oid)oid_long; - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "sp", &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) { @@ -3544,8 +3465,6 @@ PHP_FUNCTION(pg_lo_export) php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); RETURN_FALSE; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "spr", &oid_string, &oid_strlen, &file_out, &name_len, &pgsql_link) == SUCCESS) { @@ -3569,20 +3488,16 @@ PHP_FUNCTION(pg_lo_export) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 2 or 3 arguments"); RETURN_FALSE; } - + + PGSQL_GET_LINK(pgsql_link); + if (php_check_open_basedir(file_out TSRMLS_CC)) { RETURN_FALSE; } - if (pgsql_link == NULL && id == -1) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (lo_export(pgsql, oid, file_out)) { RETURN_TRUE; - } + } RETURN_FALSE; } /* }}} */ @@ -3594,9 +3509,8 @@ PHP_FUNCTION(pg_lo_seek) zval *pgsql_id = NULL; long offset = 0, whence = SEEK_CUR; pgLofp *pgsql; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rl|l", &pgsql_id, &offset, &whence) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &pgsql_id, &offset, &whence) == FAILURE) { return; } if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { @@ -3621,9 +3535,8 @@ PHP_FUNCTION(pg_lo_tell) zval *pgsql_id = NULL; int offset = 0; pgLofp *pgsql; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "r", &pgsql_id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pgsql_id) == FAILURE) { return; } @@ -3648,19 +3561,13 @@ PHP_FUNCTION(pg_set_error_verbosity) if (zend_parse_parameters(argc TSRMLS_CC, "l", &verbosity) == FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc TSRMLS_CC, "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)) { Z_LVAL_P(return_value) = PQsetErrorVerbosity(pgsql, verbosity); @@ -3687,19 +3594,13 @@ PHP_FUNCTION(pg_set_client_encoding) if (zend_parse_parameters(argc TSRMLS_CC, "s", &encoding, &encoding_len) == FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc TSRMLS_CC, "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); Z_LVAL_P(return_value) = PQsetClientEncoding(pgsql, encoding); Z_TYPE_P(return_value) = IS_LONG; @@ -3711,23 +3612,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 TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { return; } - - if (argc == 0) { - id = PGG(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... */ @@ -3752,24 +3644,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 TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &pgsql_link) == FAILURE) { return; } - - if (argc == 0) { - id = PGG(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); @@ -3796,19 +3679,13 @@ PHP_FUNCTION(pg_put_line) if (zend_parse_parameters(argc TSRMLS_CC, "s", &query, &query_len) == FAILURE) { return; } - id = PGG(default_link); - CHECK_DEFAULT_LINK(id); } else { if (zend_parse_parameters(argc TSRMLS_CC, "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) { @@ -3837,9 +3714,8 @@ PHP_FUNCTION(pg_copy_to) #endif char *csv = (char *)NULL; int ret; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rs|ss", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ss", &pgsql_link, &table_name, &table_name_len, &pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) { return; @@ -3848,7 +3724,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 = safe_estrdup("\\\\N"); @@ -3903,7 +3779,7 @@ PHP_FUNCTION(pg_copy_to) PHP_PQ_ERROR("getline failed: %s", pgsql); RETURN_FALSE; } - + if (copybuf[0] == '\\' && copybuf[1] == '.' && copybuf[2] == '\0') @@ -3918,7 +3794,7 @@ PHP_FUNCTION(pg_copy_to) csv = (char *)erealloc(csv, strlen(csv) + sizeof(char)*(COPYBUFSIZ+1)); strcat(csv, copybuf); } - + switch (ret) { case EOF: @@ -3970,9 +3846,8 @@ PHP_FUNCTION(pg_copy_from) PGconn *pgsql; PGresult *pgsql_result; ExecStatusType status; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rsa|ss", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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; @@ -3985,7 +3860,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))) { @@ -4116,7 +3991,7 @@ PHP_FUNCTION(pg_escape_string) if (pgsql_link != NULL || id != -1) { ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); to_len = (int) PQescapeStringConn(pgsql, to, from, (size_t)from_len, NULL); - } else + } else #endif to_len = (int) PQescapeString(to, from, (size_t)from_len); @@ -4246,7 +4121,7 @@ static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t * if (isdigit(*sp)) /* state=4 */ { unsigned char *start, *end, buf[4]; /* 000 + '\0' */ - + bp -= 3; memcpy(buf, sp-2, 3); buf[3] = '\0'; @@ -4315,7 +4190,7 @@ static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t le /* * NOTE: multibyte strings that could cointain slashes should be considered. - * (e.g. SJIS, BIG5) However, it cannot be done without valid PGconn and mbstring. + * (e.g. SJIS, BIG5) However, it cannot be done without valid PGconn and mbstring. * Therefore, this function does not support such encodings currently. * FIXME: add encoding check and skip multibyte char bytes if there is vaild PGconn. */ @@ -4344,7 +4219,7 @@ static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t le } *rp++ = quote_char; *rp = '\0'; - + return result; } #endif @@ -4361,8 +4236,6 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &from, &from_len) == FAILURE) { return; } - pgsql_link = NULL; - id = PGG(default_link); break; default: @@ -4372,12 +4245,8 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l break; } - if (pgsql_link == NULL && id == -1) { - php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, E_WARNING,"Cannot get pgsql link"); RETURN_FALSE; @@ -4399,7 +4268,7 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l to = estrdup(tmp); PQfreemem(tmp); } -#else +#else to = php_pgsql_PQescapeInternal(pgsql, from, (size_t)from_len, escape_literal); if (!to) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape"); @@ -4441,7 +4310,7 @@ PHP_FUNCTION(pg_result_error) &result) == FAILURE) { RETURN_FALSE; } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; @@ -4468,7 +4337,7 @@ PHP_FUNCTION(pg_result_error_field) &result, &fieldcode) == FAILURE) { RETURN_FALSE; } - + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); pgsql_result = pg_result->result; @@ -4511,7 +4380,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)); } @@ -4532,7 +4401,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)); } @@ -4544,17 +4413,17 @@ 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; - + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r", &pgsql_link) == FAILURE) { 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) { RETURN_FALSE; @@ -4566,14 +4435,14 @@ PHP_FUNCTION(pg_connection_reset) #define PHP_PG_ASYNC_IS_BUSY 1 #define PHP_PG_ASYNC_REQUEST_CANCEL 2 - + /* {{{ php_pgsql_flush_query */ -static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC) +static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC) { PGresult *res; int leftover = 0; - + if (PQ_SETNONBLOCKING(pgsql, 1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE,"Cannot set connection to nonblocking mode"); return -1; @@ -4586,12 +4455,12 @@ static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC) return leftover; } /* }}} */ - + /* {{{ php_pgsql_do_async */ -static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) +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; @@ -4601,7 +4470,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 TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode"); @@ -4651,7 +4520,7 @@ PHP_FUNCTION(pg_connection_busy) Send asynchronous query */ PHP_FUNCTION(pg_send_query) { - zval *pgsql_link; + zval *pgsql_link = NULL; char *query; int len; int id = -1; @@ -4665,7 +4534,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); if (PQ_SETNONBLOCKING(pgsql, 1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode"); @@ -4706,7 +4575,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; @@ -4720,11 +4589,7 @@ PHP_FUNCTION(pg_send_query_params) 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, 1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode"); @@ -4743,7 +4608,7 @@ PHP_FUNCTION(pg_send_query_params) if (num_params > 0) { int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - + for(i = 0; i < num_params; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); @@ -4802,7 +4667,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; int stmtname_len, query_len, id = -1; PGconn *pgsql; @@ -4814,11 +4679,7 @@ PHP_FUNCTION(pg_send_prepare) 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, 1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode"); @@ -4860,7 +4721,7 @@ PHP_FUNCTION(pg_send_prepare) Executes prevriously prepared stmtname asynchronously */ PHP_FUNCTION(pg_send_execute) { - zval *pgsql_link; + zval *pgsql_link = NULL; zval *pv_param_arr, **tmp; int num_params = 0; char **params = NULL; @@ -4875,11 +4736,7 @@ PHP_FUNCTION(pg_send_execute) 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, 1)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode"); @@ -4898,7 +4755,7 @@ PHP_FUNCTION(pg_send_execute) if (num_params > 0) { int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - + for(i = 0; i < num_params; i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter"); @@ -4956,7 +4813,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; @@ -4966,8 +4823,8 @@ 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) { /* no result */ @@ -5018,7 +4875,7 @@ PHP_FUNCTION(pg_result_status) Get asynchronous notification */ PHP_FUNCTION(pg_get_notify) { - zval *pgsql_link; + zval *pgsql_link = NULL; int id = -1; long result_type = PGSQL_ASSOC; PGconn *pgsql; @@ -5029,7 +4886,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 TSRMLS_CC, E_WARNING, "Invalid result type"); @@ -5046,11 +4903,11 @@ PHP_FUNCTION(pg_get_notify) if (result_type & PGSQL_NUM) { add_index_string(return_value, 0, pgsql_notify->relname, 1); add_index_long(return_value, 1, pgsql_notify->be_pid); -#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS +#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) { -#else +#else if (atof(PG_VERSION) >= 9.0) { -#endif +#endif #if HAVE_PQPARAMETERSTATUS add_index_string(return_value, 2, pgsql_notify->extra, 1); #endif @@ -5059,11 +4916,11 @@ PHP_FUNCTION(pg_get_notify) if (result_type & PGSQL_ASSOC) { add_assoc_string(return_value, "message", pgsql_notify->relname, 1); add_assoc_long(return_value, "pid", pgsql_notify->be_pid); -#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS +#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) { -#else +#else if (atof(PG_VERSION) >= 9.0) { -#endif +#endif #if HAVE_PQPARAMETERSTATUS add_assoc_string(return_value, "payload", pgsql_notify->extra, 1); #endif @@ -5077,7 +4934,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; @@ -5086,7 +4943,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)); } @@ -5095,7 +4952,7 @@ PHP_FUNCTION(pg_get_pid) /* {{{ php_pgsql_meta_data * TODO: Add meta_data cache for better performance */ -PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC) +PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC) { PGresult *pg_result; char *src, *tmp_name, *tmp_name2 = NULL; @@ -5104,7 +4961,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z size_t new_len; int i, num_rows; zval *elem; - + if (!*table_name) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified"); return FAILURE; @@ -5112,14 +4969,14 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z src = estrdup(table_name); tmp_name = php_strtok_r(src, ".", &tmp_name2); - + if (!tmp_name2 || !*tmp_name2) { /* Default schema */ tmp_name2 = tmp_name; tmp_name = "public"; } - smart_str_appends(&querystr, + smart_str_appends(&querystr, "SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotnull, a.atthasdef, a.attndims, t.typtype = 'e' " "FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n " "WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '"); @@ -5189,7 +5046,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z add_assoc_zval(meta, name, elem); } PQclear(pg_result); - + return SUCCESS; } @@ -5200,19 +5057,19 @@ 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; uint table_name_len; PGconn *pgsql; int id = -1; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pgsql_link, &table_name, &table_name_len) == FAILURE) { 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 TSRMLS_CC) == FAILURE) { zval_dtor(return_value); /* destroy array */ @@ -5238,7 +5095,7 @@ static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t { /* This is stupid way to do. I'll fix it when I decied how to support user defined types. (Yasuo) */ - + /* boolean */ if (!strcmp(type_name, "bool")|| !strcmp(type_name, "boolean")) return PG_BOOL; @@ -5317,17 +5174,17 @@ static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t return PG_POLYGON; if (!strcmp(type_name, "circle")) return PG_CIRCLE; - + return PG_UNKNOWN; } /* }}} */ /* {{{ php_pgsql_convert_match - * test field value with regular expression specified. + * test field value with regular expression specified. */ static int php_pgsql_convert_match(const char *str, const char *regex , int icase TSRMLS_DC) { - regex_t re; + regex_t re; regmatch_t *subs; int regopt = REG_EXTENDED; int regerr, ret = SUCCESS; @@ -5335,7 +5192,7 @@ static int php_pgsql_convert_match(const char *str, const char *regex , int icas if (icase) { regopt |= REG_ICASE; } - + regerr = regcomp(&re, regex, regopt); if (regerr) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex"); @@ -5346,7 +5203,7 @@ static int php_pgsql_convert_match(const char *str, const char *regex , int icas regerr = regexec(&re, str, re.re_nsub+1, subs, 0); if (regerr == REG_NOMATCH) { -#ifdef PHP_DEBUG +#ifdef PHP_DEBUG php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex); #endif ret = FAILURE; @@ -5365,10 +5222,10 @@ static int php_pgsql_convert_match(const char *str, const char *regex , int icas /* {{{ php_pgsql_add_quote * add quotes around string. */ -static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC) +static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC) { smart_str str = {0}; - + assert(Z_TYPE_P(src) == IS_STRING); assert(should_free == 1 || should_free == 0); @@ -5377,7 +5234,7 @@ static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC) smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src)); smart_str_appendc(&str, '\''); smart_str_0(&str); - + if (should_free) { efree(Z_STRVAL_P(src)); } @@ -5401,12 +5258,12 @@ static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC) php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected NULL for 'NOT NULL' field '%s'", field ); \ err = 1; \ } \ - } + } /* {{{ php_pgsql_convert * check and convert array values (fieldname=>vlaue pair) for sql */ -PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC) +PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC) { HashPosition pos; char *field = NULL; @@ -5415,7 +5272,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con zval *meta, **def, **type, **not_null, **has_default, **is_enum, **val, *new_val; int key_type, err = 0, skip_field; php_pgsql_data_type data_type; - + assert(pg_link != NULL); assert(Z_TYPE_P(values) == IS_ARRAY); assert(Z_TYPE_P(result) == IS_ARRAY); @@ -5438,7 +5295,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos)) { skip_field = 0; new_val = NULL; - + if ((key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &field, &field_len, &num_idx, 0, &pos)) == HASH_KEY_NON_EXISTENT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to get array key type"); err = 1; @@ -5519,7 +5376,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_LONG: case IS_BOOL: if (Z_LVAL_PP(val)) { @@ -5542,7 +5399,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects string, null, long or boolelan value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); } break; - + case PG_OID: case PG_INT2: case PG_INT4: @@ -5562,16 +5419,16 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_DOUBLE: ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); convert_to_long_ex(&new_val); break; - + case IS_LONG: ZVAL_LONG(new_val, Z_LVAL_PP(val)); break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -5604,15 +5461,15 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_LONG: ZVAL_LONG(new_val, Z_LVAL_PP(val)); break; - + case IS_DOUBLE: ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -5647,18 +5504,18 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con Z_STRLEN_P(new_val) = (int)PQescapeStringConn(pg_link, tmp, Z_STRVAL_PP(val), Z_STRLEN_PP(val), NULL); Z_STRVAL_P(new_val) = tmp; } -#else +#else Z_STRVAL_P(new_val) = (int)PQescapeString(Z_STRVAL_PP(val), Z_STRLEN_PP(val), &Z_STRLEN_P(new_val), 0 TSRMLS_CC); #endif php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); } break; - + case IS_LONG: ZVAL_LONG(new_val, Z_LVAL_PP(val)); convert_to_string_ex(&new_val); break; - + case IS_DOUBLE: ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); convert_to_string_ex(&new_val); @@ -5676,7 +5533,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); } break; - + case PG_UNIX_TIME: case PG_UNIX_TIME_INTERVAL: /* these are the actallay a integer */ @@ -5689,23 +5546,23 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con /* FIXME: Better regex must be used */ if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^[0-9]+$", 0 TSRMLS_CC) == FAILURE) { err = 1; - } + } else { ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); convert_to_long_ex(&new_val); } } break; - + case IS_DOUBLE: ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); convert_to_long_ex(&new_val); break; - + case IS_LONG: ZVAL_LONG(new_val, Z_LVAL_PP(val)); break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -5718,7 +5575,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for '%s' (%s)", Z_STRVAL_PP(type), field); } break; - + case PG_CIDR: case PG_INET: switch (Z_TYPE_PP(val)) { @@ -5737,20 +5594,20 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; default: err = 1; - } + } PGSQL_CONV_CHECK_IGNORE(); if (err) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for '%s' (%s)", Z_STRVAL_PP(type), field); } break; - + case PG_TIME_WITH_TIMEZONE: case PG_TIMESTAMP: case PG_TIMESTAMP_WITH_TIMEZONE: @@ -5770,7 +5627,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_NULL: ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1); break; @@ -5783,7 +5640,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field); } break; - + case PG_DATE: switch(Z_TYPE_PP(val)) { case IS_STRING: @@ -5801,7 +5658,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -5832,7 +5689,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -5858,21 +5715,21 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con interval values can be written with the following syntax: [@] quantity unit [quantity unit...] [direction] - + Where: quantity is a number (possibly signed); unit is second, minute, hour, day, week, month, year, decade, century, millennium, or abbreviations or plurals of these units [note not *all* abbreviations] ; direction can be ago or empty. The at sign (@) is optional noise. - + ... - + Quantities of days, hours, minutes, and seconds can be specified without explicit unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10 sec'. - */ + */ if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^(@?[ \\t]+)?(" - + /* Textual time units and their abbreviations: */ "(([-+]?[ \\t]+)?" "[0-9]+(\\.[0-9]*)?[ \\t]*" @@ -5881,7 +5738,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con "decades|decade|dec|decs|" "years|year|y|" "months|month|mon|" - "weeks|week|w|" + "weeks|week|w|" "days|day|d|" "hours|hour|hr|hrs|h|" "minutes|minute|mins|min|m|" @@ -5896,7 +5753,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con "years|year|y|" "months|month|mon|" "weeks|week|w|" - "days|day|d))+" + "days|day|d))+" "([-+]?[ \\t]+" "([0-9]+[ \\t]+)+" /* dd */ "(([0-9]{1,2}:){0,2}[0-9]{0,2})" /* hh:[mm:[ss]] */ @@ -5909,9 +5766,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); } - } + } break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -5953,12 +5810,12 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con Z_STRLEN_P(new_val) = s.len; } break; - + case IS_LONG: ZVAL_LONG(new_val, Z_LVAL_PP(val)); convert_to_string_ex(&new_val); break; - + case IS_DOUBLE: ZVAL_DOUBLE(new_val, Z_DVAL_PP(val)); convert_to_string_ex(&new_val); @@ -5976,7 +5833,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field); } break; - + #endif case PG_MACADDR: switch(Z_TYPE_PP(val)) { @@ -5994,7 +5851,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con } } break; - + case IS_NULL: ZVAL_STRING(new_val, "NULL", 1); break; @@ -6022,14 +5879,14 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con php_error_docref(NULL TSRMLS_CC, E_NOTICE, "PostgreSQL '%s' type (%s) is not supported", Z_STRVAL_PP(type), field); err = 1; break; - + case PG_UNKNOWN: default: php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or system data type '%s' for '%s'", Z_STRVAL_PP(type), field); err = 1; break; } /* switch */ - + if (err) { zval_dtor(new_val); FREE_ZVAL(new_val); @@ -6075,7 +5932,7 @@ PHP_FUNCTION(pg_convert) ulong option = 0; PGconn *pg_link; int id = -1; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa|l", &pgsql_link, &table_name, &table_name_len, &values, &option) == FAILURE) { return; @@ -6216,12 +6073,12 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var } querystr.len--; smart_str_appends(&querystr, ") VALUES ("); - + /* make values string */ for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(var_array), &pos); zend_hash_get_current_data_ex(Z_ARRVAL_P(var_array), (void **)&val, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(var_array), &pos)) { - + /* we can avoid the key_type check here, because we tested it in the other loop */ switch(Z_TYPE_PP(val)) { case IS_STRING: @@ -6256,10 +6113,10 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var else if (opt & PGSQL_DML_STRING) { ret = SUCCESS; } - + cleanup: if (!(opt & PGSQL_DML_NO_CONV) && converted) { - zval_dtor(converted); + zval_dtor(converted); FREE_ZVAL(converted); } if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { @@ -6276,14 +6133,14 @@ 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, *sql = NULL; int table_len; ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; - int id = -1, argc = ZEND_NUM_ARGS(); + PGconn *pgsql; + int id = -1; - if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa|l", &pgsql_link, &table, &table_len, &values, &option) == FAILURE) { return; } @@ -6291,13 +6148,13 @@ PHP_FUNCTION(pg_insert) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified"); RETURN_FALSE; } - - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (php_pgsql_flush_query(pg_link TSRMLS_CC)) { + PGSQL_GET_LINK(pgsql_link); + + if (php_pgsql_flush_query(pgsql TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection"); } - if (php_pgsql_insert(pg_link, table, values, option, &sql TSRMLS_CC) == FAILURE) { + if (php_pgsql_insert(pgsql, table, values, option, &sql TSRMLS_CC) == FAILURE) { RETURN_FALSE; } if (option & PGSQL_DML_STRING) { @@ -6320,7 +6177,7 @@ static inline int build_assignment_string(smart_str *querystr, HashTable *ht, in for (zend_hash_internal_pointer_reset_ex(ht, &pos); zend_hash_get_current_data_ex(ht, (void **)&val, &pos) == SUCCESS; zend_hash_move_forward_ex(ht, &pos)) { - key_type = zend_hash_get_current_key_ex(ht, &fld, &fld_len, &num_idx, 0, &pos); + key_type = zend_hash_get_current_key_ex(ht, &fld, &fld_len, &num_idx, 0, &pos); if (key_type == HASH_KEY_IS_LONG) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects associative array for values to be inserted"); return -1; @@ -6331,7 +6188,7 @@ static inline int build_assignment_string(smart_str *querystr, HashTable *ht, in } else { smart_str_appendc(querystr, '='); } - + switch(Z_TYPE_PP(val)) { case IS_STRING: smart_str_appendl(querystr, Z_STRVAL_PP(val), Z_STRLEN_PP(val)); @@ -6356,7 +6213,7 @@ static inline int build_assignment_string(smart_str *querystr, HashTable *ht, in /* {{{ php_pgsql_update */ -PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array, zval *ids_array, ulong opt, char **sql TSRMLS_DC) +PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array, zval *ids_array, ulong opt, char **sql TSRMLS_DC) { zval *var_converted = NULL, *ids_converted = NULL; smart_str querystr = {0}; @@ -6394,13 +6251,13 @@ PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *var if (build_assignment_string(&querystr, Z_ARRVAL_P(var_array), 0, ",", 1 TSRMLS_CC)) goto cleanup; - + smart_str_appends(&querystr, " WHERE "); - + if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC)) goto cleanup; - smart_str_appendc(&querystr, ';'); + smart_str_appendc(&querystr, ';'); smart_str_0(&querystr); if ((opt & PGSQL_DML_EXEC) && do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) { @@ -6436,10 +6293,10 @@ PHP_FUNCTION(pg_update) char *table, *sql = NULL; int table_len; ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; - int id = -1, argc = ZEND_NUM_ARGS(); + PGconn *pgsql; + int id = -1; - if (zend_parse_parameters(argc TSRMLS_CC, "rsaa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsaa|l", &pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) { return; } @@ -6447,25 +6304,25 @@ PHP_FUNCTION(pg_update) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified"); RETURN_FALSE; } - - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (php_pgsql_flush_query(pg_link TSRMLS_CC)) { + PGSQL_GET_LINK(pgsql_link); + + if (php_pgsql_flush_query(pgsql TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection"); } - if (php_pgsql_update(pg_link, table, values, ids, option, &sql TSRMLS_CC) == FAILURE) { + if (php_pgsql_update(pgsql, table, values, ids, option, &sql TSRMLS_CC) == FAILURE) { RETURN_FALSE; } if (option & PGSQL_DML_STRING) { RETURN_STRING(sql, 0); } RETURN_TRUE; -} +} /* }}} */ /* {{{ php_pgsql_delete */ -PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array, ulong opt, char **sql TSRMLS_DC) +PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array, ulong opt, char **sql TSRMLS_DC) { zval *ids_converted = NULL; smart_str querystr = {0}; @@ -6475,7 +6332,7 @@ PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids assert(table != NULL); assert(Z_TYPE_P(ids_array) == IS_ARRAY); assert(!(opt & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_EXEC|PGSQL_DML_STRING))); - + if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) { return FAILURE; } @@ -6507,7 +6364,7 @@ PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids cleanup: if (!(opt & PGSQL_DML_NO_CONV)) { - zval_dtor(ids_converted); + zval_dtor(ids_converted); FREE_ZVAL(ids_converted); } if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { @@ -6528,10 +6385,10 @@ PHP_FUNCTION(pg_delete) char *table, *sql = NULL; int table_len; ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; - int id = -1, argc = ZEND_NUM_ARGS(); + PGconn *pgsql; + int id = -1; - if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa|l", &pgsql_link, &table, &table_len, &ids, &option) == FAILURE) { return; } @@ -6539,25 +6396,24 @@ PHP_FUNCTION(pg_delete) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified"); 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 TSRMLS_CC)) { + if (php_pgsql_flush_query(pgsql TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection"); } - if (php_pgsql_delete(pg_link, table, ids, option, &sql TSRMLS_CC) == FAILURE) { + if (php_pgsql_delete(pgsql, table, ids, option, &sql TSRMLS_CC) == FAILURE) { RETURN_FALSE; } if (option & PGSQL_DML_STRING) { RETURN_STRING(sql, 0); } RETURN_TRUE; -} +} /* }}} */ /* {{{ php_pgsql_result2array */ -PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC) +PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC) { zval *row; char *field_name; @@ -6586,7 +6442,7 @@ PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TS data = safe_estrndup(element, element_len); data_len = element_len; - + field_name = PQfname(pg_result, i); add_assoc_stringl(row, field_name, data, data_len, 0); } @@ -6599,7 +6455,7 @@ PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TS /* {{{ php_pgsql_select */ -PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids_array, zval *ret_array, ulong opt, char **sql TSRMLS_DC) +PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids_array, zval *ret_array, ulong opt, char **sql TSRMLS_DC) { zval *ids_converted = NULL; smart_str querystr = {0}; @@ -6611,7 +6467,7 @@ PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids assert(Z_TYPE_P(ids_array) == IS_ARRAY); assert(Z_TYPE_P(ret_array) == IS_ARRAY); assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING))); - + if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) { return FAILURE; } @@ -6645,7 +6501,7 @@ PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids cleanup: if (!(opt & PGSQL_DML_NO_CONV)) { - zval_dtor(ids_converted); + zval_dtor(ids_converted); FREE_ZVAL(ids_converted); } if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) { @@ -6666,10 +6522,10 @@ PHP_FUNCTION(pg_select) char *table, *sql = NULL; int table_len; ulong option = PGSQL_DML_EXEC; - PGconn *pg_link; - int id = -1, argc = ZEND_NUM_ARGS(); + PGconn *pgsql; + int id = -1; - if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa|l", &pgsql_link, &table, &table_len, &ids, &option) == FAILURE) { return; } @@ -6677,14 +6533,14 @@ PHP_FUNCTION(pg_select) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified"); RETURN_FALSE; } - - ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (php_pgsql_flush_query(pg_link TSRMLS_CC)) { + PGSQL_GET_LINK(pgsql_link); + + if (php_pgsql_flush_query(pgsql TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection"); } array_init(return_value); - if (php_pgsql_select(pg_link, table, ids, return_value, option, &sql TSRMLS_CC) == FAILURE) { + if (php_pgsql_select(pgsql, table, ids, return_value, option, &sql TSRMLS_CC) == FAILURE) { zval_dtor(return_value); RETURN_FALSE; } @@ -6693,7 +6549,7 @@ PHP_FUNCTION(pg_select) RETURN_STRING(sql, 0); } return; -} +} /* }}} */ #endif diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index dcb67fe9fa6e4..fa81ba50987be 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1268,7 +1268,7 @@ PHP_METHOD(Phar, __construct) INIT_PZVAL(&arg2); ZVAL_LONG(&arg2, flags); - zend_call_method_with_2_params(&zobj, Z_OBJCE_P(zobj), + zend_call_method_with_2_params(&zobj, Z_OBJCE_P(zobj), &spl_ce_RecursiveDirectoryIterator->constructor, "__construct", NULL, &arg1, &arg2); if (!phar_data->is_persistent) { @@ -1292,7 +1292,7 @@ PHP_METHOD(Phar, getSupportedSignatures) if (zend_parse_parameters_none() == FAILURE) { return; } - + array_init(return_value); add_next_index_stringl(return_value, "MD5", 3, 1); @@ -1319,7 +1319,7 @@ PHP_METHOD(Phar, getSupportedCompression) if (zend_parse_parameters_none() == FAILURE) { return; } - + array_init(return_value); phar_request_initialize(TSRMLS_C); @@ -1593,7 +1593,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ } return ZEND_HASH_APPLY_STOP; } - + base = temp; base_len = strlen(base); @@ -1782,7 +1782,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ /* {{{ proto array Phar::buildFromDirectory(string base_dir[, string regex]) * Construct a phar archive from an existing directory, recursively. * Optional second parameter is a regular expression for filtering directory contents. - * + * * Return value is an array mapping phar index to actual files added. */ PHP_METHOD(Phar, buildFromDirectory) @@ -1822,7 +1822,7 @@ PHP_METHOD(Phar, buildFromDirectory) ZVAL_LONG(&arg2, SPL_FILE_DIR_SKIPDOTS|SPL_FILE_DIR_UNIXPATHS); #endif - zend_call_method_with_2_params(&iter, spl_ce_RecursiveDirectoryIterator, + zend_call_method_with_2_params(&iter, spl_ce_RecursiveDirectoryIterator, &spl_ce_RecursiveDirectoryIterator->constructor, "__construct", NULL, &arg, &arg2); if (EG(exception)) { @@ -1839,7 +1839,7 @@ PHP_METHOD(Phar, buildFromDirectory) RETURN_FALSE; } - zend_call_method_with_1_params(&iteriter, spl_ce_RecursiveIteratorIterator, + zend_call_method_with_1_params(&iteriter, spl_ce_RecursiveIteratorIterator, &spl_ce_RecursiveIteratorIterator->constructor, "__construct", NULL, iter); if (EG(exception)) { @@ -1864,7 +1864,7 @@ PHP_METHOD(Phar, buildFromDirectory) INIT_PZVAL(&arg2); ZVAL_STRINGL(&arg2, regex, regex_len, 0); - zend_call_method_with_2_params(®exiter, spl_ce_RegexIterator, + zend_call_method_with_2_params(®exiter, spl_ce_RegexIterator, &spl_ce_RegexIterator->constructor, "__construct", NULL, iteriter, &arg2); } @@ -1985,7 +1985,7 @@ PHP_METHOD(Phar, buildFromIterator) PHP_METHOD(Phar, count) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2150,7 +2150,7 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c spprintf(&newname, 0, "%s.%s", strtok(basename, "."), ext); efree(basename); - + basepath = estrndup(oldpath, (strlen(oldpath) - oldname_len)); phar->fname_len = spprintf(&newpath, 0, "%s%s", basepath, newname); @@ -2616,7 +2616,7 @@ PHP_METHOD(Phar, convertToData) PHP_METHOD(Phar, isCompressed) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2640,7 +2640,7 @@ PHP_METHOD(Phar, isWritable) { php_stream_statbuf ssb; PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2718,7 +2718,7 @@ PHP_METHOD(Phar, delete) PHP_METHOD(Phar, getAlias) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2735,7 +2735,7 @@ PHP_METHOD(Phar, getAlias) PHP_METHOD(Phar, getPath) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2851,7 +2851,7 @@ PHP_METHOD(Phar, setAlias) PHP_METHOD(Phar, getVersion) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2866,7 +2866,7 @@ PHP_METHOD(Phar, getVersion) PHP_METHOD(Phar, startBuffering) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2881,7 +2881,7 @@ PHP_METHOD(Phar, startBuffering) PHP_METHOD(Phar, isBuffering) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2898,7 +2898,7 @@ PHP_METHOD(Phar, stopBuffering) char *error; PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3133,7 +3133,7 @@ PHP_METHOD(Phar, setSignatureAlgorithm) PHP_METHOD(Phar, getSignature) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3177,7 +3177,7 @@ PHP_METHOD(Phar, getSignature) PHP_METHOD(Phar, getModified) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3439,7 +3439,7 @@ PHP_METHOD(Phar, decompressFiles) { char *error; PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3960,7 +3960,7 @@ PHP_METHOD(Phar, getStub) phar_entry_info *stub; PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4063,7 +4063,7 @@ PHP_METHOD(Phar, hasMetadata) PHP_METHOD(Phar, getMetadata) { PHAR_ARCHIVE_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4521,7 +4521,7 @@ PHP_METHOD(PharFileInfo, __construct) INIT_PZVAL(&arg1); ZVAL_STRINGL(&arg1, fname, fname_len, 0); - zend_call_method_with_1_params(&zobj, Z_OBJCE_P(zobj), + zend_call_method_with_1_params(&zobj, Z_OBJCE_P(zobj), &spl_ce_SplFileInfo->constructor, "__construct", NULL, &arg1); } /* }}} */ @@ -4559,7 +4559,7 @@ PHP_METHOD(PharFileInfo, __destruct) PHP_METHOD(PharFileInfo, getCompressedSize) { PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4601,7 +4601,7 @@ PHP_METHOD(PharFileInfo, isCompressed) PHP_METHOD(PharFileInfo, getCRC32) { PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4627,7 +4627,7 @@ PHP_METHOD(PharFileInfo, getCRC32) PHP_METHOD(PharFileInfo, isCRCChecked) { PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4642,7 +4642,7 @@ PHP_METHOD(PharFileInfo, isCRCChecked) PHP_METHOD(PharFileInfo, getPharFlags) { PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4720,7 +4720,7 @@ PHP_METHOD(PharFileInfo, chmod) PHP_METHOD(PharFileInfo, hasMetadata) { PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4735,7 +4735,7 @@ PHP_METHOD(PharFileInfo, hasMetadata) PHP_METHOD(PharFileInfo, getMetadata) { PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4816,7 +4816,7 @@ PHP_METHOD(PharFileInfo, delMetadata) char *error; PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -4874,7 +4874,7 @@ PHP_METHOD(PharFileInfo, getContent) phar_entry_info *link; PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -5048,7 +5048,7 @@ PHP_METHOD(PharFileInfo, decompress) { char *error; PHAR_ENTRY_OBJECT(); - + if (zend_parse_parameters_none() == FAILURE) { return; } diff --git a/ext/pspell/pspell.c b/ext/pspell/pspell.c index 79a597e86201f..41526ba6d8567 100644 --- a/ext/pspell/pspell.c +++ b/ext/pspell/pspell.c @@ -45,7 +45,7 @@ #define PSPELL_SPEED_MASK_INTERNAL 3L #define PSPELL_RUN_TOGETHER 8L -/* Largest ignored word can be 999 characters (this seems sane enough), +/* Largest ignored word can be 999 characters (this seems sane enough), * and it takes 3 bytes to represent that (see pspell_config_ignore) */ #define PSPELL_LARGEST_WORD 3 @@ -262,7 +262,6 @@ static PHP_FUNCTION(pspell_new) char *language, *spelling = NULL, *jargon = NULL, *encoding = NULL; int language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; long mode = 0L, speed = 0L; - int argc = ZEND_NUM_ARGS(); int ind; #ifdef PHP_WIN32 @@ -276,8 +275,8 @@ static PHP_FUNCTION(pspell_new) PspellCanHaveError *ret; PspellManager *manager; PspellConfig *config; - - if (zend_parse_parameters(argc TSRMLS_CC, "s|sssl", &language, &language_len, &spelling, &spelling_len, + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sssl", &language, &language_len, &spelling, &spelling_len, &jargon, &jargon_len, &encoding, &encoding_len, &mode) == FAILURE) { return; } @@ -319,7 +318,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) */ @@ -330,7 +329,7 @@ static PHP_FUNCTION(pspell_new) } else if (speed == PSPELL_BAD_SPELLERS) { pspell_config_replace(config, "sug-mode", "bad-spellers"); } - + /* Then we see if run-together words should be treated as valid components */ if (mode & PSPELL_RUN_TOGETHER) { pspell_config_replace(config, "run-together", "true"); @@ -345,7 +344,7 @@ static PHP_FUNCTION(pspell_new) delete_pspell_can_have_error(ret); RETURN_FALSE; } - + manager = to_pspell_manager(ret); ind = zend_list_insert(manager, le_pspell TSRMLS_CC); RETURN_LONG(ind); @@ -359,7 +358,6 @@ static PHP_FUNCTION(pspell_new_personal) char *personal, *language, *spelling = NULL, *jargon = NULL, *encoding = NULL; int personal_len, language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; long mode = 0L, speed = 0L; - int argc = ZEND_NUM_ARGS(); int ind; #ifdef PHP_WIN32 @@ -374,7 +372,7 @@ static PHP_FUNCTION(pspell_new_personal) PspellManager *manager; PspellConfig *config; - if (zend_parse_parameters(argc TSRMLS_CC, "ps|sssl", &personal, &personal_len, &language, &language_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ps|sssl", &personal, &personal_len, &language, &language_len, &spelling, &spelling_len, &jargon, &jargon_len, &encoding, &encoding_len, &mode) == FAILURE) { return; } @@ -424,7 +422,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) */ @@ -435,7 +433,7 @@ static PHP_FUNCTION(pspell_new_personal) } else if (speed == PSPELL_BAD_SPELLERS) { pspell_config_replace(config, "sug-mode", "bad-spellers"); } - + /* Then we see if run-together words should be treated as valid components */ if (mode & PSPELL_RUN_TOGETHER) { pspell_config_replace(config, "run-together", "true"); @@ -450,7 +448,7 @@ static PHP_FUNCTION(pspell_new_personal) delete_pspell_can_have_error(ret); RETURN_FALSE; } - + manager = to_pspell_manager(ret); ind = zend_list_insert(manager, le_pspell TSRMLS_CC); RETURN_LONG(ind); @@ -462,11 +460,11 @@ static PHP_FUNCTION(pspell_new_personal) static PHP_FUNCTION(pspell_new_config) { int type, ind; - long conf; + long conf; PspellCanHaveError *ret; PspellManager *manager; PspellConfig *config; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &conf) == FAILURE) { return; } @@ -480,7 +478,7 @@ static PHP_FUNCTION(pspell_new_config) delete_pspell_can_have_error(ret); RETURN_FALSE; } - + manager = to_pspell_manager(ret); ind = zend_list_insert(manager, le_pspell TSRMLS_CC); RETURN_LONG(ind); @@ -588,7 +586,7 @@ static PHP_FUNCTION(pspell_add_to_personal) if (word_len == 0) { RETURN_FALSE; } - + pspell_manager_add_to_personal(manager, word); if (pspell_manager_error_number(manager) == 0) { RETURN_TRUE; @@ -640,8 +638,8 @@ static PHP_FUNCTION(pspell_clear_session) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &scin) == FAILURE) { return; } - - PSPELL_FETCH_MANAGER; + + PSPELL_FETCH_MANAGER; pspell_manager_clear_session(manager); if (pspell_manager_error_number(manager) == 0) { @@ -664,8 +662,8 @@ static PHP_FUNCTION(pspell_save_wordlist) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &scin) == FAILURE) { return; } - - PSPELL_FETCH_MANAGER; + + PSPELL_FETCH_MANAGER; pspell_manager_save_all_word_lists(manager); @@ -695,8 +693,8 @@ static PHP_FUNCTION(pspell_config_create) HKEY hkey; DWORD dwType,dwLen; #endif - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sss", &language, &language_len, &spelling, &spelling_len, + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sss", &language, &language_len, &spelling, &spelling_len, &jargon, &jargon_len, &encoding, &encoding_len) == FAILURE) { return; } @@ -755,15 +753,15 @@ static PHP_FUNCTION(pspell_config_runtogether) long conf; zend_bool runtogether; PspellConfig *config; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &conf, &runtogether) == FAILURE) { return; } - PSPELL_FETCH_CONFIG; + PSPELL_FETCH_CONFIG; pspell_config_replace(config, "run-together", runtogether ? "true" : "false"); - + RETURN_TRUE; } /* }}} */ @@ -800,10 +798,10 @@ static PHP_FUNCTION(pspell_config_mode) static PHP_FUNCTION(pspell_config_ignore) { int type; - char ignore_str[MAX_LENGTH_OF_LONG + 1]; + char ignore_str[MAX_LENGTH_OF_LONG + 1]; long conf, ignore = 0L; PspellConfig *config; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &conf, &ignore) == FAILURE) { return; } @@ -824,7 +822,7 @@ static void pspell_config_path(INTERNAL_FUNCTION_PARAMETERS, char *option) char *value; int value_len; PspellConfig *config; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lp", &conf, &value, &value_len) == FAILURE) { return; } @@ -873,7 +871,7 @@ static PHP_FUNCTION(pspell_config_repl) char *repl; int repl_len; PspellConfig *config; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lp", &conf, &repl, &repl_len) == FAILURE) { return; } @@ -900,7 +898,7 @@ static PHP_FUNCTION(pspell_config_save_repl) long conf; zend_bool save; PspellConfig *config; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &conf, &save) == FAILURE) { return; } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index b1f7484f243ca..d3ae6a1855e15 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1115,7 +1115,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde while (func->fname) { int fname_len = strlen(func->fname); char *lc_name = zend_str_tolower_dup(func->fname, fname_len); - + if (zend_hash_find(EG(function_table), lc_name, fname_len + 1, (void**) &fptr) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); func++; @@ -3006,8 +3006,8 @@ ZEND_METHOD(reflection_method, invokeArgs) fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; fcc.object_ptr = object; - - /* + + /* * Copy the zend_function when calling via handler (e.g. Closure::__invoke()) */ if (mptr->type == ZEND_INTERNAL_FUNCTION && @@ -3770,17 +3770,13 @@ ZEND_METHOD(reflection_class, getMethods) { reflection_object *intern; zend_class_entry *ce; - long filter = 0; + /* If no parameters given, default to "return all" */ + 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 TSRMLS_CC, "|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); @@ -3960,17 +3956,13 @@ ZEND_METHOD(reflection_class, getProperties) { reflection_object *intern; zend_class_entry *ce; - long filter = 0; + /* If no parameters given, default to "return all" */ + 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 TSRMLS_CC, "|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 TSRMLS_CC, "|l", &filter) == FAILURE) { + return; } GET_REFLECTION_OBJECT_PTR(ce); @@ -4292,7 +4284,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) reflection_object *intern; zend_class_entry *ce, *old_scope; int argc = 0; - HashTable *args; + HashTable *args = NULL; zend_function *constructor; @@ -4302,8 +4294,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &args) == FAILURE) { return; } - - if (ZEND_NUM_ARGS() > 0) { + if (args != NULL) { argc = args->nNumOfElements; } @@ -4365,7 +4356,9 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (params) { efree(params); } - } else if (argc) { + } else if (args == NULL || !argc) { + object_init_ex(return_value, ce); + } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); } } @@ -5280,7 +5273,7 @@ ZEND_METHOD(reflection_extension, getFunctions) while (func->fname) { int fname_len = strlen(func->fname); char *lc_name = zend_str_tolower_dup(func->fname, fname_len); - + if (zend_hash_find(EG(function_table), lc_name, fname_len + 1, (void**) &fptr) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal error: Cannot find extension function %s in global function table", func->fname); func++; diff --git a/ext/session/session.c b/ext/session/session.c index 5b4820a65cfa4..57dc5a14575df 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -417,7 +417,7 @@ PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ini setting hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for now"); } - + outid = emalloc((size_t)((digest_len + 2) * ((8.0f / PS(hash_bits_per_character)) + 0.5))); j = (int) (bin_to_readable((char *)digest, digest_len, outid, (char)PS(hash_bits_per_character)) - outid); efree(digest); @@ -1861,6 +1861,12 @@ static PHP_FUNCTION(session_set_save_handler) if (zend_parse_parameters(argc TSRMLS_CC, "+", &args, &num_args) == FAILURE) { return; } + if(num_args != 6 && num_args != 7) { + if(args) { + efree(args); + } + WRONG_PARAM_COUNT; + } /* remove shutdown function */ remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") TSRMLS_CC); @@ -1875,7 +1881,7 @@ static PHP_FUNCTION(session_set_save_handler) } efree(name); } - + if (PS(mod) && PS(mod) != &ps_mod_user) { zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); } @@ -2005,15 +2011,14 @@ static PHP_FUNCTION(session_cache_limiter) static PHP_FUNCTION(session_cache_expire) { zval **expires = NULL; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "|Z", &expires) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Z", &expires) == FAILURE) { return; } RETVAL_LONG(PS(cache_expire)); - if (argc == 1) { + if (expires != NULL) { convert_to_string_ex(expires); zend_alter_ini_entry("session.cache_expire", sizeof("session.cache_expire"), Z_STRVAL_PP(expires), Z_STRLEN_PP(expires), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); } @@ -2728,12 +2733,12 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo case MULTIPART_EVENT_FILE_START: { multipart_event_file_start *data = (multipart_event_file_start *) event_data; - /* Do nothing when $_POST["PHP_SESSION_UPLOAD_PROGRESS"] is not set + /* Do nothing when $_POST["PHP_SESSION_UPLOAD_PROGRESS"] is not set * or when we have no session id */ if (!Z_TYPE(progress->sid) || !progress->key.c) { break; } - + /* First FILE_START event, initializing data */ if (!progress->data) { @@ -2783,7 +2788,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo add_assoc_zval_ex(progress->current_file, "bytes_processed", sizeof("bytes_processed"), progress->current_file_bytes_processed); add_next_index_zval(progress->files, progress->current_file); - + Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; php_session_rfc1867_update(progress, 0 TSRMLS_CC); @@ -2795,7 +2800,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo if (!Z_TYPE(progress->sid) || !progress->key.c) { break; } - + Z_LVAL_P(progress->current_file_bytes_processed) = data->offset + data->length; Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed; @@ -2808,7 +2813,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo if (!Z_TYPE(progress->sid) || !progress->key.c) { break; } - + if (data->temp_filename) { add_assoc_string_ex(progress->current_file, "tmp_name", sizeof("tmp_name"), data->temp_filename, 1); } diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index eba46b9091036..ce1671b4d58fe 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -989,7 +989,7 @@ static inline char * sxe_xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, in { xmlChar *tmp = xmlNodeListGetString(doc, list, inLine); char *res; - + if (tmp) { res = estrdup((char*)tmp); xmlFree(tmp); @@ -1147,7 +1147,7 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{ } else { if (node->type == XML_TEXT_NODE) { const xmlChar *cur = node->content; - + if (*cur != 0) { MAKE_STD_ZVAL(value); ZVAL_STRING(value, sxe_xmlNodeListGetString(node->doc, node, 1), 0); @@ -1299,7 +1299,7 @@ SXE_METHOD(xpath) result = retval->nodesetval; array_init(return_value); - + if (result != NULL) { for (i = 0; i < result->nodeNr; ++i) { nodeptr = result->nodeTab[i]; @@ -1361,18 +1361,14 @@ SXE_METHOD(asXML) xmlOutputBufferPtr outbuf; xmlChar *strval; int strval_len; - char *filename; + char *filename = NULL; int 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() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { - RETURN_FALSE; - } - + if(filename) { sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); GET_NODE(sxe, node); node = php_sxe_get_first_node(sxe, node TSRMLS_CC); @@ -1927,7 +1923,7 @@ SXE_METHOD(count) } php_sxe_count_elements_helper(sxe, &count TSRMLS_CC); - + RETURN_LONG(count); } /* }}} */ diff --git a/ext/skeleton/create_stubs b/ext/skeleton/create_stubs index f9f39b1795f7e..36cb2e915ee0b 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 4e2510afc8da3..35500138f40ff 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -475,7 +475,7 @@ static void php_snmp_session_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC) static void php_snmp_object_free_storage(void *object TSRMLS_DC) { php_snmp_object *intern = (php_snmp_object *)object; - + if (!intern) { return; } @@ -483,7 +483,7 @@ static void php_snmp_object_free_storage(void *object TSRMLS_DC) netsnmp_session_free(&(intern->session)); zend_object_std_dtor(&intern->zo TSRMLS_CC); - + efree(intern); } @@ -503,7 +503,7 @@ static zend_object_value php_snmp_object_new(zend_class_entry *class_type TSRMLS retval.handlers = (zend_object_handlers *) &php_snmp_object_handlers; return retval; - + } /* {{{ php_snmp_error @@ -702,7 +702,7 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D * SNMP object fetcher/setter for all SNMP versions * */ -static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, +static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, struct snmp_session *session, struct objid_query *objid_query) { @@ -721,7 +721,7 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, /* we start with retval=FALSE. If any actual data is acquired, retval will be set to appropriate type */ RETVAL_FALSE; - + /* reset errno and errstr */ php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_NOERROR, ""); @@ -805,8 +805,8 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, } for (vars = response->variables; vars; vars = vars->next_variable) { /* do not output errors as values */ - if ( vars->type == SNMP_ENDOFMIBVIEW || - vars->type == SNMP_NOSUCHOBJECT || + if ( vars->type == SNMP_ENDOFMIBVIEW || + vars->type == SNMP_NOSUCHOBJECT || vars->type == SNMP_NOSUCHINSTANCE ) { if ((st & SNMP_CMD_WALK) && Z_TYPE_P(return_value) == IS_ARRAY) { break; @@ -816,8 +816,8 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at '%s': %s", buf, buf2); continue; } - - if ((st & SNMP_CMD_WALK) && + + if ((st & SNMP_CMD_WALK) && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { /* not part of this subtree */ if (Z_TYPE_P(return_value) == IS_ARRAY) { /* some records are fetched already, shut down further lookup */ keepwalking = 0; @@ -1095,7 +1095,7 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu efree(objid_query->vars); return FALSE; } - } else { + } else { memmove((char *)objid_query->vars[0].name, (char *)objid_mib, sizeof(objid_mib)); objid_query->vars[0].name_length = sizeof(objid_mib) / sizeof(oid); } @@ -1431,7 +1431,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) int session_less_mode = (getThis() == NULL); php_snmp_object *snmp_object; php_snmp_object glob_snmp_object; - + objid_query.max_repetitions = -1; objid_query.non_repeaters = 0; objid_query.valueretrieval = SNMP_G(valueretrieval); @@ -1544,7 +1544,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) } php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, session, &objid_query); - + efree(objid_query.vars); if (session_less_mode) { @@ -1557,7 +1557,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) } /* }}} */ -/* {{{ proto mixed snmpget(string host, string community, mixed object_id [, int timeout [, int retries]]) +/* {{{ proto mixed snmpget(string host, string community, mixed object_id [, int timeout [, int retries]]) Fetch a SNMP object */ PHP_FUNCTION(snmpget) { @@ -1565,7 +1565,7 @@ PHP_FUNCTION(snmpget) } /* }}} */ -/* {{{ proto mixed snmpgetnext(string host, string community, mixed object_id [, int timeout [, int retries]]) +/* {{{ proto mixed snmpgetnext(string host, string community, mixed object_id [, int timeout [, int retries]]) Fetch a SNMP object */ PHP_FUNCTION(snmpgetnext) { @@ -1573,7 +1573,7 @@ PHP_FUNCTION(snmpgetnext) } /* }}} */ -/* {{{ proto mixed snmpwalk(string host, string community, mixed object_id [, int timeout [, int retries]]) +/* {{{ proto mixed snmpwalk(string host, string community, mixed object_id [, int timeout [, int retries]]) Return all objects under the specified object id */ PHP_FUNCTION(snmpwalk) { @@ -1589,7 +1589,7 @@ PHP_FUNCTION(snmprealwalk) } /* }}} */ -/* {{{ proto bool snmpset(string host, string community, mixed object_id, mixed type, mixed value [, int timeout [, int retries]]) +/* {{{ proto bool snmpset(string host, string community, mixed object_id, mixed type, mixed value [, int timeout [, int retries]]) Set the value of a SNMP object */ PHP_FUNCTION(snmpset) { @@ -1636,7 +1636,7 @@ PHP_FUNCTION(snmp_set_enum_print) netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, (int) a1); RETURN_TRUE; -} +} /* }}} */ /* {{{ proto bool snmp_set_oid_output_format(int oid_format) @@ -1664,10 +1664,10 @@ PHP_FUNCTION(snmp_set_oid_output_format) RETURN_FALSE; break; } -} +} /* }}} */ -/* {{{ proto mixed snmp2_get(string host, string community, mixed object_id [, int timeout [, int retries]]) +/* {{{ proto mixed snmp2_get(string host, string community, mixed object_id [, int timeout [, int retries]]) Fetch a SNMP object */ PHP_FUNCTION(snmp2_get) { @@ -1675,7 +1675,7 @@ PHP_FUNCTION(snmp2_get) } /* }}} */ -/* {{{ proto mixed snmp2_getnext(string host, string community, mixed object_id [, int timeout [, int retries]]) +/* {{{ proto mixed snmp2_getnext(string host, string community, mixed object_id [, int timeout [, int retries]]) Fetch a SNMP object */ PHP_FUNCTION(snmp2_getnext) { @@ -1683,7 +1683,7 @@ PHP_FUNCTION(snmp2_getnext) } /* }}} */ -/* {{{ proto mixed snmp2_walk(string host, string community, mixed object_id [, int timeout [, int retries]]) +/* {{{ proto mixed snmp2_walk(string host, string community, mixed object_id [, int timeout [, int retries]]) Return all objects under the specified object id */ PHP_FUNCTION(snmp2_walk) { @@ -1699,7 +1699,7 @@ PHP_FUNCTION(snmp2_real_walk) } /* }}} */ -/* {{{ proto bool snmp2_set(string host, string community, mixed object_id, mixed type, mixed value [, int timeout [, int retries]]) +/* {{{ proto bool snmp2_set(string host, string community, mixed object_id, mixed type, mixed value [, int timeout [, int retries]]) Set the value of a SNMP object */ PHP_FUNCTION(snmp2_set) { @@ -1810,13 +1810,12 @@ PHP_METHOD(snmp, __construct) long timeout = SNMP_DEFAULT_TIMEOUT; long retries = SNMP_DEFAULT_RETRIES; long version = SNMP_DEFAULT_VERSION; - int argc = ZEND_NUM_ARGS(); zend_error_handling error_handling; snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC); zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); - - if (zend_parse_parameters(argc TSRMLS_CC, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) { + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } @@ -1837,7 +1836,7 @@ PHP_METHOD(snmp, __construct) if (snmp_object->session) { netsnmp_session_free(&(snmp_object->session)); } - + if (netsnmp_session_init(&(snmp_object->session), version, a1, a2, timeout, retries TSRMLS_CC)) { return; } @@ -1851,7 +1850,7 @@ PHP_METHOD(snmp, __construct) } /* }}} */ -/* {{{ proto bool SNMP::close() +/* {{{ proto bool SNMP::close() Close SNMP session */ PHP_METHOD(snmp, close) { @@ -1894,7 +1893,7 @@ PHP_METHOD(snmp, walk) } /* }}} */ -/* {{{ proto bool SNMP::set(mixed object_id, mixed type, mixed value) +/* {{{ proto bool SNMP::set(mixed object_id, mixed type, mixed value) Set the value of a SNMP object */ PHP_METHOD(snmp, set) { @@ -1909,11 +1908,10 @@ PHP_METHOD(snmp, setSecurity) zval *object = getThis(); char *a1 = "", *a2 = "", *a3 = "", *a4 = "", *a5 = "", *a6 = "", *a7 = ""; int 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 = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC); - - if (zend_parse_parameters(argc TSRMLS_CC, "s|ssssss", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len, + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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; } @@ -1926,7 +1924,7 @@ PHP_METHOD(snmp, setSecurity) } /* }}} */ -/* {{{ proto long SNMP::getErrno() +/* {{{ proto long SNMP::getErrno() Get last error code number */ PHP_METHOD(snmp, getErrno) { @@ -1940,7 +1938,7 @@ PHP_METHOD(snmp, getErrno) } /* }}} */ -/* {{{ proto long SNMP::getError() +/* {{{ proto long SNMP::getError() Get last error message */ PHP_METHOD(snmp, getError) { @@ -2131,23 +2129,23 @@ static int php_snmp_read_info(php_snmp_object *snmp_object, zval **retval TSRMLS if (snmp_object->session == NULL) { return SUCCESS; } - + MAKE_STD_ZVAL(val); ZVAL_STRINGL(val, snmp_object->session->peername, strlen(snmp_object->session->peername), 1); add_assoc_zval(*retval, "hostname", val); - + MAKE_STD_ZVAL(val); ZVAL_LONG(val, snmp_object->session->remote_port); add_assoc_zval(*retval, "port", val); - + MAKE_STD_ZVAL(val); ZVAL_LONG(val, snmp_object->session->timeout); add_assoc_zval(*retval, "timeout", val); - + MAKE_STD_ZVAL(val); ZVAL_LONG(val, snmp_object->session->retries); add_assoc_zval(*retval, "retries", val); - + return SUCCESS; } /* }}} */ @@ -2220,7 +2218,7 @@ static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval TS } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "max_oids should be positive integer or NULL, got %ld", Z_LVAL_P(newval)); } - + if (newval == &ztmp) { zval_dtor(newval); } @@ -2248,7 +2246,7 @@ static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *new php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown SNMP value retrieval method '%ld'", Z_LVAL_P(newval)); ret = FAILURE; } - + if (newval == &ztmp) { zval_dtor(newval); } @@ -2291,7 +2289,7 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval * convert_to_long(&ztmp); newval = &ztmp; } - + switch(Z_LVAL_P(newval)) { case NETSNMP_OID_OUTPUT_SUFFIX: case NETSNMP_OID_OUTPUT_MODULE: @@ -2326,7 +2324,7 @@ static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval newval = &ztmp; } - snmp_object->exceptions_enabled = Z_LVAL_P(newval); + snmp_object->exceptions_enabled = Z_LVAL_P(newval); if (newval == &ztmp) { zval_dtor(newval); @@ -2461,7 +2459,7 @@ PHP_MINIT_FUNCTION(snmp) PHP_MSHUTDOWN_FUNCTION(snmp) { snmp_shutdown("snmpapp"); - + zend_hash_destroy(&php_snmp_properties); return SUCCESS; diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 00e80efbcbca4..54f664b2597b7 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -984,7 +984,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht TSRMLS_DC) HashTable *ht2; HashPosition pos1, pos2; HashTable *typemap = NULL; - + zend_hash_internal_pointer_reset_ex(ht, &pos1); while (zend_hash_get_current_data_ex(ht, (void**)&tmp, &pos1) == SUCCESS) { char *type_name = NULL; @@ -1028,7 +1028,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht TSRMLS_DC) } } zend_hash_move_forward_ex(ht2, &pos2); - } + } if (type_name) { smart_str nscat = {0}; @@ -1058,7 +1058,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht TSRMLS_DC) new_enc->to_xml = enc->to_xml; new_enc->to_zval = enc->to_zval; new_enc->details.map = emalloc(sizeof(soapMapping)); - memset(new_enc->details.map, 0, sizeof(soapMapping)); + memset(new_enc->details.map, 0, sizeof(soapMapping)); if (to_xml) { zval_add_ref(&to_xml); new_enc->details.map->to_xml = to_xml; @@ -1115,7 +1115,7 @@ PHP_METHOD(SoapServer, SoapServer) if (Z_TYPE_P(wsdl) != IS_STRING && Z_TYPE_P(wsdl) != IS_NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid parameters"); } - + service = emalloc(sizeof(soapService)); memset(service, 0, sizeof(soapService)); service->send_errors = 1; @@ -1150,7 +1150,7 @@ PHP_METHOD(SoapServer, SoapServer) if (zend_hash_find(ht, "encoding", sizeof("encoding"), (void**)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING) { xmlCharEncodingHandlerPtr encoding; - + encoding = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); if (encoding == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_PP(tmp)); @@ -1210,7 +1210,7 @@ PHP_METHOD(SoapServer, SoapServer) } } } - + if (typemap_ht) { service->typemap = soap_create_typemap(service->sdl, typemap_ht TSRMLS_CC); } @@ -1340,7 +1340,7 @@ PHP_METHOD(SoapServer, getFunctions) if (zend_parse_parameters_none() == FAILURE) { return; } - + FETCH_THIS_SERVICE(service); array_init(return_value); @@ -1500,7 +1500,7 @@ PHP_METHOD(SoapServer, handle) FETCH_THIS_SERVICE(service); SOAP_GLOBAL(soap_version) = service->version; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &arg, &arg_len) == FAILURE) { return; } @@ -1559,7 +1559,7 @@ PHP_METHOD(SoapServer, handle) php_error_docref(NULL TSRMLS_CC, E_ERROR,"ob_start failed"); } - if (ZEND_NUM_ARGS() == 0) { + if (arg == NULL) { if (SG(request_info).raw_post_data) { char *post_data = SG(request_info).raw_post_data; int post_data_length = SG(request_info).raw_post_data_length; @@ -1925,7 +1925,7 @@ PHP_METHOD(SoapServer, handle) if (size == 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Dump memory failed"); - } + } if (soap_version == SOAP_1_2) { sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1); @@ -2142,10 +2142,10 @@ static void soap_error_handler(int error_num, const char *error_filename, const use_exceptions = 1; } - if ((error_num == E_USER_ERROR || - error_num == E_COMPILE_ERROR || + if ((error_num == E_USER_ERROR || + error_num == E_COMPILE_ERROR || error_num == E_CORE_ERROR || - error_num == E_ERROR || + error_num == E_ERROR || error_num == E_PARSE) && use_exceptions) { zval *fault, *exception; @@ -2214,10 +2214,10 @@ static void soap_error_handler(int error_num, const char *error_filename, const va_list argcopy; #endif - if (error_num == E_USER_ERROR || - error_num == E_COMPILE_ERROR || + if (error_num == E_USER_ERROR || + error_num == E_COMPILE_ERROR || error_num == E_CORE_ERROR || - error_num == E_ERROR || + error_num == E_ERROR || error_num == E_PARSE) { char* code = SOAP_GLOBAL(error_code); @@ -2447,13 +2447,13 @@ PHP_METHOD(SoapClient, SoapClient) if (zend_hash_find(ht, "encoding", sizeof("encoding"), (void**)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING) { xmlCharEncodingHandlerPtr encoding; - + encoding = xmlFindCharEncodingHandler(Z_STRVAL_PP(tmp)); if (encoding == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_PP(tmp)); } else { xmlCharEncCloseFunc(encoding); - add_property_stringl(this_ptr, "_encoding", Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); + add_property_stringl(this_ptr, "_encoding", Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); } } if (zend_hash_find(ht, "classmap", sizeof("classmap"), (void**)&tmp) == SUCCESS && @@ -2488,7 +2488,7 @@ PHP_METHOD(SoapClient, SoapClient) if (context) { add_property_resource(this_ptr, "_stream_context", context->rsrc_id); } - + if (zend_hash_find(ht, "cache_wsdl", sizeof("cache_wsdl"), (void**)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_LONG) { cache_wsdl = Z_LVAL_PP(tmp); @@ -2498,7 +2498,7 @@ PHP_METHOD(SoapClient, SoapClient) Z_TYPE_PP(tmp) == IS_STRING) { add_property_stringl(this_ptr, "_user_agent", Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); } - + if (zend_hash_find(ht, "keep_alive", sizeof("keep_alive"), (void**)&tmp) == SUCCESS && (Z_TYPE_PP(tmp) == IS_BOOL || Z_TYPE_PP(tmp) == IS_LONG) && Z_LVAL_PP(tmp) == 0) { add_property_long(this_ptr, "_keep_alive", 0); @@ -2606,7 +2606,7 @@ static int do_request(zval *this_ptr, xmlDoc *request, char *location, char *act xmlFree(buf); if (ret && zend_hash_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault"), (void **) &fault) == SUCCESS) { return FALSE; - } + } return ret; } @@ -2911,7 +2911,7 @@ PHP_METHOD(SoapClient, __call) free_soap_headers = 0; } } - + arg_count = zend_hash_num_elements(Z_ARRVAL_P(args)); if (arg_count > 0) { @@ -2977,7 +2977,7 @@ PHP_METHOD(SoapClient, __getTypes) HashPosition pos; FETCH_THIS_SDL(sdl); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3006,7 +3006,7 @@ PHP_METHOD(SoapClient, __getTypes) PHP_METHOD(SoapClient, __getLastRequest) { zval **tmp; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3028,7 +3028,7 @@ PHP_METHOD(SoapClient, __getLastResponse) if (zend_parse_parameters_none() == FAILURE) { return; } - + if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_response", sizeof("__last_response"), (void **)&tmp) == SUCCESS) { RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); } @@ -3042,11 +3042,11 @@ PHP_METHOD(SoapClient, __getLastResponse) PHP_METHOD(SoapClient, __getLastRequestHeaders) { zval **tmp; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_request_headers", sizeof("__last_request_headers"), (void **)&tmp) == SUCCESS) { RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1); } @@ -3060,7 +3060,7 @@ PHP_METHOD(SoapClient, __getLastRequestHeaders) PHP_METHOD(SoapClient, __getLastResponseHeaders) { zval **tmp; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3183,10 +3183,10 @@ PHP_METHOD(SoapClient, __setSoapHeaders) /* {{{ proto string SoapClient::__setLocation([string new_location]) - Sets the location option (the endpoint URL that will be touched by the + Sets the location option (the endpoint URL that will be touched by the following SOAP requests). If new_location is not specified or null then SoapClient will use endpoint - from WSDL file. + from WSDL file. The function returns old value of location options. */ PHP_METHOD(SoapClient, __setLocation) { @@ -3235,10 +3235,10 @@ static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code, cha if (Z_TYPE_P(obj) != IS_OBJECT) { object_init_ex(obj, soap_fault_class_entry); } - + add_property_string(obj, "faultstring", fault_string ? fault_string : "", 1); zend_update_property_string(zend_exception_get_default(TSRMLS_C), obj, "message", sizeof("message")-1, (fault_string ? fault_string : "") TSRMLS_CC); - + if (fault_code != NULL) { int soap_version = SOAP_GLOBAL(soap_version); @@ -3663,7 +3663,7 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c func = func->children; } deserialize_parameters(func, function, num_params, parameters TSRMLS_CC); - + encode_finish(); return function; @@ -3945,8 +3945,8 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function } if (fault_ns == NULL && - fault && - fault->details && + fault && + fault->details && zend_hash_num_elements(fault->details) == 1) { sdlParamPtr sparam; @@ -3969,7 +3969,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function xmlChar *code = xmlBuildQName(BAD_CAST(str), nsptr->prefix, NULL, 0); xmlNodeSetContent(node, code); xmlFree(code); - } else { + } else { xmlNodeSetContentLen(node, BAD_CAST(str), (int)new_len); } efree(str); @@ -3994,7 +3994,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function xmlChar *code = xmlBuildQName(BAD_CAST(str), nsptr->prefix, NULL, 0); xmlNodeSetContent(node, code); xmlFree(code); - } else { + } else { xmlNodeSetContentLen(node, BAD_CAST(str), (int)new_len); } efree(str); @@ -4166,7 +4166,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function encode_finish(); - if (function && function->responseName == NULL && + if (function && function->responseName == NULL && body->children == NULL && head == NULL) { xmlFreeDoc(doc); return NULL; @@ -4452,7 +4452,7 @@ static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int inde return *tmp; } else { HashPosition pos; - + zend_hash_internal_pointer_reset_ex(ht, &pos); while (zend_hash_get_current_data_ex(ht, (void **)&tmp, &pos) != FAILURE) { if ((*tmp)->paramName && strcmp(param_name, (*tmp)->paramName) == 0) { diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 4a2a41b5fd830..c3b0f1900a329 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1090,7 +1090,7 @@ PHP_FUNCTION(socket_write) zval *arg1; php_socket *php_sock; int retval, str_len; - long length = 0; + long length = LONG_MAX; char *str; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &str, &str_len, &length) == FAILURE) { @@ -1099,14 +1099,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) { @@ -1385,7 +1385,7 @@ PHP_FUNCTION(socket_connect) long port = 0; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, argc TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { return; } @@ -1769,7 +1769,7 @@ PHP_FUNCTION(socket_sendto) char *buf, *addr; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, argc TSRMLS_CC, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) { return; } diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 716990d80f02a..12c4c949156f5 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -83,7 +83,7 @@ static zend_class_entry * spl_find_ce_by_name(char *name, int len, zend_bool aut php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s does not exist%s", name, autoload ? " and could not be loaded" : ""); return NULL; } - + return *ce; } @@ -98,12 +98,12 @@ PHP_FUNCTION(class_parents) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) { RETURN_FALSE; } - + if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected"); RETURN_FALSE; } - + if (Z_TYPE_P(obj) == IS_STRING) { if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) { RETURN_FALSE; @@ -111,7 +111,7 @@ PHP_FUNCTION(class_parents) } else { ce = Z_OBJCE_P(obj); } - + array_init(return_value); parent_class = ce->parent; while (parent_class) { @@ -128,7 +128,7 @@ PHP_FUNCTION(class_implements) zval *obj; zend_bool autoload = 1; zend_class_entry *ce; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) { RETURN_FALSE; } @@ -136,7 +136,7 @@ PHP_FUNCTION(class_implements) php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected"); RETURN_FALSE; } - + if (Z_TYPE_P(obj) == IS_STRING) { if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) { RETURN_FALSE; @@ -144,7 +144,7 @@ PHP_FUNCTION(class_implements) } else { ce = Z_OBJCE_P(obj); } - + array_init(return_value); spl_add_interfaces(return_value, ce, 1, ZEND_ACC_INTERFACE TSRMLS_CC); } @@ -157,7 +157,7 @@ PHP_FUNCTION(class_uses) zval *obj; zend_bool autoload = 1; zend_class_entry *ce; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) { RETURN_FALSE; } @@ -165,7 +165,7 @@ PHP_FUNCTION(class_uses) php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected"); RETURN_FALSE; } - + if (Z_TYPE_P(obj) == IS_STRING) { if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) { RETURN_FALSE; @@ -173,7 +173,7 @@ PHP_FUNCTION(class_uses) } else { ce = Z_OBJCE_P(obj); } - + array_init(return_value); spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT TSRMLS_CC); } @@ -245,7 +245,7 @@ PHP_FUNCTION(class_uses) PHP_FUNCTION(spl_classes) { array_init(return_value); - + SPL_LIST_CLASSES(return_value, 0, 0, 0) } /* }}} */ @@ -266,7 +266,7 @@ static int spl_autoload(const char *class_name, const char * lc_name, int class_ { char *ptr = class_file; char *end = ptr + class_file_len; - + while ((ptr = memchr(ptr, '\\', (end - ptr))) != NULL) { *ptr = DEFAULT_SLASH; } @@ -294,7 +294,7 @@ static int spl_autoload(const char *class_name, const char * lc_name, int class_ } zend_execute(new_op_array TSRMLS_CC); - + destroy_op_array(new_op_array TSRMLS_CC); efree(new_op_array); if (!EG(exception)) { @@ -321,7 +321,7 @@ PHP_FUNCTION(spl_autoload) zval **original_return_value = EG(return_value_ptr_ptr); zend_op **original_opline_ptr = EG(opline_ptr); zend_op_array *original_active_op_array = EG(active_op_array); - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &class_name, &class_name_len, &file_exts, &file_exts_len) == FAILURE) { RETURN_FALSE; } @@ -480,7 +480,7 @@ PHP_FUNCTION(spl_autoload_register) return; } - if (ZEND_NUM_ARGS()) { + if (zcallable != NULL) { if (Z_TYPE_P(zcallable) == IS_STRING) { if (Z_STRLEN_P(zcallable) == sizeof("spl_autoload_call") - 1) { if (!zend_binary_strcasecmp(Z_STRVAL_P(zcallable), sizeof("spl_autoload_call"), "spl_autoload_call", sizeof("spl_autoload_call"))) { @@ -491,7 +491,7 @@ PHP_FUNCTION(spl_autoload_register) } } } - + if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &func_name_len, &fcc, &error TSRMLS_CC)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; @@ -542,7 +542,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - + lc_name = safe_emalloc(func_name_len, 1, sizeof(long) + 1); zend_str_tolower_copy(lc_name, func_name, func_name_len); efree(func_name); @@ -601,7 +601,7 @@ PHP_FUNCTION(spl_autoload_register) if (zend_hash_add(SPL_G(autoload_functions), lc_name, func_name_len+1, &alfi.func_ptr, sizeof(autoload_func_info), NULL) == FAILURE) { if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { Z_DELREF_P(alfi.obj); - } + } if (alfi.closure) { Z_DELREF_P(alfi.closure); } @@ -710,7 +710,7 @@ PHP_FUNCTION(spl_autoload_functions) if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!EG(autoload_func)) { if (zend_hash_find(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME), (void **) &fptr) == SUCCESS) { array_init(return_value); @@ -774,10 +774,10 @@ PHP_FUNCTION(spl_object_hash) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { return; } - + hash = emalloc(33); php_spl_object_hash(obj, hash TSRMLS_CC); - + RETVAL_STRING(hash, 0); } /* }}} */ @@ -810,7 +810,7 @@ PHPAPI void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/ int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */ { char *res; - + spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_PP(entry)); efree(*list); *list = res; diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index ca8076a95713c..d07cc0fe193bb 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1191,12 +1191,12 @@ SPL_METHOD(Array, __construct) intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|lC", &array, &ar_flags, &ce_get_iterator) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|lC!", &array, &ar_flags, &ce_get_iterator) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } - if (ZEND_NUM_ARGS() > 2) { + if (ce_get_iterator != NULL && ce_get_iterator != spl_ce_Iterator) { intern->ce_get_iterator = ce_get_iterator; } @@ -1456,7 +1456,7 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval_ptr, arg? 2 : 1, tmp, arg TSRMLS_CC); aht->nApplyCount--; } else { - if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE || !arg) { Z_TYPE_P(tmp) = IS_NULL; zval_ptr_dtor(&tmp); zend_throw_exception(spl_ce_BadMethodCallException, "Function expects exactly one argument", 0 TSRMLS_CC); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 1a417d0f5850a..fe85764e0caaa 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -79,9 +79,9 @@ static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */ if (intern->oth_handler && intern->oth_handler->dtor) { intern->oth_handler->dtor(intern TSRMLS_CC); } - + zend_object_std_dtor(&intern->std TSRMLS_CC); - + if (intern->_path) { efree(intern->_path); } @@ -98,7 +98,7 @@ static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */ } if (intern->u.dir.sub_path) { efree(intern->u.dir.sub_path); - } + } break; case SPL_FS_FILE: if (intern->u.file.stream) { @@ -134,13 +134,13 @@ static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */ } /* }}} */ /* {{{ spl_ce_dir_object_new */ -/* creates the object by - - allocating memory +/* creates the object by + - allocating memory - initializing the object members - storing the object - setting it's handlers - called from + called from - clone - new */ @@ -310,7 +310,7 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu /* avoid reference counting in debug mode, thus do it manually */ ZVAL_RESOURCE(&intern->u.file.zresource, php_stream_get_resource_id(intern->u.file.stream)); Z_SET_REFCOUNT(intern->u.file.zresource, 1); - + intern->u.file.delimiter = ','; intern->u.file.enclosure = '"'; intern->u.file.escape = '\\'; @@ -322,7 +322,7 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu /* {{{ spl_filesystem_object_clone */ /* Local zend_object_value creation (on stack) - Load the 'other' object + Load the 'other' object Create a new empty object (See spl_filesystem_object_new_ex) Open the directory Clone other members (properties) @@ -367,7 +367,7 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC) php_error_docref(NULL TSRMLS_CC, E_ERROR, "An object of class %s cannot be cloned", old_object->ce->name); break; } - + intern->file_class = source->file_class; intern->info_class = source->info_class; intern->oth = source->oth; @@ -386,7 +386,7 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC) void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, int len, int use_copy TSRMLS_DC) /* {{{ */ { char *p1, *p2; - + if (intern->file_name) { efree(intern->file_name); } @@ -410,7 +410,7 @@ void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, } else { intern->_path_len = 0; } - + if (intern->_path) { efree(intern->_path); } @@ -456,7 +456,7 @@ static spl_filesystem_object * spl_filesystem_object_create_info(spl_filesystem_ } else { spl_filesystem_info_set_filename(intern, file_path, file_path_len, use_copy TSRMLS_CC); } - + zend_restore_error_handling(&error_handling TSRMLS_CC); return intern; } /* }}} */ @@ -511,7 +511,7 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); Z_TYPE_P(return_value) = IS_OBJECT; - + spl_filesystem_object_get_file_name(source TSRMLS_CC); if (ce->constructor->common.scope != spl_ce_SplFileObject) { @@ -527,12 +527,12 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil intern->file_name_len = source->file_name_len; intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len TSRMLS_CC); intern->_path = estrndup(intern->_path, intern->_path_len); - + intern->u.file.open_mode = "r"; intern->u.file.open_mode_len = 1; - - if (ht && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sbr", - &intern->u.file.open_mode, &intern->u.file.open_mode_len, + + if (ht && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sbr", + &intern->u.file.open_mode, &intern->u.file.open_mode_len, &use_include_path, &intern->u.file.zcontext) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); intern->u.file.open_mode = NULL; @@ -541,7 +541,7 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil Z_TYPE_P(return_value) = IS_NULL; return NULL; } - + if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); zval_dtor(return_value); @@ -550,7 +550,7 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil } } break; - case SPL_FS_DIR: + case SPL_FS_DIR: zend_restore_error_handling(&error_handling TSRMLS_CC); zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Operation not supported"); return NULL; @@ -614,7 +614,7 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T if (intern->file_name) { pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1, &pnlen TSRMLS_CC); spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); - + if (path_len && path_len < intern->file_name_len) { add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1); } else { @@ -662,13 +662,13 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T zend_function *spl_filesystem_object_get_method_check(zval **object_ptr, char *method, int method_len, const struct _zend_literal *key TSRMLS_DC) /* {{{ */ { spl_filesystem_object *fsobj = zend_object_store_get_object(*object_ptr TSRMLS_CC); - + if (fsobj->u.dir.entry.d_name[0] == '\0' && fsobj->orig_path == NULL) { method = "_bad_state_ex"; method_len = sizeof("_bad_state_ex") - 1; key = NULL; } - + return zend_get_std_object_handlers()->get_method(object_ptr, method, method_len, key TSRMLS_CC); } /* }}} */ @@ -748,7 +748,7 @@ SPL_METHOD(DirectoryIterator, __construct) SPL_METHOD(DirectoryIterator, rewind) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -766,7 +766,7 @@ SPL_METHOD(DirectoryIterator, rewind) SPL_METHOD(DirectoryIterator, key) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -796,7 +796,7 @@ SPL_METHOD(DirectoryIterator, next) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -854,7 +854,7 @@ SPL_METHOD(DirectoryIterator, seek) SPL_METHOD(DirectoryIterator, valid) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -870,7 +870,7 @@ SPL_METHOD(SplFileInfo, getPath) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); char *path; int path_len; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -886,13 +886,13 @@ SPL_METHOD(SplFileInfo, getFilename) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); int path_len; - + if (zend_parse_parameters_none() == FAILURE) { return; } spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); - + if (path_len && path_len < intern->file_name_len) { RETURN_STRINGL(intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1); } else { @@ -906,7 +906,7 @@ SPL_METHOD(SplFileInfo, getFilename) SPL_METHOD(DirectoryIterator, getFilename) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1014,7 +1014,7 @@ SPL_METHOD(SplFileInfo, getBasename) RETURN_STRINGL(fname, flen, 0); } -/* }}}*/ +/* }}}*/ /* {{{ proto string DirectoryIterator::getBasename([string $suffix]) U Returns filename component of current dir entry */ @@ -1024,7 +1024,7 @@ SPL_METHOD(DirectoryIterator, getBasename) char *suffix = 0, *fname; int slen = 0; size_t flen; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &suffix, &slen) == FAILURE) { return; } @@ -1060,7 +1060,7 @@ SPL_METHOD(SplFileInfo, getPathname) SPL_METHOD(FilesystemIterator, key) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1079,7 +1079,7 @@ SPL_METHOD(FilesystemIterator, key) SPL_METHOD(FilesystemIterator, current) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1102,7 +1102,7 @@ SPL_METHOD(FilesystemIterator, current) SPL_METHOD(DirectoryIterator, isDot) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1116,8 +1116,8 @@ SPL_METHOD(DirectoryIterator, isDot) /* zend_replace_error_handling() is used to throw exceptions in case the constructor fails. Here we use this to ensure the object has a valid directory resource. - - When the constructor gets called the object is already created + + When the constructor gets called the object is already created by the engine, so we must only call 'additional' initializations. */ SPL_METHOD(SplFileInfo, __construct) @@ -1135,11 +1135,11 @@ SPL_METHOD(SplFileInfo, __construct) } intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + spl_filesystem_info_set_filename(intern, path, len, 1 TSRMLS_CC); zend_restore_error_handling(&error_handling TSRMLS_CC); - + /* intern->type = SPL_FS_INFO; already set */ } /* }}} */ @@ -1244,7 +1244,7 @@ SPL_METHOD(SplFileInfo, getLinkTarget) int ret; char buff[MAXPATHLEN]; zend_error_handling error_handling; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1292,7 +1292,7 @@ SPL_METHOD(SplFileInfo, getRealPath) char buff[MAXPATHLEN]; char *filename; zend_error_handling error_handling; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1302,10 +1302,10 @@ SPL_METHOD(SplFileInfo, getRealPath) if (intern->type == SPL_FS_DIR && !intern->file_name && intern->u.dir.entry.d_name[0]) { spl_filesystem_object_get_file_name(intern TSRMLS_CC); } - + if (intern->orig_path) { filename = intern->orig_path; - } else { + } else { filename = intern->file_name; } @@ -1343,7 +1343,7 @@ SPL_METHOD(SplFileInfo, setFileClass) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = spl_ce_SplFileObject; zend_error_handling error_handling; - + zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { @@ -1361,7 +1361,7 @@ SPL_METHOD(SplFileInfo, setInfoClass) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = spl_ce_SplFileInfo; zend_error_handling error_handling; - + zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { @@ -1379,7 +1379,7 @@ SPL_METHOD(SplFileInfo, getFileInfo) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = intern->info_class; zend_error_handling error_handling; - + zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { @@ -1397,7 +1397,7 @@ SPL_METHOD(SplFileInfo, getPathInfo) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = intern->info_class; zend_error_handling error_handling; - + zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { @@ -1458,7 +1458,7 @@ SPL_METHOD(FilesystemIterator, rewind) SPL_METHOD(FilesystemIterator, getFlags) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1514,11 +1514,11 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); spl_filesystem_object *subdir; char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + spl_filesystem_object_get_file_name(intern TSRMLS_CC); if (SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) { @@ -1553,7 +1553,7 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren) SPL_METHOD(RecursiveDirectoryIterator, getSubPath) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1574,7 +1574,7 @@ SPL_METHOD(RecursiveDirectoryIterator, getSubPathname) char *sub_name; int len; char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1610,7 +1610,7 @@ SPL_METHOD(GlobIterator, __construct) SPL_METHOD(GlobIterator, count) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1665,7 +1665,7 @@ zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval iterator->current = object; } zval_add_ref(&object); - + return (zend_object_iterator*)iterator; } /* }}} */ @@ -1700,7 +1700,7 @@ static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC) static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) { spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter; - + *data = &iterator->current; } /* }}} */ @@ -1718,7 +1718,7 @@ static void spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zval * static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC) { spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter); - + object->u.dir.index++; spl_filesystem_dir_read(object TSRMLS_CC); if (object->file_name) { @@ -1732,7 +1732,7 @@ static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC) { spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter); - + object->u.dir.index = 0; if (object->u.dir.dirp) { php_stream_rewinddir(object->u.dir.dirp); @@ -1802,7 +1802,7 @@ static void spl_filesystem_tree_it_move_forward(zend_object_iterator *iter TSRML { spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter; spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator); - + object->u.dir.index++; do { spl_filesystem_dir_read(object TSRMLS_CC); @@ -1823,7 +1823,7 @@ static void spl_filesystem_tree_it_rewind(zend_object_iterator *iter TSRMLS_DC) { spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter; spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator); - + object->u.dir.index = 0; if (object->u.dir.dirp) { php_stream_rewinddir(object->u.dir.dirp); @@ -1867,7 +1867,7 @@ zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zva iterator->intern.funcs = &spl_filesystem_tree_it_funcs; } zval_add_ref(&object); - + return (zend_object_iterator*)iterator; } /* }}} */ @@ -1920,7 +1920,7 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TS /* {{{ declare method parameters */ /* supply a name and default to call by parameter */ -ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0) ZEND_ARG_INFO(0, file_name) ZEND_END_ARG_INFO() @@ -1979,11 +1979,11 @@ static const zend_function_entry spl_SplFileInfo_functions[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_dir_it_seek, 0) +ZEND_BEGIN_ARG_INFO(arginfo_dir_it_seek, 0) ZEND_ARG_INFO(0, position) ZEND_END_ARG_INFO(); @@ -2005,7 +2005,7 @@ static const zend_function_entry spl_DirectoryIterator_functions[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir___construct, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir___construct, 0, 0, 1) ZEND_ARG_INFO(0, path) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() @@ -2054,7 +2054,7 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0; spl_filesystem_file_free_line(intern TSRMLS_CC); - + if (php_stream_eof(intern->u.file.stream)) { if (!silent) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name); @@ -2082,7 +2082,7 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS line_len = strcspn(buf, "\r\n"); buf[line_len] = '\0'; } - + intern->u.file.current_line = buf; intern->u.file.current_line_len = line_len; } @@ -2103,7 +2103,7 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function zval ***params = (zval***)safe_emalloc(num_args, sizeof(zval**), 0); params[0] = &zresource_ptr; - + if (arg2) { params[1] = &arg2; } @@ -2129,7 +2129,7 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function fcic.object_ptr = NULL; result = zend_call_function(&fci, &fcic TSRMLS_CC); - + if (result == FAILURE) { RETVAL_FALSE; } else { @@ -2155,11 +2155,11 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, char escape, zval *return_value TSRMLS_DC) /* {{{ */ { int ret = SUCCESS; - + do { ret = spl_filesystem_file_read(intern, 1 TSRMLS_CC); } while (ret == SUCCESS && !intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY)); - + if (ret == SUCCESS) { size_t buf_len = intern->u.file.current_line_len; char *buf = estrndup(intern->u.file.current_line, buf_len); @@ -2233,7 +2233,7 @@ static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRML if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) && zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 1) { zval ** first = Z_ARRVAL_P(intern->u.file.current_zval)->pListHead->pData; - + return Z_TYPE_PP(first) == IS_STRING && Z_STRLEN_PP(first) == 0; } return zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 0; @@ -2256,7 +2256,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object spl_filesystem_file_free_line(intern TSRMLS_CC); ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC); } - + return ret; } /* }}} */ @@ -2290,16 +2290,16 @@ SPL_METHOD(SplFileObject, __construct) intern->u.file.open_mode = NULL; intern->u.file.open_mode_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|sbr", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|sbr", &intern->file_name, &intern->file_name_len, - &intern->u.file.open_mode, &intern->u.file.open_mode_len, - &use_include_path, &intern->u.file.zcontext) == FAILURE) { + &intern->u.file.open_mode, &intern->u.file.open_mode_len, + &use_include_path, &intern->u.file.zcontext) == FAILURE) { intern->u.file.open_mode = NULL; intern->file_name = NULL; zend_restore_error_handling(&error_handling TSRMLS_CC); return; } - + if (intern->u.file.open_mode == NULL) { intern->u.file.open_mode = "r"; intern->u.file.open_mode_len = 1; @@ -2364,7 +2364,7 @@ SPL_METHOD(SplTempFileObject, __construct) intern->u.file.open_mode = "wb"; intern->u.file.open_mode_len = 1; intern->u.file.zcontext = NULL; - + if (spl_filesystem_file_open(intern, 0, 0 TSRMLS_CC) == SUCCESS) { intern->_path_len = 0; intern->_path = estrndup("", 0); @@ -2377,7 +2377,7 @@ SPL_METHOD(SplTempFileObject, __construct) SPL_METHOD(SplFileObject, rewind) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2390,7 +2390,7 @@ SPL_METHOD(SplFileObject, rewind) SPL_METHOD(SplFileObject, eof) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2403,7 +2403,7 @@ SPL_METHOD(SplFileObject, eof) SPL_METHOD(SplFileObject, valid) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2420,7 +2420,7 @@ SPL_METHOD(SplFileObject, valid) SPL_METHOD(SplFileObject, fgets) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2436,7 +2436,7 @@ SPL_METHOD(SplFileObject, fgets) SPL_METHOD(SplFileObject, current) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2457,7 +2457,7 @@ SPL_METHOD(SplFileObject, current) SPL_METHOD(SplFileObject, key) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2474,7 +2474,7 @@ SPL_METHOD(SplFileObject, key) SPL_METHOD(SplFileObject, next) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2526,7 +2526,7 @@ SPL_METHOD(SplFileObject, setMaxLineLen) zend_throw_exception_ex(spl_ce_DomainException, 0 TSRMLS_CC, "Maximum line length must be greater than or equal zero"); return; } - + intern->u.file.max_line_len = max_len; } /* }}} */ @@ -2535,7 +2535,7 @@ SPL_METHOD(SplFileObject, setMaxLineLen) SPL_METHOD(SplFileObject, getMaxLineLen) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2550,7 +2550,7 @@ SPL_METHOD(SplFileObject, hasChildren) if (zend_parse_parameters_none() == FAILURE) { return; } - + RETURN_FALSE; } /* }}} */ @@ -2581,36 +2581,35 @@ SPL_METHOD(SplFileObject, fgetcsv) char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape; char *delim = NULL, *enclo = NULL, *esc = NULL; int d_len = 0, e_len = 0, esc_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|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 TSRMLS_CC, E_WARNING, "escape must be a character"); - RETURN_FALSE; - } - escape = esc[0]; - /* no break */ - case 2: - if (e_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 1: - if (d_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 0: - break; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) { + return; + } + + if(esc) { + if (esc_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character"); + RETURN_FALSE; + } + escape = esc[0]; + } + + if(enclo) { + if (e_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); + RETURN_FALSE; } - spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value TSRMLS_CC); + enclosure = enclo[0]; } + + if(delim) { + if (d_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); + RETURN_FALSE; + } + delimiter = delim[0]; + } + spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value TSRMLS_CC); } /* }}} */ @@ -2623,31 +2622,28 @@ SPL_METHOD(SplFileObject, fputcsv) char *delim = NULL, *enclo = NULL; int d_len = 0, e_len = 0, ret; zval *fields = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &fields, &delim, &d_len, &enclo, &e_len) == SUCCESS) { - switch(ZEND_NUM_ARGS()) - { - case 3: - if (e_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 2: - if (d_len != 1) { - php_error_docref(NULL TSRMLS_CC, 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() TSRMLS_CC, "a|ss", &fields, &delim, &d_len, &enclo, &e_len) == FAILURE) { + return; + } + + if(enclo) { + if (e_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); + RETURN_FALSE; } - ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape TSRMLS_CC); - RETURN_LONG(ret); + enclosure = enclo[0]; } + + if(delim) { + if (d_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); + RETURN_FALSE; + } + delimiter = delim[0]; + } + ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape TSRMLS_CC); + RETURN_LONG(ret); } /* }}} */ @@ -2659,38 +2655,37 @@ SPL_METHOD(SplFileObject, setCsvControl) char delimiter = ',', enclosure = '"', escape='\\'; char *delim = NULL, *enclo = NULL, *esc = NULL; int d_len = 0, e_len = 0, esc_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|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 TSRMLS_CC, E_WARNING, "escape must be a character"); - RETURN_FALSE; - } - escape = esc[0]; - /* no break */ - case 2: - if (e_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 1: - if (d_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 0: - break; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) { + return; + } + if(esc) { + if (esc_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character"); + RETURN_FALSE; } - intern->u.file.delimiter = delimiter; - intern->u.file.enclosure = enclosure; - intern->u.file.escape = escape; + escape = esc[0]; } + + if(enclo) { + if (e_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); + RETURN_FALSE; + } + enclosure = enclo[0]; + } + + if(delim) { + if (d_len != 1) { + php_error_docref(NULL TSRMLS_CC, 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; } /* }}} */ @@ -2702,7 +2697,7 @@ SPL_METHOD(SplFileObject, getCsvControl) char delimiter[2], enclosure[2]; array_init(return_value); - + delimiter[0] = intern->u.file.delimiter; delimiter[1] = '\0'; enclosure[0] = intern->u.file.enclosure; @@ -2731,7 +2726,7 @@ SPL_METHOD(SplFileObject, fflush) Return current file position */ SPL_METHOD(SplFileObject, ftell) { - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); long ret = php_stream_tell(intern->u.file.stream); if (ret == -1) { @@ -2832,20 +2827,23 @@ SPL_METHOD(SplFileObject, fwrite) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); char *str; int str_len; - long length = 0; + long length = LONG_MAX; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &length) == FAILURE) { return; } - if (ZEND_NUM_ARGS() > 1) { - str_len = MAX(0, MIN(length, str_len)); + 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)); } /* }}} */ /* {{{ proto bool SplFileObject::fstat() @@ -2859,7 +2857,7 @@ SPL_METHOD(SplFileObject, ftruncate) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); long size; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size) == FAILURE) { return; } @@ -2868,7 +2866,7 @@ SPL_METHOD(SplFileObject, ftruncate) zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't truncate file %s", intern->file_name); RETURN_FALSE; } - + RETURN_BOOL(0 == php_stream_truncate_set_size(intern->u.file.stream, size)); } /* }}} */ @@ -2878,17 +2876,17 @@ SPL_METHOD(SplFileObject, seek) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); long line_pos; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &line_pos) == FAILURE) { return; } if (line_pos < 0) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't seek file %s to negative line %ld", intern->file_name, line_pos); - RETURN_FALSE; + RETURN_FALSE; } - + spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC); - + while(intern->u.file.current_line_num < line_pos) { if (spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC) == FAILURE) { break; @@ -2924,34 +2922,34 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fputcsv, 0, 0, 1) ZEND_ARG_INFO(0, enclosure) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1) ZEND_ARG_INFO(0, operation) ZEND_ARG_INFO(1, wouldblock) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1) ZEND_ARG_INFO(0, pos) ZEND_ARG_INFO(0, whence) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0) ZEND_ARG_INFO(0, allowable_tags) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 1, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 1, 0, 1) ZEND_ARG_INFO(0, format) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, length) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1) ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1) ZEND_ARG_INFO(0, line_pos) ZEND_END_ARG_INFO() @@ -3039,7 +3037,7 @@ PHP_MINIT_FUNCTION(spl_directory) REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, FilesystemIterator, spl_filesystem_object_new, spl_RecursiveDirectoryIterator_functions); REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator); - + memcpy(&spl_filesystem_object_check_handlers, &spl_filesystem_object_handlers, sizeof(zend_object_handlers)); spl_filesystem_object_check_handlers.get_method = spl_filesystem_object_get_method_check; @@ -3056,7 +3054,7 @@ PHP_MINIT_FUNCTION(spl_directory) REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_AHEAD", SPL_FILE_OBJECT_READ_AHEAD); REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "SKIP_EMPTY", SPL_FILE_OBJECT_SKIP_EMPTY); REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_CSV", SPL_FILE_OBJECT_READ_CSV); - + REGISTER_SPL_SUB_CLASS_EX(SplTempFileObject, SplFileObject, spl_filesystem_object_new_check, spl_SplTempFileObject_functions); return SUCCESS; } diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 30532756cb6d6..849473ccdfc4c 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -161,7 +161,7 @@ static int spl_recursive_it_valid_ex(spl_recursive_it_object *object, zval *zthi { zend_object_iterator *sub_iter; int level = object->level; - + while (level >=0) { sub_iter = object->iterators[level].iterator; if (sub_iter->funcs->valid(sub_iter TSRMLS_CC) == SUCCESS) { @@ -179,7 +179,7 @@ static int spl_recursive_it_valid_ex(spl_recursive_it_object *object, zval *zthi static int spl_recursive_it_valid(zend_object_iterator *iter TSRMLS_DC) { spl_recursive_it_object *object = (spl_recursive_it_object*)iter->data; - + return spl_recursive_it_valid_ex(object, ((spl_recursive_it_iterator*)iter)->zobject TSRMLS_CC); } @@ -187,7 +187,7 @@ static void spl_recursive_it_get_current_data(zend_object_iterator *iter, zval * { spl_recursive_it_object *object = (spl_recursive_it_object*)iter->data; zend_object_iterator *sub_iter = object->iterators[object->level].iterator; - + sub_iter->funcs->get_current_data(sub_iter, data TSRMLS_CC); } @@ -230,7 +230,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv if (iterator->funcs->valid(iterator TSRMLS_CC) == FAILURE) { break; } - object->iterators[object->level].state = RS_TEST; + object->iterators[object->level].state = RS_TEST; /* break; */ case RS_TEST: ce = object->iterators[object->level].ce; @@ -374,7 +374,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv static void spl_recursive_it_rewind_ex(spl_recursive_it_object *object, zval *zthis TSRMLS_DC) { zend_object_iterator *sub_iter; - + if (!object->iterators) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "The %s instance wasn't initialized properly", Z_OBJCE_P(zthis)->name); } @@ -584,7 +584,7 @@ SPL_METHOD(RecursiveIteratorIterator, __construct) SPL_METHOD(RecursiveIteratorIterator, rewind) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -597,7 +597,7 @@ SPL_METHOD(RecursiveIteratorIterator, rewind) SPL_METHOD(RecursiveIteratorIterator, valid) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -611,7 +611,7 @@ SPL_METHOD(RecursiveIteratorIterator, key) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_object_iterator *iterator = object->iterators[object->level].iterator; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -630,7 +630,7 @@ SPL_METHOD(RecursiveIteratorIterator, current) spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_object_iterator *iterator = object->iterators[object->level].iterator; zval **data; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -646,7 +646,7 @@ SPL_METHOD(RecursiveIteratorIterator, current) SPL_METHOD(RecursiveIteratorIterator, next) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -659,11 +659,11 @@ SPL_METHOD(RecursiveIteratorIterator, next) SPL_METHOD(RecursiveIteratorIterator, getDepth) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (zend_parse_parameters_none() == FAILURE) { return; } - + RETURN_LONG(object->level); } /* }}} */ @@ -673,7 +673,7 @@ SPL_METHOD(RecursiveIteratorIterator, getSubIterator) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); long level = object->level; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &level) == FAILURE) { return; } @@ -689,11 +689,11 @@ SPL_METHOD(RecursiveIteratorIterator, getInnerIterator) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); long level = object->level; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + RETURN_ZVAL(object->iterators[level].zobject, 1, 0); } /* }}} */ @@ -724,7 +724,7 @@ SPL_METHOD(RecursiveIteratorIterator, callHasChildren) spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = object->iterators[object->level].ce; zval *retval, *zobject; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -749,7 +749,7 @@ SPL_METHOD(RecursiveIteratorIterator, callGetChildren) spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = object->iterators[object->level].ce; zval *retval, *zobject; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -801,7 +801,7 @@ SPL_METHOD(RecursiveIteratorIterator, setMaxDepth) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); long max_depth = -1; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &max_depth) == FAILURE) { return; } @@ -821,7 +821,7 @@ SPL_METHOD(RecursiveIteratorIterator, getMaxDepth) if (zend_parse_parameters_none() == FAILURE) { return; } - + if (object->max_depth == -1) { RETURN_FALSE; } else { @@ -936,7 +936,7 @@ static zend_object_value spl_RecursiveTreeIterator_new(zend_class_entry *class_t } /* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_recursive_it___construct, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_recursive_it___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) ZEND_ARG_INFO(0, mode) ZEND_ARG_INFO(0, flags) @@ -979,7 +979,7 @@ static void spl_recursive_tree_iterator_get_prefix(spl_recursive_it_object *obje int level; smart_str_appendl(&str, object->prefix[0].c, object->prefix[0].len); - + for (level = 0; level < object->level; ++level) { zend_call_method_with_0_params(&object->iterators[level].zobject, object->iterators[level].ce, NULL, "hasnext", &has_next); if (has_next) { @@ -1048,7 +1048,7 @@ SPL_METHOD(RecursiveTreeIterator, setPrefixPart) long part; char* prefix; int prefix_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &part, &prefix, &prefix_len) == FAILURE) { return; } @@ -1056,7 +1056,7 @@ SPL_METHOD(RecursiveTreeIterator, setPrefixPart) zend_throw_exception_ex(spl_ce_OutOfRangeException, 0 TSRMLS_CC, "Use RecursiveTreeIterator::PREFIX_* constant"); return; } - + smart_str_free(&object->prefix[part]); smart_str_appendl(&object->prefix[part], prefix, prefix_len); } /* }}} */ @@ -1098,7 +1098,7 @@ SPL_METHOD(RecursiveTreeIterator, getEntry) if (zend_parse_parameters_none() == FAILURE) { return; } - + spl_recursive_tree_iterator_get_entry(object, return_value TSRMLS_CC); } /* }}} */ @@ -1111,7 +1111,7 @@ SPL_METHOD(RecursiveTreeIterator, getPostfix) if (zend_parse_parameters_none() == FAILURE) { return; } - + spl_recursive_tree_iterator_get_postfix(object, return_value TSRMLS_CC); } /* }}} */ @@ -1123,7 +1123,7 @@ SPL_METHOD(RecursiveTreeIterator, current) zval prefix, entry, postfix; char *str, *ptr; size_t str_len; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1179,7 +1179,7 @@ SPL_METHOD(RecursiveTreeIterator, key) zval prefix, key, postfix, key_copy; char *str, *ptr; size_t str_len; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1227,7 +1227,7 @@ SPL_METHOD(RecursiveTreeIterator, key) RETVAL_STRINGL(str, str_len, 0); } /* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_recursive_tree_it___construct, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_recursive_tree_it___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) ZEND_ARG_INFO(0, flags) ZEND_ARG_INFO(0, caching_it_flags) @@ -1331,14 +1331,14 @@ int spl_dual_it_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) if (call_user_function_ex(EG(function_table), NULL, &func, &retval_ptr, arg_count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { RETURN_ZVAL(retval_ptr, 0, 1); - + success = SUCCESS; } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to call %s::%s()", intern->inner.ce->name, method); success = FAILURE; } - efree(func_params); + efree(func_params); return success; } #endif @@ -1362,7 +1362,7 @@ static inline int spl_cit_check_flags(int flags) cnt += (flags & CIT_TOSTRING_USE_KEY) ? 1 : 0; cnt += (flags & CIT_TOSTRING_USE_CURRENT) ? 1 : 0; cnt += (flags & CIT_TOSTRING_USE_INNER) ? 1 : 0; - + return cnt <= 1 ? SUCCESS : FAILURE; } @@ -1375,7 +1375,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z zend_error_handling error_handling; intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - + if (intern->dit_type != DIT_Unknown) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s::getIterator() must be called exactly once per instance", ce_base->name); return NULL; @@ -1432,8 +1432,8 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z } ce = Z_OBJCE_P(zobject); if (!instanceof_function(ce, zend_ce_iterator TSRMLS_CC)) { - if (ZEND_NUM_ARGS() > 1) { - if (zend_lookup_class(class_name, class_name_len, &pce_cast TSRMLS_CC) == FAILURE + if (class_name != NULL) { + if (zend_lookup_class(class_name, class_name_len, &pce_cast TSRMLS_CC) == FAILURE || !instanceof_function(ce, *pce_cast TSRMLS_CC) || !(*pce_cast)->get_iterator ) { @@ -1540,21 +1540,21 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return intern; } -/* {{{ proto void FilterIterator::__construct(Iterator it) +/* {{{ proto void FilterIterator::__construct(Iterator it) Create an Iterator from another iterator */ SPL_METHOD(FilterIterator, __construct) { spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_FilterIterator, zend_ce_iterator, DIT_FilterIterator); } /* }}} */ -/* {{{ proto void CallbackFilterIterator::__construct(Iterator it, callback) +/* {{{ proto void CallbackFilterIterator::__construct(Iterator it, callback) Create an Iterator from another iterator */ SPL_METHOD(CallbackFilterIterator, __construct) { spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_CallbackFilterIterator, zend_ce_iterator, DIT_CallbackFilterIterator); } /* }}} */ -/* {{{ proto Iterator FilterIterator::getInnerIterator() +/* {{{ proto Iterator FilterIterator::getInnerIterator() proto Iterator CachingIterator::getInnerIterator() proto Iterator LimitIterator::getInnerIterator() proto Iterator ParentIterator::getInnerIterator() @@ -1562,11 +1562,11 @@ SPL_METHOD(CallbackFilterIterator, __construct) SPL_METHOD(dual_it, getInnerIterator) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); if (intern->inner.zobject) { @@ -1671,13 +1671,13 @@ static inline void spl_dual_it_next(spl_dual_it_object *intern, int do_free TSRM SPL_METHOD(dual_it, rewind) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); - + spl_dual_it_rewind(intern TSRMLS_CC); spl_dual_it_fetch(intern, 1 TSRMLS_CC); } /* }}} */ @@ -1694,7 +1694,7 @@ SPL_METHOD(dual_it, valid) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); RETURN_BOOL(intern->current.data); @@ -1715,7 +1715,7 @@ SPL_METHOD(dual_it, key) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); if (intern->current.key) { @@ -1735,7 +1735,7 @@ SPL_METHOD(dual_it, key) SPL_METHOD(dual_it, current) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1756,7 +1756,7 @@ SPL_METHOD(dual_it, current) SPL_METHOD(dual_it, next) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1805,7 +1805,7 @@ static inline void spl_filter_it_next(zval *zthis, spl_dual_it_object *intern TS SPL_METHOD(FilterIterator, rewind) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1819,7 +1819,7 @@ SPL_METHOD(FilterIterator, rewind) SPL_METHOD(FilterIterator, next) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1849,7 +1849,7 @@ SPL_METHOD(RecursiveFilterIterator, hasChildren) { spl_dual_it_object *intern; zval *retval; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1870,7 +1870,7 @@ SPL_METHOD(RecursiveFilterIterator, getChildren) { spl_dual_it_object *intern; zval *retval; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1892,7 +1892,7 @@ SPL_METHOD(RecursiveCallbackFilterIterator, getChildren) { spl_dual_it_object *intern; zval *retval; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -1915,7 +1915,7 @@ SPL_METHOD(ParentIterator, __construct) } /* }}} */ #if HAVE_PCRE || HAVE_BUNDLED_PCRE -/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int mode [, int flags [, int preg_flags]]]) +/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int mode [, int flags [, int preg_flags]]]) Create an RegexIterator from another iterator and a regular expression */ SPL_METHOD(RegexIterator, __construct) { @@ -1972,13 +1972,13 @@ SPL_METHOD(RegexIterator, accept) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); - + if (intern->current.data == NULL) { RETURN_FALSE; } - + if (intern->u.regex.flags & REGIT_USE_KEY) { subject_ptr = intern->current.key; } else { @@ -2010,7 +2010,7 @@ SPL_METHOD(RegexIterator, accept) } zval_ptr_dtor(&intern->current.data); ALLOC_INIT_ZVAL(intern->current.data); - php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount, + php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount, intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC); count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data)); RETVAL_BOOL(count > 0); @@ -2037,7 +2037,7 @@ SPL_METHOD(RegexIterator, accept) replacement = &tmp_replacement; } result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC); - + if (intern->u.regex.flags & REGIT_USE_KEY) { zval_ptr_dtor(&intern->current.key); MAKE_STD_ZVAL(intern->current.key); @@ -2085,9 +2085,9 @@ SPL_METHOD(RegexIterator, getMode) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); - + RETURN_LONG(intern->u.regex.mode); } /* }}} */ @@ -2106,7 +2106,7 @@ SPL_METHOD(RegexIterator, setMode) zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "Illegal mode %ld", mode); return;/* NULL */ } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); intern->u.regex.mode = mode; @@ -2121,9 +2121,9 @@ SPL_METHOD(RegexIterator, getFlags) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); - + RETURN_LONG(intern->u.regex.flags); } /* }}} */ @@ -2137,7 +2137,7 @@ SPL_METHOD(RegexIterator, setFlags) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags) == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); intern->u.regex.flags = flags; @@ -2148,11 +2148,11 @@ SPL_METHOD(RegexIterator, setFlags) SPL_METHOD(RegexIterator, getPregFlags) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); if (intern->u.regex.use_flags) { @@ -2172,14 +2172,14 @@ SPL_METHOD(RegexIterator, setPregFlags) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &preg_flags) == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); intern->u.regex.preg_flags = preg_flags; intern->u.regex.use_flags = 1; } /* }}} */ -/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string regex [, int mode [, int flags [, int preg_flags]]]) +/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string regex [, int mode [, int flags [, int preg_flags]]]) Create an RecursiveRegexIterator from another recursive iterator and a regular expression */ SPL_METHOD(RecursiveRegexIterator, __construct) { @@ -2192,7 +2192,7 @@ SPL_METHOD(RecursiveRegexIterator, getChildren) { spl_dual_it_object *intern; zval *retval, *regex; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2238,7 +2238,7 @@ static void spl_dual_it_free_storage(void *_object TSRMLS_DC) if (object->inner.zobject) { zval_ptr_dtor(&object->inner.zobject); } - + if (object->dit_type == DIT_AppendIterator) { object->u.append.iterator->funcs->dtor(object->u.append.iterator TSRMLS_CC); if (object->u.append.zarrayit) { @@ -2301,7 +2301,7 @@ static zend_object_value spl_dual_it_new(zend_class_entry *class_type TSRMLS_DC) } /* }}} */ -ZEND_BEGIN_ARG_INFO(arginfo_filter_it___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_filter_it___construct, 0) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_END_ARG_INFO(); @@ -2317,7 +2317,7 @@ static const zend_function_entry spl_funcs_FilterIterator[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO(arginfo_callback_filter_it___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_callback_filter_it___construct, 0) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO(); @@ -2328,7 +2328,7 @@ static const zend_function_entry spl_funcs_CallbackFilterIterator[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO(arginfo_recursive_callback_filter_it___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_recursive_callback_filter_it___construct, 0) ZEND_ARG_OBJ_INFO(0, iterator, RecursiveIterator, 0) ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO(); @@ -2340,7 +2340,7 @@ static const zend_function_entry spl_funcs_RecursiveCallbackFilterIterator[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO(arginfo_parent_it___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_parent_it___construct, 0) ZEND_ARG_OBJ_INFO(0, iterator, RecursiveIterator, 0) ZEND_END_ARG_INFO(); @@ -2358,7 +2358,7 @@ static const zend_function_entry spl_funcs_ParentIterator[] = { }; #if HAVE_PCRE || HAVE_BUNDLED_PCRE -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it___construct, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it___construct, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_ARG_INFO(0, regex) ZEND_ARG_INFO(0, mode) @@ -2366,15 +2366,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it___construct, 0, 0, 2) ZEND_ARG_INFO(0, preg_flags) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_mode, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_mode, 0, 0, 1) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_flags, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_flags, 0, 0, 1) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_preg_flags, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_preg_flags, 0, 0, 1) ZEND_ARG_INFO(0, preg_flags) ZEND_END_ARG_INFO(); @@ -2391,7 +2391,7 @@ static const zend_function_entry spl_funcs_RegexIterator[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO_EX(arginfo_rec_regex_it___construct, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_rec_regex_it___construct, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, iterator, RecursiveIterator, 0) ZEND_ARG_INFO(0, regex) ZEND_ARG_INFO(0, mode) @@ -2464,7 +2464,7 @@ SPL_METHOD(LimitIterator, __construct) spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_LimitIterator, zend_ce_iterator, DIT_LimitIterator); } /* }}} */ -/* {{{ proto void LimitIterator::rewind() +/* {{{ proto void LimitIterator::rewind() Rewind the iterator to the specified starting offset */ SPL_METHOD(LimitIterator, rewind) { @@ -2526,7 +2526,7 @@ SPL_METHOD(LimitIterator, getPosition) RETURN_LONG(intern->current.pos); } /* }}} */ -ZEND_BEGIN_ARG_INFO(arginfo_seekable_it_seek, 0) +ZEND_BEGIN_ARG_INFO(arginfo_seekable_it_seek, 0) ZEND_ARG_INFO(0, position) ZEND_END_ARG_INFO(); @@ -2535,13 +2535,13 @@ static const zend_function_entry spl_funcs_SeekableIterator[] = { PHP_FE_END }; -ZEND_BEGIN_ARG_INFO_EX(arginfo_limit_it___construct, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_limit_it___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_ARG_INFO(0, offset) ZEND_ARG_INFO(0, count) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(arginfo_limit_it_seek, 0) +ZEND_BEGIN_ARG_INFO(arginfo_limit_it_seek, 0) ZEND_ARG_INFO(0, position) ZEND_END_ARG_INFO(); @@ -2647,7 +2647,7 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC) zval_copy_ctor(intern->u.caching.zstr); } } - spl_dual_it_next(intern, 0 TSRMLS_CC); + spl_dual_it_next(intern, 0 TSRMLS_CC); } else { intern->u.caching.flags &= ~CIT_VALID; } @@ -2672,7 +2672,7 @@ SPL_METHOD(CachingIterator, __construct) SPL_METHOD(CachingIterator, rewind) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2687,7 +2687,7 @@ SPL_METHOD(CachingIterator, rewind) SPL_METHOD(CachingIterator, valid) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2702,7 +2702,7 @@ SPL_METHOD(CachingIterator, valid) SPL_METHOD(CachingIterator, next) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2717,7 +2717,7 @@ SPL_METHOD(CachingIterator, next) SPL_METHOD(CachingIterator, hasNext) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -2804,7 +2804,7 @@ SPL_METHOD(CachingIterator, offsetGet) zend_error(E_NOTICE, "Undefined index: %s", arKey); return; } - + RETURN_ZVAL(*value, 1, 0); } /* }}} */ @@ -2839,14 +2839,14 @@ SPL_METHOD(CachingIterator, offsetExists) spl_dual_it_object *intern; char *arKey; uint nKeyLength; - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); return; } - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { return; } @@ -2860,11 +2860,11 @@ SPL_METHOD(CachingIterator, offsetExists) SPL_METHOD(CachingIterator, getCache) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { @@ -2885,7 +2885,7 @@ SPL_METHOD(CachingIterator, getFlags) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); RETURN_LONG(intern->u.caching.flags); @@ -2934,7 +2934,7 @@ SPL_METHOD(CachingIterator, count) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { @@ -2946,12 +2946,12 @@ SPL_METHOD(CachingIterator, count) } /* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_it___construct, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_it___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(arginfo_caching_it_setFlags, 0) +ZEND_BEGIN_ARG_INFO(arginfo_caching_it_setFlags, 0) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO(); @@ -3001,7 +3001,7 @@ SPL_METHOD(RecursiveCachingIterator, hasChildren) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); RETURN_BOOL(intern->u.caching.zchildren); @@ -3012,7 +3012,7 @@ SPL_METHOD(RecursiveCachingIterator, hasChildren) SPL_METHOD(RecursiveCachingIterator, getChildren) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3026,7 +3026,7 @@ SPL_METHOD(RecursiveCachingIterator, getChildren) } } /* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_rec_it___construct, 0, ZEND_RETURN_VALUE, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_rec_it___construct, 0, ZEND_RETURN_VALUE, 1) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO(); @@ -3045,7 +3045,7 @@ SPL_METHOD(IteratorIterator, __construct) spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_IteratorIterator, zend_ce_traversable, DIT_IteratorIterator); } /* }}} */ -ZEND_BEGIN_ARG_INFO(arginfo_iterator_it___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_iterator_it___construct, 0) ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) ZEND_END_ARG_INFO(); @@ -3082,7 +3082,7 @@ SPL_METHOD(NoRewindIterator, rewind) SPL_METHOD(NoRewindIterator, valid) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3096,7 +3096,7 @@ SPL_METHOD(NoRewindIterator, valid) SPL_METHOD(NoRewindIterator, key) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3116,7 +3116,7 @@ SPL_METHOD(NoRewindIterator, current) { spl_dual_it_object *intern; zval **data; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3133,7 +3133,7 @@ SPL_METHOD(NoRewindIterator, current) SPL_METHOD(NoRewindIterator, next) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3142,7 +3142,7 @@ SPL_METHOD(NoRewindIterator, next) intern->inner.iterator->funcs->move_forward(intern->inner.iterator TSRMLS_CC); } /* }}} */ -ZEND_BEGIN_ARG_INFO(arginfo_norewind_it___construct, 0) +ZEND_BEGIN_ARG_INFO(arginfo_norewind_it___construct, 0) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_END_ARG_INFO(); @@ -3169,7 +3169,7 @@ SPL_METHOD(InfiniteIterator, __construct) SPL_METHOD(InfiniteIterator, next) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3336,13 +3336,13 @@ SPL_METHOD(AppendIterator, append) SPL_METHOD(AppendIterator, rewind) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); - + intern->u.append.iterator->funcs->rewind(intern->u.append.iterator TSRMLS_CC); if (spl_append_it_next_iterator(intern TSRMLS_CC) == SUCCESS) { spl_append_it_fetch(intern TSRMLS_CC); @@ -3358,7 +3358,7 @@ SPL_METHOD(AppendIterator, valid) if (zend_parse_parameters_none() == FAILURE) { return; } - + SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); RETURN_BOOL(intern->current.data); @@ -3369,13 +3369,13 @@ SPL_METHOD(AppendIterator, valid) SPL_METHOD(AppendIterator, next) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); - + spl_append_it_next(intern TSRMLS_CC); } /* }}} */ @@ -3384,7 +3384,7 @@ SPL_METHOD(AppendIterator, next) SPL_METHOD(AppendIterator, getIteratorIndex) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3400,7 +3400,7 @@ SPL_METHOD(AppendIterator, getIteratorIndex) SPL_METHOD(AppendIterator, getArrayIterator) { spl_dual_it_object *intern; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -3410,7 +3410,7 @@ SPL_METHOD(AppendIterator, getArrayIterator) RETURN_ZVAL(intern->u.append.zarrayit, 1, 0); } /* }}} */ -ZEND_BEGIN_ARG_INFO(arginfo_append_it_append, 0) +ZEND_BEGIN_ARG_INFO(arginfo_append_it_append, 0) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_END_ARG_INFO(); @@ -3513,7 +3513,7 @@ static int spl_iterator_to_values_apply(zend_object_iterator *iter, void *puser } /* }}} */ -/* {{{ proto array iterator_to_array(Traversable it [, bool use_keys = true]) +/* {{{ proto array iterator_to_array(Traversable it [, bool use_keys = true]) Copy the iterator into an array */ PHP_FUNCTION(iterator_to_array) { @@ -3539,7 +3539,7 @@ static int spl_iterator_count_apply(zend_object_iterator *iter, void *puser TSRM } /* }}} */ -/* {{{ proto int iterator_count(Traversable it) +/* {{{ proto int iterator_count(Traversable it) Count the elements in an iterator */ PHP_FUNCTION(iterator_count) { @@ -3549,7 +3549,7 @@ PHP_FUNCTION(iterator_count) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &obj, zend_ce_traversable) == FAILURE) { RETURN_FALSE; } - + if (spl_iterator_apply(obj, spl_iterator_count_apply, (void*)&count TSRMLS_CC) == SUCCESS) { RETURN_LONG(count); } @@ -3632,7 +3632,7 @@ PHP_MINIT_FUNCTION(spl_iterators) spl_handlers_dual_it.get_method = spl_dual_it_get_method; /*spl_handlers_dual_it.call_method = spl_dual_it_call_method;*/ spl_handlers_dual_it.clone_obj = NULL; - + spl_ce_RecursiveIteratorIterator->get_iterator = spl_recursive_it_get_iterator; spl_ce_RecursiveIteratorIterator->iterator_funcs.funcs = &spl_recursive_it_iterator_funcs; @@ -3672,16 +3672,16 @@ PHP_MINIT_FUNCTION(spl_iterators) REGISTER_SPL_IMPLEMENTS(CachingIterator, ArrayAccess); REGISTER_SPL_IMPLEMENTS(CachingIterator, Countable); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CALL_TOSTRING", CIT_CALL_TOSTRING); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CATCH_GET_CHILD", CIT_CATCH_GET_CHILD); + REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CALL_TOSTRING", CIT_CALL_TOSTRING); + REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CATCH_GET_CHILD", CIT_CATCH_GET_CHILD); REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "TOSTRING_USE_KEY", CIT_TOSTRING_USE_KEY); REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "TOSTRING_USE_CURRENT", CIT_TOSTRING_USE_CURRENT); REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "TOSTRING_USE_INNER", CIT_TOSTRING_USE_INNER); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "FULL_CACHE", CIT_FULL_CACHE); + REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "FULL_CACHE", CIT_FULL_CACHE); REGISTER_SPL_SUB_CLASS_EX(RecursiveCachingIterator, CachingIterator, spl_dual_it_new, spl_funcs_RecursiveCachingIterator); REGISTER_SPL_IMPLEMENTS(RecursiveCachingIterator, RecursiveIterator); - + REGISTER_SPL_SUB_CLASS_EX(NoRewindIterator, IteratorIterator, spl_dual_it_new, spl_funcs_NoRewindIterator); REGISTER_SPL_SUB_CLASS_EX(AppendIterator, IteratorIterator, spl_dual_it_new, spl_funcs_AppendIterator); diff --git a/ext/standard/array.c b/ext/standard/array.c index ae6e5d266fa29..95b4db368f7a6 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ @@ -664,7 +664,7 @@ PHP_FUNCTION(usort) RETVAL_TRUE; } } - + if (Z_REFCOUNT_P(array) > 1) { Z_SET_ISREF_P(array); } @@ -947,13 +947,13 @@ PHP_FUNCTION(min) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) { return; } - + php_set_compare_func(PHP_SORT_REGULAR TSRMLS_CC); - + /* mixed min ( array $values ) */ if (argc == 1) { zval **result; - + if (Z_TYPE_PP(args[0]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "When only one parameter is given, it must be an array"); RETVAL_NULL(); @@ -994,13 +994,13 @@ PHP_FUNCTION(max) { zval ***args = NULL; int argc; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) { return; } php_set_compare_func(PHP_SORT_REGULAR TSRMLS_CC); - + /* mixed max ( array $values ) */ if (argc == 1) { zval **result; @@ -1032,7 +1032,7 @@ PHP_FUNCTION(max) RETVAL_ZVAL_FAST(*max); } - + if (args) { efree(args); } @@ -1056,7 +1056,7 @@ static int php_array_walk(HashTable *target_hash, zval *userdata, int recursive BG(array_walk_fci).param_count = userdata ? 3 : 2; BG(array_walk_fci).params = args; BG(array_walk_fci).no_separation = 0; - + /* Iterate through hash */ zend_hash_internal_pointer_reset(target_hash); while (!EG(exception) && zend_hash_get_current_data(target_hash, (void **)&args[0]) == SUCCESS) { @@ -1232,7 +1232,7 @@ static int php_valid_var_name(char *var_name, int var_name_len) /* {{{ */ if (!var_name || !var_name_len) { return 0; } - + /* These are allowed as first char: [a-zA-Z_\x7f-\xff] */ ch = (int)((unsigned char *)var_name)[0]; if (var_name[0] != '_' && @@ -1494,10 +1494,10 @@ PHP_FUNCTION(compact) if (ZEND_NUM_ARGS() == 1 && Z_TYPE_PP(args[0]) == IS_ARRAY) { array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_PP(args[0]))); } else { - array_init_size(return_value, ZEND_NUM_ARGS()); + array_init_size(return_value, num_args); } - for (i=0; inApplyCount++; Z_ARRVAL_PP(src_entry)->nApplyCount++; - + if (!php_array_replace_recursive(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC)) { Z_ARRVAL_PP(dest_entry)->nApplyCount--; @@ -2939,33 +2939,31 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa { Bucket *p; int argc, i; - zval ***args; + zval ***args = NULL; int (*intersect_data_compare_func)(zval **, zval ** TSRMLS_DC) = NULL; zend_bool ok; zval **data; - int req_args; char *param_spec; + int req_args = 2; /* Get the argument count */ - argc = ZEND_NUM_ARGS(); if (data_compare_type == INTERSECT_COMP_DATA_USER) { /* INTERSECT_COMP_DATA_USER - array_uintersect_assoc() */ - req_args = 3; param_spec = "+f"; + req_args = 3; intersect_data_compare_func = zval_user_compare; } else { /* INTERSECT_COMP_DATA_NONE - array_intersect_key() INTERSECT_COMP_DATA_INTERNAL - array_intersect_assoc() */ - req_args = 2; param_spec = "+"; - + if (data_compare_type == INTERSECT_COMP_DATA_INTERNAL) { intersect_data_compare_func = zval_compare; } } - - if (argc < req_args) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, argc); + + if (ZEND_NUM_ARGS() < req_args) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, ZEND_NUM_ARGS()); return; } @@ -2973,6 +2971,11 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa return; } + if (argc < 2) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, argc+req_args-2); + return; + } + for (i = 0; i < argc; i++) { if (Z_TYPE_PP(args[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1); @@ -3118,6 +3121,11 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int return; } + if (arr_argc < 2) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, arr_argc+req_args-2); + return; + } + } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "behavior is %d. This should never happen. Please report as a bug", behavior); return; @@ -3366,31 +3374,36 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty int (*diff_data_compare_func)(zval **, zval ** TSRMLS_DC) = NULL; zend_bool ok; zval **data; + int req_args = 2; + char *param_spec; /* Get the argument count */ argc = ZEND_NUM_ARGS(); if (data_compare_type == DIFF_COMP_DATA_USER) { - if (argc < 3) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least 3 parameters are required, %d given", ZEND_NUM_ARGS()); - return; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+f", &args, &argc, &BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE) { - return; - } + req_args = 3; + param_spec = "+f"; diff_data_compare_func = zval_user_compare; } else { - if (argc < 2) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least 2 parameters are required, %d given", ZEND_NUM_ARGS()); - return; - } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) { - return; - } + param_spec = "+"; if (data_compare_type == DIFF_COMP_DATA_INTERNAL) { diff_data_compare_func = zval_compare; } } + if (argc < req_args) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, ZEND_NUM_ARGS()); + return; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, param_spec, &args, &argc, &BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE) { + return; + } + + if (argc < 2) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, argc+req_args-2); + return; + } + for (i = 0; i < argc; i++) { if (Z_TYPE_PP(args[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1); @@ -3535,6 +3548,11 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ return; } + if (arr_argc < 2) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "at least %d parameters are required, %d given", req_args, arr_argc+req_args-2); + return; + } + } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "behavior is %d. This should never happen. Please report as a bug", behavior); return; @@ -4004,13 +4022,12 @@ PHP_FUNCTION(array_rand) num_avail = zend_hash_num_elements(Z_ARRVAL_P(input)); - if (ZEND_NUM_ARGS() > 1) { - if (num_req <= 0 || num_req > num_avail) { - php_error_docref(NULL TSRMLS_CC, 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 TSRMLS_CC, 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, num_req); @@ -4139,7 +4156,7 @@ PHP_FUNCTION(array_reduce) return; } - if (ZEND_NUM_ARGS() > 2) { + if (initial != NULL) { ALLOC_ZVAL(result); MAKE_COPY_ZVAL(&initial, result); } else { @@ -4213,7 +4230,7 @@ PHP_FUNCTION(array_filter) return; } - if (ZEND_NUM_ARGS() > 1) { + if (fci.size > 0) { have_callback = 1; fci.no_separation = 0; fci.retval_ptr_ptr = &retval; @@ -4428,7 +4445,7 @@ PHP_FUNCTION(array_key_exists) Split array into chunks */ PHP_FUNCTION(array_chunk) { - int argc = ZEND_NUM_ARGS(), key_type, num_in; + int key_type, num_in; long size, current = 0; char *str_key; uint str_key_len; @@ -4439,7 +4456,7 @@ PHP_FUNCTION(array_chunk) zval **entry; HashPosition pos; - if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, &preserve_keys) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 631834c97c0f3..52df769033350 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -266,16 +266,15 @@ PHP_FUNCTION(assert_options) zval **value = NULL; long what; int oldint; - int ac = ZEND_NUM_ARGS(); - if (zend_parse_parameters(ac TSRMLS_CC, "l|Z", &what, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|Z", &what, &value) == FAILURE) { return; } switch (what) { case ASSERT_ACTIVE: oldint = ASSERTG(active); - if (ac == 2) { + if (value != NULL) { convert_to_string_ex(value); zend_alter_ini_entry_ex("assert.active", sizeof("assert.active"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); } @@ -284,7 +283,7 @@ PHP_FUNCTION(assert_options) case ASSERT_BAIL: oldint = ASSERTG(bail); - if (ac == 2) { + if (value != NULL) { convert_to_string_ex(value); zend_alter_ini_entry_ex("assert.bail", sizeof("assert.bail"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); } @@ -293,7 +292,7 @@ PHP_FUNCTION(assert_options) case ASSERT_QUIET_EVAL: oldint = ASSERTG(quiet_eval); - if (ac == 2) { + if (value != NULL) { convert_to_string_ex(value); zend_alter_ini_entry_ex("assert.quiet_eval", sizeof("assert.quiet_eval"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); } @@ -302,7 +301,7 @@ PHP_FUNCTION(assert_options) case ASSERT_WARNING: oldint = ASSERTG(warning); - if (ac == 2) { + if (value != NULL) { convert_to_string_ex(value); zend_alter_ini_entry_ex("assert.warning", sizeof("assert.warning"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); } @@ -317,7 +316,7 @@ PHP_FUNCTION(assert_options) } else { RETVAL_NULL(); } - if (ac == 2) { + if (value != NULL) { if (ASSERTG(callback)) { zval_ptr_dtor(&ASSERTG(callback)); } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 3e5084e837642..5867f9c6f8be2 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2128,7 +2128,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_stream_set_write_buffer, 0) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, buffer) ZEND_END_ARG_INFO() - + ZEND_BEGIN_ARG_INFO(arginfo_stream_set_chunk_size, 0) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, chunk_size) @@ -2323,7 +2323,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_lcfirst, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() - + ZEND_BEGIN_ARG_INFO(arginfo_ucwords, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() @@ -3473,7 +3473,7 @@ static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC) /* BG(user_tick_functions) = NULL; BG(user_filter_map) = NULL; BG(serialize_lock) = 0; - + memset(&BG(serialize), 0, sizeof(BG(serialize))); memset(&BG(unserialize), 0, sizeof(BG(unserialize))); @@ -3542,7 +3542,7 @@ PHPAPI double php_get_inf(void) /* {{{ */ #define BASIC_ADD_SUBMODULE(module) \ zend_hash_add_empty_element(&basic_submodules, #module, strlen(#module)); - + #define BASIC_RINIT_SUBMODULE(module) \ if (zend_hash_exists(&basic_submodules, #module, strlen(#module))) { \ PHP_RINIT(module)(INIT_FUNC_ARGS_PASSTHRU); \ @@ -4031,8 +4031,8 @@ PHP_FUNCTION(getenv) int size; SetLastError(0); - /*If the given bugger is not large enough to hold the data, the return value is - the buffer size, in characters, required to hold the string and its terminating + /*If the given bugger is not large enough to hold the data, the return value is + the buffer size, in characters, required to hold the string and its terminating null character. We use this return value to alloc the final buffer. */ size = GetEnvironmentVariableA(str, &dummybuf, 0); if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { @@ -4136,7 +4136,7 @@ PHP_FUNCTION(putenv) error_code = SetEnvironmentVariable(pe.key, value); # if _MSC_VER < 1500 /* Yet another VC6 bug, unset may return env not found */ - if (error_code != 0 || + if (error_code != 0 || (error_code == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)) { # else if (error_code != 0) { /* success */ @@ -4628,7 +4628,7 @@ PHP_FUNCTION(set_magic_quotes_runtime) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &new_setting) == FAILURE) { return; } - + if (new_setting) { php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "magic_quotes_runtime is not supported anymore"); } @@ -4678,16 +4678,14 @@ PHP_FUNCTION(error_log) { char *message, *opt = NULL, *headers = NULL; int message_len, opt_len = 0, headers_len = 0; - int opt_err = 0, argc = ZEND_NUM_ARGS(); + int opt_err = 0; long erropt = 0; - if (zend_parse_parameters(argc TSRMLS_CC, "s|lps", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lps", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) { return; } - if (argc > 1) { - opt_err = erropt; - } + opt_err = (int)erropt; if (_php_error_log_ex(opt_err, message, message_len, opt, headers TSRMLS_CC) == FAILURE) { RETURN_FALSE; @@ -4870,17 +4868,7 @@ PHP_FUNCTION(call_user_method_array) } convert_to_string(callback); - - params_ar = HASH_OF(params); - num_elems = zend_hash_num_elements(params_ar); - method_args = (zval ***) safe_emalloc(sizeof(zval **), num_elems, 0); - - for (zend_hash_internal_pointer_reset(params_ar); - zend_hash_get_current_data(params_ar, (void **) &(method_args[element])) == SUCCESS; - zend_hash_move_forward(params_ar) - ) { - element++; - } + method_args = zend_fcall_create_args(HASH_OF(params), NULL, &num_elems); if (call_user_function_ex(EG(function_table), &object, callback, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS) { if (retval_ptr) { @@ -4916,7 +4904,7 @@ PHP_FUNCTION(forward_static_call) instanceof_function(EG(called_scope), fci_cache.calling_scope TSRMLS_CC)) { fci_cache.called_scope = EG(called_scope); } - + if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval_ptr_ptr && *fci.retval_ptr_ptr) { COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr); } @@ -4960,7 +4948,9 @@ void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_ int i; for (i = 0; i < shutdown_function_entry->arg_count; i++) { - zval_ptr_dtor(&shutdown_function_entry->arguments[i]); + if(shutdown_function_entry->arguments[i]) { + zval_ptr_dtor(&shutdown_function_entry->arguments[i]); + } } efree(shutdown_function_entry->arguments); } @@ -4971,7 +4961,9 @@ void user_tick_function_dtor(user_tick_function_entry *tick_function_entry) /* { int i; for (i = 0; i < tick_function_entry->arg_count; i++) { - zval_ptr_dtor(&tick_function_entry->arguments[i]); + if(tick_function_entry->arguments[i]) { + zval_ptr_dtor(&tick_function_entry->arguments[i]); + } } efree(tick_function_entry->arguments); } @@ -5117,7 +5109,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; } @@ -5130,7 +5121,7 @@ PHP_FUNCTION(register_shutdown_function) } /* Prevent entering of anything but valid callback (syntax check only!) */ - if (!zend_is_callable(shutdown_function_entry.arguments[0], 0, &callback_name TSRMLS_CC)) { + if (!shutdown_function_entry.arguments[0] || !zend_is_callable(shutdown_function_entry.arguments[0], 0, &callback_name TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid shutdown callback '%s' passed", callback_name); efree(shutdown_function_entry.arguments); RETVAL_FALSE; @@ -5141,7 +5132,9 @@ PHP_FUNCTION(register_shutdown_function) } for (i = 0; i < shutdown_function_entry.arg_count; i++) { - Z_ADDREF_P(shutdown_function_entry.arguments[i]); + if(shutdown_function_entry.arguments[i]) { + Z_ADDREF_P(shutdown_function_entry.arguments[i]); + } } zend_hash_next_index_insert(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry), NULL); } @@ -5617,7 +5610,7 @@ PHP_FUNCTION(getservbyname) } -/* empty string behaves like NULL on windows implementation of +/* empty string behaves like NULL on windows implementation of getservbyname. Let be portable instead. */ #ifdef PHP_WIN32 if (proto_len == 0) { @@ -5730,7 +5723,7 @@ PHP_FUNCTION(register_tick_function) RETURN_FALSE; } - if (!zend_is_callable(tick_fe.arguments[0], 0, &function_name TSRMLS_CC)) { + if (!tick_fe.arguments[0] || !zend_is_callable(tick_fe.arguments[0], 0, &function_name TSRMLS_CC)) { efree(tick_fe.arguments); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid tick callback '%s' passed", function_name); efree(function_name); @@ -5752,7 +5745,9 @@ PHP_FUNCTION(register_tick_function) } for (i = 0; i < tick_fe.arg_count; i++) { - Z_ADDREF_P(tick_fe.arguments[i]); + if(tick_fe.arguments[i]) { + Z_ADDREF_P(tick_fe.arguments[i]); + } } zend_llist_add_element(BG(user_tick_functions), &tick_fe); @@ -6045,7 +6040,7 @@ PHP_FUNCTION(parse_ini_string) /* }}} */ #if ZEND_DEBUG -/* This function returns an array of ALL valid ini options with values and +/* This function returns an array of ALL valid ini options with values and * is not the same as ini_get_all() which returns only registered ini options. Only useful for devs to debug php.ini scanner/parser! */ PHP_FUNCTION(config_get_hash) /* {{{ */ { diff --git a/ext/standard/dir.c b/ext/standard/dir.c index ca7e576c922fd..b8dc51f1cd0b9 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() TSRMLS_CC, "|r", &id) == FAILURE) { \ return; \ } \ - if (ZEND_NUM_ARGS() == 0) { \ + if (id == NULL) { \ myself = getThis(); \ if (myself) { \ if (zend_hash_find(Z_OBJPROP_P(myself), "handle", sizeof("handle"), (void **)&tmp) == FAILURE) { \ @@ -93,8 +93,8 @@ static zend_class_entry *dir_class_entry_ptr; dirp = (php_stream *) zend_fetch_resource(&id TSRMLS_CC, -1, "Directory", NULL, 1, php_file_le_stream()); \ if (!dirp) \ RETURN_FALSE; \ - } - + } + /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO_EX(arginfo_dir, 0, 0, 0) ZEND_ARG_INFO(0, dir_handle) @@ -118,7 +118,7 @@ static void php_set_default_dir(int id TSRMLS_DC) if (id != -1) { zend_list_addref(id); } - + DIRG(default_dir) = id; } @@ -168,25 +168,25 @@ PHP_MINIT_FUNCTION(dir) #ifdef GLOB_NOSORT REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_CS | CONST_PERSISTENT); -#else +#else # define GLOB_NOSORT 0 #endif #ifdef GLOB_NOCHECK REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_CS | CONST_PERSISTENT); -#else +#else # define GLOB_NOCHECK 0 #endif #ifdef GLOB_NOESCAPE REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT); -#else +#else # define GLOB_NOESCAPE 0 #endif #ifdef GLOB_ERR REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_CS | CONST_PERSISTENT); -#else +#else # define GLOB_ERR 0 #endif @@ -224,7 +224,7 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) } context = php_stream_context_from_zval(zcontext, 0); - + dirp = php_stream_opendir(dirname, REPORT_ERRORS, context); if (dirp == NULL) { @@ -232,7 +232,7 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) } dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE; - + php_set_default_dir(dirp->rsrc_id TSRMLS_CC); if (createobject) { @@ -293,11 +293,11 @@ PHP_FUNCTION(chroot) { char *str; int ret, str_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { RETURN_FALSE; } - + ret = chroot(str); if (ret != 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno); @@ -305,9 +305,9 @@ PHP_FUNCTION(chroot) } php_clear_stat_cache(1, NULL, 0 TSRMLS_CC); - + ret = chdir("/"); - + if (ret != 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno); RETURN_FALSE; @@ -324,7 +324,7 @@ PHP_FUNCTION(chdir) { char *str; int ret, str_len; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &str, &str_len) == FAILURE) { RETURN_FALSE; } @@ -333,7 +333,7 @@ PHP_FUNCTION(chdir) RETURN_FALSE; } ret = VCWD_CHDIR(str); - + if (ret != 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno); RETURN_FALSE; @@ -358,7 +358,7 @@ PHP_FUNCTION(getcwd) { char path[MAXPATHLEN]; char *ret=NULL; - + if (zend_parse_parameters_none() == FAILURE) { return; } @@ -383,7 +383,7 @@ PHP_FUNCTION(rewinddir) { zval *id = NULL, **tmp, *myself; php_stream *dirp; - + FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { @@ -450,9 +450,9 @@ PHP_FUNCTION(glob) RETURN_FALSE; } -#ifdef ZTS +#ifdef ZTS if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) { - result = VCWD_GETCWD(cwd, MAXPATHLEN); + result = VCWD_GETCWD(cwd, MAXPATHLEN); if (!result) { cwd[0] = '\0'; } @@ -465,10 +465,10 @@ PHP_FUNCTION(glob) snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern); pattern = work_pattern; - } + } #endif - + memset(&globbuf, 0, sizeof(glob_t)); globbuf.gl_offs = 0; if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) { @@ -477,7 +477,7 @@ PHP_FUNCTION(glob) /* Some glob implementation simply return no data if no matches were found, others return the GLOB_NOMATCH error code. We don't want to treat GLOB_NOMATCH as an error condition - so that PHP glob() behaves the same on both types of + so that PHP glob() behaves the same on both types of implementations and so that 'foreach (glob() as ...' can be used for simple glob() calls without further error checking. @@ -517,11 +517,11 @@ PHP_FUNCTION(glob) } /* we need to do this everytime since GLOB_ONLYDIR does not guarantee that * all directories will be filtered. GNU libc documentation states the - * following: - * If the information about the type of the file is easily available - * non-directories will be rejected but no extra work will be done to - * determine the information for each file. I.e., the caller must still be - * able to filter directories out. + * following: + * If the information about the type of the file is easily available + * non-directories will be rejected but no extra work will be done to + * determine the information for each file. I.e., the caller must still be + * able to filter directories out. */ if (flags & GLOB_ONLYDIR) { struct stat s; @@ -545,7 +545,7 @@ PHP_FUNCTION(glob) } } /* }}} */ -#endif +#endif /* {{{ proto array scandir(string dir [, int sorting_order [, resource context]]) List files & directories inside the specified path */ @@ -583,7 +583,7 @@ PHP_FUNCTION(scandir) php_error_docref(NULL TSRMLS_CC, E_WARNING, "(errno %d): %s", errno, strerror(errno)); RETURN_FALSE; } - + array_init(return_value); for (i = 0; i < n; i++) { diff --git a/ext/standard/file.c b/ext/standard/file.c index 1ec6a74f3f0b5..9c0a81cff85e7 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -994,11 +994,12 @@ PHPAPI PHP_FUNCTION(feof) PHPAPI PHP_FUNCTION(fgets) { zval *arg1; - long len = 1024; + long len = 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() TSRMLS_CC, "r|l", &arg1, &len) == FAILURE) { RETURN_FALSE; @@ -1006,28 +1007,33 @@ PHPAPI PHP_FUNCTION(fgets) PHP_STREAM_TO_ZVAL(stream, &arg1); - 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 TSRMLS_CC, 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 TSRMLS_CC, 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; + } } ZVAL_STRINGL(return_value, buf, line_len, 0); /* resize buffer if it's much larger than the result. * Only needed if the user requested a buffer size. */ - if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) { + if (alloc_buf && Z_STRLEN_P(return_value) < len / 2) { Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1); } return; @@ -1073,7 +1079,7 @@ PHPAPI PHP_FUNCTION(fgetc) PHPAPI PHP_FUNCTION(fgetss) { zval *fd; - long bytes = 0; + long bytes = LONG_MIN; size_t len = 0; size_t actual_len, retval_len; char *buf = NULL, *retval; @@ -1087,7 +1093,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 TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0"); RETURN_FALSE; @@ -1169,7 +1175,7 @@ PHPAPI PHP_FUNCTION(fwrite) int arg2len; int ret; int num_bytes; - long arg3 = 0; + long arg3 = LONG_MIN; char *buffer = NULL; php_stream *stream; @@ -1177,7 +1183,7 @@ PHPAPI PHP_FUNCTION(fwrite) RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 2) { + if (arg3 == LONG_MIN) { num_bytes = arg2len; } else { num_bytes = MAX(0, MIN((int)arg3, arg2len)); @@ -1386,6 +1392,7 @@ PHP_FUNCTION(umask) if (BG(umask) == -1) { BG(umask) = oldumask; } + arg1 = oldumask; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &arg1) == FAILURE) { RETURN_FALSE; diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 0b40e7319b398..86a3a3e375374 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -721,6 +721,8 @@ PHP_FUNCTION(touch) struct utimbuf *newtime = &newtimebuf; php_stream_wrapper *wrapper; + filetime = fileatime = time(NULL); + if (zend_parse_parameters(argc TSRMLS_CC, "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/head.c b/ext/standard/head.c index 5310ff6c03b2f..733e3f481a523 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -59,7 +59,7 @@ PHP_FUNCTION(header_remove) &ctr.line_len) == FAILURE) return; - sapi_header_op(ZEND_NUM_ARGS() == 0 ? SAPI_HEADER_DELETE_ALL : SAPI_HEADER_DELETE, &ctr TSRMLS_CC); + sapi_header_op(ctr.line == NULL ? SAPI_HEADER_DELETE_ALL : SAPI_HEADER_DELETE, &ctr TSRMLS_CC); } /* }}} */ diff --git a/ext/standard/image.c b/ext/standard/image.c index bd80f11dec974..22f3aac51277d 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -83,7 +83,7 @@ PHP_MINIT_FUNCTION(imagetypes) REGISTER_LONG_CONSTANT("IMAGETYPE_JB2", IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT); #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) REGISTER_LONG_CONSTANT("IMAGETYPE_SWC", IMAGE_FILETYPE_SWC, CONST_CS | CONST_PERSISTENT); -#endif +#endif REGISTER_LONG_CONSTANT("IMAGETYPE_IFF", IMAGE_FILETYPE_IFF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP", IMAGE_FILETYPE_WBMP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC, CONST_CS | CONST_PERSISTENT); /* keep alias */ @@ -216,7 +216,7 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) return NULL; slength = php_stream_copy_to_mem(stream, &bufz, PHP_STREAM_COPY_ALL, 0); - + /* * zlib::uncompress() wants to know the output data length * if none was given as a parameter @@ -224,26 +224,26 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) * doubling it whenever it wasn't big enough * that should be eneugh for all real life cases */ - + do { szlength=slength*(1< 2048 || width > 2048) { return 0; } - + if (!check) { (*result)->width = width; (*result)->height = height; @@ -1029,7 +1029,7 @@ static int php_get_xbm(php_stream *stream, struct gfxinfo **result TSRMLS_DC) } else { type++; } - + if (!strcmp("width", type)) { width = (unsigned int) value; if (height) { @@ -1389,13 +1389,12 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { php_stream *stream = NULL; char *input; int input_len; - const int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &input, &input_len, &info) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Z", &input, &input_len, &info) == FAILURE) { return; } - if (argc == 2) { + if (info != NULL) { zval_dtor(*info); array_init(*info); } diff --git a/ext/standard/math.c b/ext/standard/math.c index f6b3d5406ebe4..1ca974204d236 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -144,7 +144,7 @@ PHPAPI double _php_math_round(double value, int places, int mode) { if (!php_math_is_finite(value)) { return value; } - + precision_places = 14 - php_intlog10abs(value); f1 = php_intpow10(abs(places)); @@ -181,7 +181,7 @@ PHPAPI double _php_math_round(double value, int places, int mode) { /* round the temp value */ tmp_value = php_round_helper(tmp_value, mode); - + /* see if it makes sense to use simple division to round the value */ if (abs(places) < 23) { if (places > 0) { @@ -274,15 +274,15 @@ static double php_expm1(double x) /* {{{ proto int abs(int number) Return the absolute value of the number */ -PHP_FUNCTION(abs) +PHP_FUNCTION(abs) { zval **value; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &value) == FAILURE) { return; } convert_scalar_to_number_ex(value); - + if (Z_TYPE_PP(value) == IS_DOUBLE) { RETURN_DOUBLE(fabs(Z_DVAL_PP(value))); } else if (Z_TYPE_PP(value) == IS_LONG) { @@ -294,14 +294,14 @@ PHP_FUNCTION(abs) } RETURN_FALSE; } -/* }}} */ +/* }}} */ /* {{{ proto float ceil(float number) Returns the next highest integer value of the number */ -PHP_FUNCTION(ceil) +PHP_FUNCTION(ceil) { zval **value; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &value) == FAILURE) { return; } @@ -322,7 +322,7 @@ PHP_FUNCTION(ceil) PHP_FUNCTION(floor) { zval **value; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &value) == FAILURE) { return; } @@ -347,14 +347,12 @@ PHP_FUNCTION(round) long precision = 0; long mode = PHP_ROUND_HALF_UP; double return_val; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|ll", &value, &precision, &mode) == FAILURE) { return; } - if (ZEND_NUM_ARGS() >= 2) { - places = (int) precision; - } + places = (int) precision; convert_scalar_to_number_ex(value); switch (Z_TYPE_PP(value)) { @@ -396,7 +394,7 @@ PHP_FUNCTION(sin) PHP_FUNCTION(cos) { double num; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) { return; } @@ -526,7 +524,7 @@ PHP_FUNCTION(asinh) PHP_FUNCTION(acosh) { double num; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) { return; } @@ -611,7 +609,7 @@ PHP_FUNCTION(pow) /* if both base and exponent were longs, we'll try to get a long out */ if (Z_TYPE_P(zbase) == IS_LONG && Z_TYPE_P(zexp) == IS_LONG && Z_LVAL_P(zexp) >= 0) { long l1 = 1, l2 = Z_LVAL_P(zbase), i = Z_LVAL_P(zexp); - + if (i == 0) { RETURN_LONG(1L); } else if (l2 == 0) { @@ -639,7 +637,7 @@ PHP_FUNCTION(pow) } convert_to_double(zbase); convert_to_double(zexp); - + RETURN_DOUBLE(pow(Z_DVAL_P(zbase), Z_DVAL_P(zexp))); } /* }}} */ @@ -661,7 +659,7 @@ PHP_FUNCTION(exp) /* {{{ proto float expm1(float number) Returns exp(number) - 1, computed in a way that accurate even when the value of number is close to zero */ /* - WARNING: this function is expermental: it could change its name or + WARNING: this function is expermental: it could change its name or disappear in the next version of PHP! */ PHP_FUNCTION(expm1) @@ -676,9 +674,9 @@ PHP_FUNCTION(expm1) /* }}} */ /* {{{ proto float log1p(float number) - Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero */ + Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero */ /* - WARNING: this function is expermental: it could change its name or + WARNING: this function is expermental: it could change its name or disappear in the next version of PHP! */ PHP_FUNCTION(log1p) @@ -696,8 +694,8 @@ PHP_FUNCTION(log1p) Returns the natural logarithm of the number, or the base log if base is specified */ PHP_FUNCTION(log) { - double num, base = 0; - + double num, base = M_E; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|d", &num, &base) == FAILURE) { return; } @@ -705,7 +703,7 @@ PHP_FUNCTION(log) RETURN_DOUBLE(log(num)); } if (base <= 0.0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0"); RETURN_FALSE; } if (base == 1) { @@ -743,7 +741,7 @@ PHP_FUNCTION(sqrt) /* }}} */ /* {{{ proto float hypot(float num1, float num2) - Returns sqrt(num1*num1 + num2*num2) */ + Returns sqrt(num1*num1 + num2*num2) */ PHP_FUNCTION(hypot) { double num1, num2; @@ -805,12 +803,12 @@ PHPAPI long _php_math_basetolong(zval *arg, int base) for (i = Z_STRLEN_P(arg); i > 0; i--) { c = *s++; - + digit = (c >= '0' && c <= '9') ? c - '0' : (c >= 'A' && c <= 'Z') ? c - 'A' + 10 : (c >= 'a' && c <= 'z') ? c - 'a' + 10 : base; - + if (digit >= base) { continue; } @@ -854,23 +852,23 @@ PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret) cutoff = LONG_MAX / base; cutlim = LONG_MAX % base; - + for (i = Z_STRLEN_P(arg); i > 0; i--) { c = *s++; /* might not work for EBCDIC */ - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') c -= '0'; - else if (c >= 'A' && c <= 'Z') + else if (c >= 'A' && c <= 'Z') c -= 'A' - 10; - else if (c >= 'a' && c <= 'z') + else if (c >= 'a' && c <= 'z') c -= 'a' - 10; else continue; if (c >= base) continue; - + switch (mode) { case 0: /* Integer */ if (num < cutoff || (num == cutoff && c <= cutlim)) { @@ -883,7 +881,7 @@ PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret) /* fall-through */ case 1: /* Float */ fnum = fnum * base + c; - } + } } if (mode == 1) { @@ -959,9 +957,9 @@ PHPAPI char * _php_math_zvaltobase(zval *arg, int base TSRMLS_DC) return estrndup(ptr, end - ptr); } - + return _php_math_longtobase(arg, base); -} +} /* }}} */ /* {{{ proto int bindec(string binary_number) @@ -969,7 +967,7 @@ PHPAPI char * _php_math_zvaltobase(zval *arg, int base TSRMLS_DC) PHP_FUNCTION(bindec) { zval **arg; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) { return; } @@ -985,7 +983,7 @@ PHP_FUNCTION(bindec) PHP_FUNCTION(hexdec) { zval **arg; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) { return; } @@ -1001,7 +999,7 @@ PHP_FUNCTION(hexdec) PHP_FUNCTION(octdec) { zval **arg; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) { return; } @@ -1072,7 +1070,7 @@ PHP_FUNCTION(base_convert) return; } convert_to_string_ex(number); - + if (frombase < 2 || frombase > 36) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `from base' (%ld)", frombase); RETURN_FALSE; @@ -1087,10 +1085,10 @@ PHP_FUNCTION(base_convert) } result = _php_math_zvaltobase(&temp, tobase TSRMLS_CC); RETVAL_STRING(result, 0); -} +} /* }}} */ -/* {{{ _php_math_number_format +/* {{{ _php_math_number_format */ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep) { @@ -1146,9 +1144,9 @@ static char *_php_math_number_format_ex_len(double d, int dec, char *dec_point, if (thousand_sep) { integral += thousand_sep_len * ((integral-1) / 3); } - + reslen = integral; - + if (dec) { reslen += dec; @@ -1178,7 +1176,7 @@ static char *_php_math_number_format_ex_len(double d, int dec, char *dec_point, while (topad--) { *t-- = '0'; } - + if (dp) { s -= declen + 1; /* +1 to skip the point */ t -= declen; @@ -1210,7 +1208,7 @@ static char *_php_math_number_format_ex_len(double d, int dec, char *dec_point, } efree(tmpbuf); - + if (result_len) { *result_len = reslen; } @@ -1235,7 +1233,7 @@ PHP_FUNCTION(number_format) char *thousand_sep = NULL, *dec_point = NULL; char thousand_sep_chr = ',', dec_point_chr = '.'; int thousand_sep_len = 0, dec_point_len = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|ls!s!", &num, &dec, &dec_point, &dec_point_len, &thousand_sep, &thousand_sep_len) == FAILURE) { return; } diff --git a/ext/standard/rand.c b/ext/standard/rand.c index 5f55a41f91d7a..cc127b3a80cd4 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -110,7 +110,7 @@ PHPAPI long php_rand(TSRMLS_D) Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, Copyright (C) 2000 - 2003, Richard J. Wagner - All rights reserved. + All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -123,8 +123,8 @@ PHPAPI long php_rand(TSRMLS_D) notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -210,14 +210,14 @@ PHPAPI php_uint32 php_mt_rand(TSRMLS_D) { /* Pull a 32-bit integer from the generator state Every other access function simply transforms the numbers extracted here */ - + register php_uint32 s1; if (BG(left) == 0) { php_mt_reload(TSRMLS_C); } --BG(left); - + s1 = *BG(next)++; s1 ^= (s1 >> 11); s1 ^= (s1 << 7) & 0x9d2c5680U; @@ -232,7 +232,7 @@ PHP_FUNCTION(srand) { long seed = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) return; if (ZEND_NUM_ARGS() == 0) @@ -248,7 +248,7 @@ PHP_FUNCTION(mt_srand) { long seed = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) return; if (ZEND_NUM_ARGS() == 0) @@ -280,10 +280,10 @@ PHP_FUNCTION(mt_srand) # number of b+1 which would be bad. So we bump M up by one to make sure # this will never happen, and the final algorithm looks like this: # - # n' = a + n(b-a+1)/(M+1) + # n' = a + n(b-a+1)/(M+1) * * -RL - */ + */ /* {{{ proto int rand([int min, int max]) Returns a random number */ @@ -332,8 +332,8 @@ PHP_FUNCTION(mt_rand) * Melo: hmms.. randomMT() returns 32 random bits... * Yet, the previous php_rand only returns 31 at most. * So I put a right shift to loose the lsb. It *seems* - * better than clearing the msb. - * Update: + * better than clearing the msb. + * Update: * I talked with Cokus via email and it won't ruin the algorithm */ number = (long) (php_mt_rand(TSRMLS_C) >> 1); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 0610ecfc49fd7..bd12baa6feca8 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -692,7 +692,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) } else { /* HASH_KEY_IS_STRING */ zend_hash_update(new_hash, key, key_len, (void *)elem, sizeof(zval *), (void **)&dest_elem); } - + if (dest_elem) { zval_add_ref(dest_elem); } @@ -1377,9 +1377,8 @@ PHP_FUNCTION(stream_set_timeout) long seconds, microseconds = 0; struct timeval t; php_stream *stream; - int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rl|l", &socket, &seconds, µseconds) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &socket, &seconds, µseconds) == FAILURE) { return; } @@ -1387,7 +1386,7 @@ PHP_FUNCTION(stream_set_timeout) t.tv_sec = seconds; - if (argc == 3) { + if (microseconds != 0) { t.tv_usec = microseconds % 1000000; t.tv_sec += microseconds / 1000000; } else { @@ -1449,7 +1448,7 @@ PHP_FUNCTION(stream_set_chunk_size) php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size must be a positive integer, given %ld", csize); RETURN_FALSE; } - /* stream.chunk_size is actually a size_t, but php_stream_set_option + /* stream.chunk_size is actually a size_t, but php_stream_set_option * can only use an int to accept the new value and return the old one. * In any case, values larger than INT_MAX for a chunk size make no sense. */ @@ -1457,11 +1456,11 @@ PHP_FUNCTION(stream_set_chunk_size) php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size cannot be larger than %d", INT_MAX); RETURN_FALSE; } - + php_stream_from_zval(stream, &zstream); ret = php_stream_set_option(stream, PHP_STREAM_OPTION_SET_CHUNK_SIZE, (int)csize, NULL); - + RETURN_LONG(ret > 0 ? (long)ret : (long)EOF); } /* }}} */ @@ -1499,7 +1498,7 @@ PHP_FUNCTION(stream_set_read_buffer) Enable or disable a specific kind of crypto on the stream */ PHP_FUNCTION(stream_socket_enable_crypto) { - long cryptokind = 0; + long cryptokind = -1; zval *zstream, *zsessstream = NULL; php_stream *stream, *sessstream = NULL; zend_bool enable; @@ -1511,7 +1510,7 @@ PHP_FUNCTION(stream_socket_enable_crypto) php_stream_from_zval(stream, &zstream); - if (ZEND_NUM_ARGS() >= 3) { + if (cryptokind != -1) { if (zsessstream) { php_stream_from_zval(sessstream, &zsessstream); } diff --git a/ext/standard/string.c b/ext/standard/string.c index 2f05b65bb939c..ad8e62e11ea94 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -289,7 +289,7 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / int len1, len2; long start = 0, len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", &s11, &len1, + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", &s11, &len1, &s22, &len2, &start, &len) == FAILURE) { return; } @@ -1271,7 +1271,7 @@ PHP_FUNCTION(strtok) return; } - if (ZEND_NUM_ARGS() == 1) { + if (tok == NULL) { tok = str; tok_len = str_len; } else { @@ -2217,22 +2217,17 @@ PHP_FUNCTION(chunk_split) PHP_FUNCTION(substr) { char *str; - long l = 0, f; + long l = LONG_MAX, f; int str_len; - int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &str, &str_len, &f, &l) == FAILURE) { return; } - if (argc > 2) { - if ((l < 0 && -l > str_len)) { - RETURN_FALSE; - } else if (l > str_len) { - l = str_len; - } - } else { + if (l > str_len) { l = str_len; + } else if ((l < 0 && -l > str_len)) { + RETURN_FALSE; } if (f > str_len) { @@ -2289,7 +2284,6 @@ PHP_FUNCTION(substr_replace) int result_len; int l = 0; int f; - int argc = ZEND_NUM_ARGS(); HashPosition pos_str, pos_from, pos_repl, pos_len; zval **tmp_str = NULL, **tmp_from = NULL, **tmp_repl = NULL, **tmp_len= NULL; @@ -2317,7 +2311,7 @@ PHP_FUNCTION(substr_replace) convert_to_long_ex(from); } - if (argc > 3) { + if (len != NULL) { SEPARATE_ZVAL(len); if (Z_TYPE_PP(len) != IS_ARRAY) { convert_to_long_ex(len); @@ -2331,13 +2325,13 @@ PHP_FUNCTION(substr_replace) if (Z_TYPE_PP(str) == IS_STRING) { if ( - (argc == 3 && Z_TYPE_PP(from) == IS_ARRAY) || - (argc == 4 && Z_TYPE_PP(from) != Z_TYPE_PP(len)) + (len == NULL && Z_TYPE_PP(from) == IS_ARRAY) || + (len != NULL && Z_TYPE_PP(from) != Z_TYPE_PP(len)) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "'from' and 'len' should be of same type - numerical or array "); RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); } - if (argc == 4 && Z_TYPE_PP(from) == IS_ARRAY) { + if (len != NULL && Z_TYPE_PP(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_PP(from)) != zend_hash_num_elements(Z_ARRVAL_PP(len))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "'from' and 'len' should have the same number of elements"); RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); @@ -2415,7 +2409,7 @@ PHP_FUNCTION(substr_replace) zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(from), &pos_from); } - if (argc > 3 && Z_TYPE_PP(len) == IS_ARRAY) { + if (len != NULL && Z_TYPE_PP(len) == IS_ARRAY) { zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(len), &pos_len); } @@ -2477,7 +2471,7 @@ PHP_FUNCTION(substr_replace) } } - if (argc > 3 && Z_TYPE_PP(len) == IS_ARRAY) { + if (len != NULL && Z_TYPE_PP(len) == IS_ARRAY) { if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(len), (void **) &tmp_len, &pos_len)) { if(Z_TYPE_PP(tmp_len) != IS_LONG) { zval dummy = **tmp_len; @@ -2491,7 +2485,7 @@ PHP_FUNCTION(substr_replace) } else { l = Z_STRLEN_P(orig_str); } - } else if (argc > 3) { + } else if (len != NULL) { l = Z_LVAL_PP(len); } else { l = Z_STRLEN_P(orig_str); @@ -3111,13 +3105,12 @@ PHP_FUNCTION(strtr) zval **from; char *str, *to = NULL; int str_len, to_len = 0; - int ac = ZEND_NUM_ARGS(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sZ|s", &str, &str_len, &from, &to, &to_len) == FAILURE) { return; } - if (ac == 2 && Z_TYPE_PP(from) != IS_ARRAY) { + if (to == NULL && Z_TYPE_PP(from) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument is not an array"); RETURN_FALSE; } @@ -3127,7 +3120,7 @@ PHP_FUNCTION(strtr) RETURN_EMPTY_STRING(); } - if (ac == 2) { + if (to == NULL) { php_strtr_array(return_value, str, str_len, HASH_OF(*from)); } else { convert_to_string_ex(from); @@ -3223,7 +3216,6 @@ PHP_FUNCTION(similar_text) { char *t1, *t2; zval **percent = NULL; - int ac = ZEND_NUM_ARGS(); int sim; int t1_len, t2_len; @@ -3231,12 +3223,12 @@ PHP_FUNCTION(similar_text) 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_PP(percent) = 0; } @@ -3245,7 +3237,7 @@ PHP_FUNCTION(similar_text) sim = php_similar_char(t1, t1_len, t2, t2_len); - if (ac > 2) { + if (percent != NULL) { Z_DVAL_PP(percent) = sim * 200.0 / (t1_len + t2_len); } @@ -3946,7 +3938,6 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit uint string_key_len; ulong num_key; int count = 0; - int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZZ|Z", &search, &replace, &subject, &zcount) == FAILURE) { return; @@ -3975,7 +3966,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit if (Z_TYPE_PP(subject_entry) != IS_ARRAY && Z_TYPE_PP(subject_entry) != IS_OBJECT) { MAKE_STD_ZVAL(result); SEPARATE_ZVAL(subject_entry); - php_str_replace_in_subject(*search, *replace, subject_entry, result, case_sensitivity, (argc > 3) ? &count : NULL); + php_str_replace_in_subject(*search, *replace, subject_entry, result, case_sensitivity, (zcount) ? &count : NULL); } else { ALLOC_ZVAL(result); Z_ADDREF_P(*subject_entry); @@ -3996,9 +3987,9 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit zend_hash_move_forward(Z_ARRVAL_PP(subject)); } } else { /* if subject is not an array */ - php_str_replace_in_subject(*search, *replace, subject, return_value, case_sensitivity, (argc > 3) ? &count : NULL); + php_str_replace_in_subject(*search, *replace, subject, return_value, case_sensitivity, (zcount) ? &count : NULL); } - if (argc > 3) { + if (zcount) { zval_dtor(*zcount); ZVAL_LONG(*zcount, count); } @@ -5574,7 +5565,7 @@ PHP_FUNCTION(substr_compare) zend_bool cs=0; uint cmp_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) { RETURN_FALSE; } 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/type.c b/ext/standard/type.c index 5d93f66f5b725..21a7e509f30bc 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -47,11 +47,11 @@ PHP_FUNCTION(gettype) case IS_DOUBLE: RETVAL_STRING("double", 1); break; - + case IS_STRING: RETVAL_STRING("string", 1); break; - + case IS_ARRAY: RETVAL_STRING("array", 1); break; @@ -134,27 +134,13 @@ PHP_FUNCTION(settype) PHP_FUNCTION(intval) { zval **num; - long arg_base; + long arg_base = 10; int base; - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) { - return; - } - base = 10; - break; - - case 2: - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zl", &num, &arg_base) == FAILURE) { - return; - } - base = arg_base; - break; - - default: - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|l", &num, &arg_base) == FAILURE) { + return; } + base = (int)arg_base; RETVAL_ZVAL(*num, 1, 0); convert_to_long_base(return_value, base); @@ -365,7 +351,7 @@ PHP_FUNCTION(is_scalar) } /* }}} */ -/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name]]) +/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name]]) Returns true if var is callable. */ PHP_FUNCTION(is_callable) { @@ -380,11 +366,11 @@ PHP_FUNCTION(is_callable) &syntax_only, &callable_name) == FAILURE) { return; } - + 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, NULL, &error TSRMLS_CC); zval_dtor(*callable_name); ZVAL_STRING(*callable_name, name, 0); diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index aadbcaf84ab52..f66eb59ae9b9b 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; int v1_len, v2_len, op_len = 0; - int compare, argc; + int compare; - argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "ss|s", &v1, &v1_len, &v2, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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 ee53d484cfb9b..1351c6a284134 100644 --- a/ext/sybase_ct/php_sybase_ct.c +++ b/ext/sybase_ct/php_sybase_ct.c @@ -434,7 +434,7 @@ static int _call_message_handler(zval *callback_name, CS_SERVERMSG *srvmsg TSRML ZVAL_LONG(line, srvmsg->line); args[3] = &line; - MAKE_STD_ZVAL(text); + MAKE_STD_ZVAL(text); ZVAL_STRING(text, srvmsg->text, 1); args[4] = &text; @@ -551,10 +551,10 @@ static PHP_GINIT_FUNCTION(sybase) } } - /* Set the timeout, which is per context and can't be set with - * ct_con_props(), so set it globally from the config value if + /* Set the timeout, which is per context and can't be set with + * ct_con_props(), so set it globally from the config value if * requested. The default is CS_NO_LIMIT. - * + * * Note that despite some noise in the documentation about using * signals to implement timeouts, they are actually implemented * by using poll() or select() on Solaris and Linux. @@ -652,7 +652,7 @@ static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char } if (appname) { ct_con_props(sybase->connection, CS_SET, CS_APPNAME, appname, CS_NULLTERM, NULL); - } else { + } else { ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname), CS_NULLTERM, NULL); } @@ -677,7 +677,7 @@ static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char } } } - + if (cfg_get_long("sybct.packet_size", &packetsize) == SUCCESS) { if (ct_con_props(sybase->connection, CS_SET, CS_PACKETSIZE, (CS_VOID *)&packetsize, CS_UNUSED, NULL) != CS_SUCCEED) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update connection packetsize"); @@ -685,15 +685,15 @@ static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char } /* Set the login timeout. Actually, the login timeout is per context - * and not per connection, but we will update the context here to + * and not per connection, but we will update the context here to * allow for code such as the following: - * + * * ini_set('sybct.login_timeout', $timeout); * sybase_connect(...) - * - * Note that preceding calls to sybase_connect() will now use the + * + * Note that preceding calls to sybase_connect() will now use the * updated value and not the default one! - * + * * The default value for CS_LOGIN_TIMEOUT is 60 (1 minute). */ if (SybCtG(login_timeout) != -1) { @@ -745,13 +745,13 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } } hashed_details_length = spprintf( - &hashed_details, - 0, + &hashed_details, + 0, "sybase_%s_%s_%s_%s_%s", - host ? host : "", - user ? user : "", - passwd ? passwd : "", - charset ? charset : "", + host ? host : "", + user ? user : "", + passwd ? passwd : "", + charset ? charset : "", appname ? appname : "" ); @@ -1087,12 +1087,12 @@ PHP_FUNCTION(sybase_select_db) /* }}} */ -static int php_sybase_finish_results(sybase_result *result TSRMLS_DC) +static int php_sybase_finish_results(sybase_result *result TSRMLS_DC) { int i, fail; CS_RETCODE retcode; CS_INT restype; - + efree_n(result->datafmt); efree_n(result->lengths); efree_n(result->indicators); @@ -1168,7 +1168,7 @@ static int php_sybase_finish_results(sybase_result *result TSRMLS_DC) * dead ourselves. */ result->sybase_ptr->dead = 1; - + case CS_CANCELED: default: retcode = CS_FAIL; @@ -1195,12 +1195,12 @@ static int php_sybase_fetch_result_row(sybase_result *result, int numrows TSRMLS { int i, j; CS_INT retcode; - + /* We've already fetched everything */ if (result->last_retcode == CS_END_DATA || result->last_retcode == CS_END_RESULTS) { return result->last_retcode; } - + if (numrows!=-1) numrows+= result->num_rows; while ((retcode=ct_fetch(result->sybase_ptr->cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, NULL))==CS_SUCCEED || retcode == CS_ROW_FAIL) { result->num_rows++; @@ -1228,10 +1228,10 @@ static int php_sybase_fetch_result_row(sybase_result *result, int numrows TSRMLS ZVAL_LONG(&result->data[i][j], strtol(result->tmp_buffer[j], NULL, 10)); break; } - + case 2: { /* This indicates a float */ - RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); + RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); break; } @@ -1240,15 +1240,15 @@ static int php_sybase_fetch_result_row(sybase_result *result, int numrows TSRMLS errno = 0; Z_LVAL(result->data[i][j]) = strtol(result->tmp_buffer[j], NULL, 10); if (errno == ERANGE) { - + /* An overflow occurred, so try to fit it into a double */ - RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); + RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); break; } Z_TYPE(result->data[i][j]) = IS_LONG; break; } - + default: { /* This indicates anything else, return it as string * FreeTDS doesn't correctly set result->indicators[j] correctly @@ -1278,18 +1278,18 @@ static int php_sybase_fetch_result_row(sybase_result *result, int numrows TSRMLS case CS_END_DATA: retcode = php_sybase_finish_results(result TSRMLS_CC); break; - + case CS_ROW_FAIL: case CS_SUCCEED: break; - + default: FREE_SYBASE_RESULT(result); result = NULL; retcode = CS_FAIL; /* Just to be sure */ break; } - + return retcode; } @@ -1308,7 +1308,7 @@ static sybase_result * php_sybase_fetch_result_set(sybase_link *sybase_ptr, int if (ct_res_info(sybase_ptr->cmd, CS_NUMDATA, &num_fields, CS_UNUSED, NULL)!=CS_SUCCEED) { return NULL; } - + result = (sybase_result *) emalloc(sizeof(sybase_result)); result->data = (zval **) safe_emalloc(sizeof(zval *), SYBASE_ROWS_BLOCK, 0); result->fields = NULL; @@ -1324,7 +1324,7 @@ static sybase_result * php_sybase_fetch_result_set(sybase_link *sybase_ptr, int result->datafmt = (CS_DATAFMT *) safe_emalloc(sizeof(CS_DATAFMT), num_fields, 0); result->numerics = (unsigned char *) safe_emalloc(sizeof(unsigned char), num_fields, 0); result->types = (CS_INT *) safe_emalloc(sizeof(CS_INT), num_fields, 0); - + for (i=0; icmd, i+1, &result->datafmt[i]); result->types[i] = result->datafmt[i].datatype; @@ -1408,7 +1408,7 @@ static sybase_result * php_sybase_fetch_result_set(sybase_link *sybase_ptr, int result->fields[i].numeric = result->numerics[i]; Z_TYPE(result->fields[i]) = result->types[i]; } - + if (buffered) { retcode = CS_SUCCEED; } else { @@ -1457,27 +1457,27 @@ static void php_sybase_query (INTERNAL_FUNCTION_PARAMETERS, int buffered) if (sybase_ptr->dead) { RETURN_FALSE; } - + /* Check to see if a previous sybase_unbuffered_query has read all rows */ if (sybase_ptr->active_result_index) { zval *tmp = NULL; - + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Sybase: Called without first fetching all rows from a previous unbuffered query"); if (sybase_ptr->cmd) { ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); } - + /* Get the resultset and free it */ ALLOC_ZVAL(tmp); Z_LVAL_P(tmp)= sybase_ptr->active_result_index; Z_TYPE_P(tmp)= IS_RESOURCE; INIT_PZVAL(tmp); ZEND_FETCH_RESOURCE(result, sybase_result *, &tmp, -1, "Sybase result", le_result); - + if (result) { php_sybase_finish_results(result TSRMLS_CC); } - + zval_ptr_dtor(&tmp); zend_list_delete(sybase_ptr->active_result_index); sybase_ptr->active_result_index= 0; @@ -1557,7 +1557,7 @@ static void php_sybase_query (INTERNAL_FUNCTION_PARAMETERS, int buffered) status = Q_RESULT; break; } - + /* Check for left-over results */ if (!buffered && status != Q_RESULT) { while ((retcode = ct_results(sybase_ptr->cmd, &restype))==CS_SUCCEED) { @@ -1582,7 +1582,7 @@ static void php_sybase_query (INTERNAL_FUNCTION_PARAMETERS, int buffered) RETURN_FALSE; } status = Q_RESULT; - retcode = result->last_retcode; + retcode = result->last_retcode; } else { /* Unexpected results, cancel them. */ ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT); @@ -1628,7 +1628,7 @@ static void php_sybase_query (INTERNAL_FUNCTION_PARAMETERS, int buffered) } } - /* Retry deadlocks up until deadlock_retry_count times */ + /* Retry deadlocks up until deadlock_retry_count times */ if (sybase_ptr->deadlock && SybCtG(deadlock_retry_count) != -1 && ++deadlock_count > SybCtG(deadlock_retry_count)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Retried deadlock %d times [max: %ld], giving up", deadlock_count- 1, SybCtG(deadlock_retry_count)); FREE_SYBASE_RESULT(result); @@ -1693,14 +1693,14 @@ PHP_FUNCTION(sybase_free_result) return; } ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - + /* Did we fetch up until the end? */ if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) { /* php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: canceling the rest of the results"); */ ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL); php_sybase_finish_results(result TSRMLS_CC); } - + zend_list_delete(Z_LVAL_P(sybase_result_index)); RETURN_TRUE; } @@ -1769,7 +1769,7 @@ PHP_FUNCTION(sybase_fetch_row) if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) { php_sybase_fetch_result_row(result, 1 TSRMLS_CC); } - + /* At the end? */ if (result->cur_row >= result->num_rows) { RETURN_FALSE; @@ -1812,7 +1812,7 @@ static void php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int numerics) } array_init(return_value); - + j= 1; for (i=0; inum_fields; i++) { ALLOC_ZVAL(tmp); @@ -1823,7 +1823,7 @@ static void php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int numerics) zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &tmp, sizeof(zval *), NULL); Z_ADDREF_P(tmp); } - + if (zend_hash_exists(Z_ARRVAL_P(return_value), result->fields[i].name, strlen(result->fields[i].name)+1)) { snprintf(name, 32, "%s%d", result->fields[i].name, j); result->fields[i].name= estrdup(name); @@ -1843,7 +1843,7 @@ PHP_FUNCTION(sybase_fetch_object) zval *sybase_result_index = NULL; zend_class_entry *ce = NULL; sybase_result *result; - + /* Was a second parameter given? */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z", &sybase_result_index, &object) == FAILURE) { return; @@ -1851,7 +1851,7 @@ PHP_FUNCTION(sybase_fetch_object) ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); ce = ZEND_STANDARD_CLASS_DEF_PTR; - if (NULL != object) { + if (NULL != object) { switch (Z_TYPE_P(object)) { case IS_OBJECT: { ce = Z_OBJCE_P(object); @@ -1919,7 +1919,7 @@ PHP_FUNCTION(sybase_data_seek) if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && offset >= result->num_rows) { php_sybase_fetch_result_row(result, offset+ 1 TSRMLS_CC); } - + if (offset < 0 || offset >= result->num_rows) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad row offset %ld, must be betweem 0 and %d", offset, result->num_rows - 1); RETURN_FALSE; @@ -1982,7 +1982,7 @@ PHP_FUNCTION(sybase_fetch_field) long field_offset = -1; sybase_result *result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &sybase_result_index, &field_offset) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_NODEFAULT, ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &sybase_result_index, &field_offset) == FAILURE) { return; } ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); @@ -2048,7 +2048,7 @@ PHP_FUNCTION(sybase_result) return; } ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - + /* Unbuffered ? */ if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && row >= result->num_rows) { php_sybase_fetch_result_row(result, row TSRMLS_CC); @@ -2129,7 +2129,7 @@ PHP_MINFO_FUNCTION(sybase) snprintf(buf, sizeof(buf), "%ld", SybCtG(min_server_severity)); php_info_print_table_row(2, "Min server severity", buf); snprintf(buf, sizeof(buf), "%ld", SybCtG(min_client_severity)); - php_info_print_table_row(2, "Min client severity", buf); + php_info_print_table_row(2, "Min client severity", buf); php_info_print_table_row(2, "Application Name", SybCtG(appname)); snprintf(buf, sizeof(buf), "%ld", SybCtG(deadlock_retry_count)); php_info_print_table_row(2, "Deadlock retry count", buf); @@ -2148,7 +2148,7 @@ PHP_FUNCTION(sybase_min_client_severity) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &severity) == FAILURE) { return; } - + SybCtG(min_client_severity) = severity; } /* }}} */ @@ -2163,7 +2163,7 @@ PHP_FUNCTION(sybase_min_server_severity) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &severity) == FAILURE) { return; } - + SybCtG(min_server_severity) = severity; } /* }}} */ @@ -2177,14 +2177,14 @@ PHP_FUNCTION(sybase_deadlock_retry_count) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &retry_count) == FAILURE) { return; } - + SybCtG(deadlock_retry_count) = retry_count; } /* }}} */ /* {{{ proto bool sybase_set_message_handler(mixed error_func [, resource connection]) - Set the error handler, to be called when a server message is raised. + Set the error handler, to be called when a server message is raised. If error_func is NULL the handler will be deleted */ PHP_FUNCTION(sybase_set_message_handler) { diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index ee96e2eaa11e1..0ffdee0cdbbee 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -180,12 +180,11 @@ static void tokenize(zval *return_value TSRMLS_DC) PHP_FUNCTION(token_get_all) { char *source = NULL; - int argc = ZEND_NUM_ARGS(); int source_len; zval source_z; zend_lex_state original_lex_state; - if (zend_parse_parameters(argc TSRMLS_CC, "s", &source, &source_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) { return; } @@ -200,7 +199,7 @@ PHP_FUNCTION(token_get_all) LANG_SCNG(yy_state) = yycINITIAL; tokenize(return_value TSRMLS_CC); - + zend_restore_lexical_state(&original_lex_state TSRMLS_CC); zval_dtor(&source_z); } @@ -210,10 +209,9 @@ PHP_FUNCTION(token_get_all) */ PHP_FUNCTION(token_name) { - int argc = ZEND_NUM_ARGS(); long type; - if (zend_parse_parameters(argc TSRMLS_CC, "l", &type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) { return; } RETVAL_STRING(get_token_type_name(type), 1); diff --git a/ext/xmlrpc/xmlrpc-epi-php.c b/ext/xmlrpc/xmlrpc-epi-php.c index b73cbcfe2478b..92fa1504b022a 100644 --- a/ext/xmlrpc/xmlrpc-epi-php.c +++ b/ext/xmlrpc/xmlrpc-epi-php.c @@ -1,33 +1,33 @@ /* - This file is part of, or distributed with, libXMLRPC - a C library for + This file is part of, or distributed with, libXMLRPC - a C library for xml-encoded function calls. Author: Dan Libby (dan@libby.com) Epinions.com may be contacted at feedback@epinions-inc.com */ -/* - Copyright 2001 Epinions, Inc. +/* + Copyright 2001 Epinions, Inc. - Subject to the following 3 conditions, Epinions, Inc. permits you, free - of charge, to (a) use, copy, distribute, modify, perform and display this - software and associated documentation files (the "Software"), and (b) - permit others to whom the Software is furnished to do so as well. + Subject to the following 3 conditions, Epinions, Inc. permits you, free + of charge, to (a) use, copy, distribute, modify, perform and display this + software and associated documentation files (the "Software"), and (b) + permit others to whom the Software is furnished to do so as well. - 1) The above copyright notice and this permission notice shall be included - without modification in all copies or substantial portions of the - Software. + 1) The above copyright notice and this permission notice shall be included + without modification in all copies or substantial portions of the + Software. - 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF - ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY - IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR - PURPOSE OR NONINFRINGEMENT. + 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF + ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY + IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE OR NONINFRINGEMENT. - 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, - SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT - OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING - NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH - DAMAGES. + 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, + SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT + OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING + NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH + DAMAGES. */ @@ -144,7 +144,7 @@ ZEND_END_ARG_INFO() /* }}} */ const zend_function_entry xmlrpc_functions[] = { - PHP_FE(xmlrpc_encode, arginfo_xmlrpc_encode) + PHP_FE(xmlrpc_encode, arginfo_xmlrpc_encode) PHP_FE(xmlrpc_decode, arginfo_xmlrpc_decode) PHP_FE(xmlrpc_decode_request, arginfo_xmlrpc_decode_request) PHP_FE(xmlrpc_encode_request, arginfo_xmlrpc_encode_request) @@ -350,7 +350,7 @@ static int add_zval(zval* list, const char* id, zval** val) return zend_hash_update(Z_ARRVAL_P(list), (char*) id, strlen(id) + 1, (void *) val, sizeof(zval **), NULL); } } else { - return zend_hash_next_index_insert(Z_ARRVAL_P(list), (void *) val, sizeof(zval **), NULL); + return zend_hash_next_index_insert(Z_ARRVAL_P(list), (void *) val, sizeof(zval **), NULL); } } /* what is the correct return on error? */ @@ -491,7 +491,7 @@ static XMLRPC_VECTOR_TYPE determine_vector_type (HashTable *ht) zend_hash_internal_pointer_reset(ht); while (1) { int res = my_zend_hash_get_current_key(ht, &my_key, &num_index); - + if (res == HASH_KEY_IS_LONG) { if (bStruct) { bMixed = 1; @@ -524,7 +524,7 @@ static XMLRPC_VALUE PHP_to_XMLRPC_worker (const char* key, zval* in_val, int dep if (in_val) { zval* val = NULL; XMLRPC_VALUE_TYPE type = get_zval_xmlrpc_type(in_val, &val); - + if (val) { switch (type) { case xmlrpc_base64: @@ -573,7 +573,7 @@ static XMLRPC_VALUE PHP_to_XMLRPC_worker (const char* key, zval* in_val, int dep MAKE_STD_ZVAL(val_arr); MAKE_COPY_ZVAL(&val, val_arr); convert_to_array(val_arr); - + vtype = determine_vector_type(Z_ARRVAL_P(val_arr)); xReturn = XMLRPC_CreateVector(key, vtype); @@ -592,7 +592,7 @@ static XMLRPC_VALUE PHP_to_XMLRPC_worker (const char* key, zval* in_val, int dep } if (res == HASH_KEY_IS_LONG) { char *num_str = NULL; - + if (vtype != xmlrpc_vector_array) { spprintf(&num_str, 0, "%ld", num_index); } @@ -609,7 +609,7 @@ static XMLRPC_VALUE PHP_to_XMLRPC_worker (const char* key, zval* in_val, int dep break; } zend_hash_move_forward(Z_ARRVAL_P(val_arr)); - } + } zval_ptr_dtor(&val_arr); } break; @@ -736,7 +736,7 @@ PHP_FUNCTION(xmlrpc_encode_request) XMLRPC_RequestFree(xRequest, 1); } } - + if (strcmp(out.xmlrpc_out.xml_elem_opts.encoding, ENCODING_DEFAULT) != 0) { efree((char *)out.xmlrpc_out.xml_elem_opts.encoding); } @@ -871,10 +871,10 @@ PHP_FUNCTION(xmlrpc_server_create) xmlrpc_server_data *server = emalloc(sizeof(xmlrpc_server_data)); MAKE_STD_ZVAL(method_map); MAKE_STD_ZVAL(introspection_map); - + array_init(method_map); array_init(introspection_map); - + /* allocate server data. free'd in destroy_server_data() */ server->method_map = method_map; server->introspection_map = introspection_map; @@ -912,7 +912,7 @@ PHP_FUNCTION(xmlrpc_server_destroy) RETVAL_LONG(bSuccess == SUCCESS); } /* }}} */ - + /* called by xmlrpc C engine as method handler for all registered methods. * it then calls the corresponding PHP function to handle the method. */ @@ -930,11 +930,11 @@ static XMLRPC_VALUE php_xmlrpc_callback(XMLRPC_SERVER server, XMLRPC_REQUEST xRe /* convert xmlrpc to native php types */ ZVAL_STRING(pData->xmlrpc_method, XMLRPC_RequestGetMethodName(xRequest), 1); xmlrpc_params = XMLRPC_to_PHP(XMLRPC_RequestGetData(xRequest)); - + /* check if the called method has been previous registered */ if(zend_hash_find(Z_ARRVAL_P(pData->server->method_map), - Z_STRVAL_P(pData->xmlrpc_method), - Z_STRLEN_P(pData->xmlrpc_method) + 1, + Z_STRVAL_P(pData->xmlrpc_method), + Z_STRLEN_P(pData->xmlrpc_method) + 1, (void**)&php_function) == SUCCESS) { pData->php_function = *php_function; @@ -995,7 +995,7 @@ static void php_xmlrpc_introspection_callback(XMLRPC_SERVER server, void* data) } else { /* could not create description */ if (err.xml_elem_error.parser_code) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error: [line %ld, column %ld, message: %s] Unable to add introspection data returned from %s()", + php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error: [line %ld, column %ld, message: %s] Unable to add introspection data returned from %s()", err.xml_elem_error.column, err.xml_elem_error.line, err.xml_elem_error.parser_error, php_function_name); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to add introspection data returned from %s()", php_function_name); @@ -1015,7 +1015,7 @@ static void php_xmlrpc_introspection_callback(XMLRPC_SERVER server, void* data) } zend_hash_move_forward(Z_ARRVAL_P(pData->server->introspection_map)); } - + /* so we don't call the same callbacks ever again */ zend_hash_clean(Z_ARRVAL_P(pData->server->introspection_map)); } @@ -1038,7 +1038,7 @@ PHP_FUNCTION(xmlrpc_server_register_method) server = zend_list_find(Z_LVAL_P(handle), &type); if (type == le_xmlrpc_server) { - /* register with C engine. every method just calls our standard callback, + /* register with C engine. every method just calls our standard callback, * and it then dispatches to php as necessary */ if (XMLRPC_ServerRegisterMethod(server->server_ptr, method_key, php_xmlrpc_callback)) { @@ -1098,17 +1098,12 @@ PHP_FUNCTION(xmlrpc_server_call_method) char *rawxml; int rawxml_len, type; php_output_options out; - int argc =ZEND_NUM_ARGS(); - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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); server = zend_list_find(Z_LVAL_P(handle), &type); @@ -1132,7 +1127,7 @@ PHP_FUNCTION(xmlrpc_server_call_method) data.php_executed = 0; data.server = server; - /* We could just call the php method directly ourselves at this point, but we do this + /* We could just call the php method directly ourselves at this point, but we do this * with a C callback in case the xmlrpc library ever implements some cool usage stats, * or somesuch. */ @@ -1153,7 +1148,7 @@ PHP_FUNCTION(xmlrpc_server_call_method) int buf_len = 0; /* automagically determine output serialization type from request type */ - if (out.b_auto_version) { + if (out.b_auto_version) { XMLRPC_REQUEST_OUTPUT_OPTIONS opts = XMLRPC_RequestGetOutputOptions(xRequest); if (opts) { out.xmlrpc_out.version = opts->version; @@ -1247,7 +1242,7 @@ PHP_FUNCTION(xmlrpc_parse_method_descriptions) } else { /* could not create description */ if (err.xml_elem_error.parser_code) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error: [line %ld, column %ld, message: %s] Unable to create introspection data", + php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error: [line %ld, column %ld, message: %s] Unable to create introspection data", err.xml_elem_error.column, err.xml_elem_error.line, err.xml_elem_error.parser_error); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid xml structure. Unable to create introspection data"); @@ -1340,7 +1335,7 @@ XMLRPC_VECTOR_TYPE xmlrpc_str_as_vector_type(const char* str) /* {{{ */ } /* }}} */ -/* set a given value to a particular type. +/* set a given value to a particular type. * note: this only works on strings, and only for date and base64, * which do not have native php types. black magic lies herein. */ @@ -1507,7 +1502,7 @@ PHP_FUNCTION(xmlrpc_get_type) if (type == xmlrpc_vector) { vtype = determine_vector_type((Z_TYPE_PP(arg) == IS_OBJECT) ? Z_OBJPROP_PP(arg) : Z_ARRVAL_PP(arg)); } - + RETURN_STRING((char*) xmlrpc_type_as_str(type, vtype), 1); } /* }}} */ @@ -1528,7 +1523,7 @@ PHP_FUNCTION(xmlrpc_is_fault) * array, which is rather expensive, especially if it was * a big array. Thus, we resort to this not so clever hackery. */ - if (zend_hash_find(Z_ARRVAL_P(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS && + if (zend_hash_find(Z_ARRVAL_P(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS && zend_hash_find(Z_ARRVAL_P(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS) { RETURN_TRUE; } diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 221b0021756dc..d3d62fbd71f3e 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1518,9 +1518,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(); } @@ -1577,9 +1577,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); @@ -1688,9 +1688,9 @@ static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS PHP_FUNCTION(apache_response_headers) /* {{{ */ { - if (ZEND_NUM_ARGS() > 0) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters_none() == FAILURE) { + RETURN_FALSE; + } if (!&SG(sapi_headers).headers) { RETURN_FALSE;