Skip to content

Commit e250fb2

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

File tree

3 files changed

+53
-54
lines changed

3 files changed

+53
-54
lines changed

ext/pgsql/pgsql.c

Lines changed: 13 additions & 14 deletions
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

@@ -774,11 +774,11 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
774774
char *msgbuf;
775775
char *result;
776776

777-
if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) {
777+
if (zend_parse_parameters(argc, "|r!", &pgsql_link) == FAILURE) {
778778
RETURN_THROWS();
779779
}
780780

781-
if (argc == 0) {
781+
if (!pgsql_link) {
782782
link = FETCH_DEFAULT_LINK();
783783
CHECK_DEFAULT_LINK(link);
784784
} else {
@@ -937,7 +937,7 @@ PHP_FUNCTION(pg_ping)
937937
PGresult *res;
938938
zend_resource *link;
939939

940-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
940+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
941941
RETURN_THROWS();
942942
}
943943

@@ -2227,17 +2227,16 @@ PHP_FUNCTION(pg_trace)
22272227
char *z_filename, *mode = "w";
22282228
size_t z_filename_len, mode_len;
22292229
zval *pgsql_link = NULL;
2230-
int argc = ZEND_NUM_ARGS();
22312230
PGconn *pgsql;
22322231
FILE *fp = NULL;
22332232
php_stream *stream;
22342233
zend_resource *link;
22352234

2236-
if (zend_parse_parameters(argc, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
2235+
if (zend_parse_parameters(argc, "p|sr!", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
22372236
RETURN_THROWS();
22382237
}
22392238

2240-
if (argc < 3) {
2239+
if (!pgsql_link) {
22412240
link = FETCH_DEFAULT_LINK();
22422241
CHECK_DEFAULT_LINK(link);
22432242
} else {
@@ -2271,7 +2270,7 @@ PHP_FUNCTION(pg_untrace)
22712270
PGconn *pgsql;
22722271
zend_resource *link;
22732272

2274-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
2273+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
22752274
RETURN_THROWS();
22762275
}
22772276

@@ -2622,16 +2621,16 @@ PHP_FUNCTION(pg_lo_write)
26222621
zval *pgsql_id;
26232622
char *str;
26242623
zend_long z_len;
2624+
zend_bool z_len_is_null = 1;
26252625
size_t str_len, nbytes;
26262626
size_t len;
26272627
pgLofp *pgsql;
2628-
int argc = ZEND_NUM_ARGS();
26292628

2630-
if (zend_parse_parameters(argc, "rs|l", &pgsql_id, &str, &str_len, &z_len) == FAILURE) {
2629+
if (zend_parse_parameters(argc, "rs|l!", &pgsql_id, &str, &str_len, &z_len, &z_len_is_null) == FAILURE) {
26312630
RETURN_THROWS();
26322631
}
26332632

2634-
if (argc > 2) {
2633+
if (!z_len_is_null) {
26352634
if (z_len < 0) {
26362635
zend_argument_value_error(3, "must be greater than or equal to 0");
26372636
RETURN_THROWS();
@@ -3006,7 +3005,7 @@ PHP_FUNCTION(pg_client_encoding)
30063005
PGconn *pgsql;
30073006
zend_resource *link;
30083007

3009-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
3008+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
30103009
RETURN_THROWS();
30113010
}
30123011

@@ -3035,7 +3034,7 @@ PHP_FUNCTION(pg_end_copy)
30353034
int result = 0;
30363035
zend_resource *link;
30373036

3038-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
3037+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) {
30393038
RETURN_THROWS();
30403039
}
30413040

@@ -3372,7 +3371,7 @@ PHP_FUNCTION(pg_unescape_bytea)
33723371
char *from = NULL, *to = NULL, *tmp = NULL;
33733372
size_t to_len;
33743373
size_t from_len;
3375-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
3374+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!",
33763375
&from, &from_len) == FAILURE) {
33773376
RETURN_THROWS();
33783377
}

ext/pgsql/pgsql.stub.php

Lines changed: 33 additions & 33 deletions
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 {}

ext/pgsql/pgsql_arginfo.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 90dd576049fe13617343fe689000b94b20f47655 */
2+
* Stub hash: 907a616e7138369e6e3ccbbb10e6c0f2a380fe93 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_connect, 0, 0, 1)
55
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,
1313
ZEND_END_ARG_INFO()
1414

1515
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_close, 0, 0, _IS_BOOL, 0)
16-
ZEND_ARG_INFO(0, connection)
16+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
1717
ZEND_END_ARG_INFO()
1818

1919
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_dbname, 0, 0, IS_STRING, 0)
20-
ZEND_ARG_INFO(0, connection)
20+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
2121
ZEND_END_ARG_INFO()
2222

2323
#define arginfo_pg_last_error arginfo_pg_dbname
@@ -33,7 +33,7 @@ ZEND_END_ARG_INFO()
3333
#define arginfo_pg_host arginfo_pg_dbname
3434

3535
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_version, 0, 0, IS_ARRAY, 0)
36-
ZEND_ARG_INFO(0, connection)
36+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
3737
ZEND_END_ARG_INFO()
3838

3939
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()
197197
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_trace, 0, 1, _IS_BOOL, 0)
198198
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
199199
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 0, "\"w\"")
200-
ZEND_ARG_INFO(0, connection)
200+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection, "null")
201201
ZEND_END_ARG_INFO()
202202

203203
#define arginfo_pg_untrace arginfo_pg_close
@@ -240,7 +240,7 @@ ZEND_END_ARG_INFO()
240240
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_lo_write, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
241241
ZEND_ARG_INFO(0, large_object)
242242
ZEND_ARG_TYPE_INFO(0, buf, IS_STRING, 0)
243-
ZEND_ARG_TYPE_INFO(0, len, IS_LONG, 0)
243+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, len, IS_LONG, 1, "null")
244244
ZEND_END_ARG_INFO()
245245

246246
#define arginfo_pg_lowrite arginfo_pg_lo_write
@@ -326,7 +326,7 @@ ZEND_END_ARG_INFO()
326326
#define arginfo_pg_escape_bytea arginfo_pg_escape_string
327327

328328
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_unescape_bytea, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
329-
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
329+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, data, IS_STRING, 1, "null")
330330
ZEND_END_ARG_INFO()
331331

332332
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_escape_literal, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)

0 commit comments

Comments
 (0)