summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-09-16 22:33:23 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-09-17 11:00:59 +0200
commit8d37c37bcdbf6fa99cd275413342457eeb2c664e (patch)
treef3b55ebb8246b89075be7e1e2270359efdcbf849 /ext/pgsql
parente9820bf470c125266abfd9fac1bb0e2f766db90f (diff)
downloadphp-git-8d37c37bcdbf6fa99cd275413342457eeb2c664e.tar.gz
Fix a few UNKNOWN default values in ext/pgsql
Closes GH-6149
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/pgsql.c56
-rw-r--r--ext/pgsql/pgsql.stub.php66
-rw-r--r--ext/pgsql/pgsql_arginfo.h14
3 files changed, 63 insertions, 73 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 314f28404a..31bb834314 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -729,7 +729,7 @@ PHP_FUNCTION(pg_close)
zval *pgsql_link = NULL;
zend_resource *link;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
@@ -769,16 +769,15 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
{
zend_resource *link;
zval *pgsql_link = NULL;
- int argc = ZEND_NUM_ARGS();
PGconn *pgsql;
char *msgbuf;
char *result;
- if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
- if (argc == 0) {
+ if (!pgsql_link) {
link = FETCH_DEFAULT_LINK();
CHECK_DEFAULT_LINK(link);
} else {
@@ -937,7 +936,7 @@ PHP_FUNCTION(pg_ping)
PGresult *res;
zend_resource *link;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
@@ -983,13 +982,13 @@ PHP_FUNCTION(pg_query)
ExecStatusType status;
if (argc == 1) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &query, &query_len) == FAILURE) {
+ if (zend_parse_parameters(argc, "s", &query, &query_len) == FAILURE) {
RETURN_THROWS();
}
link = FETCH_DEFAULT_LINK();
CHECK_DEFAULT_LINK(link);
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &pgsql_link, &query, &query_len) == FAILURE) {
+ if (zend_parse_parameters(argc, "rs", &pgsql_link, &query, &query_len) == FAILURE) {
RETURN_THROWS();
}
link = Z_RES_P(pgsql_link);
@@ -2227,17 +2226,16 @@ PHP_FUNCTION(pg_trace)
char *z_filename, *mode = "w";
size_t z_filename_len, mode_len;
zval *pgsql_link = NULL;
- int argc = ZEND_NUM_ARGS();
PGconn *pgsql;
FILE *fp = NULL;
php_stream *stream;
zend_resource *link;
- if (zend_parse_parameters(argc, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sr!", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
- if (argc < 3) {
+ if (!pgsql_link) {
link = FETCH_DEFAULT_LINK();
CHECK_DEFAULT_LINK(link);
} else {
@@ -2271,7 +2269,7 @@ PHP_FUNCTION(pg_untrace)
PGconn *pgsql;
zend_resource *link;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
@@ -2622,16 +2620,16 @@ PHP_FUNCTION(pg_lo_write)
zval *pgsql_id;
char *str;
zend_long z_len;
+ zend_bool z_len_is_null = 1;
size_t str_len, nbytes;
size_t len;
pgLofp *pgsql;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rs|l", &pgsql_id, &str, &str_len, &z_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l!", &pgsql_id, &str, &str_len, &z_len, &z_len_is_null) == FAILURE) {
RETURN_THROWS();
}
- if (argc > 2) {
+ if (!z_len_is_null) {
if (z_len < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
RETURN_THROWS();
@@ -2840,9 +2838,8 @@ PHP_FUNCTION(pg_lo_seek)
zval *pgsql_id = NULL;
zend_long result, offset = 0, whence = SEEK_CUR;
pgLofp *pgsql;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rl|l", &pgsql_id, &offset, &whence) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &pgsql_id, &offset, &whence) == FAILURE) {
RETURN_THROWS();
}
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) {
@@ -2877,9 +2874,8 @@ PHP_FUNCTION(pg_lo_tell)
zval *pgsql_id = NULL;
zend_long offset = 0;
pgLofp *pgsql;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "r", &pgsql_id) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pgsql_id) == FAILURE) {
RETURN_THROWS();
}
@@ -2906,10 +2902,9 @@ PHP_FUNCTION(pg_lo_truncate)
zval *pgsql_id = NULL;
size_t size;
pgLofp *pgsql;
- int argc = ZEND_NUM_ARGS();
int result;
- if (zend_parse_parameters(argc, "rl", &pgsql_id, &size) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &pgsql_id, &size) == FAILURE) {
RETURN_THROWS();
}
@@ -3006,7 +3001,7 @@ PHP_FUNCTION(pg_client_encoding)
PGconn *pgsql;
zend_resource *link;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
@@ -3035,7 +3030,7 @@ PHP_FUNCTION(pg_end_copy)
int result = 0;
zend_resource *link;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
RETURN_THROWS();
}
@@ -3107,9 +3102,8 @@ PHP_FUNCTION(pg_copy_to)
PGresult *pgsql_result;
ExecStatusType status;
char *csv = (char *)NULL;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rs|ss",
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|ss",
&pgsql_link, &table_name, &table_name_len,
&pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) {
RETURN_THROWS();
@@ -3198,9 +3192,8 @@ PHP_FUNCTION(pg_copy_from)
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rsa|ss",
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|ss",
&pgsql_link, &table_name, &table_name_len, &pg_rows,
&pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) {
RETURN_THROWS();
@@ -3372,7 +3365,7 @@ PHP_FUNCTION(pg_unescape_bytea)
char *from = NULL, *to = NULL, *tmp = NULL;
size_t to_len;
size_t from_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!",
&from, &from_len) == FAILURE) {
RETURN_THROWS();
}
@@ -5461,9 +5454,8 @@ PHP_FUNCTION(pg_insert)
PGresult *pg_result;
ExecStatusType status;
zend_string *sql = NULL;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rsa|l",
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l",
&pgsql_link, &table, &table_len, &values, &option) == FAILURE) {
RETURN_THROWS();
}
@@ -5678,9 +5670,8 @@ PHP_FUNCTION(pg_update)
zend_ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
zend_string *sql = NULL;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rsaa|l",
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsaa|l",
&pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) {
RETURN_THROWS();
}
@@ -5775,9 +5766,8 @@ PHP_FUNCTION(pg_delete)
zend_ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
zend_string *sql;
- int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc, "rsa|l",
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l",
&pgsql_link, &table, &table_len, &ids, &option) == FAILURE) {
RETURN_THROWS();
}
diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php
index 3d8ce3a701..0995e0463f 100644
--- a/ext/pgsql/pgsql.stub.php
+++ b/ext/pgsql/pgsql.stub.php
@@ -11,41 +11,41 @@ function pg_pconnect(string $connection_string, int $connection_type = 0) {}
/** @param resource $connection */
function pg_connect_poll($connection): int {}
-/** @param resource $connection */
-function pg_close($connection = UNKNOWN): bool {}
+/** @param resource|null $connection */
+function pg_close($connection = null): bool {}
-/** @param resource $connection */
-function pg_dbname($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_dbname($connection = null): string {}
-/** @param resource $connection */
-function pg_last_error($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_last_error($connection = null): string {}
/**
- * @param resource $connection
+ * @param resource|null $connection
* @alias pg_last_error
*/
-function pg_errormessage($connection = UNKNOWN): string {}
+function pg_errormessage($connection = null): string {}
-/** @param resource $connection */
-function pg_options($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_options($connection = null): string {}
-/** @param resource $connection */
-function pg_port($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_port($connection = null): string {}
-/** @param resource $connection */
-function pg_tty($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_tty($connection = null): string {}
-/** @param resource $connection */
-function pg_host($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_host($connection = null): string {}
-/** @param resource $connection */
-function pg_version($connection = UNKNOWN): array {}
+/** @param resource|null $connection */
+function pg_version($connection = null): array {}
/** @param resource|string $connection */
function pg_parameter_status($connection, string $param_name = UNKNOWN): string|false {}
-/** @param resource $connection */
-function pg_ping($connection = UNKNOWN): bool {}
+/** @param resource|null $connection */
+function pg_ping($connection = null): bool {}
/**
* @param resource|string $connection
@@ -236,11 +236,11 @@ function pg_last_oid($result): string|int|false {}
*/
function pg_getlastoid($result): string|int|false {}
-/** @param resource $connection */
-function pg_trace(string $filename, string $mode = "w", $connection = UNKNOWN): bool {}
+/** @param resource|null $connection */
+function pg_trace(string $filename, string $mode = "w", $connection = null): bool {}
-/** @param resource $connection */
-function pg_untrace($connection = UNKNOWN): bool {}
+/** @param resource|null $connection */
+function pg_untrace($connection = null): bool {}
/**
* @param resource $connection
@@ -302,13 +302,13 @@ function pg_lo_read($large_object, int $len = 8192): string|false {}
function pg_loread($large_object, int $len = 8192): string|false {}
/** @param resource $large_object */
-function pg_lo_write($large_object, string $buf, int $len = UNKNOWN): int|false {}
+function pg_lo_write($large_object, string $buf, ?int $len = null): int|false {}
/**
* @param resource $large_object
* @alias pg_lo_write
*/
-function pg_lowrite($large_object, string $buf, int $len = UNKNOWN): int|false {}
+function pg_lowrite($large_object, string $buf, ?int $len = null): int|false {}
/** @param resource $large_object */
function pg_lo_read_all($large_object): int {}
@@ -374,17 +374,17 @@ function pg_set_client_encoding($connection, string $encoding = UNKNOWN): int {}
*/
function pg_setclientencoding($connection, string $encoding = UNKNOWN): int {}
-/** @param resource $connection */
-function pg_client_encoding($connection = UNKNOWN): string {}
+/** @param resource|null $connection */
+function pg_client_encoding($connection = null): string {}
/**
- * @param resource $connection
+ * @param resource|null $connection
* @alias pg_client_encoding
*/
-function pg_clientencoding($connection = UNKNOWN): string {}
+function pg_clientencoding($connection = null): string {}
-/** @param resource $connection */
-function pg_end_copy($connection = UNKNOWN): bool {}
+/** @param resource|null $connection */
+function pg_end_copy($connection = null): bool {}
/** @param resource|string $connection */
function pg_put_line($connection, string $query = UNKNOWN): bool {}
@@ -401,7 +401,7 @@ function pg_escape_string($connection, string $data = UNKNOWN): string {}
/** @param resource|string $connection */
function pg_escape_bytea($connection, string $data = UNKNOWN): string {}
-function pg_unescape_bytea(string $data = UNKNOWN): string|false {}
+function pg_unescape_bytea(?string $data = null): string|false {}
/** @param resource|string $connection */
function pg_escape_literal($connection, string $data = UNKNOWN): string|false {}
diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h
index 0c9234acdc..544e0ad4a6 100644
--- a/ext/pgsql/pgsql_arginfo.h
+++ b/ext/pgsql/pgsql_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 90dd576049fe13617343fe689000b94b20f47655 */
+ * Stub hash: 907a616e7138369e6e3ccbbb10e6c0f2a380fe93 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_connect, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0)
@@ -13,11 +13,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_connect_poll, 0, 1, IS_LONG,
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_close, 0, 0, _IS_BOOL, 0)
- ZEND_ARG_INFO(0, connection)
+ ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_dbname, 0, 0, IS_STRING, 0)
- ZEND_ARG_INFO(0, connection)
+ ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
ZEND_END_ARG_INFO()
#define arginfo_pg_last_error arginfo_pg_dbname
@@ -33,7 +33,7 @@ ZEND_END_ARG_INFO()
#define arginfo_pg_host arginfo_pg_dbname
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_version, 0, 0, IS_ARRAY, 0)
- ZEND_ARG_INFO(0, connection)
+ ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_parameter_status, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
@@ -197,7 +197,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_trace, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 0, "\"w\"")
- ZEND_ARG_INFO(0, connection)
+ ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
ZEND_END_ARG_INFO()
#define arginfo_pg_untrace arginfo_pg_close
@@ -240,7 +240,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_lo_write, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_INFO(0, large_object)
ZEND_ARG_TYPE_INFO(0, buf, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, len, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, len, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_pg_lowrite arginfo_pg_lo_write
@@ -326,7 +326,7 @@ ZEND_END_ARG_INFO()
#define arginfo_pg_escape_bytea arginfo_pg_escape_string
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_unescape_bytea, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, data, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_escape_literal, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)