summaryrefslogtreecommitdiff
path: root/ext/intl/breakiterator/breakiterator_class.cpp
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2014-06-28 00:02:50 +0800
committerXinchen Hui <laruence@php.net>2014-06-28 00:02:50 +0800
commit4fbaddb4f8b041769bea7efdd12313641387bd14 (patch)
tree7e3a8f8fd232dd52e0a666ef5b9e9b27734ddde1 /ext/intl/breakiterator/breakiterator_class.cpp
parentf609d8c1c677d03d9ae380480ae72383c5a98106 (diff)
downloadphp-git-4fbaddb4f8b041769bea7efdd12313641387bd14.tar.gz
Refactoring ext/intl (incompleted)
Diffstat (limited to 'ext/intl/breakiterator/breakiterator_class.cpp')
-rw-r--r--ext/intl/breakiterator/breakiterator_class.cpp81
1 files changed, 31 insertions, 50 deletions
diff --git a/ext/intl/breakiterator/breakiterator_class.cpp b/ext/intl/breakiterator/breakiterator_class.cpp
index 181d0e03b9..e756f366ef 100644
--- a/ext/intl/breakiterator/breakiterator_class.cpp
+++ b/ext/intl/breakiterator/breakiterator_class.cpp
@@ -81,8 +81,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 +93,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);
+ STR_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);
@@ -148,23 +143,23 @@ static HashTable *BreakIterator_get_debug_info(zval *object, int *is_temp TSRMLS
array_init_size(&zv, 8);
- 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);
+ add_assoc_bool_ex(&zv, "valid", sizeof("valid") - 1, 0);
return Z_ARRVAL(zv);
}
- add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 1);
+ add_assoc_bool_ex(&zv, "valid", sizeof("valid") - 1, 1);
- if (bio->text == NULL) {
- add_assoc_null_ex(&zv, "text", sizeof("text"));
+ if (Z_ISUNDEF(bio->text)) {
+ add_assoc_null_ex(&zv, "text", sizeof("text") - 1);
} else {
- zval_add_ref(&bio->text);
- add_assoc_zval_ex(&zv, "text", sizeof("text"), bio->text);
+ Z_TRY_ADDREF(bio->text);
+ add_assoc_zval_ex(&zv, "text", sizeof("text") - 1, &bio->text);
}
- add_assoc_string_ex(&zv, "type", sizeof("type"),
+ add_assoc_string_ex(&zv, "type", sizeof("type") - 1,
const_cast<char*>(typeid(*biter).name()));
return Z_ARRVAL(zv);
@@ -178,26 +173,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 +197,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 +321,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);