summaryrefslogtreecommitdiff
path: root/ext/intl/breakiterator/breakiterator_class.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ext/intl/breakiterator/breakiterator_class.cpp')
-rw-r--r--ext/intl/breakiterator/breakiterator_class.cpp108
1 files changed, 48 insertions, 60 deletions
diff --git a/ext/intl/breakiterator/breakiterator_class.cpp b/ext/intl/breakiterator/breakiterator_class.cpp
index 7ca7e94c95..715a866111 100644
--- a/ext/intl/breakiterator/breakiterator_class.cpp
+++ b/ext/intl/breakiterator/breakiterator_class.cpp
@@ -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 |
@@ -47,7 +47,7 @@ zend_object_handlers BreakIterator_handlers;
/* }}} */
U_CFUNC void breakiterator_object_create(zval *object,
- BreakIterator *biter TSRMLS_DC)
+ BreakIterator *biter, int brand_new TSRMLS_DC)
{
UClassID classId = biter->getDynamicClassID();
zend_class_entry *ce;
@@ -60,7 +60,9 @@ U_CFUNC void breakiterator_object_create(zval *object,
ce = BreakIterator_ce_ptr;
}
- object_init_ex(object, ce);
+ if (brand_new) {
+ object_init_ex(object, ce);
+ }
breakiterator_object_construct(object, biter TSRMLS_CC);
}
@@ -81,8 +83,8 @@ static int BreakIterator_compare_objects(zval *object1,
BreakIterator_object *bio1,
*bio2;
- bio1 = (BreakIterator_object*)zend_object_store_get_object(object1 TSRMLS_CC);
- bio2 = (BreakIterator_object*)zend_object_store_get_object(object2 TSRMLS_CC);
+ bio1 = Z_INTL_BREAKITERATOR_P(object1);
+ bio2 = Z_INTL_BREAKITERATOR_P(object2);
if (bio1->biter == NULL || bio2->biter == NULL) {
return bio1->biter == bio2->biter ? 0 : 1;
@@ -93,41 +95,36 @@ static int BreakIterator_compare_objects(zval *object1,
/* }}} */
/* {{{ clone handler for BreakIterator */
-static zend_object_value BreakIterator_clone_obj(zval *object TSRMLS_DC)
+static zend_object *BreakIterator_clone_obj(zval *object TSRMLS_DC)
{
BreakIterator_object *bio_orig,
*bio_new;
- zend_object_value ret_val;
+ zend_object *ret_val;
- bio_orig = (BreakIterator_object*)zend_object_store_get_object(object TSRMLS_CC);
+ bio_orig = Z_INTL_BREAKITERATOR_P(object);
intl_errors_reset(INTL_DATA_ERROR_P(bio_orig) TSRMLS_CC);
ret_val = BreakIterator_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
- bio_new = (BreakIterator_object*)zend_object_store_get_object_by_handle(
- ret_val.handle TSRMLS_CC);
+ bio_new = php_intl_breakiterator_fetch_object(ret_val);
- zend_objects_clone_members(&bio_new->zo, ret_val,
- &bio_orig->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC);
+ zend_objects_clone_members(&bio_new->zo, &bio_orig->zo TSRMLS_CC);
if (bio_orig->biter != NULL) {
BreakIterator *new_biter;
new_biter = bio_orig->biter->clone();
if (!new_biter) {
- char *err_msg;
+ zend_string *err_msg;
intl_errors_set_code(BREAKITER_ERROR_P(bio_orig),
U_MEMORY_ALLOCATION_ERROR TSRMLS_CC);
intl_errors_set_custom_msg(BREAKITER_ERROR_P(bio_orig),
"Could not clone BreakIterator", 0 TSRMLS_CC);
err_msg = intl_error_get_message(BREAKITER_ERROR_P(bio_orig) TSRMLS_CC);
- zend_throw_exception(NULL, err_msg, 0 TSRMLS_CC);
- efree(err_msg);
+ zend_throw_exception(NULL, err_msg->val, 0 TSRMLS_CC);
+ zend_string_free(err_msg);
} else {
bio_new->biter = new_biter;
- bio_new->text = bio_orig->text;
- if (bio_new->text) {
- zval_add_ref(&bio_new->text);
- }
+ ZVAL_COPY(&bio_new->text, &bio_orig->text);
}
} else {
zend_throw_exception(NULL, "Cannot clone unconstructed BreakIterator", 0 TSRMLS_CC);
@@ -140,34 +137,39 @@ static zend_object_value BreakIterator_clone_obj(zval *object TSRMLS_DC)
/* {{{ get_debug_info handler for BreakIterator */
static HashTable *BreakIterator_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
{
- zval zv = zval_used_for_init;
+ zval val;
+ HashTable *debug_info;
BreakIterator_object *bio;
const BreakIterator *biter;
*is_temp = 1;
- array_init_size(&zv, 8);
+ ALLOC_HASHTABLE(debug_info);
+ zend_hash_init(debug_info, 8, NULL, ZVAL_PTR_DTOR, 0);
- bio = (BreakIterator_object*)zend_object_store_get_object(object TSRMLS_CC);
+ bio = Z_INTL_BREAKITERATOR_P(object);
biter = bio->biter;
if (biter == NULL) {
- add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 0);
- return Z_ARRVAL(zv);
+ ZVAL_FALSE(&val);
+ zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &val);
+ return debug_info;
}
- add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 1);
+ ZVAL_TRUE(&val);
+ zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &val);
- if (bio->text == NULL) {
- add_assoc_null_ex(&zv, "text", sizeof("text"));
+ if (Z_ISUNDEF(bio->text)) {
+ ZVAL_NULL(&val);
+ zend_hash_str_update(debug_info, "text", sizeof("text") - 1, &val);
} else {
- zval_add_ref(&bio->text);
- add_assoc_zval_ex(&zv, "text", sizeof("text"), bio->text);
+ Z_TRY_ADDREF(bio->text);
+ zend_hash_str_update(debug_info, "text", sizeof("text") - 1, &bio->text);
}
- add_assoc_string_ex(&zv, "type", sizeof("type"),
- const_cast<char*>(typeid(*biter).name()), 1);
+ ZVAL_STRING(&val, const_cast<char*>(typeid(*biter).name()));
+ zend_hash_str_update(debug_info, "type", sizeof("type") - 1, &bio->text);
- return Z_ARRVAL(zv);
+ return debug_info;
}
/* }}} */
@@ -178,26 +180,23 @@ static void breakiterator_object_init(BreakIterator_object *bio TSRMLS_DC)
{
intl_error_init(BREAKITER_ERROR_P(bio) TSRMLS_CC);
bio->biter = NULL;
- bio->text = NULL;
+ ZVAL_UNDEF(&bio->text);
}
/* }}} */
/* {{{ BreakIterator_objects_dtor */
-static void BreakIterator_objects_dtor(void *object,
- zend_object_handle handle TSRMLS_DC)
+static void BreakIterator_objects_dtor(zend_object *object TSRMLS_DC)
{
- zend_objects_destroy_object((zend_object*)object, handle TSRMLS_CC);
+ zend_objects_destroy_object(object TSRMLS_CC);
}
/* }}} */
/* {{{ BreakIterator_objects_free */
static void BreakIterator_objects_free(zend_object *object TSRMLS_DC)
{
- BreakIterator_object* bio = (BreakIterator_object*) object;
+ BreakIterator_object* bio = php_intl_breakiterator_fetch_object(object);
- if (bio->text) {
- zval_ptr_dtor(&bio->text);
- }
+ zval_ptr_dtor(&bio->text);
if (bio->biter) {
delete bio->biter;
bio->biter = NULL;
@@ -205,37 +204,23 @@ static void BreakIterator_objects_free(zend_object *object TSRMLS_DC)
intl_error_reset(BREAKITER_ERROR_P(bio) TSRMLS_CC);
zend_object_std_dtor(&bio->zo TSRMLS_CC);
-
- efree(bio);
}
/* }}} */
/* {{{ BreakIterator_object_create */
-static zend_object_value BreakIterator_object_create(zend_class_entry *ce TSRMLS_DC)
+static zend_object *BreakIterator_object_create(zend_class_entry *ce TSRMLS_DC)
{
- zend_object_value retval;
BreakIterator_object* intern;
- intern = (BreakIterator_object*)ecalloc(1, sizeof(BreakIterator_object));
+ intern = (BreakIterator_object*)ecalloc(1, sizeof(BreakIterator_object) + sizeof(zval) * (ce->default_properties_count - 1));
zend_object_std_init(&intern->zo, ce TSRMLS_CC);
-#if PHP_VERSION_ID < 50399
- zend_hash_copy(intern->zo.properties, &(ce->default_properties),
- (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
-#else
object_properties_init((zend_object*) intern, ce);
-#endif
breakiterator_object_init(intern TSRMLS_CC);
- retval.handle = zend_objects_store_put(
- intern,
- BreakIterator_objects_dtor,
- (zend_objects_free_object_storage_t) BreakIterator_objects_free,
- NULL TSRMLS_CC);
-
- retval.handlers = &BreakIterator_handlers;
+ intern->zo.handlers = &BreakIterator_handlers;
- return retval;
+ return &intern->zo;
}
/* }}} */
@@ -343,9 +328,12 @@ U_CFUNC void breakiterator_register_BreakIterator_class(TSRMLS_D)
memcpy(&BreakIterator_handlers, zend_get_std_object_handlers(),
sizeof BreakIterator_handlers);
+ BreakIterator_handlers.offset = XtOffsetOf(BreakIterator_object, zo);
BreakIterator_handlers.compare_objects = BreakIterator_compare_objects;
BreakIterator_handlers.clone_obj = BreakIterator_clone_obj;
BreakIterator_handlers.get_debug_info = BreakIterator_get_debug_info;
+ BreakIterator_handlers.dtor_obj = BreakIterator_objects_dtor;
+ BreakIterator_handlers.free_obj = BreakIterator_objects_free;
zend_class_implements(BreakIterator_ce_ptr TSRMLS_CC, 1,
zend_ce_traversable);
@@ -386,12 +374,12 @@ U_CFUNC void breakiterator_register_BreakIterator_class(TSRMLS_D)
INIT_CLASS_ENTRY(ce, "IntlRuleBasedBreakIterator",
RuleBasedBreakIterator_class_functions);
RuleBasedBreakIterator_ce_ptr = zend_register_internal_class_ex(&ce,
- BreakIterator_ce_ptr, NULL TSRMLS_CC);
+ BreakIterator_ce_ptr TSRMLS_CC);
/* Create and register 'CodePointBreakIterator' class. */
INIT_CLASS_ENTRY(ce, "IntlCodePointBreakIterator",
CodePointBreakIterator_class_functions);
CodePointBreakIterator_ce_ptr = zend_register_internal_class_ex(&ce,
- BreakIterator_ce_ptr, NULL TSRMLS_CC);
+ BreakIterator_ce_ptr TSRMLS_CC);
}
/* }}} */