Skip to content

Fix a few UNKNOWN default values in ext/pgsql #6149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
66 changes: 33 additions & 33 deletions ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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 {}
Expand All @@ -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 {}
Expand Down
Loading