]> granicus.if.org Git - php/commitdiff
Convert UNKNOWN default values to null in ext/calendar
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 1 May 2020 18:49:55 +0000 (20:49 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Sat, 2 May 2020 09:05:27 +0000 (11:05 +0200)
ext/calendar/cal_unix.c
ext/calendar/calendar.c
ext/calendar/calendar.stub.php
ext/calendar/calendar_arginfo.h
ext/calendar/easter.c

index 47387726498f1bf1e1ce0b6eed63fe2600bdacbb..cfcc62f11b333d669b5193e159396f18132748d4 100644 (file)
    Convert UNIX timestamp to Julian Day */
 PHP_FUNCTION(unixtojd)
 {
-       time_t ts = 0;
+       time_t ts;
+       zend_bool ts_is_null = 1;
        struct tm *ta, tmbuf;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &ts) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &ts, &ts_is_null) == FAILURE) {
                RETURN_THROWS();
        }
 
-       if (!ts) {
+       if (ts_is_null) {
                ts = time(NULL);
        } else if (ts < 0) {
                zend_argument_value_error(1, "must be greater than or equal to 0");
index 2853e727754e4a8c984310a94d30fa5508055fb6..fd8b1071569114f4d12430d795d8c54faaf058cb 100644 (file)
@@ -192,14 +192,12 @@ PHP_FUNCTION(cal_info)
                return;
        }
 
-
-       if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
+       if (cal < 0 || cal >= CAL_NUM_CALS) {
                zend_argument_value_error(1, "must be a valid calendar ID");
                RETURN_THROWS();
        }
 
        _php_cal_info(cal, return_value);
-
 }
 /* }}} */
 
index 1c2db30ce41b2743d091851ed27411fcee885492..baa2075beefd915236a9e32aa7a5622efe239e79 100644 (file)
@@ -6,13 +6,13 @@ function cal_days_in_month(int $calendar, int $month, int $year): int {}
 
 function cal_from_jd(int $jd, int $calendar): array {}
 
-function cal_info(?int $calendar = UNKNOWN): array {}
+function cal_info(int $calendar = -1): array {}
 
 function cal_to_jd(int $calendar, int $month, int $day, int $year): int {}
 
-function easter_date(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
+function easter_date(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
 
-function easter_days(int $year = UNKNOWN, int $method = CAL_EASTER_DEFAULT): int {}
+function easter_days(?int $year = null, int $method = CAL_EASTER_DEFAULT): int {}
 
 function frenchtojd(int $month, int $day, int $year): int {}
 
@@ -36,4 +36,4 @@ function jewishtojd(int $month, int $day, int $year): int {}
 
 function juliantojd(int $month, int $day, int $year): int {}
 
-function unixtojd(int $timestamp = UNKNOWN): int|false {}
+function unixtojd(?int $timestamp = null): int|false {}
index 45abb0b0b222940543c7767dafda80083dccc10c..620f3daec3b6be322a3ee65a316c295c25ecf44a 100644 (file)
@@ -12,7 +12,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_from_jd, 0, 2, IS_ARRAY, 0)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_cal_info, 0, 0, IS_ARRAY, 0)
-       ZEND_ARG_TYPE_INFO(0, calendar, IS_LONG, 1)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, calendar, IS_LONG, 0, "-1")
 ZEND_END_ARG_INFO()
 
 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)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_easter_date, 0, 0, IS_LONG, 0)
-       ZEND_ARG_TYPE_INFO(0, year, IS_LONG, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, year, IS_LONG, 1, "null")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, method, IS_LONG, 0, "CAL_EASTER_DEFAULT")
 ZEND_END_ARG_INFO()
 
@@ -70,7 +70,7 @@ ZEND_END_ARG_INFO()
 #define arginfo_juliantojd arginfo_frenchtojd
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unixtojd, 0, 0, MAY_BE_LONG|MAY_BE_FALSE)
-       ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null")
 ZEND_END_ARG_INFO()
 
 
index 7f26de0c006ab8ba4a67262e16cbdd42bc59b973..05f54084b4cf86d6ddd9f46241d90946483fd906 100644 (file)
 
 static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
 {
-
        /* based on code by Simon Kershaw, <webmaster@ely.anglican.org> */
 
        struct tm te;
        zend_long year, golden, solar, lunar, pfm, dom, tmp, easter, result;
        zend_long method = CAL_EASTER_DEFAULT;
+       zend_bool year_is_null = 1;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS(),
+               "|l!l", &year, &year_is_null, &method) == FAILURE) {
+                       RETURN_THROWS();
+       }
 
        /* Default to the current year if year parameter is not given */
-       {
+       if (year_is_null) {
                time_t a;
                struct tm b, *res;
                time(&a);
@@ -43,11 +48,6 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
                }
        }
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(),
-               "|ll", &year, &method) == FAILURE) {
-                       RETURN_THROWS();
-       }
-
        if (gm && (year<1970 || year>2037)) {                           /* out of range for timestamps */
                zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
                RETURN_THROWS();