Refactoring ext/intl (incompleted)

This commit is contained in:
Xinchen Hui 2014-06-28 00:02:50 +08:00
parent f609d8c1c6
commit 4fbaddb4f8
57 changed files with 967 additions and 1075 deletions

View file

@ -84,7 +84,7 @@ U_CFUNC PHP_FUNCTION(intltz_from_date_time_zone)
RETURN_NULL();
}
tzobj = (php_timezone_obj *)zend_objects_get_address(zv_timezone TSRMLS_CC);
tzobj = Z_PHPTIMEZONE_P(zv_timezone);
if (!tzobj->initialized) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intltz_from_date_time_zone: DateTimeZone object is unconstructed",
@ -145,54 +145,52 @@ U_CFUNC PHP_FUNCTION(intltz_get_unknown)
U_CFUNC PHP_FUNCTION(intltz_create_enumeration)
{
zval **arg = NULL;
zval *arg = NULL;
StringEnumeration *se = NULL;
intl_error_reset(NULL TSRMLS_CC);
/* double indirection to have the zend engine destroy the new zval that
* results from separation */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Z", &arg) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &arg) == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intltz_create_enumeration: bad arguments", 0 TSRMLS_CC);
RETURN_FALSE;
}
if (arg == NULL || Z_TYPE_PP(arg) == IS_NULL) {
if (arg == NULL || Z_TYPE_P(arg) == IS_NULL) {
se = TimeZone::createEnumeration();
} else if (Z_TYPE_PP(arg) == IS_LONG) {
} else if (Z_TYPE_P(arg) == IS_LONG) {
int_offset:
if (Z_LVAL_PP(arg) < (long)INT32_MIN ||
Z_LVAL_PP(arg) > (long)INT32_MAX) {
if (Z_LVAL_P(arg) < (long)INT32_MIN ||
Z_LVAL_P(arg) > (long)INT32_MAX) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intltz_create_enumeration: value is out of range", 0 TSRMLS_CC);
RETURN_FALSE;
} else {
se = TimeZone::createEnumeration((int32_t) Z_LVAL_PP(arg));
se = TimeZone::createEnumeration((int32_t) Z_LVAL_P(arg));
}
} else if (Z_TYPE_PP(arg) == IS_DOUBLE) {
} else if (Z_TYPE_P(arg) == IS_DOUBLE) {
double_offset:
convert_to_long_ex(arg);
goto int_offset;
} else if (Z_TYPE_PP(arg) == IS_OBJECT || Z_TYPE_PP(arg) == IS_STRING) {
} else if (Z_TYPE_P(arg) == IS_OBJECT || Z_TYPE_P(arg) == IS_STRING) {
long lval;
double dval;
convert_to_string_ex(arg);
switch (is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &lval, &dval, 0)) {
switch (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &lval, &dval, 0)) {
case IS_DOUBLE:
SEPARATE_ZVAL(arg);
zval_dtor(*arg);
Z_TYPE_PP(arg) = IS_DOUBLE;
Z_DVAL_PP(arg) = dval;
zval_dtor(arg);
ZVAL_DOUBLE(arg, dval);
goto double_offset;
case IS_LONG:
SEPARATE_ZVAL(arg);
zval_dtor(*arg);
Z_TYPE_PP(arg) = IS_LONG;
Z_LVAL_PP(arg) = lval;
zval_dtor(arg);
ZVAL_LONG(arg, lval);
goto int_offset;
}
/* else call string version */
se = TimeZone::createEnumeration(Z_STRVAL_PP(arg));
se = TimeZone::createEnumeration(Z_STRVAL_P(arg));
} else {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intltz_create_enumeration: invalid argument type", 0 TSRMLS_CC);
@ -317,11 +315,14 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id)
TimeZone::getCanonicalID(id, result, isSystemID, status);
INTL_CHECK_STATUS(status, "intltz_get_canonical_id: error obtaining canonical ID");
intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value),
result.getBuffer(), result.length(), &status);
char *str;
int str_len;
intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), &status);
INTL_CHECK_STATUS(status,
"intltz_get_canonical_id: could not convert time zone id to UTF-16");
Z_TYPE_P(return_value) = IS_STRING;
RETVAL_STRINGL(str, str_len);
//????
efree(str);
if (is_systemid) { /* by-ref argument passed */
zval_dtor(is_systemid);
@ -355,7 +356,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_region)
int32_t region_len = TimeZone::getRegion(id, outbuf, sizeof(outbuf), status);
INTL_CHECK_STATUS(status, "intltz_get_region: Error obtaining region");
RETURN_STRINGL(outbuf, region_len, 1);
RETURN_STRINGL(outbuf, region_len);
}
#endif
@ -374,7 +375,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_tz_data_version)
INTL_CHECK_STATUS(status, "intltz_get_tz_data_version: "
"Error obtaining time zone data version");
RETURN_STRING(res, 1);
RETURN_STRING(res);
}
U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id)
@ -401,11 +402,15 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id)
}
const UnicodeString result = TimeZone::getEquivalentID(id, (int32_t)index);
intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value),
result.getBuffer(), result.length(), &status);
char *str;
int str_len;
intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), &status);
INTL_CHECK_STATUS(status, "intltz_get_equivalent_id: "
"could not convert resulting time zone id to UTF-16");
Z_TYPE_P(return_value) = IS_STRING;
RETVAL_STRINGL(str, str_len);
//????
efree(str);
}
U_CFUNC PHP_FUNCTION(intltz_get_id)
@ -431,7 +436,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_id)
id_us.getBuffer(), id_us.length(), TIMEZONE_ERROR_CODE_P(to));
INTL_METHOD_CHECK_STATUS(to, "intltz_get_id: Could not convert id to UTF-8");
RETURN_STRINGL(id, id_len, 0);
RETURN_STRINGL(id, id_len);
//???
efree(id);
}
U_CFUNC PHP_FUNCTION(intltz_use_daylight_time)
@ -513,7 +520,7 @@ U_CFUNC PHP_FUNCTION(intltz_has_same_rules)
RETURN_FALSE;
}
TIMEZONE_METHOD_FETCH_OBJECT;
other_to = (TimeZone_object *) zend_object_store_get_object(other_object TSRMLS_CC);
other_to = Z_INTL_TIMEZONE_P(other_object);
if (other_to->utimezone == NULL) {
intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR,
"intltz_has_same_rules: The second IntlTimeZone is unconstructed", 0 TSRMLS_CC);
@ -569,12 +576,15 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name)
to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type,
Locale::createFromName(locale_str), result);
intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value),
result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to));
char *str;
int str_len;
intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to));
INTL_METHOD_CHECK_STATUS(to, "intltz_get_display_name: "
"could not convert resulting time zone id to UTF-16");
Z_TYPE_P(return_value) = IS_STRING;
RETVAL_STRINGL(str, str_len);
//????
efree(str);
}
U_CFUNC PHP_FUNCTION(intltz_get_dst_savings)
@ -595,6 +605,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_dst_savings)
U_CFUNC PHP_FUNCTION(intltz_to_date_time_zone)
{
zval tmp;
TIMEZONE_METHOD_INIT_VARS;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
@ -607,7 +618,7 @@ U_CFUNC PHP_FUNCTION(intltz_to_date_time_zone)
TIMEZONE_METHOD_FETCH_OBJECT;
zval *ret = timezone_convert_to_datetimezone(to->utimezone,
&TIMEZONE_ERROR(to), "intltz_to_date_time_zone" TSRMLS_CC);
&TIMEZONE_ERROR(to), "intltz_to_date_time_zone", &tmp TSRMLS_CC);
if (ret) {
RETURN_ZVAL(ret, 1, 1);
@ -628,7 +639,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_code)
}
/* Fetch the object (without resetting its last error code ). */
to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC);
to = Z_INTL_TIMEZONE_P(object);
if (to == NULL)
RETURN_FALSE;
@ -637,7 +648,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_code)
U_CFUNC PHP_FUNCTION(intltz_get_error_message)
{
const char* message = NULL;
zend_string* message = NULL;
TIMEZONE_METHOD_INIT_VARS
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
@ -649,11 +660,11 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_message)
/* Fetch the object (without resetting its last error code ). */
to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC);
to = Z_INTL_TIMEZONE_P(object);
if (to == NULL)
RETURN_FALSE;
/* Return last error message. */
message = intl_error_get_message(TIMEZONE_ERROR_P(to) TSRMLS_CC);
RETURN_STRING(message, 0);
RETURN_STR(message);
}