Skip to content

ext/intl: BreakIterator clean-up #18419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/intl/breakiterator/breakiterator_class.cpp
Original file line number Diff line number Diff line change
@@ -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<BreakIterator_object *>(zend_object_alloc(sizeof(BreakIterator_object), ce));

zend_object_std_init(&intern->zo, ce);
object_properties_init(&intern->zo, ce);
54 changes: 25 additions & 29 deletions ext/intl/breakiterator/breakiterator_iterators.cpp
Original file line number Diff line number Diff line change
@@ -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 <zend_exceptions.h>
#include <zend_interfaces.h>
}
@@ -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<zoi_with_current *>(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<zend_long>(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<zoi_with_current *>(iter);

int32_t pos = biter->first();
ZVAL_LONG(&zoi_iter->current, (zend_long)pos);
ZVAL_LONG(&zoi_iter->current, static_cast<zend_long>(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<zoi_with_current *>(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<zoi_break_iter_parts *>(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<zoi_break_iter_parts *>(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<zend_object_iterator *>(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<zoi_with_current *>(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<zoi_break_iter_parts *>(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)
1 change: 0 additions & 1 deletion ext/intl/breakiterator/breakiterator_iterators.h
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
#include <unicode/umachine.h>

U_CDECL_BEGIN
#include <math.h>
#include <php.h>
U_CDECL_END

21 changes: 10 additions & 11 deletions ext/intl/breakiterator/breakiterator_methods.cpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ extern "C" {
#include "../php_intl.h"
#define USE_BREAKITERATOR_POINTER 1
#include "breakiterator_class.h"
#include "../locale/locale.h"
#include <zend_exceptions.h>
#include <zend_interfaces.h>
}
@@ -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<char *>(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<zend_long>(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<int32_t>(arg));

RETURN_LONG((zend_long)res);
RETURN_LONG(static_cast<zend_long>(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<zend_long>(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<int32_t>(offset));

RETURN_BOOL((zend_long)res);
RETURN_BOOL(static_cast<zend_long>(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<ULocDataLocaleType>(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<parts_iter_key_type>(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<zend_long>(BREAKITER_ERROR_CODE(bio)));
}

U_CFUNC PHP_METHOD(IntlBreakIterator, getErrorMessage)
18 changes: 9 additions & 9 deletions ext/intl/breakiterator/codepointiterator_internal.cpp
Original file line number Diff line number Diff line change
@@ -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<int32_t>(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<int32_t>(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<int32_t>(UTEXT_GETNATIVEINDEX(this->fText));
}

int32_t CodePointBreakIterator::current(void) const
{
return (int32_t)UTEXT_GETNATIVEINDEX(this->fText);
return static_cast<int32_t>(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<int32_t>(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<int32_t>(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<int32_t>(UTEXT_GETNATIVEINDEX(this->fText));
} else {
this->lastCodePoint = U_SENTINEL;
return BreakIterator::DONE;
@@ -243,15 +243,15 @@ CodePointBreakIterator *CodePointBreakIterator::createBufferClone(
return NULL;
}

char *buf = (char*)stackBuffer;
char *buf = static_cast<char *>(stackBuffer);
uint32_t s = bufferSize;

if (stackBuffer == NULL) {
s = 0;
}

if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) {
uint32_t offsetUp = (uint32_t)U_ALIGNMENT_OFFSET_UP(buf);
uint32_t offsetUp = static_cast<uint32_t>(U_ALIGNMENT_OFFSET_UP(buf));
s -= offsetUp;
buf += offsetUp;
}
3 changes: 1 addition & 2 deletions ext/intl/breakiterator/codepointiterator_internal.h
Original file line number Diff line number Diff line change
@@ -81,8 +81,7 @@ namespace PHP {

CodePointBreakIterator &refreshInputText(UText *input, UErrorCode &status) override;

inline UChar32 getLastCodePoint()
{
inline UChar32 getLastCodePoint() const {
return this->lastCodePoint;
}

6 changes: 1 addition & 5 deletions ext/intl/breakiterator/codepointiterator_methods.cpp
Original file line number Diff line number Diff line change
@@ -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<CodePointBreakIterator *>(bio->biter)->getLastCodePoint());
}
Loading
Loading