diff options
Diffstat (limited to 'ext/intl/formatter/formatter_parse.c')
-rw-r--r-- | ext/intl/formatter/formatter_parse.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/ext/intl/formatter/formatter_parse.c b/ext/intl/formatter/formatter_parse.c index 6f3a3a12b5..0959d11830 100644 --- a/ext/intl/formatter/formatter_parse.c +++ b/ext/intl/formatter/formatter_parse.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -36,11 +36,11 @@ */ PHP_FUNCTION( numfmt_parse ) { - long type = FORMAT_TYPE_DOUBLE; + zend_long type = FORMAT_TYPE_DOUBLE; UChar* sstr = NULL; int sstr_len = 0; char* str = NULL; - int str_len; + size_t str_len; int32_t val32, position = 0; int64_t val64; double val_double; @@ -50,7 +50,7 @@ PHP_FUNCTION( numfmt_parse ) FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|lz!", + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|lz/!", &object, NumberFormatter_ce_ptr, &str, &str_len, &type, &zposition ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -67,13 +67,16 @@ PHP_FUNCTION( numfmt_parse ) INTL_METHOD_CHECK_STATUS( nfo, "String conversion to UTF-16 failed" ); if(zposition) { + ZVAL_DEREF(zposition); convert_to_long(zposition); position = (int32_t)Z_LVAL_P( zposition ); position_p = &position; } #if ICU_LOCALE_BUG && defined(LC_NUMERIC) - oldlocale = setlocale(LC_NUMERIC, "C"); + /* need to copy here since setlocale may change it later */ + oldlocale = estrdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); #endif switch(type) { @@ -83,10 +86,10 @@ PHP_FUNCTION( numfmt_parse ) break; case FORMAT_TYPE_INT64: val64 = unum_parseInt64(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, &INTL_DATA_ERROR_CODE(nfo)); - if(val64 > LONG_MAX || val64 < LONG_MIN) { + if(val64 > ZEND_LONG_MAX || val64 < ZEND_LONG_MIN) { RETVAL_DOUBLE(val64); } else { - RETVAL_LONG((long)val64); + RETVAL_LONG((zend_long)val64); } break; case FORMAT_TYPE_DOUBLE: @@ -94,12 +97,13 @@ PHP_FUNCTION( numfmt_parse ) RETVAL_DOUBLE(val_double); break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported format type %ld", type); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported format type %pd", type); RETVAL_FALSE; break; } #if ICU_LOCALE_BUG && defined(LC_NUMERIC) setlocale(LC_NUMERIC, oldlocale); + efree(oldlocale); #endif if(zposition) { zval_dtor(zposition); @@ -128,14 +132,14 @@ PHP_FUNCTION( numfmt_parse_currency ) char *currency_str = NULL; int currency_len = 0; char *str; - int str_len; + size_t str_len; int32_t* position_p = NULL; int32_t position = 0; zval *zcurrency, *zposition = NULL; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz|z!", + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz/|z/!", &object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -152,6 +156,7 @@ PHP_FUNCTION( numfmt_parse_currency ) INTL_METHOD_CHECK_STATUS( nfo, "String conversion to UTF-16 failed" ); if(zposition) { + ZVAL_DEREF(zposition); convert_to_long(zposition); position = (int32_t)Z_LVAL_P( zposition ); position_p = &position; @@ -171,7 +176,9 @@ PHP_FUNCTION( numfmt_parse_currency ) intl_convert_utf16_to_utf8(¤cy_str, ¤cy_len, currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" ); zval_dtor( zcurrency ); - ZVAL_STRINGL(zcurrency, currency_str, currency_len, 0); + ZVAL_STRINGL(zcurrency, currency_str, currency_len); + //???? + efree(currency_str); RETVAL_DOUBLE( number ); } |