Skip to content

Commit 089d8cb

Browse files
committed
Convert UNKNOWN default values to null in ext/calendar
1 parent 8a41c9e commit 089d8cb

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

ext/calendar/cal_unix.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
Convert UNIX timestamp to Julian Day */
2626
PHP_FUNCTION(unixtojd)
2727
{
28-
time_t ts = 0;
28+
time_t ts;
29+
zend_bool ts_is_null = 1;
2930
struct tm *ta, tmbuf;
3031

31-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &ts) == FAILURE) {
32+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &ts, &ts_is_null) == FAILURE) {
3233
RETURN_THROWS();
3334
}
3435

35-
if (!ts) {
36+
if (ts_is_null) {
3637
ts = time(NULL);
3738
} else if (ts < 0) {
3839
zend_argument_value_error(1, "must be greater than or equal to 0");

ext/calendar/calendar.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,12 @@ PHP_FUNCTION(cal_info)
192192
return;
193193
}
194194

195-
196-
if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
195+
if (cal < 0 || cal >= CAL_NUM_CALS) {
197196
zend_argument_value_error(1, "must be a valid calendar ID");
198197
RETURN_THROWS();
199198
}
200199

201200
_php_cal_info(cal, return_value);
202-
203201
}
204202
/* }}} */
205203

ext/calendar/calendar.stub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ function cal_days_in_month(int $calendar, int $month, int $year): int {}
66

77
function cal_from_jd(int $jd, int $calendar): array {}
88

9-
function cal_info(?int $calendar = UNKNOWN): array {}
9+
function cal_info(int $calendar = -1): array {}
1010

1111
function cal_to_jd(int $calendar, int $month, int $day, int $year): int {}
1212

13-
function easter_date(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
13+
function easter_date(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
1414

15-
function easter_days(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
15+
function easter_days(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
1616

1717
function frenchtojd(int $month, int $day, int $year): int {}
1818

@@ -36,4 +36,4 @@ function jewishtojd(int $month, int $day, int $year): int {}
3636

3737
function juliantojd(int $month, int $day, int $year): int {}
3838

39-
function unixtojd(int $timestamp = UNKNOWN): int|false {}
39+
function unixtojd(?int $timestamp = null): int|false {}

ext/calendar/calendar_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_from_jd, 0, 2, IS_ARRAY, 0)
1212
ZEND_END_ARG_INFO()
1313

1414
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_info, 0, 0, IS_ARRAY, 0)
15-
ZEND_ARG_TYPE_INFO(0, calendar, IS_LONG, 1)
15+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, calendar, IS_LONG, 0, "-1")
1616
ZEND_END_ARG_INFO()
1717

1818
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_to_jd, 0, 4, IS_LONG, 0)
@@ -23,7 +23,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_to_jd, 0, 4, IS_LONG, 0)
2323
ZEND_END_ARG_INFO()
2424

2525
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_easter_date, 0, 0, IS_LONG, 0)
26-
ZEND_ARG_TYPE_INFO(0, year, IS_LONG, 0)
26+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, year, IS_LONG, 1, "null")
2727
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, method, IS_LONG, 0, "CAL_EASTER_DEFAULT")
2828
ZEND_END_ARG_INFO()
2929

@@ -70,7 +70,7 @@ ZEND_END_ARG_INFO()
7070
#define arginfo_juliantojd arginfo_frenchtojd
7171

7272
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unixtojd, 0, 0, MAY_BE_LONG|MAY_BE_FALSE)
73-
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
73+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null")
7474
ZEND_END_ARG_INFO()
7575

7676

ext/calendar/easter.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@
2323

2424
static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
2525
{
26-
2726
/* based on code by Simon Kershaw, <[email protected]> */
2827

2928
struct tm te;
3029
zend_long year, golden, solar, lunar, pfm, dom, tmp, easter, result;
3130
zend_long method = CAL_EASTER_DEFAULT;
31+
zend_bool year_is_null = 1;
32+
33+
if (zend_parse_parameters(ZEND_NUM_ARGS(),
34+
"|l!l", &year, &year_is_null, &method) == FAILURE) {
35+
RETURN_THROWS();
36+
}
3237

3338
/* Default to the current year if year parameter is not given */
34-
{
39+
if (year_is_null) {
3540
time_t a;
3641
struct tm b, *res;
3742
time(&a);
@@ -43,11 +48,6 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
4348
}
4449
}
4550

46-
if (zend_parse_parameters(ZEND_NUM_ARGS(),
47-
"|ll", &year, &method) == FAILURE) {
48-
RETURN_THROWS();
49-
}
50-
5151
if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */
5252
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
5353
RETURN_THROWS();

0 commit comments

Comments
 (0)