]> granicus.if.org Git - php/commitdiff
More zpp cleanup in ext/intl
authorNikita Popov <nikic@php.net>
Tue, 6 Oct 2015 20:32:28 +0000 (22:32 +0200)
committerNikita Popov <nikic@php.net>
Tue, 6 Oct 2015 20:58:02 +0000 (22:58 +0200)
ext/intl/calendar/calendar_methods.cpp
ext/intl/tests/calendar_clear_error.phpt
ext/intl/timezone/timezone_methods.cpp

index adeae6b222700dfee66dc10e7e60022b5ac1d557..155ed5f7f480d2c528adb1dad1f1d99e03f915c2 100644 (file)
@@ -522,48 +522,28 @@ U_CFUNC PHP_FUNCTION(intlcal_roll)
 
 U_CFUNC PHP_FUNCTION(intlcal_clear)
 {
-       zval    args_a[2] = {0},
-                       *args           = &args_a[0];
-       zend_long       field;
-       int             variant;
+       zend_long field;
+       zend_bool field_is_null = 1;
        CALENDAR_METHOD_INIT_VARS;
 
-       if (ZEND_NUM_ARGS() > (getThis() ? 1 : 2) ||
-                       zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
-               intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "intlcal_clear: too many arguments", 0);
-               RETURN_FALSE;
-       }
-       if (!getThis()) {
-               args++;
-       }
-       if (Z_ISUNDEF(args[0]) || Z_TYPE(args[0]) == IS_NULL) {
-               zval *dummy; /* we know it's null */
-               if (zend_parse_method_parameters(ZEND_NUM_ARGS(),
-                               getThis(), "O|z", &object, Calendar_ce_ptr, &dummy) == FAILURE) {
-                       intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                               "intlcal_clear: bad arguments", 0);
-                       RETURN_FALSE;
-               }
-               variant = 0;
-       } else if (zend_parse_method_parameters(ZEND_NUM_ARGS(),
-                       getThis(), "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) {
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS(),
+                       getThis(), "O|l!", &object, Calendar_ce_ptr, &field, &field_is_null) == FAILURE) {
                intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
                        "intlcal_clear: bad arguments", 0);
                RETURN_FALSE;
-       } else if (field < 0 || field >= UCAL_FIELD_COUNT) {
-               intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "intlcal_clear: invalid field", 0);
-               RETURN_FALSE;
-       } else {
-               variant = 1;
        }
 
        CALENDAR_METHOD_FETCH_OBJECT;
 
-       if (variant == 0) {
+       if (field_is_null) {
                co->ucal->clear();
        } else {
+               if (field < 0 || field >= UCAL_FIELD_COUNT) {
+                       intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+                               "intlcal_clear: invalid field", 0);
+                       RETURN_FALSE;
+               }
+
                co->ucal->clear((UCalendarDateFields)field);
        }
 
@@ -614,7 +594,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_actual_minimum)
 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
 U_CFUNC PHP_FUNCTION(intlcal_get_day_of_week_type)
 {
-       zend_ulong      dow;
+       zend_long       dow;
        CALENDAR_METHOD_INIT_VARS;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
index 7e9c52b2a57d6eddbea7c610c7da0aa772e5fbef..7ff2ff08672c5295381d9272cf7cf71bd24b8d8c 100644 (file)
@@ -18,8 +18,9 @@ var_dump($c->clear(-1));
 var_dump(intlcal_clear($c, -1));
 var_dump(intlcal_clear(1, 2));
 --EXPECTF--
+Warning: IntlCalendar::clear() expects at most 1 parameter, 2 given in %s on line %d
 
-Warning: IntlCalendar::clear(): intlcal_clear: too many arguments in %s on line %d
+Warning: IntlCalendar::clear(): intlcal_clear: bad arguments in %s on line %d
 bool(false)
 
 Warning: IntlCalendar::clear(): intlcal_clear: invalid field in %s on line %d
index c46b448bbe5454504b14c6984d521dbab575f966..a35174d3da92a00c43b7c1c536cebf76fd0b6773 100644 (file)
@@ -440,7 +440,7 @@ U_CFUNC PHP_FUNCTION(intltz_use_daylight_time)
 
 U_CFUNC PHP_FUNCTION(intltz_get_offset)
 {
-       UDate           date;
+       double          date;
        zend_bool       local;
        zval            *rawOffsetArg,
                                *dstOffsetArg;
@@ -458,7 +458,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_offset)
 
        TIMEZONE_METHOD_FETCH_OBJECT;
 
-       to->utimezone->getOffset(date, (UBool) local, rawOffset, dstOffset,
+       to->utimezone->getOffset((UDate) date, (UBool) local, rawOffset, dstOffset,
                TIMEZONE_ERROR_CODE(to));
 
        INTL_METHOD_CHECK_STATUS(to, "intltz_get_offset: error obtaining offset");