diff options
author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-09-07 17:38:14 +0200 |
---|---|---|
committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-09-08 15:38:23 +0200 |
commit | 3b0fecd508a3541f539a4aa4841ed8b96df14255 (patch) | |
tree | fd7c8fd1c75f4eb6819dc7a2b1349dc33bc263fd | |
parent | 7e339a335e87d9c8d0b6994039220890284df63e (diff) | |
download | php-git-3b0fecd508a3541f539a4aa4841ed8b96df14255.tar.gz |
Fix UNKNOWN default values in ext/oci8
Closes GH-6089
-rw-r--r-- | ext/oci8/oci8.c | 2 | ||||
-rw-r--r-- | ext/oci8/oci8.stub.php | 40 | ||||
-rw-r--r-- | ext/oci8/oci8_arginfo.h | 30 | ||||
-rw-r--r-- | ext/oci8/oci8_interface.c | 77 |
4 files changed, 67 insertions, 82 deletions
diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index f9e65939a5..48b6c5c936 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -877,7 +877,7 @@ void php_oci_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent, int exclus Z_PARAM_STRING(username, username_len) Z_PARAM_STRING(password, password_len) Z_PARAM_OPTIONAL - Z_PARAM_STRING(dbname, dbname_len) + Z_PARAM_STRING_OR_NULL(dbname, dbname_len) Z_PARAM_STRING(charset, charset_len) Z_PARAM_LONG(session_mode) ZEND_PARSE_PARAMETERS_END(); diff --git a/ext/oci8/oci8.stub.php b/ext/oci8/oci8.stub.php index 7a17430dc0..8e8537274a 100644 --- a/ext/oci8/oci8.stub.php +++ b/ext/oci8/oci8.stub.php @@ -69,13 +69,13 @@ function oci_lob_seek(OCILob $lob_descriptor, int $offset, int $whence = OCI_SEE function oci_lob_size(OCILob $lob_descriptor): int|false {} -function oci_lob_write(OCILob $lob_descriptor, string $string, int $length = UNKNOWN): int|false {} +function oci_lob_write(OCILob $lob_descriptor, string $string, ?int $length = null): int|false {} function oci_lob_append(OCILob $lob_descriptor_to, OCILob $lob_descriptor_from): bool {} function oci_lob_truncate(OCILob $lob_descriptor, int $length = 0): bool {} -function oci_lob_erase(OCILob $lob_descriptor, int $offset = UNKNOWN, int $length = UNKNOWN): int|false {} +function oci_lob_erase(OCILob $lob_descriptor, ?int $offset = null, ?int $length = null): int|false {} function oci_lob_flush(OCILob $lob_descriptor, int $flag = 0): bool {} @@ -83,17 +83,17 @@ function ocisetbufferinglob(OCILob $lob_descriptor, bool $mode): bool {} function ocigetbufferinglob(OCILob $lob_descriptor): bool {} -function oci_lob_copy(OCILob $lob_descriptor_to, OCILob $lob_descriptor_from, int $length = UNKNOWN): bool {} +function oci_lob_copy(OCILob $lob_descriptor_to, OCILob $lob_descriptor_from, ?int $length = null): bool {} function oci_lob_is_equal(OCILob $lob_descriptor_first, OCILob $lob_descriptor_second): bool {} -function oci_lob_export(OCILob $lob_descriptor, string $path, int $start = UNKNOWN, int $length = UNKNOWN): bool {} +function oci_lob_export(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {} /** * @alias oci_lob_export * @deprecated */ -function ociwritelobtofile(OCILob $lob_descriptor, string $path, int $start = UNKNOWN, int $length = UNKNOWN): bool {} +function ociwritelobtofile(OCILob $lob_descriptor, string $path, ?int $start = null, ?int $length = null): bool {} /** * @param resource $connection_resource @@ -332,50 +332,50 @@ function ocilogoff($connection_resource): bool|null {} /** * @return resource|false */ -function oci_new_connect(string $username, string $password, string $connection_string = UNKNOWN, string $character_set = '', int $session_mode = OCI_DEFAULT) {} +function oci_new_connect(string $username, string $password, ?string $connection_string = null, string $character_set = '', int $session_mode = OCI_DEFAULT) {} /** * @return resource|false * @alias oci_new_connect * @deprecated */ -function ocinlogon(string $username, string $password, string $connection_string = UNKNOWN, string $character_set = '', int $session_mode = OCI_DEFAULT) {} +function ocinlogon(string $username, string $password, ?string $connection_string = null, string $character_set = '', int $session_mode = OCI_DEFAULT) {} /** * @return resource|false */ -function oci_connect(string $username, string $password, string $connection_string = UNKNOWN, string $character_set = '', int $session_mode = OCI_DEFAULT) {} +function oci_connect(string $username, string $password, ?string $connection_string = null, string $character_set = '', int $session_mode = OCI_DEFAULT) {} /** * @return resource|false * @alias oci_connect * @deprecated */ -function ocilogon(string $username, string $password, string $connection_string = UNKNOWN, string $character_set = '', int $session_mode = OCI_DEFAULT) {} +function ocilogon(string $username, string $password, ?string $connection_string = null, string $character_set = '', int $session_mode = OCI_DEFAULT) {} /** * @return resource|false */ -function oci_pconnect(string $username, string $password, string $connection_string = UNKNOWN, string $character_set = '', int $session_mode = OCI_DEFAULT) {} +function oci_pconnect(string $username, string $password, ?string $connection_string = null, string $character_set = '', int $session_mode = OCI_DEFAULT) {} /** * @return resource|false * @alias oci_pconnect * @deprecated */ -function ociplogon(string $username, string $password, string $connection_string = UNKNOWN, string $character_set = '', int $session_mode = OCI_DEFAULT) {} +function ociplogon(string $username, string $password, ?string $connection_string = null, string $character_set = '', int $session_mode = OCI_DEFAULT) {} /** - * @param resource $connection_or_statement_resource + * @param resource|null $connection_or_statement_resource */ -function oci_error($connection_or_statement_resource = UNKNOWN): array|false {} +function oci_error($connection_or_statement_resource = null): array|false {} /** * @param resource|null $connection_or_statement_resource * @alias oci_error * @deprecated */ -function ocierror($connection_or_statement_resource = UNKNOWN): array|false {} +function ocierror($connection_or_statement_resource = null): array|false {} /** * @param resource $statement_resource @@ -592,14 +592,14 @@ function ocicolltrim(OCICollection $collection, int $number): bool {} /** * @param resource $connection_resource */ -function oci_new_collection($connection_resource, string $type_name, string $schema_name = UNKNOWN): OCICollection|false {} +function oci_new_collection($connection_resource, string $type_name, ?string $schema_name = null): OCICollection|false {} /** * @param resource $connection_resource * @alias oci_new_collection * @deprecated */ -function ocinewcollection($connection_resource, string $type_name, string $schema_name = UNKNOWN): OCICollection|false {} +function ocinewcollection($connection_resource, string $type_name, ?string $schema_name = null): OCICollection|false {} /** * @param resource $connection_resource @@ -676,7 +676,7 @@ class OCILob { * @alias oci_lob_write * @return int|false */ - public function write(string $string, int $length = UNKNOWN) {} + public function write(string $string, ?int $length = null) {} /** * @alias oci_lob_append @@ -694,7 +694,7 @@ class OCILob { * @alias oci_lob_erase * @return int|false */ - public function erase(int $offset = UNKNOWN, int $length = UNKNOWN) {} + public function erase(?int $offset = null, ?int $length = null) {} /** * @alias oci_lob_flush @@ -718,13 +718,13 @@ class OCILob { * @alias oci_lob_export * @return bool */ - public function writetofile(string $path, int $start = UNKNOWN, int $length = UNKNOWN) {} + public function writetofile(string $path, ?int $start = null, ?int $length = null) {} /** * @alias oci_lob_export * @return bool */ - public function export(string $path, int $start = UNKNOWN, int $length = UNKNOWN) {} + public function export(string $path, ?int $start = null, ?int $length = null) {} /** * @alias oci_lob_write_temporary diff --git a/ext/oci8/oci8_arginfo.h b/ext/oci8/oci8_arginfo.h index 729ac02240..3285278999 100644 --- a/ext/oci8/oci8_arginfo.h +++ b/ext/oci8/oci8_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 447880a4bc4add36beab835cc07c09a254dc0c2b */ + * Stub hash: 2d553815c21edd58bc29b1ca8d294d5750fd7312 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0) ZEND_ARG_INFO(0, statement_resource) @@ -80,7 +80,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_oci_lob_write, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, lob_descriptor, OCILob, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_append, 0, 2, _IS_BOOL, 0) @@ -95,8 +95,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_oci_lob_erase, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, lob_descriptor, OCILob, 0) - ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_flush, 0, 1, _IS_BOOL, 0) @@ -114,7 +114,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_copy, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, lob_descriptor_to, OCILob, 0) ZEND_ARG_OBJ_INFO(0, lob_descriptor_from, OCILob, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_is_equal, 0, 2, _IS_BOOL, 0) @@ -125,8 +125,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_lob_export, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, lob_descriptor, OCILob, 0) ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() #define arginfo_ociwritelobtofile arginfo_oci_lob_export @@ -254,7 +254,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_new_connect, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, connection_string, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, character_set, IS_STRING, 0, "\'\'") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, session_mode, IS_LONG, 0, "OCI_DEFAULT") ZEND_END_ARG_INFO() @@ -270,7 +270,7 @@ ZEND_END_ARG_INFO() #define arginfo_ociplogon arginfo_oci_new_connect ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_oci_error, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, connection_or_statement_resource) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection_or_statement_resource, "null") ZEND_END_ARG_INFO() #define arginfo_ocierror arginfo_oci_error @@ -426,7 +426,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_oci_new_collection, 0, 2, OCICollection, MAY_BE_FALSE) ZEND_ARG_INFO(0, connection_resource) ZEND_ARG_TYPE_INFO(0, type_name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, schema_name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, schema_name, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_ocinewcollection arginfo_oci_new_collection @@ -471,7 +471,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_write, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_append, 0, 0, 1) @@ -483,8 +483,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_truncate, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_erase, 0, 0, 0) - ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_OCILob_flush, 0, 0, _IS_BOOL, 0) @@ -499,8 +499,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_OCILob_writetofile, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() #define arginfo_class_OCILob_export arginfo_class_OCILob_writetofile diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 500011ab51..0c083c72cb 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -530,19 +530,16 @@ PHP_FUNCTION(oci_lob_write) zval *tmp, *z_descriptor; php_oci_descriptor *descriptor; size_t data_len; - zend_long write_len = 0; + zend_long write_len; + zend_bool write_len_is_null = 1; ub4 bytes_written; char *data; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &write_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l!", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &write_len, &write_len_is_null) == FAILURE) { RETURN_THROWS(); } - if (getThis() && ZEND_NUM_ARGS() == 2) { - data_len = MIN((zend_long) data_len, write_len); - } - - if (!getThis() && ZEND_NUM_ARGS() == 3) { + if (!write_len_is_null) { data_len = MIN((zend_long) data_len, write_len); } @@ -633,28 +630,23 @@ PHP_FUNCTION(oci_lob_erase) zval *tmp, *z_descriptor; php_oci_descriptor *descriptor; ub4 bytes_erased; - zend_long offset = -1, length = -1; + zend_long offset, length; + zend_bool offset_is_null = 1, length_is_null = 1; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &offset, &offset_is_null, &length, &length_is_null) == FAILURE) { RETURN_THROWS(); } - if (getThis() && ZEND_NUM_ARGS() > 0 && offset < 0) { + if (offset_is_null) { + offset = -1; + } else if (offset < 0) { php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0"); RETURN_FALSE; } - if (getThis() && ZEND_NUM_ARGS() > 1 && length < 0) { - php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0"); - RETURN_FALSE; - } - - if (!getThis() && ZEND_NUM_ARGS() > 1 && offset < 0) { - php_error_docref(NULL, E_WARNING, "Offset must be greater than or equal to 0"); - RETURN_FALSE; - } - - if (!getThis() && ZEND_NUM_ARGS() > 2 && length < 0) { + if (length_is_null) { + length = -1; + } else if (length < 0) { php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0"); RETURN_FALSE; } @@ -757,9 +749,10 @@ PHP_FUNCTION(oci_lob_copy) { zval *tmp_dest, *tmp_from, *z_descriptor_dest, *z_descriptor_from; php_oci_descriptor *descriptor_dest, *descriptor_from; - zend_long length = 0; + zend_long length; + zend_bool length_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO|l", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO|l!", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length, &length_is_null) == FAILURE) { RETURN_THROWS(); } @@ -776,16 +769,13 @@ PHP_FUNCTION(oci_lob_copy) 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) { + if (length_is_null) { + length = -1; + } else if (length < 0) { php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0"); RETURN_FALSE; } - if (ZEND_NUM_ARGS() == 2) { - /* indicate that we want to copy from the current position to the end of the LOB */ - length = -1; - } - if (php_oci_lob_copy(descriptor_dest, descriptor_from, length)) { RETURN_FALSE; } @@ -836,30 +826,25 @@ PHP_FUNCTION(oci_lob_export) char *filename; char *buffer; size_t filename_len; - zend_long start = -1, length = -1, block_length; + zend_long start, length, block_length; + zend_bool start_is_null = 1, length_is_null = 1; php_stream *stream; ub4 lob_length; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|ll", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|l!l!", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) { RETURN_THROWS(); } - if (getThis() && ZEND_NUM_ARGS() > 1 && start < 0) { + if (start_is_null) { + start = -1; + } else if (start < 0) { php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0"); RETURN_FALSE; } - if (getThis() && ZEND_NUM_ARGS() > 2 && length < 0) { - php_error_docref(NULL, E_WARNING, "length parameter must be greater than or equal to 0"); - RETURN_FALSE; - } - - if (!getThis() && ZEND_NUM_ARGS() > 2 && start < 0) { - php_error_docref(NULL, E_WARNING, "Start parameter must be greater than or equal to 0"); - RETURN_FALSE; - } - - if (!getThis() && ZEND_NUM_ARGS() > 3 && length < 0) { + if (length_is_null) { + length = -1; + } else if (length < 0) { php_error_docref(NULL, E_WARNING, "length parameter must be greater than or equal to 0"); RETURN_FALSE; } @@ -1531,10 +1516,10 @@ PHP_FUNCTION(oci_error) ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_RESOURCE(arg) + Z_PARAM_RESOURCE_OR_NULL(arg) ZEND_PARSE_PARAMETERS_END(); - if (ZEND_NUM_ARGS() > 0) { + if (arg) { statement = (php_oci_statement *) zend_fetch_resource_ex(arg, NULL, le_statement); if (statement) { errh = statement->err; @@ -2313,7 +2298,7 @@ PHP_FUNCTION(oci_new_collection) char *tdo, *schema = NULL; size_t tdo_len, schema_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s!", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) { RETURN_THROWS(); } |