Skip to content

Commit 3523d0f

Browse files
committed
Fix a few UNKNOWN default values in ext/pgsql
1 parent 36fd95b commit 3523d0f

File tree

3 files changed

+63
-73
lines changed

3 files changed

+63
-73
lines changed

ext/pgsql/pgsql.c

+23-33
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ PHP_FUNCTION(pg_close)
729729
zval *pgsql_link = NULL;
730730
zend_resource *link;
731731

732-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
732+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
733733
RETURN_THROWS();
734734
}
735735

@@ -769,16 +769,15 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
769769
{
770770
zend_resource *link;
771771
zval *pgsql_link = NULL;
772-
int argc = ZEND_NUM_ARGS();
773772
PGconn *pgsql;
774773
char *msgbuf;
775774
char *result;
776775

777-
if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) {
776+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
778777
RETURN_THROWS();
779778
}
780779

781-
if (argc == 0) {
780+
if (!pgsql_link) {
782781
link = FETCH_DEFAULT_LINK();
783782
CHECK_DEFAULT_LINK(link);
784783
} else {
@@ -937,7 +936,7 @@ PHP_FUNCTION(pg_ping)
937936
PGresult *res;
938937
zend_resource *link;
939938

940-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
939+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
941940
RETURN_THROWS();
942941
}
943942

@@ -983,13 +982,13 @@ PHP_FUNCTION(pg_query)
983982
ExecStatusType status;
984983

985984
if (argc == 1) {
986-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &query, &query_len) == FAILURE) {
985+
if (zend_parse_parameters(argc, "s", &query, &query_len) == FAILURE) {
987986
RETURN_THROWS();
988987
}
989988
link = FETCH_DEFAULT_LINK();
990989
CHECK_DEFAULT_LINK(link);
991990
} else {
992-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &pgsql_link, &query, &query_len) == FAILURE) {
991+
if (zend_parse_parameters(argc, "rs", &pgsql_link, &query, &query_len) == FAILURE) {
993992
RETURN_THROWS();
994993
}
995994
link = Z_RES_P(pgsql_link);
@@ -2227,17 +2226,16 @@ PHP_FUNCTION(pg_trace)
22272226
char *z_filename, *mode = "w";
22282227
size_t z_filename_len, mode_len;
22292228
zval *pgsql_link = NULL;
2230-
int argc = ZEND_NUM_ARGS();
22312229
PGconn *pgsql;
22322230
FILE *fp = NULL;
22332231
php_stream *stream;
22342232
zend_resource *link;
22352233

2236-
if (zend_parse_parameters(argc, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
2234+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sr!", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
22372235
RETURN_THROWS();
22382236
}
22392237

2240-
if (argc < 3) {
2238+
if (!pgsql_link) {
22412239
link = FETCH_DEFAULT_LINK();
22422240
CHECK_DEFAULT_LINK(link);
22432241
} else {
@@ -2271,7 +2269,7 @@ PHP_FUNCTION(pg_untrace)
22712269
PGconn *pgsql;
22722270
zend_resource *link;
22732271

2274-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
2272+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
22752273
RETURN_THROWS();
22762274
}
22772275

@@ -2622,16 +2620,16 @@ PHP_FUNCTION(pg_lo_write)
26222620
zval *pgsql_id;
26232621
char *str;
26242622
zend_long z_len;
2623+
zend_bool z_len_is_null = 1;
26252624
size_t str_len, nbytes;
26262625
size_t len;
26272626
pgLofp *pgsql;
2628-
int argc = ZEND_NUM_ARGS();
26292627

2630-
if (zend_parse_parameters(argc, "rs|l", &pgsql_id, &str, &str_len, &z_len) == FAILURE) {
2628+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l!", &pgsql_id, &str, &str_len, &z_len, &z_len_is_null) == FAILURE) {
26312629
RETURN_THROWS();
26322630
}
26332631

2634-
if (argc > 2) {
2632+
if (!z_len_is_null) {
26352633
if (z_len < 0) {
26362634
zend_argument_value_error(3, "must be greater than or equal to 0");
26372635
RETURN_THROWS();
@@ -2840,9 +2838,8 @@ PHP_FUNCTION(pg_lo_seek)
28402838
zval *pgsql_id = NULL;
28412839
zend_long result, offset = 0, whence = SEEK_CUR;
28422840
pgLofp *pgsql;
2843-
int argc = ZEND_NUM_ARGS();
28442841

2845-
if (zend_parse_parameters(argc, "rl|l", &pgsql_id, &offset, &whence) == FAILURE) {
2842+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &pgsql_id, &offset, &whence) == FAILURE) {
28462843
RETURN_THROWS();
28472844
}
28482845
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) {
@@ -2877,9 +2874,8 @@ PHP_FUNCTION(pg_lo_tell)
28772874
zval *pgsql_id = NULL;
28782875
zend_long offset = 0;
28792876
pgLofp *pgsql;
2880-
int argc = ZEND_NUM_ARGS();
28812877

2882-
if (zend_parse_parameters(argc, "r", &pgsql_id) == FAILURE) {
2878+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &pgsql_id) == FAILURE) {
28832879
RETURN_THROWS();
28842880
}
28852881

@@ -2906,10 +2902,9 @@ PHP_FUNCTION(pg_lo_truncate)
29062902
zval *pgsql_id = NULL;
29072903
size_t size;
29082904
pgLofp *pgsql;
2909-
int argc = ZEND_NUM_ARGS();
29102905
int result;
29112906

2912-
if (zend_parse_parameters(argc, "rl", &pgsql_id, &size) == FAILURE) {
2907+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &pgsql_id, &size) == FAILURE) {
29132908
RETURN_THROWS();
29142909
}
29152910

@@ -3006,7 +3001,7 @@ PHP_FUNCTION(pg_client_encoding)
30063001
PGconn *pgsql;
30073002
zend_resource *link;
30083003

3009-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
3004+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
30103005
RETURN_THROWS();
30113006
}
30123007

@@ -3035,7 +3030,7 @@ PHP_FUNCTION(pg_end_copy)
30353030
int result = 0;
30363031
zend_resource *link;
30373032

3038-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
3033+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
30393034
RETURN_THROWS();
30403035
}
30413036

@@ -3107,9 +3102,8 @@ PHP_FUNCTION(pg_copy_to)
31073102
PGresult *pgsql_result;
31083103
ExecStatusType status;
31093104
char *csv = (char *)NULL;
3110-
int argc = ZEND_NUM_ARGS();
31113105

3112-
if (zend_parse_parameters(argc, "rs|ss",
3106+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|ss",
31133107
&pgsql_link, &table_name, &table_name_len,
31143108
&pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) {
31153109
RETURN_THROWS();
@@ -3198,9 +3192,8 @@ PHP_FUNCTION(pg_copy_from)
31983192
PGconn *pgsql;
31993193
PGresult *pgsql_result;
32003194
ExecStatusType status;
3201-
int argc = ZEND_NUM_ARGS();
32023195

3203-
if (zend_parse_parameters(argc, "rsa|ss",
3196+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|ss",
32043197
&pgsql_link, &table_name, &table_name_len, &pg_rows,
32053198
&pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) {
32063199
RETURN_THROWS();
@@ -3372,7 +3365,7 @@ PHP_FUNCTION(pg_unescape_bytea)
33723365
char *from = NULL, *to = NULL, *tmp = NULL;
33733366
size_t to_len;
33743367
size_t from_len;
3375-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
3368+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!",
33763369
&from, &from_len) == FAILURE) {
33773370
RETURN_THROWS();
33783371
}
@@ -5461,9 +5454,8 @@ PHP_FUNCTION(pg_insert)
54615454
PGresult *pg_result;
54625455
ExecStatusType status;
54635456
zend_string *sql = NULL;
5464-
int argc = ZEND_NUM_ARGS();
54655457

5466-
if (zend_parse_parameters(argc, "rsa|l",
5458+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l",
54675459
&pgsql_link, &table, &table_len, &values, &option) == FAILURE) {
54685460
RETURN_THROWS();
54695461
}
@@ -5678,9 +5670,8 @@ PHP_FUNCTION(pg_update)
56785670
zend_ulong option = PGSQL_DML_EXEC;
56795671
PGconn *pg_link;
56805672
zend_string *sql = NULL;
5681-
int argc = ZEND_NUM_ARGS();
56825673

5683-
if (zend_parse_parameters(argc, "rsaa|l",
5674+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsaa|l",
56845675
&pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) {
56855676
RETURN_THROWS();
56865677
}
@@ -5775,9 +5766,8 @@ PHP_FUNCTION(pg_delete)
57755766
zend_ulong option = PGSQL_DML_EXEC;
57765767
PGconn *pg_link;
57775768
zend_string *sql;
5778-
int argc = ZEND_NUM_ARGS();
57795769

5780-
if (zend_parse_parameters(argc, "rsa|l",
5770+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|l",
57815771
&pgsql_link, &table, &table_len, &ids, &option) == FAILURE) {
57825772
RETURN_THROWS();
57835773
}

ext/pgsql/pgsql.stub.php

+33-33
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@ function pg_pconnect(string $connection_string, int $connection_type = 0) {}
1111
/** @param resource $connection */
1212
function pg_connect_poll($connection): int {}
1313

14-
/** @param resource $connection */
15-
function pg_close($connection = UNKNOWN): bool {}
14+
/** @param resource|null $connection */
15+
function pg_close($connection = null): bool {}
1616

17-
/** @param resource $connection */
18-
function pg_dbname($connection = UNKNOWN): string {}
17+
/** @param resource|null $connection */
18+
function pg_dbname($connection = null): string {}
1919

20-
/** @param resource $connection */
21-
function pg_last_error($connection = UNKNOWN): string {}
20+
/** @param resource|null $connection */
21+
function pg_last_error($connection = null): string {}
2222

2323
/**
24-
* @param resource $connection
24+
* @param resource|null $connection
2525
* @alias pg_last_error
2626
*/
27-
function pg_errormessage($connection = UNKNOWN): string {}
27+
function pg_errormessage($connection = null): string {}
2828

29-
/** @param resource $connection */
30-
function pg_options($connection = UNKNOWN): string {}
29+
/** @param resource|null $connection */
30+
function pg_options($connection = null): string {}
3131

32-
/** @param resource $connection */
33-
function pg_port($connection = UNKNOWN): string {}
32+
/** @param resource|null $connection */
33+
function pg_port($connection = null): string {}
3434

35-
/** @param resource $connection */
36-
function pg_tty($connection = UNKNOWN): string {}
35+
/** @param resource|null $connection */
36+
function pg_tty($connection = null): string {}
3737

38-
/** @param resource $connection */
39-
function pg_host($connection = UNKNOWN): string {}
38+
/** @param resource|null $connection */
39+
function pg_host($connection = null): string {}
4040

41-
/** @param resource $connection */
42-
function pg_version($connection = UNKNOWN): array {}
41+
/** @param resource|null $connection */
42+
function pg_version($connection = null): array {}
4343

4444
/** @param resource|string $connection */
4545
function pg_parameter_status($connection, string $param_name = UNKNOWN): string|false {}
4646

47-
/** @param resource $connection */
48-
function pg_ping($connection = UNKNOWN): bool {}
47+
/** @param resource|null $connection */
48+
function pg_ping($connection = null): bool {}
4949

5050
/**
5151
* @param resource|string $connection
@@ -236,11 +236,11 @@ function pg_last_oid($result): string|int|false {}
236236
*/
237237
function pg_getlastoid($result): string|int|false {}
238238

239-
/** @param resource $connection */
240-
function pg_trace(string $filename, string $mode = "w", $connection = UNKNOWN): bool {}
239+
/** @param resource|null $connection */
240+
function pg_trace(string $filename, string $mode = "w", $connection = null): bool {}
241241

242-
/** @param resource $connection */
243-
function pg_untrace($connection = UNKNOWN): bool {}
242+
/** @param resource|null $connection */
243+
function pg_untrace($connection = null): bool {}
244244

245245
/**
246246
* @param resource $connection
@@ -302,13 +302,13 @@ function pg_lo_read($large_object, int $len = 8192): string|false {}
302302
function pg_loread($large_object, int $len = 8192): string|false {}
303303

304304
/** @param resource $large_object */
305-
function pg_lo_write($large_object, string $buf, int $len = UNKNOWN): int|false {}
305+
function pg_lo_write($large_object, string $buf, ?int $len = null): int|false {}
306306

307307
/**
308308
* @param resource $large_object
309309
* @alias pg_lo_write
310310
*/
311-
function pg_lowrite($large_object, string $buf, int $len = UNKNOWN): int|false {}
311+
function pg_lowrite($large_object, string $buf, ?int $len = null): int|false {}
312312

313313
/** @param resource $large_object */
314314
function pg_lo_read_all($large_object): int {}
@@ -374,17 +374,17 @@ function pg_set_client_encoding($connection, string $encoding = UNKNOWN): int {}
374374
*/
375375
function pg_setclientencoding($connection, string $encoding = UNKNOWN): int {}
376376

377-
/** @param resource $connection */
378-
function pg_client_encoding($connection = UNKNOWN): string {}
377+
/** @param resource|null $connection */
378+
function pg_client_encoding($connection = null): string {}
379379

380380
/**
381-
* @param resource $connection
381+
* @param resource|null $connection
382382
* @alias pg_client_encoding
383383
*/
384-
function pg_clientencoding($connection = UNKNOWN): string {}
384+
function pg_clientencoding($connection = null): string {}
385385

386-
/** @param resource $connection */
387-
function pg_end_copy($connection = UNKNOWN): bool {}
386+
/** @param resource|null $connection */
387+
function pg_end_copy($connection = null): bool {}
388388

389389
/** @param resource|string $connection */
390390
function pg_put_line($connection, string $query = UNKNOWN): bool {}
@@ -401,7 +401,7 @@ function pg_escape_string($connection, string $data = UNKNOWN): string {}
401401
/** @param resource|string $connection */
402402
function pg_escape_bytea($connection, string $data = UNKNOWN): string {}
403403

404-
function pg_unescape_bytea(string $data = UNKNOWN): string|false {}
404+
function pg_unescape_bytea(?string $data = null): string|false {}
405405

406406
/** @param resource|string $connection */
407407
function pg_escape_literal($connection, string $data = UNKNOWN): string|false {}

0 commit comments

Comments
 (0)