diff --git a/ext/intl/breakiterator/breakiterator_class.cpp b/ext/intl/breakiterator/breakiterator_class.cpp index 4976d4ff675bc..9a4fe9010ac44 100644 --- a/ext/intl/breakiterator/breakiterator_class.cpp +++ b/ext/intl/breakiterator/breakiterator_class.cpp @@ -186,9 +186,9 @@ static void BreakIterator_objects_free(zend_object *object) /* {{{ BreakIterator_object_create */ static zend_object *BreakIterator_object_create(zend_class_entry *ce) { - BreakIterator_object* intern; + BreakIterator_object* intern; - intern = (BreakIterator_object*) zend_object_alloc(sizeof(BreakIterator_object), ce); + intern = static_cast(zend_object_alloc(sizeof(BreakIterator_object), ce)); zend_object_std_init(&intern->zo, ce); object_properties_init(&intern->zo, ce); diff --git a/ext/intl/breakiterator/breakiterator_iterators.cpp b/ext/intl/breakiterator/breakiterator_iterators.cpp index 6817f52ffb020..31aac140f525e 100644 --- a/ext/intl/breakiterator/breakiterator_iterators.cpp +++ b/ext/intl/breakiterator/breakiterator_iterators.cpp @@ -25,8 +25,6 @@ extern "C" { #define USE_BREAKITERATOR_POINTER #include "breakiterator_class.h" #include "breakiterator_iterators_arginfo.h" -#include "../intl_convert.h" -#include "../locale/locale.h" #include #include } @@ -35,10 +33,9 @@ static zend_class_entry *IntlPartsIterator_ce_ptr; /* BreakIterator's iterator */ -inline BreakIterator *_breakiter_prolog(zend_object_iterator *iter) +static BreakIterator *_breakiter_prolog(const zend_object_iterator *iter) { - BreakIterator_object *bio; - bio = Z_INTL_BREAKITERATOR_P(&iter->data); + BreakIterator_object *bio = Z_INTL_BREAKITERATOR_P(&iter->data); intl_errors_reset(BREAKITER_ERROR_P(bio)); if (bio->biter == NULL) { intl_errors_set(BREAKITER_ERROR_P(bio), U_INVALID_STATE_ERROR, @@ -57,7 +54,7 @@ static void _breakiterator_destroy_it(zend_object_iterator *iter) static void _breakiterator_move_forward(zend_object_iterator *iter) { BreakIterator *biter = _breakiter_prolog(iter); - zoi_with_current *zoi_iter = (zoi_with_current*)iter; + zoi_with_current *zoi_iter = reinterpret_cast(iter); iter->funcs->invalidate_current(iter); @@ -67,23 +64,23 @@ static void _breakiterator_move_forward(zend_object_iterator *iter) int32_t pos = biter->next(); if (pos != BreakIterator::DONE) { - ZVAL_LONG(&zoi_iter->current, (zend_long)pos); + ZVAL_LONG(&zoi_iter->current, static_cast(pos)); } //else we've reached the end of the enum, nothing more is required } static void _breakiterator_rewind(zend_object_iterator *iter) { BreakIterator *biter = _breakiter_prolog(iter); - zoi_with_current *zoi_iter = (zoi_with_current*)iter; + zoi_with_current *zoi_iter = reinterpret_cast(iter); int32_t pos = biter->first(); - ZVAL_LONG(&zoi_iter->current, (zend_long)pos); + ZVAL_LONG(&zoi_iter->current, static_cast(pos)); } static void zoi_with_current_dtor_self(zend_object_iterator *iter) { // Note: wrapping_obj is unused, call to zoi_with_current_dtor() not necessary - zoi_with_current *zoi_iter = (zoi_with_current*)iter; + zoi_with_current *zoi_iter = reinterpret_cast(iter); ZEND_ASSERT(Z_ISUNDEF(zoi_iter->wrapping_obj)); // Unlike the other iterators, this iterator is a new, standalone instance @@ -112,7 +109,7 @@ U_CFUNC zend_object_iterator *_breakiterator_get_iterator( } bio = Z_INTL_BREAKITERATOR_P(object); - BreakIterator *biter = bio->biter; + const BreakIterator *biter = bio->biter; if (biter == NULL) { zend_throw_exception(NULL, @@ -162,19 +159,16 @@ static void _breakiterator_parts_get_current_key(zend_object_iterator *iter, zva static void _breakiterator_parts_move_forward(zend_object_iterator *iter) { - zoi_break_iter_parts *zoi_bit = (zoi_break_iter_parts*)iter; + zoi_break_iter_parts *zoi_bit = reinterpret_cast(iter); BreakIterator_object *bio = zoi_bit->bio; iter->funcs->invalidate_current(iter); - int32_t cur, - next; - - cur = bio->biter->current(); + const int32_t cur = bio->biter->current(); if (cur == BreakIterator::DONE) { return; } - next = bio->biter->next(); + const int32_t next = bio->biter->next(); if (next == BreakIterator::DONE) { return; } @@ -191,8 +185,8 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter) const char *s = Z_STRVAL(bio->text); zend_string *res; - assert(next <= Z_STRLEN(bio->text) && next >= cur); - res = zend_string_alloc(next - cur, 0); + ZEND_ASSERT(next <= Z_STRLEN(bio->text) && next >= cur); + res = zend_string_alloc(next - cur, false); memcpy(ZSTR_VAL(res), &s[cur], ZSTR_LEN(res)); ZSTR_VAL(res)[ZSTR_LEN(res)] = '\0'; @@ -202,8 +196,8 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter) static void _breakiterator_parts_rewind(zend_object_iterator *iter) { - zoi_break_iter_parts *zoi_bit = (zoi_break_iter_parts*)iter; - BreakIterator_object *bio = zoi_bit->bio; + const zoi_break_iter_parts *zoi_bit = reinterpret_cast(iter); + const BreakIterator_object *bio = zoi_bit->bio; if (!Z_ISUNDEF(zoi_bit->zoi_cur.current)) { iter->funcs->invalidate_current(iter); @@ -234,23 +228,25 @@ void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv, object_init_ex(object, IntlPartsIterator_ce_ptr); ii = Z_INTL_ITERATOR_P(object); - ii->iterator = (zend_object_iterator*)emalloc(sizeof(zoi_break_iter_parts)); + ii->iterator = static_cast(emalloc(sizeof(zoi_break_iter_parts))); zend_iterator_init(ii->iterator); ZVAL_COPY(&ii->iterator->data, break_iter_zv); ii->iterator->funcs = &breakiterator_parts_it_funcs; ii->iterator->index = 0; - ((zoi_with_current*)ii->iterator)->destroy_it = _breakiterator_parts_destroy_it; - ZVAL_OBJ_COPY(&((zoi_with_current*)ii->iterator)->wrapping_obj, Z_OBJ_P(object)); - ZVAL_UNDEF(&((zoi_with_current*)ii->iterator)->current); + zoi_with_current *zend_iterator_with_current = reinterpret_cast(ii->iterator); + zend_iterator_with_current->destroy_it = _breakiterator_parts_destroy_it; + ZVAL_OBJ_COPY(&zend_iterator_with_current->wrapping_obj, Z_OBJ_P(object)); + ZVAL_UNDEF(&zend_iterator_with_current->current); - ((zoi_break_iter_parts*)ii->iterator)->bio = Z_INTL_BREAKITERATOR_P(break_iter_zv); + zoi_break_iter_parts *zend_break_iterator_parts = reinterpret_cast(ii->iterator); + zend_break_iterator_parts->bio = Z_INTL_BREAKITERATOR_P(break_iter_zv); - assert(((zoi_break_iter_parts*)ii->iterator)->bio->biter != NULL); + ZEND_ASSERT(zend_break_iterator_parts->bio->biter != NULL); - ((zoi_break_iter_parts*)ii->iterator)->key_type = key_type; - ((zoi_break_iter_parts*)ii->iterator)->index_right = 0; + zend_break_iterator_parts->key_type = key_type; + zend_break_iterator_parts->index_right = 0; } U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator) diff --git a/ext/intl/breakiterator/breakiterator_iterators.h b/ext/intl/breakiterator/breakiterator_iterators.h index e52d066ac9edb..753501f6dd9b4 100644 --- a/ext/intl/breakiterator/breakiterator_iterators.h +++ b/ext/intl/breakiterator/breakiterator_iterators.h @@ -17,7 +17,6 @@ #include U_CDECL_BEGIN -#include #include U_CDECL_END diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp index 56a3a35c97f81..711e382f7f0c9 100644 --- a/ext/intl/breakiterator/breakiterator_methods.cpp +++ b/ext/intl/breakiterator/breakiterator_methods.cpp @@ -25,7 +25,6 @@ extern "C" { #include "../php_intl.h" #define USE_BREAKITERATOR_POINTER 1 #include "breakiterator_class.h" -#include "../locale/locale.h" #include #include } @@ -58,7 +57,7 @@ static void _breakiter_factory(const char *func_name, ZEND_PARSE_PARAMETERS_END(); if (locale_str == NULL) { - locale_str = (char *)intl_locale_get_default(); + locale_str = const_cast(intl_locale_get_default()); } biter = func(Locale::createFromName(locale_str), status); @@ -178,7 +177,7 @@ static void _breakiter_no_args_ret_int32( int32_t res = (bio->biter->*func)(); - RETURN_LONG((zend_long)res); + RETURN_LONG(static_cast(res)); } static void _breakiter_int32_ret_int32( @@ -200,9 +199,9 @@ static void _breakiter_int32_ret_int32( RETURN_THROWS(); } - int32_t res = (bio->biter->*func)((int32_t)arg); + int32_t res = (bio->biter->*func)(static_cast(arg)); - RETURN_LONG((zend_long)res); + RETURN_LONG(static_cast(res)); } U_CFUNC PHP_METHOD(IntlBreakIterator, first) @@ -253,7 +252,7 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, current) int32_t res = bio->biter->current(); - RETURN_LONG((zend_long)res); + RETURN_LONG(static_cast(res)); } U_CFUNC PHP_METHOD(IntlBreakIterator, following) @@ -287,9 +286,9 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, isBoundary) BREAKITER_METHOD_FETCH_OBJECT; - UBool res = bio->biter->isBoundary((int32_t)offset); + UBool res = bio->biter->isBoundary(static_cast(offset)); - RETURN_BOOL((zend_long)res); + RETURN_BOOL(static_cast(res)); } U_CFUNC PHP_METHOD(IntlBreakIterator, getLocale) @@ -311,7 +310,7 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getLocale) BREAKITER_METHOD_FETCH_OBJECT; - Locale locale = bio->biter->getLocale((ULocDataLocaleType)locale_type, + Locale locale = bio->biter->getLocale(static_cast(locale_type), BREAKITER_ERROR_CODE(bio)); INTL_METHOD_CHECK_STATUS(bio, "breakiter_get_locale: Call to ICU method has failed"); @@ -341,7 +340,7 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getPartsIterator) BREAKITER_METHOD_FETCH_OBJECT; IntlIterator_from_BreakIterator_parts( - object, return_value, (parts_iter_key_type)key_type); + object, return_value, static_cast(key_type)); } U_CFUNC PHP_METHOD(IntlBreakIterator, getErrorCode) @@ -353,7 +352,7 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getErrorCode) /* Fetch the object (without resetting its last error code ). */ bio = Z_INTL_BREAKITERATOR_P(object); - RETURN_LONG((zend_long)BREAKITER_ERROR_CODE(bio)); + RETURN_LONG(static_cast(BREAKITER_ERROR_CODE(bio))); } U_CFUNC PHP_METHOD(IntlBreakIterator, getErrorMessage) diff --git a/ext/intl/breakiterator/codepointiterator_internal.cpp b/ext/intl/breakiterator/codepointiterator_internal.cpp index 3982a599af38f..b82ee9f6ab549 100644 --- a/ext/intl/breakiterator/codepointiterator_internal.cpp +++ b/ext/intl/breakiterator/codepointiterator_internal.cpp @@ -154,7 +154,7 @@ int32_t CodePointBreakIterator::first(void) int32_t CodePointBreakIterator::last(void) { - int32_t pos = (int32_t)utext_nativeLength(this->fText); + int32_t pos = static_cast(utext_nativeLength(this->fText)); UTEXT_SETNATIVEINDEX(this->fText, pos); this->lastCodePoint = U_SENTINEL; @@ -168,7 +168,7 @@ int32_t CodePointBreakIterator::previous(void) return BreakIterator::DONE; } - return (int32_t)UTEXT_GETNATIVEINDEX(this->fText); + return static_cast(UTEXT_GETNATIVEINDEX(this->fText)); } int32_t CodePointBreakIterator::next(void) @@ -178,12 +178,12 @@ int32_t CodePointBreakIterator::next(void) return BreakIterator::DONE; } - return (int32_t)UTEXT_GETNATIVEINDEX(this->fText); + return static_cast(UTEXT_GETNATIVEINDEX(this->fText)); } int32_t CodePointBreakIterator::current(void) const { - return (int32_t)UTEXT_GETNATIVEINDEX(this->fText); + return static_cast(UTEXT_GETNATIVEINDEX(this->fText)); } int32_t CodePointBreakIterator::following(int32_t offset) @@ -193,7 +193,7 @@ int32_t CodePointBreakIterator::following(int32_t offset) return BreakIterator::DONE; } - return (int32_t)UTEXT_GETNATIVEINDEX(this->fText); + return static_cast(UTEXT_GETNATIVEINDEX(this->fText)); } int32_t CodePointBreakIterator::preceding(int32_t offset) @@ -203,7 +203,7 @@ int32_t CodePointBreakIterator::preceding(int32_t offset) return BreakIterator::DONE; } - return (int32_t)UTEXT_GETNATIVEINDEX(this->fText); + return static_cast(UTEXT_GETNATIVEINDEX(this->fText)); } UBool CodePointBreakIterator::isBoundary(int32_t offset) @@ -223,7 +223,7 @@ int32_t CodePointBreakIterator::next(int32_t n) if (res) { this->lastCodePoint = UTEXT_CURRENT32(this->fText); - return (int32_t)UTEXT_GETNATIVEINDEX(this->fText); + return static_cast(UTEXT_GETNATIVEINDEX(this->fText)); } else { this->lastCodePoint = U_SENTINEL; return BreakIterator::DONE; @@ -243,7 +243,7 @@ CodePointBreakIterator *CodePointBreakIterator::createBufferClone( return NULL; } - char *buf = (char*)stackBuffer; + char *buf = static_cast(stackBuffer); uint32_t s = bufferSize; if (stackBuffer == NULL) { @@ -251,7 +251,7 @@ CodePointBreakIterator *CodePointBreakIterator::createBufferClone( } if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) { - uint32_t offsetUp = (uint32_t)U_ALIGNMENT_OFFSET_UP(buf); + uint32_t offsetUp = static_cast(U_ALIGNMENT_OFFSET_UP(buf)); s -= offsetUp; buf += offsetUp; } diff --git a/ext/intl/breakiterator/codepointiterator_internal.h b/ext/intl/breakiterator/codepointiterator_internal.h index 8090bfbbd3cc3..92f768e31d992 100644 --- a/ext/intl/breakiterator/codepointiterator_internal.h +++ b/ext/intl/breakiterator/codepointiterator_internal.h @@ -81,8 +81,7 @@ namespace PHP { CodePointBreakIterator &refreshInputText(UText *input, UErrorCode &status) override; - inline UChar32 getLastCodePoint() - { + inline UChar32 getLastCodePoint() const { return this->lastCodePoint; } diff --git a/ext/intl/breakiterator/codepointiterator_methods.cpp b/ext/intl/breakiterator/codepointiterator_methods.cpp index 49beb41be4e97..27e2725d72ea2 100644 --- a/ext/intl/breakiterator/codepointiterator_methods.cpp +++ b/ext/intl/breakiterator/codepointiterator_methods.cpp @@ -21,10 +21,6 @@ extern "C" { using PHP::CodePointBreakIterator; -static inline CodePointBreakIterator *fetch_cpbi(BreakIterator_object *bio) { - return (CodePointBreakIterator*)bio->biter; -} - U_CFUNC PHP_METHOD(IntlCodePointBreakIterator, getLastCodePoint) { BREAKITER_METHOD_INIT_VARS; @@ -34,5 +30,5 @@ U_CFUNC PHP_METHOD(IntlCodePointBreakIterator, getLastCodePoint) BREAKITER_METHOD_FETCH_OBJECT; - RETURN_LONG(fetch_cpbi(bio)->getLastCodePoint()); + RETURN_LONG(static_cast(bio->biter)->getLastCodePoint()); } diff --git a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp index c84972fe5b98c..37bf47ad99224 100644 --- a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp +++ b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp @@ -28,8 +28,9 @@ extern "C" { using icu::RuleBasedBreakIterator; using icu::Locale; -static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) { - return (RuleBasedBreakIterator*)bio->biter; +static inline RuleBasedBreakIterator *fetch_rbbi(const BreakIterator_object *bio) { + ZEND_ASSERT(bio != nullptr); + return static_cast(bio->biter); } static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced) @@ -54,7 +55,7 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_er } zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling); - *error_handling_replaced = 1; + *error_handling_replaced = true; // instantiation of ICU object RuleBasedBreakIterator *rbbi; @@ -84,7 +85,7 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_er RETURN_THROWS(); } } else { // compiled - rbbi = new RuleBasedBreakIterator((uint8_t*)rules, rules_len, status); + rbbi = new RuleBasedBreakIterator(reinterpret_cast(rules), rules_len, status); if (U_FAILURE(status)) { zend_throw_exception(IntlException_ce_ptr, "IntlRuleBasedBreakIterator::__construct(): " @@ -100,7 +101,7 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_er U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct) { zend_error_handling error_handling; - bool error_handling_replaced = 0; + bool error_handling_replaced = false; return_value = ZEND_THIS; _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced); @@ -159,7 +160,7 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getRuleStatusVec) ZEND_ASSERT(BREAKITER_ERROR_CODE(bio) == U_BUFFER_OVERFLOW_ERROR); BREAKITER_ERROR_CODE(bio) = U_ZERO_ERROR; - std::unique_ptr rules = std::unique_ptr(new int32_t[num_rules]); + const std::unique_ptr rules = std::unique_ptr(new int32_t[num_rules]); num_rules = fetch_rbbi(bio)->getRuleStatusVec(rules.get(), num_rules, BREAKITER_ERROR_CODE(bio)); if (U_FAILURE(BREAKITER_ERROR_CODE(bio))) {