diff options
Diffstat (limited to 'ext/intl/calendar/calendar_methods.cpp')
| -rw-r--r-- | ext/intl/calendar/calendar_methods.cpp | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 179602d8fa..ad2a0b499e 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -49,14 +49,14 @@ U_CFUNC PHP_METHOD(IntlCalendar, __construct) U_CFUNC PHP_FUNCTION(intlcal_create_instance) { - zval **zv_timezone = NULL; + zval *zv_timezone = NULL; const char *locale_str = NULL; int dummy; TimeZone *timeZone; UErrorCode status = U_ZERO_ERROR; intl_error_reset(NULL TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Zs!", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zs!", &zv_timezone, &locale_str, &dummy) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_create_calendar: bad arguments", 0 TSRMLS_CC); @@ -344,8 +344,8 @@ U_CFUNC PHP_FUNCTION(intlcal_set_time_zone) RETURN_TRUE; /* the method does nothing if passed null */ } - timeZone = timezone_process_timezone_argument(&zv_timezone, - CALENDAR_ERROR_P(co), "intlcal_set_time_zone" TSRMLS_CC); + timeZone = timezone_process_timezone_argument(zv_timezone, + CALENDAR_ERROR_P(co), "intlcal_set_time_zone" TSRMLS_CC); if (timeZone == NULL) { RETURN_FALSE; } @@ -374,8 +374,7 @@ static void _php_intlcal_before_after( CALENDAR_METHOD_FETCH_OBJECT; - when_co = static_cast<Calendar_object*>( - zend_object_store_get_object(when_object TSRMLS_CC)); + when_co = Z_INTL_CALENDAR_P(when_object); if (when_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_before/after: Other IntlCalendar was unconstructed", 0 TSRMLS_CC); @@ -401,8 +400,8 @@ U_CFUNC PHP_FUNCTION(intlcal_before) U_CFUNC PHP_FUNCTION(intlcal_set) { long arg1, arg2, arg3, arg4, arg5, arg6; - zval **args_a[7] = {0}, - ***args = &args_a[0]; + zval args_a[7] = {0}, + *args = args_a; int i; int variant; /* number of args of the set() overload */ CALENDAR_METHOD_INIT_VARS; @@ -418,7 +417,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set) args++; } variant = ZEND_NUM_ARGS() - (getThis() ? 0 : 1); - while (variant > 2 && Z_TYPE_PP(args[variant - 1]) == IS_NULL) { + while (variant > 2 && Z_TYPE(args[variant - 1]) == IS_NULL) { variant--; } @@ -432,7 +431,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set) } for (i = 0; i < variant; i++) { - if (Z_LVAL_PP(args[i]) < INT32_MIN || Z_LVAL_PP(args[i]) > INT32_MAX) { + if (Z_LVAL(args[i]) < INT32_MIN || Z_LVAL(args[i]) > INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: at least one of the arguments has an absolute " "value that is too large", 0 TSRMLS_CC); @@ -465,8 +464,8 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) { long field, value; - zval **args_a[3] = {0}, - ***args = &args_a[0]; + zval args_a[3] = {0}, + *args = args_a; zend_bool bool_variant_val = (zend_bool)-1; CALENDAR_METHOD_INIT_VARS; @@ -479,7 +478,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) if (!getThis()) { args++; } - if (args[1] != NULL && Z_TYPE_PP(args[1]) == IS_BOOL) { + if (!Z_ISUNDEF(args[1]) && (Z_TYPE(args[1]) == IS_TRUE || Z_TYPE(args[1]) == IS_FALSE)) { if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olb", &object, Calendar_ce_ptr, &field, &bool_variant_val) == FAILURE) { @@ -487,7 +486,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) "intlcal_roll: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } - bool_variant_val = Z_BVAL_PP(args[1]); + bool_variant_val = Z_TYPE(args[1]) == IS_TRUE? 1 : 0; } else if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -523,8 +522,8 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) U_CFUNC PHP_FUNCTION(intlcal_clear) { - zval **args_a[2] = {0}, - ***args = &args_a[0]; + zval args_a[2] = {0}, + *args = &args_a[0]; long field; int variant; CALENDAR_METHOD_INIT_VARS; @@ -538,7 +537,7 @@ U_CFUNC PHP_FUNCTION(intlcal_clear) if (!getThis()) { args++; } - if (args[0] == NULL || Z_TYPE_PP(args[0]) == IS_NULL) { + 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() TSRMLS_CC, getThis(), "O|z", &object, Calendar_ce_ptr, &dummy) == FAILURE) { @@ -731,7 +730,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_locale) INTL_METHOD_CHECK_STATUS(co, "intlcal_get_locale: Call to ICU method has failed"); - RETURN_STRING(locale.getName(), 1); + RETURN_STRING(locale.getName()); } U_CFUNC PHP_FUNCTION(intlcal_get_maximum) @@ -802,7 +801,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_type) CALENDAR_METHOD_FETCH_OBJECT; - RETURN_STRING(co->ucal->getType(), 1); + RETURN_STRING(co->ucal->getType()); } #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44 @@ -869,7 +868,7 @@ U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) RETURN_FALSE; } - other_co = (Calendar_object*)zend_object_store_get_object(other_object TSRMLS_CC); + other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to:" " Other IntlCalendar is unconstructed", 0 TSRMLS_CC); @@ -1037,7 +1036,7 @@ U_CFUNC PHP_FUNCTION(intlcal_equals) } CALENDAR_METHOD_FETCH_OBJECT; - other_co = (Calendar_object *) zend_object_store_get_object(other_object TSRMLS_CC); + other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_equals: The second IntlCalendar is unconstructed", 0 TSRMLS_CC); @@ -1139,8 +1138,9 @@ U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option) U_CFUNC PHP_FUNCTION(intlcal_from_date_time) { - zval **zv_arg, - *zv_datetime = NULL, + zval *zv_arg, + zv_tmp, + *zv_datetime = NULL, *zv_timestamp = NULL; php_date_obj *datetime; char *locale_str = NULL; @@ -1150,28 +1150,27 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) Calendar *cal; intl_error_reset(NULL TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|s!", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s!", &zv_arg, &locale_str, &locale_str_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad arguments", 0 TSRMLS_CC); RETURN_NULL(); } - if (!(Z_TYPE_PP(zv_arg) == IS_OBJECT && instanceof_function( - Z_OBJCE_PP(zv_arg), php_date_get_date_ce() TSRMLS_CC))) { - ALLOC_INIT_ZVAL(zv_datetime); - object_init_ex(zv_datetime, php_date_get_date_ce()); - zend_call_method_with_1_params(&zv_datetime, NULL, NULL, "__construct", - NULL, *zv_arg); + if (!(Z_TYPE_P(zv_arg) == IS_OBJECT && instanceof_function( + Z_OBJCE_P(zv_arg), php_date_get_date_ce() TSRMLS_CC))) { + object_init_ex(&zv_tmp, php_date_get_date_ce()); + zend_call_method_with_1_params(&zv_tmp, NULL, NULL, "__construct", NULL, zv_arg); if (EG(exception)) { - zend_object_store_ctor_failed(zv_datetime TSRMLS_CC); + zend_object_store_ctor_failed(Z_OBJ(zv_tmp) TSRMLS_CC); goto error; } + zv_datetime = &zv_tmp; } else { - zv_datetime = *zv_arg; + zv_datetime = zv_arg; } - datetime = (php_date_obj*)zend_object_store_get_object(zv_datetime TSRMLS_CC); + datetime = Z_PHPDATE_P(zv_datetime); if (!datetime->time) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: DateTime object is unconstructed", @@ -1179,8 +1178,7 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) goto error; } - zend_call_method_with_0_params(&zv_datetime, php_date_get_date_ce(), - NULL, "gettimestamp", &zv_timestamp); + zend_call_method_with_0_params(zv_datetime, php_date_get_date_ce(), NULL, "gettimestamp", zv_timestamp); if (!zv_timestamp || Z_TYPE_P(zv_timestamp) != IS_LONG) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad DateTime; call to " @@ -1222,17 +1220,17 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) calendar_object_create(return_value, cal TSRMLS_CC); error: - if (zv_datetime != *zv_arg) { - zval_ptr_dtor(&zv_datetime); + if (zv_datetime != zv_arg) { + zval_ptr_dtor(zv_datetime); } if (zv_timestamp) { - zval_ptr_dtor(&zv_timestamp); + zval_ptr_dtor(zv_timestamp); } } U_CFUNC PHP_FUNCTION(intlcal_to_date_time) { - zval *retval = NULL; + zval retval; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -1250,7 +1248,7 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) int64_t ts; char ts_str[sizeof("@-9223372036854775808")]; int ts_str_len; - zval ts_zval = zval_used_for_init; + zval ts_tmp, ts_zval = zval_used_for_init; INTL_METHOD_CHECK_STATUS(co, "Call to ICU method has failed"); @@ -1261,15 +1259,18 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) RETURN_FALSE; } + ZVAL_UNDEF(&retval); ts = (int64_t)date; ts_str_len = slprintf(ts_str, sizeof(ts_str), "@%I64d", ts); - ZVAL_STRINGL(&ts_zval, ts_str, ts_str_len, 0); + ZVAL_STRINGL(&ts_zval, ts_str, ts_str_len); + //??? + efree(ts_str); /* Now get the time zone */ const TimeZone& tz = co->ucal->getTimeZone(); zval *timezone_zval = timezone_convert_to_datetimezone( - &tz, CALENDAR_ERROR_P(co), "intlcal_to_date_time" TSRMLS_CC); + &tz, CALENDAR_ERROR_P(co), "intlcal_to_date_time", &ts_zval TSRMLS_CC); if (timezone_zval == NULL) { RETURN_FALSE; } @@ -1278,36 +1279,33 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) /* Finally, instantiate object and call constructor */ object_init_ex(return_value, php_date_get_date_ce()); - zend_call_method_with_2_params(&return_value, NULL, NULL, "__construct", - NULL, &ts_zval, timezone_zval); + zend_call_method_with_2_params(return_value, NULL, NULL, "__construct", NULL, &ts_zval, timezone_zval); if (EG(exception)) { intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR, "intlcal_to_date_time: DateTime constructor has thrown exception", 1 TSRMLS_CC); - zend_object_store_ctor_failed(return_value TSRMLS_CC); - zval_ptr_dtor(&return_value); + zend_object_store_ctor_failed(Z_OBJ_P(return_value) TSRMLS_CC); + zval_ptr_dtor(return_value); RETVAL_FALSE; goto error; } /* due to bug #40743, we have to set the time zone again */ - zend_call_method_with_1_params(&return_value, NULL, NULL, "settimezone", + zend_call_method_with_1_params(return_value, NULL, NULL, "settimezone", &retval, timezone_zval); - if (retval == NULL || Z_TYPE_P(retval) == IS_BOOL) { + if (Z_ISUNDEF(retval) || Z_TYPE(retval) == IS_FALSE) { intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR, "intlcal_to_date_time: call to DateTime::setTimeZone has failed", 1 TSRMLS_CC); - zval_ptr_dtor(&return_value); + zval_ptr_dtor(return_value); RETVAL_FALSE; goto error; } error: - zval_ptr_dtor(&timezone_zval); - if (retval != NULL) { - zval_ptr_dtor(&retval); - } + zval_ptr_dtor(timezone_zval); + zval_ptr_dtor(&retval); } U_CFUNC PHP_FUNCTION(intlcal_get_error_code) @@ -1322,7 +1320,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_error_code) } /* Fetch the object (without resetting its last error code ). */ - co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + co = Z_INTL_CALENDAR_P(object); if (co == NULL) RETURN_FALSE; @@ -1331,7 +1329,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_error_code) U_CFUNC PHP_FUNCTION(intlcal_get_error_message) { - const char* message = NULL; + zend_string* message = NULL; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -1343,11 +1341,11 @@ U_CFUNC PHP_FUNCTION(intlcal_get_error_message) /* Fetch the object (without resetting its last error code ). */ - co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + co = Z_INTL_CALENDAR_P(object); if (co == NULL) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message(CALENDAR_ERROR_P(co) TSRMLS_CC); - RETURN_STRING(message, 0); + RETURN_STR(message); } |
