From: Xinchen Hui Date: Fri, 27 Jun 2014 16:02:50 +0000 (+0800) Subject: Refactoring ext/intl (incompleted) X-Git-Tag: POST_PHPNG_MERGE~128 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fbaddb4f8b041769bea7efdd12313641387bd14;p=php Refactoring ext/intl (incompleted) --- 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(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); diff --git a/ext/intl/breakiterator/breakiterator_class.h b/ext/intl/breakiterator/breakiterator_class.h index cc5d51256f..81074c28bd 100644 --- a/ext/intl/breakiterator/breakiterator_class.h +++ b/ext/intl/breakiterator/breakiterator_class.h @@ -29,8 +29,6 @@ typedef void BreakIterator; #endif typedef struct { - zend_object zo; - // error handling intl_error err; @@ -38,9 +36,16 @@ typedef struct { BreakIterator* biter; // current text - zval *text; + zval text; + + zend_object zo; } BreakIterator_object; +static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_object *obj) { + return (BreakIterator_object *)((char*)(obj) - XtOffsetOf(BreakIterator_object, zo)); +} +#define Z_INTL_BREAKITERATOR_P(zv) php_intl_breakiterator_fetch_object(Z_OBJ_P(zv)) + #define BREAKITER_ERROR(bio) (bio)->err #define BREAKITER_ERROR_P(bio) &(BREAKITER_ERROR(bio)) @@ -48,7 +53,7 @@ typedef struct { #define BREAKITER_ERROR_CODE_P(bio) &(INTL_ERROR_CODE(BREAKITER_ERROR(bio))) #define BREAKITER_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(BreakIterator, bio) -#define BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(BreakIterator, bio) +#define BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_BREAKITERATOR, bio) #define BREAKITER_METHOD_FETCH_OBJECT \ BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (bio->biter == NULL) \ diff --git a/ext/intl/calendar/calendar_class.cpp b/ext/intl/calendar/calendar_class.cpp index 99828c43ea..151fc2508e 100644 --- a/ext/intl/calendar/calendar_class.cpp +++ b/ext/intl/calendar/calendar_class.cpp @@ -59,8 +59,7 @@ U_CFUNC void calendar_object_create(zval *object, U_CFUNC Calendar *calendar_fetch_native_calendar(zval *object TSRMLS_DC) { - Calendar_object *co = (Calendar_object*) - zend_object_store_get_object(object TSRMLS_CC); + Calendar_object *co = Z_INTL_CALENDAR_P(object); return co->ucal; } @@ -76,35 +75,34 @@ U_CFUNC void calendar_object_construct(zval *object, } /* {{{ clone handler for Calendar */ -static zend_object_value Calendar_clone_obj(zval *object TSRMLS_DC) +static zend_object *Calendar_clone_obj(zval *object TSRMLS_DC) { Calendar_object *co_orig, *co_new; - zend_object_value ret_val; + zend_object *ret_val; intl_error_reset(NULL TSRMLS_CC); - co_orig = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + co_orig = Z_INTL_CALENDAR_P(object); intl_error_reset(INTL_DATA_ERROR_P(co_orig) TSRMLS_CC); ret_val = Calendar_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); - co_new = (Calendar_object*)zend_object_store_get_object_by_handle(ret_val.handle TSRMLS_CC); + co_new = php_intl_calendar_fetch_object(ret_val); - zend_objects_clone_members(&co_new->zo, ret_val, - &co_orig->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC); + zend_objects_clone_members(&co_new->zo, &co_orig->zo TSRMLS_CC); if (co_orig->ucal != NULL) { Calendar *newCalendar; newCalendar = co_orig->ucal->clone(); if (!newCalendar) { - char *err_msg; + zend_string *err_msg; intl_errors_set_code(CALENDAR_ERROR_P(co_orig), U_MEMORY_ALLOCATION_ERROR TSRMLS_CC); intl_errors_set_custom_msg(CALENDAR_ERROR_P(co_orig), "Could not clone IntlCalendar", 0 TSRMLS_CC); err_msg = intl_error_get_message(CALENDAR_ERROR_P(co_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 { co_new->ucal = newCalendar; } @@ -149,7 +147,7 @@ static const struct { static HashTable *Calendar_get_debug_info(zval *object, int *is_temp TSRMLS_DC) { zval zv = zval_used_for_init, - *zfields; + zfields; Calendar_object *co; const Calendar *cal; @@ -157,7 +155,7 @@ static HashTable *Calendar_get_debug_info(zval *object, int *is_temp TSRMLS_DC) array_init_size(&zv, 8); - co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + co = Z_INTL_CALENDAR_P(object); cal = co->ucal; if (cal == NULL) { @@ -172,7 +170,7 @@ static HashTable *Calendar_get_debug_info(zval *object, int *is_temp TSRMLS_DC) { zval ztz = zval_used_for_init, - *ztz_debug; + ztz_debug; int is_tmp; HashTable *debug_info; @@ -180,26 +178,23 @@ static HashTable *Calendar_get_debug_info(zval *object, int *is_temp TSRMLS_DC) debug_info = Z_OBJ_HANDLER(ztz, get_debug_info)(&ztz, &is_tmp TSRMLS_CC); assert(is_tmp == 1); - ALLOC_INIT_ZVAL(ztz_debug); - Z_TYPE_P(ztz_debug) = IS_ARRAY; - Z_ARRVAL_P(ztz_debug) = debug_info; - add_assoc_zval_ex(&zv, "timeZone", sizeof("timeZone"), ztz_debug); + zend_hash_copy(Z_ARRVAL(ztz_debug), debug_info, NULL); + add_assoc_zval_ex(&zv, "timeZone", sizeof("timeZone") - 1, &ztz_debug); } { UErrorCode uec = U_ZERO_ERROR; Locale locale = cal->getLocale(ULOC_VALID_LOCALE, uec); if (U_SUCCESS(uec)) { - add_assoc_string_ex(&zv, "locale", sizeof("locale"), + add_assoc_string_ex(&zv, "locale", sizeof("locale") - 1, const_cast(locale.getName())); } else { - add_assoc_string_ex(&zv, "locale", sizeof("locale"), + add_assoc_string_ex(&zv, "locale", sizeof("locale") - 1, const_cast(u_errorName(uec))); } } - ALLOC_INIT_ZVAL(zfields); - array_init_size(zfields, UCAL_FIELD_COUNT); + array_init_size(&zfields, UCAL_FIELD_COUNT); for (int i = 0; i < sizeof(debug_info_fields) / sizeof(*debug_info_fields); @@ -208,13 +203,13 @@ static HashTable *Calendar_get_debug_info(zval *object, int *is_temp TSRMLS_DC) const char *name = debug_info_fields[i].name; int32_t res = cal->get(debug_info_fields[i].field, uec); if (U_SUCCESS(uec)) { - add_assoc_long(zfields, name, (long)res); + add_assoc_long(&zfields, name, (long)res); } else { - add_assoc_string(zfields, name, const_cast(u_errorName(uec))); + add_assoc_string(&zfields, name, const_cast(u_errorName(uec))); } } - add_assoc_zval_ex(&zv, "fields", sizeof("fields"), zfields); + add_assoc_zval_ex(&zv, "fields", sizeof("fields") - 1, &zfields); return Z_ARRVAL(zv); } @@ -231,10 +226,9 @@ static void calendar_object_init(Calendar_object *co TSRMLS_DC) /* }}} */ /* {{{ Calendar_objects_dtor */ -static void Calendar_objects_dtor(void *object, - zend_object_handle handle TSRMLS_DC) +static void Calendar_objects_dtor(zend_object *object TSRMLS_DC) { - zend_objects_destroy_object((zend_object*)object, handle TSRMLS_CC); + zend_objects_destroy_object(object TSRMLS_CC); } /* }}} */ @@ -256,31 +250,20 @@ static void Calendar_objects_free(zend_object *object TSRMLS_DC) /* }}} */ /* {{{ Calendar_object_create */ -static zend_object_value Calendar_object_create(zend_class_entry *ce TSRMLS_DC) +static zend_object *Calendar_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; Calendar_object* intern; - intern = (Calendar_object*)ecalloc(1, sizeof(Calendar_object)); + intern = (Calendar_object*)ecalloc(1, sizeof(Calendar_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 calendar_object_init(intern TSRMLS_CC); - retval.handle = zend_objects_store_put( - intern, - Calendar_objects_dtor, - (zend_objects_free_object_storage_t) Calendar_objects_free, - NULL TSRMLS_CC); - retval.handlers = &Calendar_handlers; + intern->zo.handlers = &Calendar_handlers; - return retval; + return &intern->zo; } /* }}} */ @@ -484,8 +467,11 @@ void calendar_register_IntlCalendar_class(TSRMLS_D) } memcpy( &Calendar_handlers, zend_get_std_object_handlers(), sizeof Calendar_handlers); + Calendar_handlers.offset = XtOffsetOf(Calendar_object, zo); Calendar_handlers.clone_obj = Calendar_clone_obj; Calendar_handlers.get_debug_info = Calendar_get_debug_info; + Calendar_handlers.dtor_obj = Calendar_objects_dtor; + Calendar_handlers.free_obj = Calendar_objects_free; /* Create and register 'IntlGregorianCalendar' class. */ INIT_CLASS_ENTRY(ce, "IntlGregorianCalendar", GregorianCalendar_class_functions); diff --git a/ext/intl/calendar/calendar_class.h b/ext/intl/calendar/calendar_class.h index 140389b639..2e7fbd2172 100644 --- a/ext/intl/calendar/calendar_class.h +++ b/ext/intl/calendar/calendar_class.h @@ -29,15 +29,20 @@ typedef void Calendar; #endif typedef struct { - zend_object zo; - // error handling intl_error err; // ICU calendar Calendar* ucal; + + zend_object zo; } Calendar_object; +static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj) { + return (Calendar_object *)((char*)(obj) - XtOffsetOf(Calendar_object, zo)); +} +#define Z_INTL_CALENDAR_P(zv) php_intl_calendar_fetch_object(Z_OBJ_P(zv)) + #define CALENDAR_ERROR(co) (co)->err #define CALENDAR_ERROR_P(co) &(CALENDAR_ERROR(co)) @@ -45,7 +50,7 @@ typedef struct { #define CALENDAR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(CALENDAR_ERROR(co))) #define CALENDAR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(Calendar, co) -#define CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(Calendar, co) +#define CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_CALENDAR, co) #define CALENDAR_METHOD_FETCH_OBJECT \ CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \ if (co->ucal == NULL) \ diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 179602d8fa..ad2a0b499e 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -49,14 +49,14 @@ U_CFUNC PHP_METHOD(IntlCalendar, __construct) U_CFUNC PHP_FUNCTION(intlcal_create_instance) { - zval **zv_timezone = NULL; + zval *zv_timezone = NULL; const char *locale_str = NULL; int dummy; TimeZone *timeZone; UErrorCode status = U_ZERO_ERROR; intl_error_reset(NULL TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Zs!", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zs!", &zv_timezone, &locale_str, &dummy) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_create_calendar: bad arguments", 0 TSRMLS_CC); @@ -344,8 +344,8 @@ U_CFUNC PHP_FUNCTION(intlcal_set_time_zone) RETURN_TRUE; /* the method does nothing if passed null */ } - timeZone = timezone_process_timezone_argument(&zv_timezone, - CALENDAR_ERROR_P(co), "intlcal_set_time_zone" TSRMLS_CC); + timeZone = timezone_process_timezone_argument(zv_timezone, + CALENDAR_ERROR_P(co), "intlcal_set_time_zone" TSRMLS_CC); if (timeZone == NULL) { RETURN_FALSE; } @@ -374,8 +374,7 @@ static void _php_intlcal_before_after( CALENDAR_METHOD_FETCH_OBJECT; - when_co = static_cast( - zend_object_store_get_object(when_object TSRMLS_CC)); + when_co = Z_INTL_CALENDAR_P(when_object); if (when_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_before/after: Other IntlCalendar was unconstructed", 0 TSRMLS_CC); @@ -401,8 +400,8 @@ U_CFUNC PHP_FUNCTION(intlcal_before) U_CFUNC PHP_FUNCTION(intlcal_set) { long arg1, arg2, arg3, arg4, arg5, arg6; - zval **args_a[7] = {0}, - ***args = &args_a[0]; + zval args_a[7] = {0}, + *args = args_a; int i; int variant; /* number of args of the set() overload */ CALENDAR_METHOD_INIT_VARS; @@ -418,7 +417,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set) args++; } variant = ZEND_NUM_ARGS() - (getThis() ? 0 : 1); - while (variant > 2 && Z_TYPE_PP(args[variant - 1]) == IS_NULL) { + while (variant > 2 && Z_TYPE(args[variant - 1]) == IS_NULL) { variant--; } @@ -432,7 +431,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set) } for (i = 0; i < variant; i++) { - if (Z_LVAL_PP(args[i]) < INT32_MIN || Z_LVAL_PP(args[i]) > INT32_MAX) { + if (Z_LVAL(args[i]) < INT32_MIN || Z_LVAL(args[i]) > INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: at least one of the arguments has an absolute " "value that is too large", 0 TSRMLS_CC); @@ -465,8 +464,8 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) { long field, value; - zval **args_a[3] = {0}, - ***args = &args_a[0]; + zval args_a[3] = {0}, + *args = args_a; zend_bool bool_variant_val = (zend_bool)-1; CALENDAR_METHOD_INIT_VARS; @@ -479,7 +478,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) if (!getThis()) { args++; } - if (args[1] != NULL && Z_TYPE_PP(args[1]) == IS_BOOL) { + if (!Z_ISUNDEF(args[1]) && (Z_TYPE(args[1]) == IS_TRUE || Z_TYPE(args[1]) == IS_FALSE)) { if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olb", &object, Calendar_ce_ptr, &field, &bool_variant_val) == FAILURE) { @@ -487,7 +486,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) "intlcal_roll: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } - bool_variant_val = Z_BVAL_PP(args[1]); + bool_variant_val = Z_TYPE(args[1]) == IS_TRUE? 1 : 0; } else if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -523,8 +522,8 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) U_CFUNC PHP_FUNCTION(intlcal_clear) { - zval **args_a[2] = {0}, - ***args = &args_a[0]; + zval args_a[2] = {0}, + *args = &args_a[0]; long field; int variant; CALENDAR_METHOD_INIT_VARS; @@ -538,7 +537,7 @@ U_CFUNC PHP_FUNCTION(intlcal_clear) if (!getThis()) { args++; } - if (args[0] == NULL || Z_TYPE_PP(args[0]) == IS_NULL) { + if (Z_ISUNDEF(args[0]) || Z_TYPE(args[0]) == IS_NULL) { zval *dummy; /* we know it's null */ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|z", &object, Calendar_ce_ptr, &dummy) == FAILURE) { @@ -731,7 +730,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_locale) INTL_METHOD_CHECK_STATUS(co, "intlcal_get_locale: Call to ICU method has failed"); - RETURN_STRING(locale.getName(), 1); + RETURN_STRING(locale.getName()); } U_CFUNC PHP_FUNCTION(intlcal_get_maximum) @@ -802,7 +801,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_type) CALENDAR_METHOD_FETCH_OBJECT; - RETURN_STRING(co->ucal->getType(), 1); + RETURN_STRING(co->ucal->getType()); } #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44 @@ -869,7 +868,7 @@ U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) RETURN_FALSE; } - other_co = (Calendar_object*)zend_object_store_get_object(other_object TSRMLS_CC); + other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to:" " Other IntlCalendar is unconstructed", 0 TSRMLS_CC); @@ -1037,7 +1036,7 @@ U_CFUNC PHP_FUNCTION(intlcal_equals) } CALENDAR_METHOD_FETCH_OBJECT; - other_co = (Calendar_object *) zend_object_store_get_object(other_object TSRMLS_CC); + other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_equals: The second IntlCalendar is unconstructed", 0 TSRMLS_CC); @@ -1139,8 +1138,9 @@ U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option) U_CFUNC PHP_FUNCTION(intlcal_from_date_time) { - zval **zv_arg, - *zv_datetime = NULL, + zval *zv_arg, + zv_tmp, + *zv_datetime = NULL, *zv_timestamp = NULL; php_date_obj *datetime; char *locale_str = NULL; @@ -1150,28 +1150,27 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) Calendar *cal; intl_error_reset(NULL TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|s!", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s!", &zv_arg, &locale_str, &locale_str_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad arguments", 0 TSRMLS_CC); RETURN_NULL(); } - if (!(Z_TYPE_PP(zv_arg) == IS_OBJECT && instanceof_function( - Z_OBJCE_PP(zv_arg), php_date_get_date_ce() TSRMLS_CC))) { - ALLOC_INIT_ZVAL(zv_datetime); - object_init_ex(zv_datetime, php_date_get_date_ce()); - zend_call_method_with_1_params(&zv_datetime, NULL, NULL, "__construct", - NULL, *zv_arg); + if (!(Z_TYPE_P(zv_arg) == IS_OBJECT && instanceof_function( + Z_OBJCE_P(zv_arg), php_date_get_date_ce() TSRMLS_CC))) { + object_init_ex(&zv_tmp, php_date_get_date_ce()); + zend_call_method_with_1_params(&zv_tmp, NULL, NULL, "__construct", NULL, zv_arg); if (EG(exception)) { - zend_object_store_ctor_failed(zv_datetime TSRMLS_CC); + zend_object_store_ctor_failed(Z_OBJ(zv_tmp) TSRMLS_CC); goto error; } + zv_datetime = &zv_tmp; } else { - zv_datetime = *zv_arg; + zv_datetime = zv_arg; } - datetime = (php_date_obj*)zend_object_store_get_object(zv_datetime TSRMLS_CC); + datetime = Z_PHPDATE_P(zv_datetime); if (!datetime->time) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: DateTime object is unconstructed", @@ -1179,8 +1178,7 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) goto error; } - zend_call_method_with_0_params(&zv_datetime, php_date_get_date_ce(), - NULL, "gettimestamp", &zv_timestamp); + zend_call_method_with_0_params(zv_datetime, php_date_get_date_ce(), NULL, "gettimestamp", zv_timestamp); if (!zv_timestamp || Z_TYPE_P(zv_timestamp) != IS_LONG) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad DateTime; call to " @@ -1222,17 +1220,17 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) calendar_object_create(return_value, cal TSRMLS_CC); error: - if (zv_datetime != *zv_arg) { - zval_ptr_dtor(&zv_datetime); + if (zv_datetime != zv_arg) { + zval_ptr_dtor(zv_datetime); } if (zv_timestamp) { - zval_ptr_dtor(&zv_timestamp); + zval_ptr_dtor(zv_timestamp); } } U_CFUNC PHP_FUNCTION(intlcal_to_date_time) { - zval *retval = NULL; + zval retval; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -1250,7 +1248,7 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) int64_t ts; char ts_str[sizeof("@-9223372036854775808")]; int ts_str_len; - zval ts_zval = zval_used_for_init; + zval ts_tmp, ts_zval = zval_used_for_init; INTL_METHOD_CHECK_STATUS(co, "Call to ICU method has failed"); @@ -1261,15 +1259,18 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) RETURN_FALSE; } + ZVAL_UNDEF(&retval); ts = (int64_t)date; ts_str_len = slprintf(ts_str, sizeof(ts_str), "@%I64d", ts); - ZVAL_STRINGL(&ts_zval, ts_str, ts_str_len, 0); + ZVAL_STRINGL(&ts_zval, ts_str, ts_str_len); + //??? + efree(ts_str); /* Now get the time zone */ const TimeZone& tz = co->ucal->getTimeZone(); zval *timezone_zval = timezone_convert_to_datetimezone( - &tz, CALENDAR_ERROR_P(co), "intlcal_to_date_time" TSRMLS_CC); + &tz, CALENDAR_ERROR_P(co), "intlcal_to_date_time", &ts_zval TSRMLS_CC); if (timezone_zval == NULL) { RETURN_FALSE; } @@ -1278,36 +1279,33 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) /* Finally, instantiate object and call constructor */ object_init_ex(return_value, php_date_get_date_ce()); - zend_call_method_with_2_params(&return_value, NULL, NULL, "__construct", - NULL, &ts_zval, timezone_zval); + zend_call_method_with_2_params(return_value, NULL, NULL, "__construct", NULL, &ts_zval, timezone_zval); if (EG(exception)) { intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR, "intlcal_to_date_time: DateTime constructor has thrown exception", 1 TSRMLS_CC); - zend_object_store_ctor_failed(return_value TSRMLS_CC); - zval_ptr_dtor(&return_value); + zend_object_store_ctor_failed(Z_OBJ_P(return_value) TSRMLS_CC); + zval_ptr_dtor(return_value); RETVAL_FALSE; goto error; } /* due to bug #40743, we have to set the time zone again */ - zend_call_method_with_1_params(&return_value, NULL, NULL, "settimezone", + zend_call_method_with_1_params(return_value, NULL, NULL, "settimezone", &retval, timezone_zval); - if (retval == NULL || Z_TYPE_P(retval) == IS_BOOL) { + if (Z_ISUNDEF(retval) || Z_TYPE(retval) == IS_FALSE) { intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR, "intlcal_to_date_time: call to DateTime::setTimeZone has failed", 1 TSRMLS_CC); - zval_ptr_dtor(&return_value); + zval_ptr_dtor(return_value); RETVAL_FALSE; goto error; } error: - zval_ptr_dtor(&timezone_zval); - if (retval != NULL) { - zval_ptr_dtor(&retval); - } + zval_ptr_dtor(timezone_zval); + zval_ptr_dtor(&retval); } U_CFUNC PHP_FUNCTION(intlcal_get_error_code) @@ -1322,7 +1320,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_error_code) } /* Fetch the object (without resetting its last error code ). */ - co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + co = Z_INTL_CALENDAR_P(object); if (co == NULL) RETURN_FALSE; @@ -1331,7 +1329,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_error_code) U_CFUNC PHP_FUNCTION(intlcal_get_error_message) { - const char* message = NULL; + zend_string* message = NULL; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -1343,11 +1341,11 @@ U_CFUNC PHP_FUNCTION(intlcal_get_error_message) /* Fetch the object (without resetting its last error code ). */ - co = (Calendar_object*)zend_object_store_get_object(object TSRMLS_CC); + co = Z_INTL_CALENDAR_P(object); if (co == NULL) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message(CALENDAR_ERROR_P(co) TSRMLS_CC); - RETURN_STRING(message, 0); + RETURN_STR(message); } diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 08b894964c..a665e35286 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -38,9 +38,9 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) { static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) { - zval **tz_object = NULL; - zval **args_a[6] = {0}, - ***args = &args_a[0]; + zval *tz_object = NULL; + zval args_a[6] = {0}, + *args = &args_a[0]; char *locale = NULL; int locale_len; long largs[6]; @@ -56,7 +56,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) RETURN_NULL(); } for (variant = ZEND_NUM_ARGS(); - variant > 0 && Z_TYPE_PP(args[variant - 1]) == IS_NULL; + variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant--) {} if (variant == 4) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -68,7 +68,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) // argument parsing if (variant <= 2) { if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2) TSRMLS_CC, - "|Z!s!", &tz_object, &locale, &locale_len) == FAILURE) { + "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC); RETURN_NULL(); @@ -158,8 +158,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) gcal->adoptTimeZone(tz); } - Calendar_object *co = (Calendar_object*)zend_object_store_get_object( - return_value TSRMLS_CC); + Calendar_object *co = Z_INTL_CALENDAR_P(return_value); co->ucal = gcal; } @@ -169,12 +168,12 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) intl_error_reset(NULL TSRMLS_CC); object_init_ex(return_value, GregorianCalendar_ce_ptr); - orig = *return_value; + ZVAL_COPY_VALUE(&orig, return_value); _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_NULL) { - zend_object_store_ctor_failed(&orig TSRMLS_CC); + zend_object_store_ctor_failed(Z_OBJ(orig) TSRMLS_CC); zval_dtor(&orig); } } @@ -189,7 +188,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct) _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_NULL) { - zend_object_store_ctor_failed(&orig_this TSRMLS_CC); + zend_object_store_ctor_failed(Z_OBJ(orig_this) TSRMLS_CC); zval_dtor(&orig_this); } } diff --git a/ext/intl/collator/collator_class.c b/ext/intl/collator/collator_class.c index d1fa10ef2c..8e1255c023 100644 --- a/ext/intl/collator/collator_class.c +++ b/ext/intl/collator/collator_class.c @@ -36,48 +36,36 @@ static zend_object_handlers Collator_handlers; */ /* {{{ Collator_objects_dtor */ -static void Collator_objects_dtor( - void *object, - zend_object_handle handle TSRMLS_DC ) +static void Collator_objects_dtor(zend_object *object TSRMLS_DC ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object(object TSRMLS_CC ); } /* }}} */ /* {{{ Collator_objects_free */ -void Collator_objects_free( zend_object *object TSRMLS_DC ) +void Collator_objects_free(zend_object *object TSRMLS_DC ) { - Collator_object* co = (Collator_object*)object; + Collator_object* co = php_collator_fetch_object(object); - zend_object_std_dtor( &co->zo TSRMLS_CC ); + zend_object_std_dtor(&co->zo TSRMLS_CC ); - collator_object_destroy( co TSRMLS_CC ); - - efree( co ); + collator_object_destroy(co TSRMLS_CC ); } /* }}} */ /* {{{ Collator_object_create */ -zend_object_value Collator_object_create( - zend_class_entry *ce TSRMLS_DC ) +zend_object *Collator_object_create(zend_class_entry *ce TSRMLS_DC ) { - zend_object_value retval; Collator_object* intern; - intern = ecalloc( 1, sizeof(Collator_object) ); - intl_error_init( COLLATOR_ERROR_P( intern ) TSRMLS_CC ); - zend_object_std_init( &intern->zo, ce TSRMLS_CC ); + intern = ecalloc(1, sizeof(Collator_object) + sizeof(zval) * (ce->default_properties_count - 1)); + intl_error_init(COLLATOR_ERROR_P(intern) TSRMLS_CC); + zend_object_std_init(&intern->zo, ce TSRMLS_CC ); object_properties_init(&intern->zo, ce); - retval.handle = zend_objects_store_put( - intern, - Collator_objects_dtor, - (zend_objects_free_object_storage_t)Collator_objects_free, - NULL TSRMLS_CC ); - - retval.handlers = &Collator_handlers; + intern->zo.handlers = &Collator_handlers; - return retval; + return &intern->zo; } /* }}} */ @@ -148,7 +136,10 @@ void collator_register_Collator_class( TSRMLS_D ) sizeof Collator_handlers); /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer for which we don't have the place to keep */ + Collator_handlers.offset = XtOffsetOf(Collator_object, zo); Collator_handlers.clone_obj = NULL; + Collator_handlers.dtor_obj = Collator_objects_dtor; + Collator_handlers.free_obj = Collator_objects_free; /* Declare 'Collator' class properties. */ if( !Collator_ce_ptr ) diff --git a/ext/intl/collator/collator_class.h b/ext/intl/collator/collator_class.h index 7a56dfce50..75a3cab8fa 100644 --- a/ext/intl/collator/collator_class.h +++ b/ext/intl/collator/collator_class.h @@ -27,13 +27,14 @@ #include typedef struct { - zend_object zo; - // error handling intl_error err; // ICU collator UCollator* ucoll; + + zend_object zo; + } Collator_object; #define COLLATOR_ERROR(co) (co)->err @@ -42,6 +43,11 @@ typedef struct { #define COLLATOR_ERROR_CODE(co) INTL_ERROR_CODE(COLLATOR_ERROR(co)) #define COLLATOR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(COLLATOR_ERROR(co))) +static inline Collator_object *php_intl_collator_fetch_object(zend_object *obj) { + return (Collator_object *)((char*)(obj) - XtOffsetOf(Collator_object, zo)); +} +#define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv)) + void collator_register_Collator_class( TSRMLS_D ); void collator_object_init( Collator_object* co TSRMLS_DC ); void collator_object_destroy( Collator_object* co TSRMLS_DC ); @@ -55,7 +61,7 @@ extern zend_class_entry *Collator_ce_ptr; Collator_object* co = NULL; \ intl_error_reset( NULL TSRMLS_CC ); \ -#define COLLATOR_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(Collator, co) +#define COLLATOR_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(INIL_COLLATOR, co) // Macro to check return value of a ucol_* function call. #define COLLATOR_CHECK_STATUS( co, msg ) \ diff --git a/ext/intl/collator/collator_convert.c b/ext/intl/collator/collator_convert.c index 2a3ac10fbf..de5d4adbab 100644 --- a/ext/intl/collator/collator_convert.c +++ b/ext/intl/collator/collator_convert.c @@ -35,31 +35,31 @@ #endif #define COLLATOR_CONVERT_RETURN_FAILED(retval) { \ - zval_add_ref( &retval ); \ + zval_add_ref( retval ); \ return retval; \ } /* {{{ collator_convert_hash_item_from_utf8_to_utf16 */ static void collator_convert_hash_item_from_utf8_to_utf16( - HashTable* hash, int hashKeyType, char* hashKey, ulong hashIndex, + HashTable* hash, zend_string *hashKey, ulong hashIndex, UErrorCode* status ) { const char* old_val; int old_val_len; UChar* new_val = NULL; int new_val_len = 0; - zval** hashData = NULL; - zval* znew_val = NULL; + zval* hashData = NULL; + zval znew_val; /* Get current hash item. */ - zend_hash_get_current_data( hash, (void**) &hashData ); + hashData = zend_hash_get_current_data( hash ); /* Process string values only. */ - if( Z_TYPE_P( *hashData ) != IS_STRING ) + if( Z_TYPE_P( hashData ) != IS_STRING ) return; - old_val = Z_STRVAL_P( *hashData ); - old_val_len = Z_STRLEN_P( *hashData ); + old_val = Z_STRVAL_P( hashData ); + old_val_len = Z_STRLEN_P( hashData ); /* Convert it from UTF-8 to UTF-16LE and save the result to new_val[_len]. */ intl_convert_utf8_to_utf16( &new_val, &new_val_len, old_val, old_val_len, status ); @@ -67,43 +67,42 @@ static void collator_convert_hash_item_from_utf8_to_utf16( return; /* Update current hash item with the converted value. */ - MAKE_STD_ZVAL( znew_val ); - ZVAL_STRINGL( znew_val, (char*)new_val, UBYTES(new_val_len), FALSE ); + ZVAL_STRINGL( &znew_val, (char*)new_val, UBYTES(new_val_len) ); + //??? + efree(new_val); - if( hashKeyType == HASH_KEY_IS_STRING ) + if( hashKey) { - zend_hash_update( hash, hashKey, strlen( hashKey ) + 1, - (void*) &znew_val, sizeof(zval*), NULL ); + zend_hash_update( hash, hashKey, &znew_val); } else /* hashKeyType == HASH_KEY_IS_LONG */ { - zend_hash_index_update( hash, hashIndex, - (void*) &znew_val, sizeof(zval*), NULL ); + zend_hash_index_update( hash, hashIndex, &znew_val); } } /* }}} */ /* {{{ collator_convert_hash_item_from_utf16_to_utf8 */ static void collator_convert_hash_item_from_utf16_to_utf8( - HashTable* hash, int hashKeyType, char* hashKey, ulong hashIndex, + HashTable* hash, zend_string* hashKey, ulong hashIndex, UErrorCode* status ) { const char* old_val; - int old_val_len; - char* new_val = NULL; - int new_val_len = 0; - zval** hashData = NULL; - zval* znew_val = NULL; + int old_val_len; + char* new_val = NULL; + int new_val_len = 0; + zval* hashData = NULL; + zval znew_val; /* Get current hash item. */ - zend_hash_get_current_data( hash, (void**) &hashData ); + hashData = zend_hash_get_current_data( hash ); /* Process string values only. */ - if( Z_TYPE_P( *hashData ) != IS_STRING ) + if( Z_TYPE_P( hashData ) != IS_STRING ) return; - old_val = Z_STRVAL_P( *hashData ); - old_val_len = Z_STRLEN_P( *hashData ); + old_val = Z_STRVAL_P( hashData ); + old_val_len = Z_STRLEN_P( hashData ); /* Convert it from UTF-16LE to UTF-8 and save the result to new_val[_len]. */ intl_convert_utf16_to_utf8( &new_val, &new_val_len, @@ -112,18 +111,17 @@ static void collator_convert_hash_item_from_utf16_to_utf8( return; /* Update current hash item with the converted value. */ - MAKE_STD_ZVAL( znew_val ); - ZVAL_STRINGL( znew_val, (char*)new_val, new_val_len, FALSE ); + ZVAL_STRINGL( &znew_val, (char*)new_val, new_val_len); + //??? + efree(new_val); - if( hashKeyType == HASH_KEY_IS_STRING ) + if( hashKey ) { - zend_hash_update( hash, hashKey, strlen( hashKey ) + 1, - (void*) &znew_val, sizeof(zval*), NULL ); + zend_hash_update( hash, hashKey, &znew_val); } else /* hashKeyType == HASH_KEY_IS_LONG */ { - zend_hash_index_update( hash, hashIndex, - (void*) &znew_val, sizeof(zval*), NULL ); + zend_hash_index_update( hash, hashIndex, &znew_val); } } /* }}} */ @@ -133,23 +131,16 @@ static void collator_convert_hash_item_from_utf16_to_utf8( */ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* status ) { - ulong hashIndex = 0; - char* hashKey = NULL; - int hashKeyType = 0; + ulong hashIndex; + zend_string *hashKey; - zend_hash_internal_pointer_reset( hash ); - while( ( hashKeyType = zend_hash_get_current_key( hash, &hashKey, &hashIndex, 0 ) ) - != HASH_KEY_NON_EXISTENT ) - { + ZEND_HASH_FOREACH_KEY(hash, hashIndex, hashKey) { /* Convert current hash item from UTF-8 to UTF-16LE. */ collator_convert_hash_item_from_utf8_to_utf16( - hash, hashKeyType, hashKey, hashIndex, status ); + hash, hashKey, hashIndex, status ); if( U_FAILURE( *status ) ) return; - - /* Proceed to the next item. */ - zend_hash_move_forward( hash ); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -158,24 +149,17 @@ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* stat */ void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* status ) { - ulong hashIndex = 0; - char* hashKey = NULL; - int hashKeyType = 0; + ulong hashIndex; + zend_string *hashKey; - zend_hash_internal_pointer_reset( hash ); - while( ( hashKeyType = zend_hash_get_current_key( hash, &hashKey, &hashIndex, 0 ) ) - != HASH_KEY_NON_EXISTENT ) - { + ZEND_HASH_FOREACH_KEY(hash, hashIndex, hashKey) { /* Convert current hash item from UTF-16LE to UTF-8. */ collator_convert_hash_item_from_utf16_to_utf8( - hash, hashKeyType, hashKey, hashIndex, status ); + hash, hashKey, hashIndex, status ); if( U_FAILURE( *status ) ) { return; } - - /* Proceed to the next item. */ - zend_hash_move_forward( hash ); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -187,7 +171,7 @@ void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* stat * * @return zval* Converted string. */ -zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval ) +zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv ) { zval* utf8_zval = NULL; char* str = NULL; @@ -200,8 +184,10 @@ zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval ) if( U_FAILURE( status ) ) php_error( E_WARNING, "Error converting utf16 to utf8 in collator_convert_zval_utf16_to_utf8()" ); - ALLOC_INIT_ZVAL( utf8_zval ); - ZVAL_STRINGL( utf8_zval, str, str_len, FALSE ); + utf8_zval = rv; + ZVAL_STRINGL( utf8_zval, str, str_len); + //??? + efree(str); return utf8_zval; } @@ -215,7 +201,7 @@ zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval ) * * @return zval* Converted string. */ -zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval ) +zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval, zval *rv ) { zval* zstr = NULL; UChar* ustr = NULL; @@ -231,8 +217,10 @@ zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval ) php_error( E_WARNING, "Error casting object to string in collator_convert_zstr_utf8_to_utf16()" ); /* Set string. */ - ALLOC_INIT_ZVAL( zstr ); - ZVAL_STRINGL( zstr, (char*)ustr, UBYTES(ustr_len), FALSE ); + zstr = rv; + ZVAL_STRINGL( zstr, (char*)ustr, UBYTES(ustr_len)); + //??? + efree((char *)ustr); return zstr; } @@ -241,7 +229,7 @@ zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval ) /* {{{ collator_convert_object_to_string * Convert object to UTF16-encoded string. */ -zval* collator_convert_object_to_string( zval* obj TSRMLS_DC ) +zval* collator_convert_object_to_string( zval* obj, zval *rv TSRMLS_DC ) { zval* zstr = NULL; UErrorCode status = U_ZERO_ERROR; @@ -257,14 +245,14 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC ) /* Try object's handlers. */ if( Z_OBJ_HT_P(obj)->get ) { - zstr = Z_OBJ_HT_P(obj)->get( obj TSRMLS_CC ); + zstr = Z_OBJ_HT_P(obj)->get( obj, rv TSRMLS_CC ); switch( Z_TYPE_P( zstr ) ) { case IS_OBJECT: { /* Bail out. */ - zval_ptr_dtor( &zstr ); + zval_ptr_dtor( zstr ); COLLATOR_CONVERT_RETURN_FAILED( obj ); } break; @@ -279,12 +267,12 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC ) } else if( Z_OBJ_HT_P(obj)->cast_object ) { - ALLOC_INIT_ZVAL( zstr ); + zstr = rv; if( Z_OBJ_HT_P(obj)->cast_object( obj, zstr, IS_STRING CAST_OBJECT_SHOULD_FREE TSRMLS_CC ) == FAILURE ) { /* cast_object failed => bail out. */ - zval_ptr_dtor( &zstr ); + zval_ptr_dtor( zstr ); COLLATOR_CONVERT_RETURN_FAILED( obj ); } } @@ -307,7 +295,9 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC ) zval_dtor( zstr ); /* Set string. */ - ZVAL_STRINGL( zstr, (char*)ustr, UBYTES(ustr_len), FALSE ); + ZVAL_STRINGL( zstr, (char*)ustr, UBYTES(ustr_len)); + //??? + efree((char *)ustr); /* Don't free ustr cause it's set in zstr without copy. * efree( ustr ); @@ -325,15 +315,15 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC ) * * @return zval* Number. If str is not numeric string return number zero. */ -zval* collator_convert_string_to_number( zval* str ) +zval* collator_convert_string_to_number( zval* str, zval *rv ) { - zval* num = collator_convert_string_to_number_if_possible( str ); + zval* num = collator_convert_string_to_number_if_possible( str, rv ); if( num == str ) { /* String wasn't converted => return zero. */ - zval_ptr_dtor( &num ); + zval_ptr_dtor( num ); - ALLOC_INIT_ZVAL( num ); + num = rv; ZVAL_LONG( num, 0 ); } @@ -349,9 +339,9 @@ zval* collator_convert_string_to_number( zval* str ) * * @return zval* Number. If str is not numeric string return number zero. */ -zval* collator_convert_string_to_double( zval* str ) +zval* collator_convert_string_to_double( zval* str, zval *rv ) { - zval* num = collator_convert_string_to_number( str ); + zval* num = collator_convert_string_to_number( str, rv ); if( Z_TYPE_P(num) == IS_LONG ) { ZVAL_DOUBLE( num, Z_LVAL_P( num ) ); @@ -370,9 +360,8 @@ zval* collator_convert_string_to_double( zval* str ) * @return zval* Number if str is numeric string. Otherwise * original str param. */ -zval* collator_convert_string_to_number_if_possible( zval* str ) +zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv ) { - zval* num = NULL; int is_numeric = 0; long lval = 0; double dval = 0; @@ -384,21 +373,18 @@ zval* collator_convert_string_to_number_if_possible( zval* str ) if( ( is_numeric = collator_is_numeric( (UChar*) Z_STRVAL_P(str), UCHARS( Z_STRLEN_P(str) ), &lval, &dval, 1 ) ) ) { - ALLOC_INIT_ZVAL( num ); - - if( is_numeric == IS_LONG ) - Z_LVAL_P(num) = lval; + if( is_numeric == IS_LONG ) { + ZVAL_LONG(rv, lval); + } if( is_numeric == IS_DOUBLE ) - Z_DVAL_P(num) = dval; - - Z_TYPE_P(num) = is_numeric; + ZVAL_DOUBLE(rv, dval); } else { COLLATOR_CONVERT_RETURN_FAILED( str ); } - return num; + return rv; } /* }}} */ @@ -410,7 +396,7 @@ zval* collator_convert_string_to_number_if_possible( zval* str ) * * @return zval* UTF16 string. */ -zval* collator_make_printable_zval( zval* arg ) +zval* collator_make_printable_zval( zval* arg, zval *rv ) { zval arg_copy; int use_copy = 0; @@ -422,12 +408,12 @@ zval* collator_make_printable_zval( zval* arg ) if( use_copy ) { - str = collator_convert_zstr_utf8_to_utf16( &arg_copy ); + str = collator_convert_zstr_utf8_to_utf16( &arg_copy, rv ); zval_dtor( &arg_copy ); } else { - str = collator_convert_zstr_utf8_to_utf16( arg ); + str = collator_convert_zstr_utf8_to_utf16( arg, rv ); } } else @@ -448,7 +434,7 @@ zval* collator_make_printable_zval( zval* arg ) * @return zval* Normalized copy of arg or unmodified arg * if normalization is not needed. */ -zval* collator_normalize_sort_argument( zval* arg ) +zval* collator_normalize_sort_argument( zval* arg, zval *rv ) { zval* n_arg = NULL; @@ -461,15 +447,15 @@ zval* collator_normalize_sort_argument( zval* arg ) } /* Try convert to number. */ - n_arg = collator_convert_string_to_number_if_possible( arg ); + n_arg = collator_convert_string_to_number_if_possible( arg, rv ); if( n_arg == arg ) { /* Conversion to number failed. */ - zval_ptr_dtor( &n_arg ); + zval_ptr_dtor( n_arg ); /* Convert string to utf8. */ - n_arg = collator_convert_zstr_utf16_to_utf8( arg ); + n_arg = collator_convert_zstr_utf16_to_utf8( arg, rv ); } return n_arg; diff --git a/ext/intl/collator/collator_convert.h b/ext/intl/collator/collator_convert.h index 8322ea998b..7e169d559e 100644 --- a/ext/intl/collator/collator_convert.h +++ b/ext/intl/collator/collator_convert.h @@ -24,15 +24,15 @@ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* status ); void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* status ); -zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval ); -zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval ); +zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv ); +zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval, zval *rv ); -zval* collator_normalize_sort_argument( zval* arg ); -zval* collator_convert_object_to_string( zval* obj TSRMLS_DC ); -zval* collator_convert_string_to_number( zval* arg ); -zval* collator_convert_string_to_number_if_possible( zval* str ); -zval* collator_convert_string_to_double( zval* str ); +zval* collator_normalize_sort_argument( zval* arg, zval *rv ); +zval* collator_convert_object_to_string( zval* obj, zval *rv TSRMLS_DC ); +zval* collator_convert_string_to_number( zval* arg, zval *rv ); +zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv ); +zval* collator_convert_string_to_double( zval* str, zval *rv ); -zval* collator_make_printable_zval( zval* arg ); +zval* collator_make_printable_zval( zval* arg, zval *rv ); #endif // COLLATOR_CONVERT_H diff --git a/ext/intl/collator/collator_error.c b/ext/intl/collator/collator_error.c index c4e41250a2..2be25d1c5d 100644 --- a/ext/intl/collator/collator_error.c +++ b/ext/intl/collator/collator_error.c @@ -43,7 +43,7 @@ PHP_FUNCTION( collator_get_error_code ) } /* Fetch the object (without resetting its last error code). */ - co = (Collator_object *) zend_object_store_get_object(object TSRMLS_CC); + co = Z_INTL_COLLATOR_P(object); if( co == NULL ) RETURN_FALSE; @@ -74,13 +74,15 @@ PHP_FUNCTION( collator_get_error_message ) } /* Fetch the object (without resetting its last error code). */ - co = (Collator_object *) zend_object_store_get_object( object TSRMLS_CC ); + co = Z_INTL_COLLATOR_P( object ); if( co == NULL ) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message( COLLATOR_ERROR_P( co ) TSRMLS_CC ); - RETURN_STRING( (char*)message, FALSE ); + RETVAL_STRING( (char*)message); + //??? + efree((char *)message); } /* }}} */ diff --git a/ext/intl/collator/collator_locale.c b/ext/intl/collator/collator_locale.c index b30b021ee8..e5640beca6 100644 --- a/ext/intl/collator/collator_locale.c +++ b/ext/intl/collator/collator_locale.c @@ -66,7 +66,7 @@ PHP_FUNCTION( collator_get_locale ) COLLATOR_CHECK_STATUS( co, "Error getting locale by type" ); /* Return it. */ - RETVAL_STRINGL( locale_name, strlen(locale_name), TRUE ); + RETVAL_STRINGL( locale_name, strlen(locale_name) ); } /* }}} */ diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index 24c8daf7fe..dc916090bf 100644 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -36,7 +36,7 @@ typedef long ptrdiff_t; */ typedef struct _collator_sort_key_index { char* key; /* pointer to sort key */ - zval** zstr; /* pointer to original string(hash-item) */ + zval* zstr; /* pointer to original string(hash-item) */ } collator_sort_key_index_t; ZEND_EXTERN_MODULE_GLOBALS( intl ) @@ -53,25 +53,23 @@ static const size_t DEF_UTF16_BUF_SIZE = 1024; static int collator_regular_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) { Collator_object* co = NULL; - - int rc = SUCCESS; - - zval* str1 = collator_convert_object_to_string( op1 TSRMLS_CC ); - zval* str2 = collator_convert_object_to_string( op2 TSRMLS_CC ); - - zval* num1 = NULL; - zval* num2 = NULL; - zval* norm1 = NULL; - zval* norm2 = NULL; + int rc = SUCCESS; + zval str1, str2; + zval num1, num2; + zval norm1, norm2; + zval *num1_p = NULL, *num2_p = NULL; + zval *norm1_p = NULL, *norm2_p = NULL; + zval* str1_p = collator_convert_object_to_string( op1, &str1 TSRMLS_CC ); + zval* str2_p = collator_convert_object_to_string( op2, &str2 TSRMLS_CC ); /* If both args are strings AND either of args is not numeric string * then use ICU-compare. Otherwise PHP-compare. */ - if( Z_TYPE_P(str1) == IS_STRING && Z_TYPE_P(str2) == IS_STRING && - ( str1 == ( num1 = collator_convert_string_to_number_if_possible( str1 ) ) || - str2 == ( num2 = collator_convert_string_to_number_if_possible( str2 ) ) ) ) + if( Z_TYPE_P(str1_p) == IS_STRING && Z_TYPE_P(str2_p) == IS_STRING && + ( str1_p == ( num1_p = collator_convert_string_to_number_if_possible( str1_p, &num1 ) ) || + str2_p == ( num2_p = collator_convert_string_to_number_if_possible( str2_p, &num2 ) ) ) ) { /* Fetch collator object. */ - co = (Collator_object *) zend_object_store_get_object( INTL_G(current_collator) TSRMLS_CC ); + co = Z_INTL_COLLATOR_P(&INTL_G(current_collator) TSRMLS_CC ); if (!co || !co->ucoll) { intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC ); @@ -82,61 +80,60 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2 } /* Compare the strings using ICU. */ - result->value.lval = ucol_strcoll( - co->ucoll, - INTL_Z_STRVAL_P(str1), INTL_Z_STRLEN_P(str1), - INTL_Z_STRVAL_P(str2), INTL_Z_STRLEN_P(str2) ); - result->type = IS_LONG; + ZVAL_LONG(result, ucol_strcoll( + co->ucoll, + INTL_Z_STRVAL_P(str1_p), INTL_Z_STRLEN_P(str1_p), + INTL_Z_STRVAL_P(str2_p), INTL_Z_STRLEN_P(str2_p) )); } else { /* num1 is set if str1 and str2 are strings. */ - if( num1 ) + if( num1_p ) { - if( num1 == str1 ) + if( num1_p == str1_p ) { /* str1 is string but not numeric string * just convert it to utf8. */ - norm1 = collator_convert_zstr_utf16_to_utf8( str1 ); + norm1_p = collator_convert_zstr_utf16_to_utf8( str1_p, &norm1 ); /* num2 is not set but str2 is string => do normalization. */ - norm2 = collator_normalize_sort_argument( str2 ); + norm2_p = collator_normalize_sort_argument( str2_p, &norm2 ); } else { /* str1 is numeric strings => passthru to PHP-compare. */ - zval_add_ref( &num1 ); - norm1 = num1; + zval_add_ref( num1_p ); + norm1_p = num1_p; /* str2 is numeric strings => passthru to PHP-compare. */ - zval_add_ref( &num2 ); - norm2 = num2; + zval_add_ref( num2_p ); + norm2_p = num2_p; } } else { /* num1 is not set if str1 or str2 is not a string => do normalization. */ - norm1 = collator_normalize_sort_argument( str1 ); + norm1_p = collator_normalize_sort_argument( str1_p, &norm1 ); /* if num1 is not set then num2 is not set as well => do normalization. */ - norm2 = collator_normalize_sort_argument( str2 ); + norm2_p = collator_normalize_sort_argument( str2_p, &norm2 ); } - rc = compare_function( result, norm1, norm2 TSRMLS_CC ); + rc = compare_function( result, norm1_p, norm2_p TSRMLS_CC ); - zval_ptr_dtor( &norm1 ); - zval_ptr_dtor( &norm2 ); + zval_ptr_dtor( norm1_p ); + zval_ptr_dtor( norm2_p ); } - if( num1 ) - zval_ptr_dtor( &num1 ); + if( num1_p ) + zval_ptr_dtor( num1_p ); - if( num2 ) - zval_ptr_dtor( &num2 ); + if( num2_p ) + zval_ptr_dtor( num2_p ); - zval_ptr_dtor( &str1 ); - zval_ptr_dtor( &str2 ); + zval_ptr_dtor( str1_p ); + zval_ptr_dtor( str2_p ); return rc; } @@ -148,27 +145,28 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2 static int collator_numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) { int rc = SUCCESS; - zval* num1 = NULL; - zval* num2 = NULL; + zval num1, num2; + zval *num1_p = NULL; + zval *num2_p = NULL; if( Z_TYPE_P(op1) == IS_STRING ) { - num1 = collator_convert_string_to_double( op1 ); - op1 = num1; + num1_p = collator_convert_string_to_double( op1, &num1 ); + op1 = num1_p; } if( Z_TYPE_P(op2) == IS_STRING ) { - num2 = collator_convert_string_to_double( op2 ); - op2 = num2; + num2_p = collator_convert_string_to_double( op2, &num2 ); + op2 = num2_p; } rc = numeric_compare_function( result, op1, op2 TSRMLS_CC); - if( num1 ) - zval_ptr_dtor( &num1 ); - if( num2 ) - zval_ptr_dtor( &num2 ); + if( num1_p ) + zval_ptr_dtor( num1_p ); + if( num2_p ) + zval_ptr_dtor( num2_p ); return rc; } @@ -179,26 +177,26 @@ static int collator_numeric_compare_function(zval *result, zval *op1, zval *op2 */ static int collator_icu_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) { + zval str1, str2; int rc = SUCCESS; Collator_object* co = NULL; - zval* str1 = NULL; - zval* str2 = NULL; + zval *str1_p = NULL; + zval *str2_p = NULL; - str1 = collator_make_printable_zval( op1 ); - str2 = collator_make_printable_zval( op2 ); + str1_p = collator_make_printable_zval( op1, &str1); + str2_p = collator_make_printable_zval( op2, &str2 ); /* Fetch collator object. */ - co = (Collator_object *) zend_object_store_get_object( INTL_G(current_collator) TSRMLS_CC ); + co = Z_INTL_COLLATOR_P(&INTL_G(current_collator) TSRMLS_CC ); /* Compare the strings using ICU. */ - result->value.lval = ucol_strcoll( - co->ucoll, - INTL_Z_STRVAL_P(str1), INTL_Z_STRLEN_P(str1), - INTL_Z_STRVAL_P(str2), INTL_Z_STRLEN_P(str2) ); - result->type = IS_LONG; + ZVAL_LONG(result, ucol_strcoll( + co->ucoll, + INTL_Z_STRVAL_P(str1_p), INTL_Z_STRLEN_P(str1_p), + INTL_Z_STRVAL_P(str2_p), INTL_Z_STRLEN_P(str2_p) )); - zval_ptr_dtor( &str1 ); - zval_ptr_dtor( &str2 ); + zval_ptr_dtor( str1_p ); + zval_ptr_dtor( str2_p ); return rc; } @@ -218,8 +216,8 @@ static int collator_compare_func( const void* a, const void* b TSRMLS_DC ) f = (Bucket *) a; s = (Bucket *) b; - first = *((zval **) f->pData); - second = *((zval **) s->pData); + first = &f->val; + second = &s->val; if( INTL_G(compare_func)( &result, first, second TSRMLS_CC) == FAILURE ) return 0; @@ -289,9 +287,9 @@ static collator_compare_func_t collator_get_compare_function( const long sort_fl */ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS ) { + zval saved_collator; zval* array = NULL; HashTable* hash = NULL; - zval* saved_collator = NULL; long sort_flags = COLLATOR_SORT_REGULAR; COLLATOR_METHOD_INIT_VARS @@ -319,14 +317,14 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS ) COLLATOR_CHECK_STATUS( co, "Error converting hash from UTF-8 to UTF-16" ); /* Save specified collator in the request-global (?) variable. */ - saved_collator = INTL_G( current_collator ); - INTL_G( current_collator ) = object; + ZVAL_COPY_VALUE(&saved_collator, &INTL_G( current_collator )); + ZVAL_COPY_VALUE(&INTL_G( current_collator ), object); /* Sort specified array. */ zend_hash_sort( hash, zend_qsort, collator_compare_func, renumber TSRMLS_CC ); /* Restore saved collator. */ - INTL_G( current_collator ) = saved_collator; + ZVAL_COPY_VALUE(&INTL_G( current_collator ), &saved_collator); /* Convert strings in the specified array back to UTF-8. */ collator_convert_hash_from_utf16_to_utf8( hash, COLLATOR_ERROR_CODE_P( co ) ); @@ -358,7 +356,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) { zval* array = NULL; HashTable* hash = NULL; - zval** hashData = NULL; /* currently processed item of input hash */ + zval* hashData = NULL; /* currently processed item of input hash */ char* sortKeyBuf = NULL; /* buffer to store sort keys */ uint32_t sortKeyBufSize = DEF_SORT_KEYS_BUF_SIZE; /* buffer size */ @@ -418,17 +416,15 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) utf16_buf = eumalloc( utf16_buf_size ); /* Iterate through input hash and create a sort key for each value. */ - zend_hash_internal_pointer_reset( hash ); - while( zend_hash_get_current_data( hash, (void**) &hashData ) == SUCCESS ) - { + ZEND_HASH_FOREACH_VAL(hash, hashData) { /* Convert current hash item from UTF-8 to UTF-16LE and save the result to utf16_buf. */ utf16_len = utf16_buf_size; /* Process string values only. */ - if( Z_TYPE_PP( hashData ) == IS_STRING ) + if( Z_TYPE_P( hashData ) == IS_STRING ) { - intl_convert_utf8_to_utf16( &utf16_buf, &utf16_len, Z_STRVAL_PP( hashData ), Z_STRLEN_PP( hashData ), COLLATOR_ERROR_CODE_P( co ) ); + intl_convert_utf8_to_utf16( &utf16_buf, &utf16_len, Z_STRVAL_P( hashData ), Z_STRLEN_P( hashData ), COLLATOR_ERROR_CODE_P( co ) ); if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) { @@ -493,8 +489,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) sortKeyBufOffset += sortKeyLen; ++sortKeyCount; - zend_hash_move_forward( hash ); - } + } ZEND_HASH_FOREACH_END(); /* update ptrs to point to valid keys. */ for( j = 0; j < sortKeyCount; j++ ) @@ -503,21 +498,16 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) /* sort it */ zend_qsort( sortKeyIndxBuf, sortKeyCount, sortKeyIndxSize, collator_cmp_sort_keys TSRMLS_CC ); + zval_dtor( array ); /* for resulting hash we'll assign new hash keys rather then reordering */ - ALLOC_HASHTABLE( sortedHash ); - zend_hash_init( sortedHash, 0, NULL, ZVAL_PTR_DTOR, 0 ); + array_init(array); for( j = 0; j < sortKeyCount; j++ ) { - zval_add_ref( sortKeyIndxBuf[j].zstr ); - zend_hash_next_index_insert( sortedHash, sortKeyIndxBuf[j].zstr, sizeof(zval **), NULL ); + Z_TRY_ADDREF_P( sortKeyIndxBuf[j].zstr ); + zend_hash_next_index_insert( Z_ARRVAL_P(array), sortKeyIndxBuf[j].zstr); } - /* Save sorted hash into return variable. */ - zval_dtor( array ); - (array)->value.ht = sortedHash; - (array)->type = IS_ARRAY; - if( utf16_buf ) efree( utf16_buf ); @@ -608,7 +598,9 @@ PHP_FUNCTION( collator_get_sort_key ) if(!key_len) { RETURN_FALSE; } - RETURN_STRINGL((char *)key, key_len - 1, 0); + RETVAL_STRINGL((char *)key, key_len - 1); + //???? + efree(key); } /* }}} */ diff --git a/ext/intl/common/common_date.cpp b/ext/intl/common/common_date.cpp index ee998818d9..7c7510d554 100644 --- a/ext/intl/common/common_date.cpp +++ b/ext/intl/common/common_date.cpp @@ -110,7 +110,7 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, intl_error *err, const char *func TSRMLS_DC) { zval retval; - zval *zfuncname; + zval zfuncname; char *message; if (err && U_FAILURE(err->code)) { @@ -125,10 +125,8 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, } if (millis) { - INIT_ZVAL(retval); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, "getTimestamp", 1); - if (call_user_function(NULL, &(z), zfuncname, &retval, 0, NULL TSRMLS_CC) + ZVAL_STRING(&zfuncname, "getTimestamp"); + if (call_user_function(NULL, z, &zfuncname, &retval, 0, NULL TSRMLS_CC) != SUCCESS || Z_TYPE(retval) != IS_LONG) { spprintf(&message, 0, "%s: error calling ::getTimeStamp() on the " "object", func); @@ -145,7 +143,7 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, if (tz) { php_date_obj *datetime; - datetime = (php_date_obj*)zend_object_store_get_object(z TSRMLS_CC); + datetime = Z_PHPDATE_P(z); if (!datetime->time) { spprintf(&message, 0, "%s: the DateTime object is not properly " "initialized", func); @@ -210,8 +208,7 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func TS if (instanceof_function(Z_OBJCE_P(z), php_date_get_date_ce() TSRMLS_CC)) { intl_datetime_decompose(z, &rv, NULL, err, func TSRMLS_CC); } else if (instanceof_function(Z_OBJCE_P(z), Calendar_ce_ptr TSRMLS_CC)) { - Calendar_object *co = (Calendar_object *) - zend_object_store_get_object(z TSRMLS_CC ); + Calendar_object *co = Z_INTL_CALENDAR_P(z); if (co->ucal == NULL) { spprintf(&message, 0, "%s: IntlCalendar object is not properly " "constructed", func); diff --git a/ext/intl/common/common_enum.cpp b/ext/intl/common/common_enum.cpp index 3ba7855827..3436e5843f 100644 --- a/ext/intl/common/common_enum.cpp +++ b/ext/intl/common/common_enum.cpp @@ -37,14 +37,14 @@ void zoi_with_current_dtor(zend_object_iterator *iter TSRMLS_DC) { zoi_with_current *zoiwc = (zoi_with_current*)iter; - if (zoiwc->wrapping_obj) { + if (!Z_ISUNDEF(zoiwc->wrapping_obj)) { /* we have to copy the pointer because zoiwc->wrapping_obj may be * changed midway the execution of zval_ptr_dtor() */ - zval *zwo = zoiwc->wrapping_obj; + zval *zwo = &zoiwc->wrapping_obj; /* object is still here, we can rely on it to call this again and * destroy this object */ - zval_ptr_dtor(&zwo); + zval_ptr_dtor(zwo); } else { /* Object not here anymore (we've been called by the object free handler) * Note that the iterator wrapper objects (that also depend on this @@ -60,20 +60,20 @@ void zoi_with_current_dtor(zend_object_iterator *iter TSRMLS_DC) U_CFUNC int zoi_with_current_valid(zend_object_iterator *iter TSRMLS_DC) { - return ((zoi_with_current*)iter)->current != NULL ? SUCCESS : FAILURE; + return Z_ISUNDEF(((zoi_with_current*)iter)->current)? FAILURE : SUCCESS; } -U_CFUNC void zoi_with_current_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) +U_CFUNC zval *zoi_with_current_get_current_data(zend_object_iterator *iter TSRMLS_DC) { - *data = &((zoi_with_current*)iter)->current; + return &((zoi_with_current*)iter)->current; } U_CFUNC void zoi_with_current_invalidate_current(zend_object_iterator *iter TSRMLS_DC) { zoi_with_current *zoi_iter = (zoi_with_current*)iter; - if (zoi_iter->current) { + if (!Z_ISUNDEF(zoi_iter->current)) { zval_ptr_dtor(&zoi_iter->current); - zoi_iter->current = NULL; //valid would return FAILURE now + ZVAL_UNDEF(&zoi_iter->current); //valid would return FAILURE now } } @@ -84,11 +84,11 @@ static void string_enum_current_move_forward(zend_object_iterator *iter TSRMLS_D iter->funcs->invalidate_current(iter TSRMLS_CC); - object = zoi_iter->wrapping_obj; + object = &zoi_iter->wrapping_obj; INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; int32_t result_length; - const char *result = ((StringEnumeration*)iter->data)->next( + const char *result = ((StringEnumeration*)Z_PTR(iter->data))->next( &result_length, INTLITERATOR_ERROR_CODE(ii)); intl_error_set_code(NULL, INTLITERATOR_ERROR_CODE(ii) TSRMLS_CC); @@ -96,8 +96,7 @@ static void string_enum_current_move_forward(zend_object_iterator *iter TSRMLS_D intl_errors_set_custom_msg(INTL_DATA_ERROR_P(ii), "Error fetching next iteration element", 0 TSRMLS_CC); } else if (result) { - MAKE_STD_ZVAL(zoi_iter->current); - ZVAL_STRINGL(zoi_iter->current, result, result_length, 1); + ZVAL_STRINGL(&zoi_iter->current, result, result_length); } //else we've reached the end of the enum, nothing more is required } @@ -106,14 +105,14 @@ static void string_enum_rewind(zend_object_iterator *iter TSRMLS_DC) zoi_with_current *zoi_iter = (zoi_with_current*)iter; INTLITERATOR_METHOD_INIT_VARS; - if (zoi_iter->current) { + if (!Z_ISUNDEF(zoi_iter->current)) { iter->funcs->invalidate_current(iter TSRMLS_CC); } - object = zoi_iter->wrapping_obj; + object = &zoi_iter->wrapping_obj; INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; - ((StringEnumeration*)iter->data)->reset(INTLITERATOR_ERROR_CODE(ii)); + ((StringEnumeration*)Z_PTR(iter->data))->reset(INTLITERATOR_ERROR_CODE(ii)); intl_error_set_code(NULL, INTLITERATOR_ERROR_CODE(ii) TSRMLS_CC); if (U_FAILURE(INTLITERATOR_ERROR_CODE(ii))) { @@ -126,7 +125,7 @@ static void string_enum_rewind(zend_object_iterator *iter TSRMLS_DC) static void string_enum_destroy_it(zend_object_iterator *iter TSRMLS_DC) { - delete (StringEnumeration*)iter->data; + delete (StringEnumeration*)Z_PTR(iter->data); } static zend_object_iterator_funcs string_enum_object_iterator_funcs = { @@ -143,23 +142,24 @@ U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *ob { IntlIterator_object *ii; object_init_ex(object, IntlIterator_ce_ptr); - ii = (IntlIterator_object*)zend_object_store_get_object(object TSRMLS_CC); + ii = (IntlIterator_object*)Z_OBJ_P(object); ii->iterator = (zend_object_iterator*)emalloc(sizeof(zoi_with_current)); - ii->iterator->data = (void*)se; + zend_iterator_init(ii->iterator TSRMLS_CC); + ZVAL_PTR(&ii->iterator->data, se); ii->iterator->funcs = &string_enum_object_iterator_funcs; ii->iterator->index = 0; ((zoi_with_current*)ii->iterator)->destroy_it = string_enum_destroy_it; - ((zoi_with_current*)ii->iterator)->wrapping_obj = object; - ((zoi_with_current*)ii->iterator)->current = NULL; + ZVAL_COPY_VALUE(&((zoi_with_current*)ii->iterator)->wrapping_obj, object); + ZVAL_UNDEF(&((zoi_with_current*)ii->iterator)->current); } static void IntlIterator_objects_free(zend_object *object TSRMLS_DC) { - IntlIterator_object *ii = (IntlIterator_object*) object; + IntlIterator_object *ii = php_intl_iterator_fetch_object(object); if (ii->iterator) { - zval **wrapping_objp = &((zoi_with_current*)ii->iterator)->wrapping_obj; - *wrapping_objp = NULL; + zval *wrapping_objp = &((zoi_with_current*)ii->iterator)->wrapping_obj; + ZVAL_UNDEF(wrapping_objp); ii->iterator->funcs->dtor(ii->iterator TSRMLS_CC); } intl_error_reset(INTLITERATOR_ERROR_P(ii) TSRMLS_CC); @@ -178,8 +178,7 @@ static zend_object_iterator *IntlIterator_get_iterator( return NULL; } - IntlIterator_object *ii = (IntlIterator_object*) - zend_object_store_get_object(object TSRMLS_CC); + IntlIterator_object *ii = Z_INTL_ITERATOR_P(object); if (ii->iterator == NULL) { zend_throw_exception(NULL, @@ -187,42 +186,31 @@ static zend_object_iterator *IntlIterator_get_iterator( return NULL; } - zval_add_ref(&object); + zval_add_ref(object); return ii->iterator; } -static zend_object_value IntlIterator_object_create(zend_class_entry *ce TSRMLS_DC) +static zend_object *IntlIterator_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; IntlIterator_object *intern; - intern = (IntlIterator_object*)ecalloc(1, sizeof(IntlIterator_object)); + intern = (IntlIterator_object*)ecalloc(1, sizeof(IntlIterator_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 intl_error_init(INTLITERATOR_ERROR_P(intern) TSRMLS_CC); - intern->iterator = NULL; - retval.handle = zend_objects_store_put( - intern, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)IntlIterator_objects_free, - NULL TSRMLS_CC); + intern->iterator = NULL; - retval.handlers = &IntlIterator_handlers; + intern->zo.handlers = &IntlIterator_handlers; - return retval; + return &intern->zo; } static PHP_METHOD(IntlIterator, current) { - zval **data; + zval *data; INTLITERATOR_METHOD_INIT_VARS; if (zend_parse_parameters_none() == FAILURE) { @@ -232,9 +220,9 @@ static PHP_METHOD(IntlIterator, current) } INTLITERATOR_METHOD_FETCH_OBJECT; - ii->iterator->funcs->get_current_data(ii->iterator, &data TSRMLS_CC); - if (data && *data) { - RETURN_ZVAL(*data, 1, 0); + data = ii->iterator->funcs->get_current_data(ii->iterator TSRMLS_CC); + if (data) { + RETURN_ZVAL(data, 1, 0); } } @@ -337,6 +325,9 @@ U_CFUNC void intl_register_IntlIterator_class(TSRMLS_D) memcpy(&IntlIterator_handlers, zend_get_std_object_handlers(), sizeof IntlIterator_handlers); + IntlIterator_handlers.offset = XtOffsetOf(IntlIterator_object, zo); IntlIterator_handlers.clone_obj = NULL; + IntlIterator_handlers.dtor_obj = zend_objects_destroy_object; + IntlIterator_handlers.free_obj = IntlIterator_objects_free; } diff --git a/ext/intl/common/common_enum.h b/ext/intl/common/common_enum.h index 4c6abdb8f5..2b6d1790d9 100644 --- a/ext/intl/common/common_enum.h +++ b/ext/intl/common/common_enum.h @@ -38,7 +38,7 @@ extern "C" { #define INTLITERATOR_ERROR_CODE_P(ii) &(INTL_ERROR_CODE(INTLITERATOR_ERROR(ii))) #define INTLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlIterator, ii) -#define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(IntlIterator, ii) +#define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_ITERATOR, ii) #define INTLITERATOR_METHOD_FETCH_OBJECT\ object = getThis(); \ INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ @@ -48,15 +48,21 @@ extern "C" { } typedef struct { - zend_object zo; intl_error err; zend_object_iterator *iterator; + zend_object zo; } IntlIterator_object; + +static inline IntlIterator_object *php_intl_iterator_fetch_object(zend_object *obj) { + return (IntlIterator_object *)((char*)(obj) - XtOffsetOf(IntlIterator_object, zo)); +} +#define Z_INTL_ITERATOR_P(zv) php_intl_iterator_fetch_object(Z_OBJ_P(zv)) + typedef struct { zend_object_iterator zoi; - zval *current; - zval *wrapping_obj; + zval current; + zval wrapping_obj; void (*destroy_it)(zend_object_iterator *iterator TSRMLS_DC); } zoi_with_current; @@ -65,7 +71,7 @@ extern zend_object_handlers IntlIterator_handlers; U_CFUNC void zoi_with_current_dtor(zend_object_iterator *iter TSRMLS_DC); U_CFUNC int zoi_with_current_valid(zend_object_iterator *iter TSRMLS_DC); -U_CFUNC void zoi_with_current_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC); +U_CFUNC zval *zoi_with_current_get_current_data(zend_object_iterator *iter TSRMLS_DC); U_CFUNC void zoi_with_current_invalidate_current(zend_object_iterator *iter TSRMLS_DC); #ifdef __cplusplus diff --git a/ext/intl/common/common_error.c b/ext/intl/common/common_error.c index a0ee7c145f..f9289ad23b 100644 --- a/ext/intl/common/common_error.c +++ b/ext/intl/common/common_error.c @@ -37,8 +37,7 @@ PHP_FUNCTION( intl_get_error_code ) */ PHP_FUNCTION( intl_get_error_message ) { - char* message = intl_error_get_message( NULL TSRMLS_CC ); - RETURN_STRING( message, FALSE ); + RETURN_STR(intl_error_get_message( NULL TSRMLS_CC )); } /* }}} */ @@ -63,6 +62,7 @@ PHP_FUNCTION( intl_is_failure ) RETURN_BOOL( U_FAILURE( err_code ) ); } +/* }}} */ /* {{{ proto string intl_error_name() * Return a string for a given error code. @@ -82,7 +82,7 @@ PHP_FUNCTION( intl_error_name ) RETURN_FALSE; } - RETURN_STRING( (char*)u_errorName( err_code ), 1 ); + RETURN_STRING( (char*)u_errorName( err_code ) ); } /* }}} */ diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 0e45f31d2d..af78a3a830 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -24,7 +24,6 @@ #include "../intl_error.h" typedef struct _php_converter_object { - zend_object obj; #ifdef ZTS void ***tsrm_ls; #endif @@ -32,12 +31,19 @@ typedef struct _php_converter_object { zend_fcall_info to_cb, from_cb; zend_fcall_info_cache to_cache, from_cache; intl_error error; + zend_object obj; } php_converter_object; + +static inline php_converter_object *php_converter_fetch_object(zend_object *obj) { + return (php_converter_object *)((char*)(obj) - XtOffsetOf(php_converter_object, obj)); +} +#define Z_INTL_CONVERTER_P(zv) php_converter_fetch_object(Z_OBJ_P(zv)) + static zend_class_entry *php_converter_ce; static zend_object_handlers php_converter_object_handlers; -#define CONV_GET(pzv) ((php_converter_object*)zend_objects_get_address((pzv) TSRMLS_CC)) +#define CONV_GET(pzv) (Z_INTL_CONVERTER_P((pzv))) #define THROW_UFAILURE(obj, fname, error) php_converter_throw_failure(obj, error TSRMLS_CC, \ fname "() returned error %ld: %s", (long)error, u_errorName(error)) @@ -75,7 +81,7 @@ static void php_converter_default_callback(zval *return_value, zval *zobj, long chars[1] = 0; chars_len = 1; ZVAL_LONG(error, U_INVALID_STATE_ERROR); - RETVAL_STRINGL(chars, chars_len, 1); + RETVAL_STRINGL(chars, chars_len); return; } @@ -94,7 +100,7 @@ static void php_converter_default_callback(zval *return_value, zval *zobj, long chars_len = 1; ZVAL_LONG(error, uerror); } - RETVAL_STRINGL(chars, chars_len, 1); + RETVAL_STRINGL(chars, chars_len); } } } @@ -199,14 +205,11 @@ static void php_converter_append_toUnicode_target(zval *val, UConverterToUnicode case IS_ARRAY: { HashTable *ht = Z_ARRVAL_P(val); - HashPosition pos; - zval **tmpzval; + zval *tmpzval; - for(zend_hash_internal_pointer_reset_ex(ht, &pos); - zend_hash_get_current_data_ex(ht, (void**)&tmpzval, &pos) == SUCCESS; - zend_hash_move_forward_ex(ht, &pos)) { - php_converter_append_toUnicode_target(*tmpzval, args, objval TSRMLS_CC); - } + ZEND_HASH_FOREACH_VAL(ht, tmpzval) { + php_converter_append_toUnicode_target(tmpzval, args, objval TSRMLS_CC); + } ZEND_HASH_FOREACH_END(); return; } default: @@ -223,48 +226,37 @@ static void php_converter_to_u_callback(const void *context, UConverterCallbackReason reason, UErrorCode *pErrorCode) { php_converter_object *objval = (php_converter_object*)context; - zval *zreason, *zsource, *zcodeunits, *zerror, *retval = NULL; - zval **zargs[4]; + zval retval; + zval zargs[4]; #ifdef ZTS TSRMLS_D = objval->tsrm_ls; #endif - MAKE_STD_ZVAL(zreason); - ZVAL_LONG(zreason, reason); - zargs[0] = &zreason; - - MAKE_STD_ZVAL(zsource); - ZVAL_STRINGL(zsource, args->source, args->sourceLimit - args->source, 1); - zargs[1] = &zsource; - - MAKE_STD_ZVAL(zcodeunits); - ZVAL_STRINGL(zcodeunits, codeUnits, length, 1); - zargs[2] = &zcodeunits; - - MAKE_STD_ZVAL(zerror); - ZVAL_LONG(zerror, *pErrorCode); - zargs[3] = &zerror; + ZVAL_LONG(&zargs[0], reason); + ZVAL_STRINGL(&zargs[1], args->source, args->sourceLimit - args->source); + ZVAL_STRINGL(&zargs[2], codeUnits, length); + ZVAL_LONG(&zargs[3], *pErrorCode); objval->to_cb.param_count = 4; - objval->to_cb.params = zargs; - objval->to_cb.retval_ptr_ptr = &retval; + objval->to_cb.params = zargs; + objval->to_cb.retval = &retval; objval->to_cb.no_separation = 0; if (zend_call_function(&(objval->to_cb), &(objval->to_cache) TSRMLS_CC) == FAILURE) { /* Unlikely */ php_converter_throw_failure(objval, U_INTERNAL_PROGRAM_ERROR TSRMLS_CC, "Unexpected failure calling toUCallback()"); - } else if (retval) { - php_converter_append_toUnicode_target(retval, args, objval TSRMLS_CC); + } else if (!Z_ISUNDEF(retval)) { + php_converter_append_toUnicode_target(&retval, args, objval TSRMLS_CC); zval_ptr_dtor(&retval); } - if (Z_TYPE_P(zerror) == IS_LONG) { - *pErrorCode = Z_LVAL_P(zerror); + if (Z_TYPE(zargs[3]) == IS_LONG) { + *pErrorCode = Z_LVAL(zargs[3]); } - zval_ptr_dtor(&zreason); - zval_ptr_dtor(&zsource); - zval_ptr_dtor(&zcodeunits); - zval_ptr_dtor(&zerror); + zval_ptr_dtor(&zargs[0]); + zval_ptr_dtor(&zargs[1]); + zval_ptr_dtor(&zargs[2]); + zval_ptr_dtor(&zargs[3]); } /* }}} */ @@ -291,13 +283,10 @@ static void php_converter_append_fromUnicode_target(zval *val, UConverterFromUni case IS_ARRAY: { HashTable *ht = Z_ARRVAL_P(val); - HashPosition pos; - zval **tmpzval; - for(zend_hash_internal_pointer_reset_ex(ht, &pos); - zend_hash_get_current_data_ex(ht, (void**)&tmpzval, &pos) == SUCCESS; - zend_hash_move_forward_ex(ht, &pos)) { - php_converter_append_fromUnicode_target(*tmpzval, args, objval TSRMLS_CC); - } + zval *tmpzval; + ZEND_HASH_FOREACH_VAL(ht, tmpzval) { + php_converter_append_fromUnicode_target(tmpzval, args, objval TSRMLS_CC); + } ZEND_HASH_FOREACH_END(); return; } default: @@ -313,55 +302,44 @@ static void php_converter_from_u_callback(const void *context, UConverterCallbackReason reason, UErrorCode *pErrorCode) { php_converter_object *objval = (php_converter_object*)context; - zval *zreason, *zsource, *zcodepoint, *zerror, *retval = NULL; - zval **zargs[4]; + zval retval; + zval zargs[4]; int i; #ifdef ZTS TSRMLS_D = objval->tsrm_ls; #endif - MAKE_STD_ZVAL(zreason); - ZVAL_LONG(zreason, reason); - zargs[0] = &zreason; - - MAKE_STD_ZVAL(zsource); - array_init(zsource); + ZVAL_LONG(&zargs[0], reason); + array_init(&zargs[1]); i = 0; while (i < length) { UChar32 c; U16_NEXT(codeUnits, i, length, c); - add_next_index_long(zsource, c); + add_next_index_long(&zargs[1], c); } - zargs[1] = &zsource; - - MAKE_STD_ZVAL(zcodepoint); - ZVAL_LONG(zcodepoint, codePoint); - zargs[2] = &zcodepoint; - - MAKE_STD_ZVAL(zerror); - ZVAL_LONG(zerror, *pErrorCode); - zargs[3] = &zerror; + ZVAL_LONG(&zargs[2], codePoint); + ZVAL_LONG(&zargs[3], *pErrorCode); - objval->from_cb.param_count = 4; - objval->from_cb.params = zargs; - objval->from_cb.retval_ptr_ptr = &retval; + objval->from_cb.param_count = 4; + objval->from_cb.params = zargs; + objval->from_cb.retval = &retval; objval->from_cb.no_separation = 0; if (zend_call_function(&(objval->from_cb), &(objval->from_cache) TSRMLS_CC) == FAILURE) { /* Unlikely */ php_converter_throw_failure(objval, U_INTERNAL_PROGRAM_ERROR TSRMLS_CC, "Unexpected failure calling fromUCallback()"); - } else if (retval) { - php_converter_append_fromUnicode_target(retval, args, objval TSRMLS_CC); + } else if (!Z_ISUNDEF(retval)) { + php_converter_append_fromUnicode_target(&retval, args, objval TSRMLS_CC); zval_ptr_dtor(&retval); } - if (Z_TYPE_P(zerror) == IS_LONG) { - *pErrorCode = Z_LVAL_P(zerror); + if (Z_TYPE(zargs[3]) == IS_LONG) { + *pErrorCode = Z_LVAL(zargs[3]); } - zval_ptr_dtor(&zreason); - zval_ptr_dtor(&zsource); - zval_ptr_dtor(&zcodepoint); - zval_ptr_dtor(&zerror); + zval_ptr_dtor(&zargs[0]); + zval_ptr_dtor(&zargs[1]); + zval_ptr_dtor(&zargs[2]); + zval_ptr_dtor(&zargs[3]); } /* }}} */ @@ -489,7 +467,7 @@ static void php_converter_do_get_encoding(php_converter_object *objval, UConvert RETURN_FALSE; } - RETURN_STRING(name, 1); + RETURN_STRING(name); } /* }}} */ @@ -674,7 +652,7 @@ static PHP_METHOD(UConverter, getSubstChars) { RETURN_FALSE; } - RETURN_STRINGL(chars, chars_len, 1); + RETURN_STRINGL(chars, chars_len); } /* }}} */ @@ -742,7 +720,7 @@ static zend_bool php_converter_do_convert(UConverter *dest_cnv, char **pdest, in /* }}} */ /* {{{ proto string UConverter::reasonText(long reason) */ -#define UCNV_REASON_CASE(v) case (UCNV_ ## v) : RETURN_STRINGL( "REASON_" #v , sizeof( "REASON_" #v ) - 1, 1); +#define UCNV_REASON_CASE(v) case (UCNV_ ## v) : RETURN_STRINGL( "REASON_" #v , sizeof( "REASON_" #v ) - 1); ZEND_BEGIN_ARG_INFO_EX(php_converter_reasontext_arginfo, 0, ZEND_RETURN_VALUE, 0) ZEND_ARG_INFO(0, reason) ZEND_END_ARG_INFO(); @@ -795,7 +773,9 @@ static PHP_METHOD(UConverter, convert) { reverse ? objval->dest : objval->src, str, str_len, objval TSRMLS_CC)) { - RETURN_STRINGL(dest, dest_len, 0); + RETURN_STRINGL(dest, dest_len); + //??? + efree(dest); } else { RETURN_FALSE; } @@ -831,25 +811,27 @@ static PHP_METHOD(UConverter, transcode) { UErrorCode error = U_ZERO_ERROR; if (options && zend_hash_num_elements(Z_ARRVAL_P(options))) { - zval **tmpzval; + zval *tmpzval; if (U_SUCCESS(error) && - zend_hash_find(Z_ARRVAL_P(options), "from_subst", sizeof("from_subst"), (void**)&tmpzval) == SUCCESS && - Z_TYPE_PP(tmpzval) == IS_STRING) { + (tmpzval = zend_hash_str_find(Z_ARRVAL_P(options), "from_subst", sizeof("from_subst") - 1)) != NULL && + Z_TYPE_P(tmpzval) == IS_STRING) { error = U_ZERO_ERROR; - ucnv_setSubstChars(src_cnv, Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval) & 0x7F, &error); + ucnv_setSubstChars(src_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error); } if (U_SUCCESS(error) && - zend_hash_find(Z_ARRVAL_P(options), "to_subst", sizeof("to_subst"), (void**)&tmpzval) == SUCCESS && - Z_TYPE_PP(tmpzval) == IS_STRING) { + (tmpzval = zend_hash_str_find(Z_ARRVAL_P(options), "to_subst", sizeof("to_subst") - 1)) != NULL && + Z_TYPE_P(tmpzval) == IS_STRING) { error = U_ZERO_ERROR; - ucnv_setSubstChars(dest_cnv, Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval) & 0x7F, &error); + ucnv_setSubstChars(dest_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error); } } if (U_SUCCESS(error) && php_converter_do_convert(dest_cnv, &out, &out_len, src_cnv, str, str_len, NULL TSRMLS_CC)) { - RETVAL_STRINGL(out, out_len, 0); + RETVAL_STRINGL(out, out_len); + //??? + efree(out); } if (U_FAILURE(error)) { @@ -890,7 +872,7 @@ ZEND_BEGIN_ARG_INFO_EX(php_converter_geterrormsg_arginfo, 0, ZEND_RETURN_VALUE, ZEND_END_ARG_INFO(); static PHP_METHOD(UConverter, getErrorMessage) { php_converter_object *objval = CONV_GET(getThis()); - char *message = intl_error_get_message(&(objval->error) TSRMLS_CC); + zend_string *message = intl_error_get_message(&(objval->error) TSRMLS_CC); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -899,7 +881,7 @@ static PHP_METHOD(UConverter, getErrorMessage) { } if (message) { - RETURN_STRING(message, 1); + RETURN_STR(message); } else { RETURN_NULL(); } @@ -1033,7 +1015,9 @@ static zend_function_entry php_converter_methods[] = { }; /* {{{ Converter create/clone/destroy */ -static void php_converter_free_object(php_converter_object *objval TSRMLS_DC) { +static void php_converter_free_object(zend_object *obj TSRMLS_DC) { + php_converter_object *objval = php_converter_fetch_object(obj); + if (objval->src) { ucnv_close(objval->src); } @@ -1044,15 +1028,12 @@ static void php_converter_free_object(php_converter_object *objval TSRMLS_DC) { intl_error_reset(&(objval->error) TSRMLS_CC); zend_object_std_dtor(&(objval->obj) TSRMLS_CC); - - efree(objval); } -static zend_object_value php_converter_object_ctor(zend_class_entry *ce, php_converter_object **pobjval TSRMLS_DC) { +static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converter_object **pobjval TSRMLS_DC) { php_converter_object *objval; - zend_object_value retval; - objval = ecalloc(1, sizeof(php_converter_object)); + objval = ecalloc(1, sizeof(php_converter_object) + sizeof(zval) * (ce->default_properties_count - 1)); objval->obj.ce = ce; #ifdef ZTS @@ -1060,25 +1041,24 @@ static zend_object_value php_converter_object_ctor(zend_class_entry *ce, php_con #endif intl_error_init(&(objval->error) TSRMLS_CC); - retval.handle = zend_objects_store_put(objval, NULL, (zend_objects_free_object_storage_t)php_converter_free_object, NULL TSRMLS_CC); - retval.handlers = &php_converter_object_handlers; + objval->obj.handlers = &php_converter_object_handlers; *pobjval = objval; - return retval; + return &objval->obj; } -static zend_object_value php_converter_create_object(zend_class_entry *ce TSRMLS_DC) { +static zend_object *php_converter_create_object(zend_class_entry *ce TSRMLS_DC) { php_converter_object *objval = NULL; - zend_object_value retval = php_converter_object_ctor(ce, &objval TSRMLS_CC); + zend_object *retval = php_converter_object_ctor(ce, &objval TSRMLS_CC); object_properties_init(&(objval->obj), ce); return retval; } -static zend_object_value php_converter_clone_object(zval *object TSRMLS_DC) { - php_converter_object *objval, *oldobj = (php_converter_object*)zend_objects_get_address(object TSRMLS_CC); - zend_object_value retval = php_converter_object_ctor(Z_OBJCE_P(object), &objval TSRMLS_CC); +static zend_object *php_converter_clone_object(zval *object TSRMLS_DC) { + php_converter_object *objval, *oldobj = Z_INTL_CONVERTER_P(object); + zend_object *retval = php_converter_object_ctor(Z_OBJCE_P(object), &objval TSRMLS_CC); UErrorCode error = U_ZERO_ERROR; intl_errors_reset(&oldobj->error TSRMLS_CC); @@ -1089,12 +1069,12 @@ static zend_object_value php_converter_clone_object(zval *object TSRMLS_DC) { objval->dest = ucnv_safeClone(oldobj->dest, NULL, NULL, &error); } if (U_FAILURE(error)) { - char *err_msg; + zend_string *err_msg; THROW_UFAILURE(oldobj, "ucnv_safeClone", error); err_msg = intl_error_get_message(&oldobj->error 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_RELEASE(err_msg); return retval; } @@ -1103,7 +1083,7 @@ static zend_object_value php_converter_clone_object(zval *object TSRMLS_DC) { php_converter_set_callbacks(objval, objval->src TSRMLS_CC); php_converter_set_callbacks(objval, objval->dest TSRMLS_CC); - zend_objects_clone_members(&(objval->obj), retval, &(oldobj->obj), Z_OBJ_HANDLE_P(object) TSRMLS_CC); + zend_objects_clone_members(&(objval->obj), &(oldobj->obj) TSRMLS_CC); /* Newly cloned object deliberately does not inherit error state from original object */ @@ -1123,6 +1103,7 @@ int php_converter_minit(INIT_FUNC_ARGS) { php_converter_ce->create_object = php_converter_create_object; memcpy(&php_converter_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); php_converter_object_handlers.clone_obj = php_converter_clone_object; + php_converter_object_handlers.free_obj = php_converter_free_object; /* enum UConverterCallbackReason */ CONV_REASON_CONST(UNASSIGNED); diff --git a/ext/intl/dateformat/dateformat.c b/ext/intl/dateformat/dateformat.c index fb83eeef05..29cb6ff3ce 100644 --- a/ext/intl/dateformat/dateformat.c +++ b/ext/intl/dateformat/dateformat.c @@ -82,7 +82,7 @@ PHP_FUNCTION( datefmt_get_error_code ) RETURN_FALSE; } - dfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + dfo = Z_INTL_DATEFORMATTER_P( object TSRMLS_CC ); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(dfo) ); @@ -96,7 +96,7 @@ PHP_FUNCTION( datefmt_get_error_code ) */ PHP_FUNCTION( datefmt_get_error_message ) { - char* message = NULL; + zend_string *message = NULL; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ @@ -109,10 +109,10 @@ PHP_FUNCTION( datefmt_get_error_message ) RETURN_FALSE; } - dfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + dfo = Z_INTL_DATEFORMATTER_P( object TSRMLS_CC ); /* Return last error message. */ message = intl_error_get_message( INTL_DATA_ERROR_P(dfo) TSRMLS_CC ); - RETURN_STRING( message, 0); + RETURN_STR( message); } /* }}} */ diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.c index bf6b544667..e13b0f4cd2 100644 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.c @@ -189,7 +189,7 @@ PHP_FUNCTION( datefmt_get_locale ) loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale"); - RETURN_STRING(loc, 1); + RETURN_STRING(loc); } /* }}} */ diff --git a/ext/intl/dateformat/dateformat_attrcpp.cpp b/ext/intl/dateformat/dateformat_attrcpp.cpp index b68abec659..8ca880d956 100644 --- a/ext/intl/dateformat/dateformat_attrcpp.cpp +++ b/ext/intl/dateformat/dateformat_attrcpp.cpp @@ -44,6 +44,8 @@ static inline DateFormat *fetch_datefmt(IntlDateFormatter_object *dfo) { */ U_CFUNC PHP_FUNCTION(datefmt_get_timezone_id) { + char *str; + int str_len; DATE_FORMAT_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -57,11 +59,12 @@ U_CFUNC PHP_FUNCTION(datefmt_get_timezone_id) UnicodeString res = UnicodeString(); fetch_datefmt(dfo)->getTimeZone().getID(res); - intl_charFromString(res, &Z_STRVAL_P(return_value), - &Z_STRLEN_P(return_value), &INTL_DATA_ERROR_CODE(dfo)); + intl_charFromString(res, &str, &str_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Could not convert time zone id to UTF-8"); - Z_TYPE_P(return_value) = IS_STRING; + RETVAL_STRINGL(str, str_len); + //???? + efree(str); } /* {{{ proto IntlTimeZone IntlDateFormatter::getTimeZone() @@ -111,13 +114,13 @@ U_CFUNC PHP_FUNCTION(datefmt_set_timezone_id) */ U_CFUNC PHP_FUNCTION(datefmt_set_timezone) { - zval **timezone_zv; + zval *timezone_zv; TimeZone *timezone; DATE_FORMAT_METHOD_INIT_VARS; if ( zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), - "OZ", &object, IntlDateFormatter_ce_ptr, &timezone_zv) == FAILURE) { + "Oz", &object, IntlDateFormatter_ce_ptr, &timezone_zv) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_set_timezone: " "unable to parse input params", 0 TSRMLS_CC); RETURN_FALSE; diff --git a/ext/intl/dateformat/dateformat_class.c b/ext/intl/dateformat/dateformat_class.c index 211c87f59f..4c46a7d694 100644 --- a/ext/intl/dateformat/dateformat_class.c +++ b/ext/intl/dateformat/dateformat_class.c @@ -35,16 +35,16 @@ static zend_object_handlers IntlDateFormatter_handlers; */ /* {{{ IntlDateFormatter_objects_dtor */ -static void IntlDateFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC ) +static void IntlDateFormatter_object_dtor(zend_object *object TSRMLS_DC ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object( object TSRMLS_CC ); } /* }}} */ /* {{{ IntlDateFormatter_objects_free */ void IntlDateFormatter_object_free( zend_object *object TSRMLS_DC ) { - IntlDateFormatter_object* dfo = (IntlDateFormatter_object*)object; + IntlDateFormatter_object* dfo = php_intl_dateformatter_fetch_object(object); zend_object_std_dtor( &dfo->zo TSRMLS_CC ); @@ -53,18 +53,15 @@ void IntlDateFormatter_object_free( zend_object *object TSRMLS_DC ) } dateformat_data_free( &dfo->datef_data TSRMLS_CC ); - - efree( dfo ); } /* }}} */ /* {{{ IntlDateFormatter_object_create */ -zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC) +zend_object *IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; IntlDateFormatter_object* intern; - intern = ecalloc( 1, sizeof(IntlDateFormatter_object) ); + intern = ecalloc( 1, sizeof(IntlDateFormatter_object) + sizeof(zval) * (ce->default_properties_count - 1) ); dateformat_data_init( &intern->datef_data TSRMLS_CC ); zend_object_std_init( &intern->zo, ce TSRMLS_CC ); object_properties_init(&intern->zo, ce); @@ -73,31 +70,25 @@ zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC intern->calendar = -1; intern->requested_locale = NULL; - retval.handle = zend_objects_store_put( - intern, - IntlDateFormatter_object_dtor, - (zend_objects_free_object_storage_t)IntlDateFormatter_object_free, - NULL TSRMLS_CC ); - retval.handlers = &IntlDateFormatter_handlers; + intern->zo.handlers = &IntlDateFormatter_handlers; - return retval; + return &intern->zo; } /* }}} */ /* {{{ IntlDateFormatter_object_clone */ -zend_object_value IntlDateFormatter_object_clone(zval *object TSRMLS_DC) +zend_object *IntlDateFormatter_object_clone(zval *object TSRMLS_DC) { - zend_object_value new_obj_val; - zend_object_handle handle = Z_OBJ_HANDLE_P(object); IntlDateFormatter_object *dfo, *new_dfo; + zend_object *new_obj; DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; - new_obj_val = IntlDateFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); - new_dfo = (IntlDateFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC); + new_obj = IntlDateFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); + new_dfo = php_intl_dateformatter_fetch_object(new_obj); /* clone standard parts */ - zend_objects_clone_members(&new_dfo->zo, new_obj_val, &dfo->zo, handle TSRMLS_CC); + zend_objects_clone_members(&new_dfo->zo, &dfo->zo TSRMLS_CC); /* clone formatter object */ if (dfo->datef_data.udatf != NULL) { DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &INTL_DATA_ERROR_CODE(dfo)); @@ -110,7 +101,7 @@ zend_object_value IntlDateFormatter_object_clone(zval *object TSRMLS_DC) } else { zend_throw_exception(NULL, "Cannot clone unconstructed IntlDateFormatter", 0 TSRMLS_CC); } - return new_obj_val; + return new_obj; } /* }}} */ @@ -208,7 +199,10 @@ void dateformat_register_IntlDateFormatter_class( TSRMLS_D ) memcpy(&IntlDateFormatter_handlers, zend_get_std_object_handlers(), sizeof IntlDateFormatter_handlers); + IntlDateFormatter_handlers.offset = XtOffsetOf(IntlDateFormatter_object, zo); IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone; + IntlDateFormatter_handlers.dtor_obj = IntlDateFormatter_object_dtor; + IntlDateFormatter_handlers.free_obj = IntlDateFormatter_object_free; /* Declare 'IntlDateFormatter' class properties. */ if( !IntlDateFormatter_ce_ptr ) diff --git a/ext/intl/dateformat/dateformat_class.h b/ext/intl/dateformat/dateformat_class.h index b4304660e2..a3eb4b9839 100644 --- a/ext/intl/dateformat/dateformat_class.h +++ b/ext/intl/dateformat/dateformat_class.h @@ -24,21 +24,26 @@ #include "dateformat_data.h" typedef struct { - zend_object zo; dateformat_data datef_data; int date_type; int time_type; int calendar; char *requested_locale; + zend_object zo; } IntlDateFormatter_object; +static inline IntlDateFormatter_object *php_intl_dateformatter_fetch_object(zend_object *obj) { + return (IntlDateFormatter_object *)((char*)(obj) - XtOffsetOf(IntlDateFormatter_object, zo)); +} +#define Z_INTL_DATEFORMATTER_P(zv) php_intl_dateformatter_fetch_object(Z_OBJ_P(zv)) + void dateformat_register_IntlDateFormatter_class( TSRMLS_D ); extern zend_class_entry *IntlDateFormatter_ce_ptr; /* Auxiliary macros */ #define DATE_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDateFormatter, dfo) -#define DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(IntlDateFormatter, dfo) +#define DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_DATEFORMATTER, dfo) #define DATE_FORMAT_METHOD_FETCH_OBJECT \ DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (dfo->datef_data.udatf == NULL) \ diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index a2899f7974..bdc7351f37 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -49,7 +49,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) Calendar *calendar = NULL; long calendar_type; bool calendar_owned; - zval **timezone_zv = NULL; + zval *timezone_zv = NULL; TimeZone *timezone = NULL; bool explicit_tz; char* pattern_str = NULL; @@ -61,7 +61,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) intl_error_reset(NULL TSRMLS_CC); object = return_value; /* Parse parameters. */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll|Zzs", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll|zzs", &locale_str, &locale_len, &date_type, &time_type, &timezone_zv, &calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " @@ -93,7 +93,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } /* process timezone */ - explicit_tz = timezone_zv != NULL && Z_TYPE_PP(timezone_zv) != IS_NULL; + explicit_tz = timezone_zv != NULL && Z_TYPE_P(timezone_zv) != IS_NULL; if (explicit_tz || calendar_owned ) { //we have an explicit time zone or a non-object calendar diff --git a/ext/intl/dateformat/dateformat_format.c b/ext/intl/dateformat/dateformat_format.c index ffae15518b..467053ef84 100644 --- a/ext/intl/dateformat/dateformat_format.c +++ b/ext/intl/dateformat/dateformat_format.c @@ -62,7 +62,7 @@ static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp, zval static int32_t internal_get_arr_ele(IntlDateFormatter_object *dfo, HashTable* hash_arr, char* key_name, intl_error *err TSRMLS_DC) { - zval **ele_value = NULL; + zval *ele_value = NULL; int32_t result = 0; char *message; @@ -70,23 +70,22 @@ static int32_t internal_get_arr_ele(IntlDateFormatter_object *dfo, return result; } - if (zend_hash_find(hash_arr, key_name, strlen(key_name) + 1, - (void **)&ele_value) == SUCCESS) { - if(Z_TYPE_PP(ele_value) != IS_LONG) { + if ((ele_value = zend_hash_str_find(hash_arr, key_name, strlen(key_name))) != NULL) { + if(Z_TYPE_P(ele_value) != IS_LONG) { spprintf(&message, 0, "datefmt_format: parameter array contains " "a non-integer element for key '%s'", key_name); intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); efree(message); } else { - if (Z_LVAL_PP(ele_value) > INT32_MAX || - Z_LVAL_PP(ele_value) < INT32_MIN) { + if (Z_LVAL_P(ele_value) > INT32_MAX || + Z_LVAL_P(ele_value) < INT32_MIN) { spprintf(&message, 0, "datefmt_format: value %ld is out of " "bounds for a 32-bit integer in key '%s'", - Z_LVAL_PP(ele_value), key_name); + Z_LVAL_P(ele_value), key_name); intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); efree(message); } else { - result = Z_LVAL_PP(ele_value); + result = Z_LVAL_P(ele_value); } } } diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index e8981faa26..ac8aa2fe4c 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -45,9 +45,9 @@ static const DateFormat::EStyle valid_styles[] = { DateFormat::kShortRelative, }; -static bool valid_format(zval **z) { - if (Z_TYPE_PP(z) == IS_LONG) { - long lval = Z_LVAL_PP(z); +static bool valid_format(zval *z) { + if (Z_TYPE_P(z) == IS_LONG) { + long lval = Z_LVAL_P(z); for (int i = 0; i < sizeof(valid_styles) / sizeof(*valid_styles); i++) { if ((long)valid_styles[i] == lval) { return true; @@ -61,7 +61,7 @@ static bool valid_format(zval **z) { U_CFUNC PHP_FUNCTION(datefmt_format_object) { zval *object, - **format = NULL; + *format = NULL; const char *locale_str = NULL; int locale_len; bool pattern = false; @@ -73,7 +73,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) DateFormat::EStyle dateStyle = DateFormat::kDefault, timeStyle = DateFormat::kDefault; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|Zs!", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|zs!", &object, &format, &locale_str, &locale_len) == FAILURE) { RETURN_FALSE; } @@ -82,12 +82,12 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) locale_str = intl_locale_get_default(TSRMLS_C); } - if (format == NULL || Z_TYPE_PP(format) == IS_NULL) { + if (format == NULL || Z_TYPE_P(format) == IS_NULL) { //nothing - } else if (Z_TYPE_PP(format) == IS_ARRAY) { - HashTable *ht = Z_ARRVAL_PP(format); + } else if (Z_TYPE_P(format) == IS_ARRAY) { + HashTable *ht = Z_ARRVAL_P(format); HashPosition pos = {0}; - zval **z; + zval *z; if (zend_hash_num_elements(ht) != 2) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: bad format; if array, it must have " @@ -96,35 +96,35 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) } zend_hash_internal_pointer_reset_ex(ht, &pos); - zend_hash_get_current_data_ex(ht, (void**)&z, &pos); + z = zend_hash_get_current_data_ex(ht, &pos); if (!valid_format(z)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: bad format; the date format (first " "element of the array) is not valid", 0 TSRMLS_CC); RETURN_FALSE; } - dateStyle = (DateFormat::EStyle)Z_LVAL_PP(z); + dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); zend_hash_move_forward_ex(ht, &pos); - zend_hash_get_current_data_ex(ht, (void**)&z, &pos); + z = zend_hash_get_current_data_ex(ht, &pos); if (!valid_format(z)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: bad format; the time format (" "second element of the array) is not valid", 0 TSRMLS_CC); RETURN_FALSE; } - timeStyle = (DateFormat::EStyle)Z_LVAL_PP(z); - } else if (Z_TYPE_PP(format) == IS_LONG) { + timeStyle = (DateFormat::EStyle)Z_LVAL_P(z); + } else if (Z_TYPE_P(format) == IS_LONG) { if (!valid_format(format)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: the date/time format type is invalid", 0 TSRMLS_CC); RETURN_FALSE; } - dateStyle = timeStyle = (DateFormat::EStyle)Z_LVAL_PP(format); + dateStyle = timeStyle = (DateFormat::EStyle)Z_LVAL_P(format); } else { convert_to_string_ex(format); - if (Z_STRLEN_PP(format) == 0) { + if (Z_STRLEN_P(format) == 0) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: the format is empty", 0 TSRMLS_CC); RETURN_FALSE; @@ -176,7 +176,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) if (pattern) { df = new SimpleDateFormat( - UnicodeString(Z_STRVAL_PP(format), Z_STRLEN_PP(format), + UnicodeString(Z_STRVAL_P(format), Z_STRLEN_P(format), UnicodeString::kInvariant), Locale::createFromName(locale_str), status); @@ -208,18 +208,21 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) timeZone = NULL; { + char *ret_str; + int ret_str_len; UnicodeString result = UnicodeString(); df->format(date, result); - Z_TYPE_P(return_value) = IS_STRING; - if (intl_charFromString(result, &Z_STRVAL_P(return_value), - &Z_STRLEN_P(return_value), &status) == FAILURE) { + if (intl_charFromString(result, &ret_str, &ret_str_len, &status) == FAILURE) { intl_error_set(NULL, status, "datefmt_format_object: error converting result to UTF-8", 0 TSRMLS_CC); RETVAL_FALSE; goto cleanup; } + RETVAL_STRINGL(ret_str, ret_str_len); + //??? + efree(ret_str); } diff --git a/ext/intl/formatter/formatter_attr.c b/ext/intl/formatter/formatter_attr.c index 448a9db721..af58cfe37f 100644 --- a/ext/intl/formatter/formatter_attr.c +++ b/ext/intl/formatter/formatter_attr.c @@ -146,11 +146,11 @@ PHP_FUNCTION( numfmt_get_text_attribute ) PHP_FUNCTION( numfmt_set_attribute ) { long attribute; - zval **value; + zval *value; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OlZ", + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olz", &object, NumberFormatter_ce_ptr, &attribute, &value ) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -183,11 +183,11 @@ PHP_FUNCTION( numfmt_set_attribute ) case UNUM_MAX_SIGNIFICANT_DIGITS: case UNUM_LENIENT_PARSE: convert_to_long_ex(value); - unum_setAttribute(FORMATTER_OBJECT(nfo), attribute, Z_LVAL_PP(value)); + unum_setAttribute(FORMATTER_OBJECT(nfo), attribute, Z_LVAL_P(value)); break; case UNUM_ROUNDING_INCREMENT: convert_to_double_ex(value); - unum_setDoubleAttribute(FORMATTER_OBJECT(nfo), attribute, Z_DVAL_PP(value)); + unum_setDoubleAttribute(FORMATTER_OBJECT(nfo), attribute, Z_DVAL_P(value)); break; default: INTL_DATA_ERROR_CODE(nfo) = U_UNSUPPORTED_ERROR; @@ -445,7 +445,7 @@ PHP_FUNCTION( numfmt_get_locale ) loc = (char *)unum_getLocaleByType(FORMATTER_OBJECT(nfo), type, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Error getting locale" ); - RETURN_STRING(loc, 1); + RETURN_STRING(loc); } /* }}} */ diff --git a/ext/intl/formatter/formatter_class.c b/ext/intl/formatter/formatter_class.c index 2246cd29a5..cc4631cc3a 100644 --- a/ext/intl/formatter/formatter_class.c +++ b/ext/intl/formatter/formatter_class.c @@ -35,61 +35,49 @@ static zend_object_handlers NumberFormatter_handlers; /* {{{ NumberFormatter_objects_dtor */ static void NumberFormatter_object_dtor( - void *object, - zend_object_handle handle TSRMLS_DC ) + zend_object *object + TSRMLS_DC ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object( object TSRMLS_CC ); } /* }}} */ /* {{{ NumberFormatter_objects_free */ void NumberFormatter_object_free( zend_object *object TSRMLS_DC ) { - NumberFormatter_object* nfo = (NumberFormatter_object*)object; + NumberFormatter_object* nfo = php_intl_number_format_fetch_object(object); zend_object_std_dtor( &nfo->zo TSRMLS_CC ); formatter_data_free( &nfo->nf_data TSRMLS_CC ); - - efree( nfo ); } /* }}} */ /* {{{ NumberFormatter_object_create */ -zend_object_value NumberFormatter_object_create(zend_class_entry *ce TSRMLS_DC) +zend_object *NumberFormatter_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; NumberFormatter_object* intern; - intern = ecalloc( 1, sizeof(NumberFormatter_object) ); + intern = ecalloc( 1, sizeof(NumberFormatter_object) + sizeof(zval) * (ce->default_properties_count - 1) ); formatter_data_init( &intern->nf_data TSRMLS_CC ); zend_object_std_init( &intern->zo, ce TSRMLS_CC ); object_properties_init(&intern->zo, ce); - retval.handle = zend_objects_store_put( - intern, - NumberFormatter_object_dtor, - (zend_objects_free_object_storage_t)NumberFormatter_object_free, - NULL TSRMLS_CC ); - - retval.handlers = &NumberFormatter_handlers; + intern->zo.handlers = &NumberFormatter_handlers; - return retval; + return &intern->zo; } /* }}} */ /* {{{ NumberFormatter_object_clone */ -zend_object_value NumberFormatter_object_clone(zval *object TSRMLS_DC) +zend_object *NumberFormatter_object_clone(zval *object TSRMLS_DC) { - zend_object_value new_obj_val; - zend_object_handle handle = Z_OBJ_HANDLE_P(object); NumberFormatter_object *nfo, *new_nfo; FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; - new_obj_val = NumberFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); - new_nfo = (NumberFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC); + new_nfo = NumberFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); /* clone standard parts */ - zend_objects_clone_members(&new_nfo->zo, new_obj_val, &nfo->zo, handle TSRMLS_CC); + zend_objects_clone_members(&new_nfo->zo, &nfo->zo TSRMLS_CC); /* clone formatter object. It may fail, the destruction code must handle this case */ if (FORMATTER_OBJECT(nfo) != NULL) { FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo), @@ -103,7 +91,7 @@ zend_object_value NumberFormatter_object_clone(zval *object TSRMLS_DC) } else { zend_throw_exception(NULL, "Cannot clone unconstructed NumberFormatter", 0 TSRMLS_CC); } - return new_obj_val; + return new_nfo; } /* }}} */ @@ -205,7 +193,10 @@ void formatter_register_class( TSRMLS_D ) memcpy(&NumberFormatter_handlers, zend_get_std_object_handlers(), sizeof(NumberFormatter_handlers)); + NumberFormatter_handlers.offset = XtOffsetOf(NumberFormatter_object, zo); NumberFormatter_handlers.clone_obj = NumberFormatter_object_clone; + NumberFormatter_handlers.dtor_obj = NumberFormatter_object_dtor; + NumberFormatter_handlers.free_obj = NumberFormatter_object_free; /* Declare 'NumberFormatter' class properties. */ if( !NumberFormatter_ce_ptr ) diff --git a/ext/intl/formatter/formatter_class.h b/ext/intl/formatter/formatter_class.h index 9582866664..12061ba5df 100644 --- a/ext/intl/formatter/formatter_class.h +++ b/ext/intl/formatter/formatter_class.h @@ -25,10 +25,15 @@ #include "formatter_data.h" typedef struct { - zend_object zo; formatter_data nf_data; + zend_object zo; } NumberFormatter_object; +static inline NumberFormatter_object *php_intl_number_format_fetch_object(zend_object *obj) { + return (NumberFormatter_object *)((char*)(obj) - XtOffsetOf(NumberFormatter_object, zo)); +} +#define Z_INTL_NUMBERFORMATTER_P(zv) php_intl_number_format_fetch_object(Z_OBJ_P(zv)) + void formatter_register_class( TSRMLS_D ); extern zend_class_entry *NumberFormatter_ce_ptr; @@ -36,7 +41,7 @@ extern zend_class_entry *NumberFormatter_ce_ptr; #define FORMATTER_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(NumberFormatter, nfo) #define FORMATTER_OBJECT(nfo) (nfo)->nf_data.unum -#define FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(NumberFormatter, nfo) +#define FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_NUMBERFORMATTER, nfo) #define FORMATTER_METHOD_FETCH_OBJECT \ FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (FORMATTER_OBJECT(nfo) == NULL) \ diff --git a/ext/intl/formatter/formatter_format.c b/ext/intl/formatter/formatter_format.c index ce1c941e19..4b98f4fb17 100644 --- a/ext/intl/formatter/formatter_format.c +++ b/ext/intl/formatter/formatter_format.c @@ -32,7 +32,7 @@ */ PHP_FUNCTION( numfmt_format ) { - zval **number; + zval *number; long type = FORMAT_TYPE_DEFAULT; UChar format_buf[32]; UChar* formatted = format_buf; @@ -40,7 +40,7 @@ PHP_FUNCTION( numfmt_format ) FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OZ|l", + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz|l", &object, NumberFormatter_ce_ptr, &number, &type ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -53,34 +53,34 @@ PHP_FUNCTION( numfmt_format ) FORMATTER_METHOD_FETCH_OBJECT; if(type == FORMAT_TYPE_DEFAULT) { - if(Z_TYPE_PP(number) == IS_STRING) { + if(Z_TYPE_P(number) == IS_STRING) { convert_scalar_to_number_ex(number); } - if(Z_TYPE_PP(number) == IS_LONG) { + if(Z_TYPE_P(number) == IS_LONG) { /* take INT32 on 32-bit, int64 on 64-bit */ type = (sizeof(long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32; - } else if(Z_TYPE_PP(number) == IS_DOUBLE) { + } else if(Z_TYPE_P(number) == IS_DOUBLE) { type = FORMAT_TYPE_DOUBLE; } else { type = FORMAT_TYPE_INT32; } } - if(Z_TYPE_PP(number) != IS_DOUBLE && Z_TYPE_PP(number) != IS_LONG) { + if(Z_TYPE_P(number) != IS_DOUBLE && Z_TYPE_P(number) != IS_LONG) { SEPARATE_ZVAL_IF_NOT_REF(number); - convert_scalar_to_number( *number TSRMLS_CC ); + convert_scalar_to_number(number TSRMLS_CC ); } switch(type) { case FORMAT_TYPE_INT32: convert_to_long_ex(number); - formatted_len = unum_format(FORMATTER_OBJECT(nfo), (int32_t)Z_LVAL_PP(number), + formatted_len = unum_format(FORMATTER_OBJECT(nfo), (int32_t)Z_LVAL_P(number), formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); if (INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR) { intl_error_reset(INTL_DATA_ERROR_P(nfo) TSRMLS_CC); formatted = eumalloc(formatted_len); - formatted_len = unum_format(FORMATTER_OBJECT(nfo), (int32_t)Z_LVAL_PP(number), + formatted_len = unum_format(FORMATTER_OBJECT(nfo), (int32_t)Z_LVAL_P(number), formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); if (U_FAILURE( INTL_DATA_ERROR_CODE(nfo) ) ) { efree(formatted); @@ -91,7 +91,7 @@ PHP_FUNCTION( numfmt_format ) case FORMAT_TYPE_INT64: { - int64_t value = (Z_TYPE_PP(number) == IS_DOUBLE)?(int64_t)Z_DVAL_PP(number):Z_LVAL_PP(number); + int64_t value = (Z_TYPE_P(number) == IS_DOUBLE)?(int64_t)Z_DVAL_P(number):Z_LVAL_P(number); formatted_len = unum_formatInt64(FORMATTER_OBJECT(nfo), value, formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); if (INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR) { intl_error_reset(INTL_DATA_ERROR_P(nfo) TSRMLS_CC); @@ -107,11 +107,11 @@ PHP_FUNCTION( numfmt_format ) case FORMAT_TYPE_DOUBLE: convert_to_double_ex(number); - formatted_len = unum_formatDouble(FORMATTER_OBJECT(nfo), Z_DVAL_PP(number), formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); + formatted_len = unum_formatDouble(FORMATTER_OBJECT(nfo), Z_DVAL_P(number), formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); if (INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR) { intl_error_reset(INTL_DATA_ERROR_P(nfo) TSRMLS_CC); formatted = eumalloc(formatted_len); - unum_formatDouble(FORMATTER_OBJECT(nfo), Z_DVAL_PP(number), formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); + unum_formatDouble(FORMATTER_OBJECT(nfo), Z_DVAL_P(number), formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo)); if (U_FAILURE( INTL_DATA_ERROR_CODE(nfo) ) ) { efree(formatted); } diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index 0a568472c4..3089a6fec7 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -111,7 +111,7 @@ PHP_FUNCTION( numfmt_get_error_code ) RETURN_FALSE; } - nfo = (NumberFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + nfo = Z_INTL_NUMERFORMATTER_P(object); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(nfo) ); @@ -125,7 +125,7 @@ PHP_FUNCTION( numfmt_get_error_code ) */ PHP_FUNCTION( numfmt_get_error_message ) { - char* message = NULL; + zend_string *message = NULL; FORMATTER_METHOD_INIT_VARS /* Parse parameters. */ @@ -138,11 +138,11 @@ PHP_FUNCTION( numfmt_get_error_message ) RETURN_FALSE; } - nfo = (NumberFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + nfo = Z_INTL_NUMERFORMATTER_P(object); /* Return last error message. */ message = intl_error_get_message( INTL_DATA_ERROR_P(nfo) TSRMLS_CC ); - RETURN_STRING( message, 0); + RETURN_STR(message); } /* }}} */ diff --git a/ext/intl/formatter/formatter_parse.c b/ext/intl/formatter/formatter_parse.c index 6f3a3a12b5..7188c22d55 100644 --- a/ext/intl/formatter/formatter_parse.c +++ b/ext/intl/formatter/formatter_parse.c @@ -171,7 +171,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 ); } diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 8a094e015e..f4172636e5 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -438,7 +438,7 @@ PHP_FUNCTION(grapheme_substr) RETURN_FALSE; } - RETURN_STRINGL(((char *)sub_str), sub_str_len, 1); + RETURN_STRINGL(((char *)sub_str), sub_str_len); } ustr = NULL; @@ -528,7 +528,10 @@ PHP_FUNCTION(grapheme_substr) } /* return the allocated string, not a duplicate */ - RETURN_STRINGL(((char *)sub_str), sub_str_len, 0); + RETVAL_STRINGL(((char *)sub_str), sub_str_len); + //??? + efree(sub_str); + return; } if(length == 0) { @@ -604,7 +607,9 @@ PHP_FUNCTION(grapheme_substr) } /* return the allocated string, not a duplicate */ - RETURN_STRINGL(((char *)sub_str), sub_str_len, 0); + RETVAL_STRINGL(((char *)sub_str), sub_str_len); + //???? + efree(sub_str); } /* }}} */ @@ -650,9 +655,9 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas size_t found_offset = found - haystack; if (part) { - RETURN_STRINGL(((char *)haystack) , found_offset, 1); + RETURN_STRINGL(((char *)haystack) , found_offset); } else { - RETURN_STRINGL(((char *)found), haystack_len - found_offset, 1); + RETURN_STRINGL(((char *)found), haystack_len - found_offset); } } @@ -671,10 +676,10 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas U8_FWD_N(haystack, ret_pos, haystack_len, uchar_pos); if (part) { - RETURN_STRINGL(((char *)haystack), ret_pos, 1); + RETURN_STRINGL(((char *)haystack), ret_pos); } else { - RETURN_STRINGL(((char *)haystack) + ret_pos, haystack_len - ret_pos, 1); + RETURN_STRINGL(((char *)haystack) + ret_pos, haystack_len - ret_pos); } } @@ -895,7 +900,7 @@ PHP_FUNCTION(grapheme_extract) if ( NULL != next ) { ZVAL_LONG(next, start+nsize); } - RETURN_STRINGL(((char *)pstr), nsize, 1); + RETURN_STRINGL(((char *)pstr), nsize); } /* convert the strings to UTF-16. */ @@ -939,7 +944,7 @@ PHP_FUNCTION(grapheme_extract) ZVAL_LONG(next, start+ret_pos); } - RETURN_STRINGL(((char *)pstr), ret_pos, 1); + RETURN_STRINGL(((char *)pstr), ret_pos); } /* }}} */ diff --git a/ext/intl/intl_data.h b/ext/intl/intl_data.h index 66ca27ae79..4b603c8d29 100644 --- a/ext/intl/intl_data.h +++ b/ext/intl/intl_data.h @@ -42,7 +42,7 @@ typedef struct _intl_data { #define INTL_DATA_ERROR_CODE(obj) INTL_ERROR_CODE(INTL_DATA_ERROR((obj))) #define INTL_METHOD_FETCH_OBJECT(oclass, obj) \ - obj = (oclass##_object *) zend_object_store_get_object( object TSRMLS_CC ); \ + obj = Z_##oclass##_P( object ); \ intl_error_reset( INTL_DATA_ERROR_P(obj) TSRMLS_CC ); \ /* Check status by error code, if error - exit */ @@ -82,7 +82,8 @@ typedef struct _intl_data { efree(ustring); \ } \ INTL_METHOD_CHECK_STATUS((obj), "Error converting value to UTF-8"); \ - RETVAL_STRINGL(u8value, u8len, 0); \ + RETVAL_STRINGL(u8value, u8len); \ + efree(u8value); \ } #define INTL_MAX_LOCALE_LEN 80 diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index c76591ba56..e692e5dc0d 100644 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -129,24 +129,24 @@ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg TSRMLS_D /* {{{ const char* intl_error_get_message( intl_error* err ) * Create output message in format ": ". */ -char* intl_error_get_message( intl_error* err TSRMLS_DC ) +zend_string * intl_error_get_message( intl_error* err TSRMLS_DC ) { - const char* uErrorName = NULL; - char* errMessage = 0; + const char *uErrorName = NULL; + zend_string *errMessage = 0; if( !err && !( err = intl_g_error_get( TSRMLS_C ) ) ) - return estrdup( "" ); + return STR_EMPTY_ALLOC(); uErrorName = u_errorName( err->code ); /* Format output string */ if( err->custom_error_message ) { - spprintf( &errMessage, 0, "%s: %s", err->custom_error_message, uErrorName ); + errMessage = strpprintf(0, "%s: %s", err->custom_error_message, uErrorName ); } else { - spprintf( &errMessage, 0, "%s", uErrorName ); + errMessage = strpprintf(0, "%s", uErrorName ); } return errMessage; diff --git a/ext/intl/intl_error.h b/ext/intl/intl_error.h index 4d8eb79327..06f33a4bd3 100644 --- a/ext/intl/intl_error.h +++ b/ext/intl/intl_error.h @@ -38,7 +38,7 @@ void intl_error_set_code( intl_error* err, UErrorCode err_code TSRMLS_DC void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg TSRMLS_DC ); void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg TSRMLS_DC ); UErrorCode intl_error_get_code( intl_error* err TSRMLS_DC ); -char* intl_error_get_message( intl_error* err TSRMLS_DC ); +zend_string* intl_error_get_message( intl_error* err TSRMLS_DC ); // Wrappers to synchonize object's and global error structures. void intl_errors_reset( intl_error* err TSRMLS_DC ); diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index f5be81f74a..f58f24a36e 100644 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -211,7 +211,7 @@ static int getSingletonPos(const char* str) Get default locale */ PHP_NAMED_FUNCTION(zif_locale_get_default) { - RETURN_STRING( intl_locale_get_default( TSRMLS_C ), TRUE ); + RETURN_STRING( intl_locale_get_default( TSRMLS_C ) ); } /* }}} */ @@ -225,6 +225,7 @@ PHP_NAMED_FUNCTION(zif_locale_set_default) { char* locale_name = NULL; int len=0; + zend_string *ini_name; if(zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &locale_name ,&len ) == FAILURE) @@ -239,8 +240,10 @@ PHP_NAMED_FUNCTION(zif_locale_set_default) locale_name = (char *)uloc_getDefault() ; len = strlen(locale_name); } - - zend_alter_ini_entry(LOCALE_INI_NAME, sizeof(LOCALE_INI_NAME), locale_name, len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + + ini_name = STR_INIT(LOCALE_INI_NAME, sizeof(LOCALE_INI_NAME) - 1, 0); + zend_alter_ini_entry(ini_name, locale_name, len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + STR_RELEASE(ini_name); RETURN_TRUE; } @@ -404,12 +407,15 @@ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS) if( tag_value){ efree( tag_value); } - RETURN_STRING( empty_result , TRUE); + RETURN_STRING( empty_result); } /* value found */ if( tag_value){ - RETURN_STRING( tag_value , FALSE); + RETVAL_STRING( tag_value ); + //??? + efree(tag_value); + return; } /* Error encountered while fetching the value */ @@ -586,7 +592,9 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME RETURN_FALSE; } - RETVAL_STRINGL( utf8value, utf8value_len , FALSE); + RETVAL_STRINGL( utf8value, utf8value_len ); + //???? + efree(utf8value); } /* }}} */ @@ -755,10 +763,10 @@ PHP_FUNCTION(locale_canonicalize) */ static int append_key_value(smart_str* loc_name, HashTable* hash_arr, char* key_name) { - zval** ele_value = NULL; + zval *ele_value; - if(zend_hash_find(hash_arr , key_name , strlen(key_name) + 1 ,(void **)&ele_value ) == SUCCESS ) { - if(Z_TYPE_PP(ele_value)!= IS_STRING ){ + if ((ele_value = zend_hash_str_find(hash_arr , key_name, strlen(key_name))) != NULL ) { + if(Z_TYPE_P(ele_value)!= IS_STRING ){ /* element value is not a string */ return FAILURE; } @@ -767,7 +775,7 @@ static int append_key_value(smart_str* loc_name, HashTable* hash_arr, char* key_ /* not lang or grandfathered tag */ smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); } - smart_str_appendl(loc_name, Z_STRVAL_PP(ele_value) , Z_STRLEN_PP(ele_value)); + smart_str_appendl(loc_name, Z_STRVAL_P(ele_value) , Z_STRLEN_P(ele_value)); return SUCCESS; } @@ -796,36 +804,33 @@ static void add_prefix(smart_str* loc_name, char* key_name) */ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, char* key_name TSRMLS_DC) { - zval** ele_value = NULL; + zval *ele_value; int i = 0; int isFirstSubtag = 0; int max_value = 0; /* Variant/ Extlang/Private etc. */ - if( zend_hash_find( hash_arr , key_name , strlen(key_name) + 1 ,(void **)&ele_value ) == SUCCESS ) { - if( Z_TYPE_PP(ele_value) == IS_STRING ){ + if ((ele_value = zend_hash_str_find( hash_arr , key_name , strlen(key_name))) != NULL) { + if( Z_TYPE_P(ele_value) == IS_STRING ){ add_prefix( loc_name , key_name); smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); - smart_str_appendl(loc_name, Z_STRVAL_PP(ele_value) , Z_STRLEN_PP(ele_value)); + smart_str_appendl(loc_name, Z_STRVAL_P(ele_value) , Z_STRLEN_P(ele_value)); return SUCCESS; - } else if(Z_TYPE_PP(ele_value) == IS_ARRAY ) { - HashPosition pos; - HashTable *arr = HASH_OF(*ele_value); - zval **data = NULL; - - zend_hash_internal_pointer_reset_ex(arr, &pos); - while(zend_hash_get_current_data_ex(arr, (void **)&data, &pos) != FAILURE) { - if(Z_TYPE_PP(data) != IS_STRING) { + } else if(Z_TYPE_P(ele_value) == IS_ARRAY ) { + HashTable *arr = HASH_OF(ele_value); + zval *data; + + ZEND_HASH_FOREACH_VAL(arr, data) { + if(Z_TYPE_P(data) != IS_STRING) { return FAILURE; } if (isFirstSubtag++ == 0){ add_prefix(loc_name , key_name); } smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); - smart_str_appendl(loc_name, Z_STRVAL_PP(data) , Z_STRLEN_PP(data)); - zend_hash_move_forward_ex(arr, &pos); - } + smart_str_appendl(loc_name, Z_STRVAL_P(data) , Z_STRLEN_P(data)); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } else { return FAILURE; @@ -847,8 +852,8 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, isFirstSubtag = 0; for( i=0 ; i< max_value; i++ ){ snprintf( cur_key_name , 30, "%s%d", key_name , i); - if( zend_hash_find( hash_arr , cur_key_name , strlen(cur_key_name) + 1,(void **)&ele_value ) == SUCCESS ){ - if( Z_TYPE_PP(ele_value)!= IS_STRING ){ + if ((ele_value = zend_hash_str_find( hash_arr , cur_key_name , strlen(cur_key_name))) != NULL) { + if( Z_TYPE_P(ele_value)!= IS_STRING ){ /* variant is not a string */ return FAILURE; } @@ -857,7 +862,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, add_prefix(loc_name , cur_key_name); } smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); - smart_str_appendl(loc_name, Z_STRVAL_PP(ele_value) , Z_STRLEN_PP(ele_value)); + smart_str_appendl(loc_name, Z_STRVAL_P(ele_value) , Z_STRLEN_P(ele_value)); } } /* end of for */ } /* end of else */ @@ -884,7 +889,7 @@ static int handleAppendResult( int result, smart_str* loc_name TSRMLS_DC) } /* }}} */ -#define RETURN_SMART_STR(s) smart_str_0((s)); RETURN_STRINGL((s)->c, (s)->len, 0) +#define RETURN_SMART_STR(str) smart_str_0((str)); RETURN_STR((str)->s) /* {{{ proto static string Locale::composeLocale($array) * Creates a locale by combining the parts of locale-ID passed * }}} */ @@ -1109,7 +1114,7 @@ PHP_FUNCTION(locale_parse) grOffset = findOffset( LOC_GRANDFATHERED , loc_name ); if( grOffset >= 0 ){ - add_assoc_string( return_value , LOC_GRANDFATHERED_LANG_TAG , loc_name); + add_assoc_string( return_value , LOC_GRANDFATHERED_LANG_TAG, (char *)loc_name); } else{ /* Not grandfathered */ @@ -1410,7 +1415,7 @@ static char* lookup_loc_range(const char* loc_range, HashTable* hash_arr, int ca int result = 0; char* lang_tag = NULL; - zval** ele_value = NULL; + zval* ele_value = NULL; char** cur_arr = NULL; char* cur_loc_range = NULL; @@ -1420,29 +1425,22 @@ static char* lookup_loc_range(const char* loc_range, HashTable* hash_arr, int ca char* return_value = NULL; cur_arr = ecalloc(zend_hash_num_elements(hash_arr)*2, sizeof(char *)); + ZEND_HASH_FOREACH_VAL(hash_arr, ele_value) { /* convert the array to lowercase , also replace hyphens with the underscore and store it in cur_arr */ - for(zend_hash_internal_pointer_reset(hash_arr); - zend_hash_has_more_elements(hash_arr) == SUCCESS; - zend_hash_move_forward(hash_arr)) { - - if (zend_hash_get_current_data(hash_arr, (void**)&ele_value) == FAILURE) { - /* Should never actually fail since the key is known to exist.*/ - continue; - } - if(Z_TYPE_PP(ele_value)!= IS_STRING) { + if(Z_TYPE_P(ele_value)!= IS_STRING) { /* element value is not a string */ intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "lookup_loc_range: locale array element is not a string", 0 TSRMLS_CC); LOOKUP_CLEAN_RETURN(NULL); } - cur_arr[cur_arr_len*2] = estrndup(Z_STRVAL_PP(ele_value), Z_STRLEN_PP(ele_value)); - result = strToMatch(Z_STRVAL_PP(ele_value), cur_arr[cur_arr_len*2]); + cur_arr[cur_arr_len*2] = estrndup(Z_STRVAL_P(ele_value), Z_STRLEN_P(ele_value)); + result = strToMatch(Z_STRVAL_P(ele_value), cur_arr[cur_arr_len*2]); if(result == 0) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "lookup_loc_range: unable to canonicalize lang_tag", 0 TSRMLS_CC); LOOKUP_CLEAN_RETURN(NULL); } - cur_arr[cur_arr_len*2+1] = Z_STRVAL_PP(ele_value); + cur_arr[cur_arr_len*2+1] = Z_STRVAL_P(ele_value); cur_arr_len++ ; - } /* end of for */ + } ZEND_HASH_FOREACH_END(); /* end of for */ /* Canonicalize array elements */ if(canonicalize) { @@ -1560,7 +1558,9 @@ PHP_FUNCTION(locale_lookup) } } - RETVAL_STRINGL(result, strlen(result), 0); + RETVAL_STRINGL(result, strlen(result)); + //???? + efree(result); } /* }}} */ @@ -1597,7 +1597,7 @@ PHP_FUNCTION(locale_accept_from_http) if (len < 0 || outResult == ULOC_ACCEPT_FAILED) { RETURN_FALSE; } - RETURN_STRINGL(resultLocale, len, 1); + RETURN_STRINGL(resultLocale, len); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index 7d8cd958e3..2a5af418e0 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -130,7 +130,7 @@ PHP_FUNCTION( msgfmt_get_error_code ) RETURN_FALSE; } - mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + mfo = Z_INTL_MESSAGEFORMATTER_P( object ); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) ); @@ -144,7 +144,7 @@ PHP_FUNCTION( msgfmt_get_error_code ) */ PHP_FUNCTION( msgfmt_get_error_message ) { - char* message = NULL; + zend_string* message = NULL; zval* object = NULL; MessageFormatter_object* mfo = NULL; @@ -158,11 +158,11 @@ PHP_FUNCTION( msgfmt_get_error_message ) RETURN_FALSE; } - mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + mfo = Z_INTL_MESSAGEFORMATTER_P( object ); /* Return last error message. */ message = intl_error_get_message( &mfo->mf_data.error TSRMLS_CC ); - RETURN_STRING( message, 0); + RETURN_STR(message); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_attr.c b/ext/intl/msgformat/msgformat_attr.c index c333a24ee1..a306fc4421 100644 --- a/ext/intl/msgformat/msgformat_attr.c +++ b/ext/intl/msgformat/msgformat_attr.c @@ -47,7 +47,7 @@ PHP_FUNCTION( msgfmt_get_pattern ) MSG_FORMAT_METHOD_FETCH_OBJECT; if(mfo->mf_data.orig_format) { - RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len, 1); + RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len); } RETURN_FALSE; @@ -137,7 +137,7 @@ PHP_FUNCTION( msgfmt_get_locale ) MSG_FORMAT_METHOD_FETCH_OBJECT; loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo)); - RETURN_STRING(loc, 1); + RETURN_STRING(loc); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_class.c b/ext/intl/msgformat/msgformat_class.c index bb3b55f39c..71504bce2c 100644 --- a/ext/intl/msgformat/msgformat_class.c +++ b/ext/intl/msgformat/msgformat_class.c @@ -34,60 +34,50 @@ static zend_object_handlers MessageFormatter_handlers; */ /* {{{ MessageFormatter_objects_dtor */ -static void MessageFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC ) +static void MessageFormatter_object_dtor(zend_object *object TSRMLS_DC ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object( object TSRMLS_CC ); } /* }}} */ /* {{{ MessageFormatter_objects_free */ void MessageFormatter_object_free( zend_object *object TSRMLS_DC ) { - MessageFormatter_object* mfo = (MessageFormatter_object*)object; + MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object); zend_object_std_dtor( &mfo->zo TSRMLS_CC ); msgformat_data_free( &mfo->mf_data TSRMLS_CC ); - - efree( mfo ); } /* }}} */ /* {{{ MessageFormatter_object_create */ -zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC) +zend_object *MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; MessageFormatter_object* intern; - intern = ecalloc( 1, sizeof(MessageFormatter_object) ); + intern = ecalloc( 1, sizeof(MessageFormatter_object) + sizeof(zval) * (ce->default_properties_count - 1)); msgformat_data_init( &intern->mf_data TSRMLS_CC ); zend_object_std_init( &intern->zo, ce TSRMLS_CC ); object_properties_init(&intern->zo, ce); - retval.handle = zend_objects_store_put( - intern, - MessageFormatter_object_dtor, - (zend_objects_free_object_storage_t)MessageFormatter_object_free, - NULL TSRMLS_CC ); - - retval.handlers = &MessageFormatter_handlers; + intern->zo.handlers = &MessageFormatter_handlers; - return retval; + return &intern->zo; } /* }}} */ /* {{{ MessageFormatter_object_clone */ -zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC) +zend_object *MessageFormatter_object_clone(zval *object TSRMLS_DC) { - zend_object_value new_obj_val; - zend_object_handle handle = Z_OBJ_HANDLE_P(object); MessageFormatter_object *mfo, *new_mfo; + zend_object *new_obj; MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; - new_obj_val = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); - new_mfo = (MessageFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC); + new_obj = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); + new_mfo = php_intl_messageformatter_fetch_object(new_obj); /* clone standard parts */ - zend_objects_clone_members(&new_mfo->zo, new_obj_val, &mfo->zo, handle TSRMLS_CC); + zend_objects_clone_members(&new_mfo->zo, &mfo->zo TSRMLS_CC); /* clone formatter object */ if (MSG_FORMAT_OBJECT(mfo) != NULL) { @@ -102,7 +92,7 @@ zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC) } else { zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Cannot clone unconstructed MessageFormatter"); } - return new_obj_val; + return new_obj; } /* }}} */ @@ -171,7 +161,11 @@ void msgformat_register_class( TSRMLS_D ) memcpy(&MessageFormatter_handlers, zend_get_std_object_handlers(), sizeof MessageFormatter_handlers); + MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo); MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone; + MessageFormatter_handlers.dtor_obj = MessageFormatter_object_dtor; + MessageFormatter_handlers.free_obj = MessageFormatter_object_free; + /* Declare 'MessageFormatter' class properties. */ if( !MessageFormatter_ce_ptr ) diff --git a/ext/intl/msgformat/msgformat_class.h b/ext/intl/msgformat/msgformat_class.h index 337e04e647..66b6ce18a5 100644 --- a/ext/intl/msgformat/msgformat_class.h +++ b/ext/intl/msgformat/msgformat_class.h @@ -27,17 +27,23 @@ #include "msgformat_data.h" typedef struct { - zend_object zo; msgformat_data mf_data; + zend_object zo; } MessageFormatter_object; + +static inline MessageFormatter_object *php_intl_messageformatter_fetch_object(zend_object *obj) { + return (MessageFormatter_object *)((char*)(obj) - XtOffsetOf(MessageFormatter_object, zo)); +} +#define Z_INTL_MESSAGEFORMATTER_P(zv) php_intl_messageformatter_fetch_object(Z_OBJ_P(zv)) + void msgformat_register_class( TSRMLS_D ); extern zend_class_entry *MessageFormatter_ce_ptr; /* Auxiliary macros */ #define MSG_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(MessageFormatter, mfo) -#define MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(MessageFormatter, mfo) +#define MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_MESSAGEFORMATTER, mfo) #define MSG_FORMAT_METHOD_FETCH_OBJECT \ MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (MSG_FORMAT_OBJECT(mfo) == NULL) { \ diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index 55ec9e84ba..e661c3c17f 100644 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.c @@ -43,8 +43,7 @@ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *ret ALLOC_HASHTABLE(args_copy); zend_hash_init(args_copy, count, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(args_copy, Z_ARRVAL_P(args), (copy_ctor_func_t)zval_add_ref, - NULL, sizeof(zval*)); + zend_hash_copy(args_copy, Z_ARRVAL_P(args), (copy_ctor_func_t)zval_add_ref); umsg_format_helper(mfo, args_copy, &formatted, &formatted_len TSRMLS_CC); diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index f75fd91dce..10e3fc3770 100644 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -108,8 +108,7 @@ static HashTable *umsg_get_numeric_types(MessageFormatter_object *mfo, for (int i = 0; i < parts_count; i++) { const Formattable::Type t = types[i]; - if (zend_hash_index_update(ret, (ulong)i, (void*)&t, sizeof(t), NULL) - == FAILURE) { + if (zend_hash_index_update_mem(ret, (ulong)i, (void*)&t, sizeof(t)) == NULL) { intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR, "Write to argument types hash table failed", 0 TSRMLS_CC); break; @@ -346,7 +345,7 @@ static void umsg_set_timezone(MessageFormatter_object *mfo, if (used_tz == NULL) { zval nullzv = zval_used_for_init, *zvptr = &nullzv; - used_tz = timezone_process_timezone_argument(&zvptr, &err, + used_tz = timezone_process_timezone_argument(zvptr, &err, "msgfmt_format" TSRMLS_CC); if (used_tz == NULL) { continue; @@ -385,30 +384,22 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, farg_names.resize(arg_count); int argNum = 0; - HashPosition pos; - zval **elem; + zval *elem; // Key related variables - int key_type; - char *str_index; - uint str_len; + zend_string *str_index; ulong num_index; - for (zend_hash_internal_pointer_reset_ex(args, &pos); - U_SUCCESS(err.code) && - (key_type = zend_hash_get_current_key_ex( - args, &str_index, &str_len, &num_index, 0, &pos), - zend_hash_get_current_data_ex(args, (void **)&elem, &pos) - ) == SUCCESS; - zend_hash_move_forward_ex(args, &pos), argNum++) - { + ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) { Formattable& formattable = fargs[argNum]; UnicodeString& key = farg_names[argNum]; Formattable::Type argType = Formattable::kObject, //unknown *storedArgType = NULL; - + if (!U_SUCCESS(err.code)) { + break; + } /* Process key and retrieve type */ - if (key_type == HASH_KEY_IS_LONG) { + if (str_index == NULL) { /* includes case where index < 0 because it's exposed as unsigned */ if (num_index > (ulong)INT32_MAX) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, @@ -420,21 +411,20 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, int32_t len = u_sprintf(temp, "%u", (uint32_t)num_index); key.append(temp, len); - zend_hash_index_find(types, (ulong)num_index, (void**)&storedArgType); + storedArgType = (Formattable::Type*)zend_hash_index_find_ptr(types, (ulong)num_index); } else { //string; assumed to be in UTF-8 - intl_stringFromChar(key, str_index, str_len-1, &err.code); + intl_stringFromChar(key, str_index->val, str_index->len, &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, - "Invalid UTF-8 data in argument key: '%s'", str_index); + "Invalid UTF-8 data in argument key: '%s'", str_index->val); intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); efree(message); continue; } - zend_hash_find(types, (char*)key.getBuffer(), key.length(), - (void**)&storedArgType); + storedArgType = (Formattable::Type*)zend_hash_str_find_ptr(types, (char*)key.getBuffer(), key.length()); } if (storedArgType != NULL) { @@ -457,12 +447,12 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, UnicodeString *text = new UnicodeString(); intl_stringFromChar(*text, - Z_STRVAL_PP(elem), Z_STRLEN_PP(elem), &err.code); + Z_STRVAL_P(elem), Z_STRLEN_P(elem), &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, "Invalid UTF-8 data in string argument: " - "'%s'", Z_STRVAL_PP(elem)); + "'%s'", Z_STRVAL_P(elem)); intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); efree(message); delete text; @@ -474,16 +464,16 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, case Formattable::kDouble: { double d; - if (Z_TYPE_PP(elem) == IS_DOUBLE) { - d = Z_DVAL_PP(elem); - } else if (Z_TYPE_PP(elem) == IS_LONG) { - d = (double)Z_LVAL_PP(elem); + if (Z_TYPE_P(elem) == IS_DOUBLE) { + d = Z_DVAL_P(elem); + } else if (Z_TYPE_P(elem) == IS_LONG) { + d = (double)Z_LVAL_P(elem); } else { SEPARATE_ZVAL_IF_NOT_REF(elem); - convert_scalar_to_number(*elem TSRMLS_CC); - d = (Z_TYPE_PP(elem) == IS_DOUBLE) - ? Z_DVAL_PP(elem) - : (double)Z_LVAL_PP(elem); + convert_scalar_to_number(elem TSRMLS_CC); + d = (Z_TYPE_P(elem) == IS_DOUBLE) + ? Z_DVAL_P(elem) + : (double)Z_LVAL_P(elem); } formattable.setDouble(d); break; @@ -492,27 +482,27 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, { int32_t tInt32 = 0; retry_klong: - if (Z_TYPE_PP(elem) == IS_DOUBLE) { - if (Z_DVAL_PP(elem) > (double)INT32_MAX || - Z_DVAL_PP(elem) < (double)INT32_MIN) { + if (Z_TYPE_P(elem) == IS_DOUBLE) { + if (Z_DVAL_P(elem) > (double)INT32_MAX || + Z_DVAL_P(elem) < (double)INT32_MIN) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found PHP float with absolute value too large for " "32 bit integer argument", 0 TSRMLS_CC); } else { - tInt32 = (int32_t)Z_DVAL_PP(elem); + tInt32 = (int32_t)Z_DVAL_P(elem); } - } else if (Z_TYPE_PP(elem) == IS_LONG) { - if (Z_LVAL_PP(elem) > INT32_MAX || - Z_LVAL_PP(elem) < INT32_MIN) { + } else if (Z_TYPE_P(elem) == IS_LONG) { + if (Z_LVAL_P(elem) > INT32_MAX || + Z_LVAL_P(elem) < INT32_MIN) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found PHP integer with absolute value too large " "for 32 bit integer argument", 0 TSRMLS_CC); } else { - tInt32 = (int32_t)Z_LVAL_PP(elem); + tInt32 = (int32_t)Z_LVAL_P(elem); } } else { SEPARATE_ZVAL_IF_NOT_REF(elem); - convert_scalar_to_number(*elem TSRMLS_CC); + convert_scalar_to_number(elem TSRMLS_CC); goto retry_klong; } formattable.setLong(tInt32); @@ -522,21 +512,21 @@ retry_klong: { int64_t tInt64 = 0; retry_kint64: - if (Z_TYPE_PP(elem) == IS_DOUBLE) { - if (Z_DVAL_PP(elem) > (double)U_INT64_MAX || - Z_DVAL_PP(elem) < (double)U_INT64_MIN) { + if (Z_TYPE_P(elem) == IS_DOUBLE) { + if (Z_DVAL_P(elem) > (double)U_INT64_MAX || + Z_DVAL_P(elem) < (double)U_INT64_MIN) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found PHP float with absolute value too large for " "64 bit integer argument", 0 TSRMLS_CC); } else { - tInt64 = (int64_t)Z_DVAL_PP(elem); + tInt64 = (int64_t)Z_DVAL_P(elem); } - } else if (Z_TYPE_PP(elem) == IS_LONG) { + } else if (Z_TYPE_P(elem) == IS_LONG) { /* assume long is not wider than 64 bits */ - tInt64 = (int64_t)Z_LVAL_PP(elem); + tInt64 = (int64_t)Z_LVAL_P(elem); } else { SEPARATE_ZVAL_IF_NOT_REF(elem); - convert_scalar_to_number(*elem TSRMLS_CC); + convert_scalar_to_number(elem TSRMLS_CC); goto retry_kint64; } formattable.setInt64(tInt64); @@ -544,7 +534,7 @@ retry_kint64: } case Formattable::kDate: { - double dd = intl_zval_to_millis(*elem, &err, "msgfmt_format" TSRMLS_CC); + double dd = intl_zval_to_millis(elem, &err, "msgfmt_format" TSRMLS_CC); if (U_FAILURE(err.code)) { char *message, *key_char; int key_len; @@ -571,15 +561,16 @@ retry_kint64: /* We couldn't find any information about the argument in the pattern, this * means it's an extra argument. So convert it to a number if it's a number or * bool or null and to a string if it's anything else except arrays . */ - switch (Z_TYPE_PP(elem)) { + switch (Z_TYPE_P(elem)) { case IS_DOUBLE: - formattable.setDouble(Z_DVAL_PP(elem)); + formattable.setDouble(Z_DVAL_P(elem)); break; - case IS_BOOL: + case IS_TRUE: + case IS_FALSE: convert_to_long_ex(elem); /* Intentional fallthrough */ case IS_LONG: - formattable.setInt64((int64_t)Z_LVAL_PP(elem)); + formattable.setInt64((int64_t)Z_LVAL_P(elem)); break; case IS_NULL: formattable.setInt64((int64_t)0); @@ -605,7 +596,8 @@ retry_kint64: } } } - } // visiting each argument + argNum++; + } ZEND_HASH_FOREACH_END(); // visiting each argument if (U_FAILURE(err.code)) { return; @@ -636,7 +628,7 @@ retry_kint64: #define cleanup_zvals() for(int j=i;j>=0;j--) { zval_ptr_dtor((*args)+i); } -U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UChar *source, int source_len, UErrorCode *status) +U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int source_len, UErrorCode *status) { UnicodeString srcString(source, source_len); Formattable *fargs = ((const MessageFormat*)fmt)->parse(srcString, *count, *status); @@ -645,7 +637,7 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UC return; } - *args = (zval **)safe_emalloc(*count, sizeof(zval *), 0); + *args = (zval *)safe_emalloc(*count, sizeof(zval), 0); // assign formattables to varargs for(int32_t i = 0; i < *count; i++) { @@ -655,28 +647,26 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UC char *stmp; int stmp_len; - ALLOC_INIT_ZVAL((*args)[i]); - switch(fargs[i].getType()) { case Formattable::kDate: aDate = ((double)fargs[i].getDate())/U_MILLIS_PER_SECOND; - ZVAL_DOUBLE((*args)[i], aDate); + ZVAL_DOUBLE(&(*args)[i], aDate); break; case Formattable::kDouble: - ZVAL_DOUBLE((*args)[i], (double)fargs[i].getDouble()); + ZVAL_DOUBLE(&(*args)[i], (double)fargs[i].getDouble()); break; case Formattable::kLong: - ZVAL_LONG((*args)[i], fargs[i].getLong()); + ZVAL_LONG(&(*args)[i], fargs[i].getLong()); break; case Formattable::kInt64: aInt64 = fargs[i].getInt64(); if(aInt64 > LONG_MAX || aInt64 < -LONG_MAX) { - ZVAL_DOUBLE((*args)[i], (double)aInt64); + ZVAL_DOUBLE(&(*args)[i], (double)aInt64); } else { - ZVAL_LONG((*args)[i], (long)aInt64); + ZVAL_LONG(&(*args)[i], (long)aInt64); } break; @@ -687,7 +677,9 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UC cleanup_zvals(); return; } - ZVAL_STRINGL((*args)[i], stmp, stmp_len, 0); + ZVAL_STRINGL(&(*args)[i], stmp, stmp_len); + //??? + efree(stmp); break; case Formattable::kObject: diff --git a/ext/intl/msgformat/msgformat_helpers.h b/ext/intl/msgformat/msgformat_helpers.h index e6eda087d2..f88fd4f06b 100644 --- a/ext/intl/msgformat/msgformat_helpers.h +++ b/ext/intl/msgformat/msgformat_helpers.h @@ -20,6 +20,6 @@ int32_t umsg_format_arg_count(UMessageFormat *fmt); void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, UChar **formatted, int *formatted_len TSRMLS_DC); -void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, +void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int source_len, UErrorCode *status); #endif // MSG_FORMAT_HELPERS_H diff --git a/ext/intl/normalizer/normalizer_normalize.c b/ext/intl/normalizer/normalizer_normalize.c index f46285e9d9..fe1d61e052 100644 --- a/ext/intl/normalizer/normalizer_normalize.c +++ b/ext/intl/normalizer/normalizer_normalize.c @@ -159,7 +159,9 @@ PHP_FUNCTION( normalizer_normalize ) } /* Return it. */ - RETVAL_STRINGL( ret_buf, ret_len, FALSE ); + RETVAL_STRINGL( ret_buf, ret_len ); + //??? + efree(ret_buf); } /* }}} */ diff --git a/ext/intl/php_intl.h b/ext/intl/php_intl.h index 7a7112317d..f863f4bd47 100644 --- a/ext/intl/php_intl.h +++ b/ext/intl/php_intl.h @@ -45,7 +45,7 @@ extern zend_module_entry intl_module_entry; #endif ZEND_BEGIN_MODULE_GLOBALS(intl) - zval* current_collator; + zval current_collator; char* default_locale; collator_compare_func_t compare_func; UBreakIterator* grapheme_iterator; diff --git a/ext/intl/resourcebundle/resourcebundle.c b/ext/intl/resourcebundle/resourcebundle.c index f5475faf1c..658f02a6af 100644 --- a/ext/intl/resourcebundle/resourcebundle.c +++ b/ext/intl/resourcebundle/resourcebundle.c @@ -47,7 +47,7 @@ void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *so case URES_BINARY: bfield = ures_getBinary( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) ); INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve binary value"); - ZVAL_STRINGL( return_value, (char *) bfield, ilen, 1 ); + ZVAL_STRINGL( return_value, (char *) bfield, ilen ); break; case URES_INT: diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c index ca1828cd37..d988d85e8f 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.c @@ -35,9 +35,9 @@ zend_class_entry *ResourceBundle_ce_ptr = NULL; static zend_object_handlers ResourceBundle_object_handlers; /* {{{ ResourceBundle_object_dtor */ -static void ResourceBundle_object_destroy( void *object, zend_object_handle handle TSRMLS_DC ) +static void ResourceBundle_object_destroy( zend_object *object TSRMLS_DC ) { - ResourceBundle_object *rb = (ResourceBundle_object *) object; + ResourceBundle_object *rb = php_intl_resourcebundle_fetch_object(object); // only free local errors intl_error_reset( INTL_DATA_ERROR_P(rb) TSRMLS_CC ); @@ -50,29 +50,26 @@ static void ResourceBundle_object_destroy( void *object, zend_object_handle hand } zend_object_std_dtor( object TSRMLS_CC ); - efree(object); } /* }}} */ /* {{{ ResourceBundle_object_create */ -static zend_object_value ResourceBundle_object_create( zend_class_entry *ce TSRMLS_DC ) +static zend_object *ResourceBundle_object_create( zend_class_entry *ce TSRMLS_DC ) { - zend_object_value retval; ResourceBundle_object *rb; - rb = ecalloc( 1, sizeof(ResourceBundle_object) ); + rb = ecalloc( 1, sizeof(ResourceBundle_object) + sizeof(zval) * (ce->default_properties_count - 1) ); - zend_object_std_init( (zend_object *) rb, ce TSRMLS_CC ); - object_properties_init((zend_object *) rb, ce); + zend_object_std_init( &rb->zend, ce TSRMLS_CC ); + object_properties_init( &rb->zend, ce); intl_error_init( INTL_DATA_ERROR_P(rb) TSRMLS_CC ); rb->me = NULL; rb->child = NULL; - retval.handlers = &ResourceBundle_object_handlers; - retval.handle = zend_objects_store_put( rb, ResourceBundle_object_destroy, NULL, NULL TSRMLS_CC ); + rb->zend.handlers = &ResourceBundle_object_handlers; - return retval; + return &rb->zend; } /* }}} */ @@ -86,7 +83,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) zend_bool fallback = 1; zval *object = return_value; - ResourceBundle_object *rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC); + ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P( object ); intl_error_reset( NULL TSRMLS_CC ); @@ -367,7 +364,7 @@ PHP_FUNCTION( resourcebundle_get_error_code ) RETURN_FALSE; } - rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC ); + rb = Z_INTL_RESOURCEBUNDLE_P( object ); RETURN_LONG(INTL_DATA_ERROR_CODE(rb)); } @@ -384,7 +381,7 @@ ZEND_END_ARG_INFO() */ PHP_FUNCTION( resourcebundle_get_error_message ) { - char* message = NULL; + zend_string* message = NULL; RESOURCEBUNDLE_METHOD_INIT_VARS; if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -395,9 +392,9 @@ PHP_FUNCTION( resourcebundle_get_error_message ) RETURN_FALSE; } - rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC ); - message = (char *)intl_error_get_message(INTL_DATA_ERROR_P(rb) TSRMLS_CC); - RETURN_STRING(message, 0); + rb = Z_INTL_RESOURCEBUNDLE_P( object ); + message = intl_error_get_message(INTL_DATA_ERROR_P(rb) TSRMLS_CC); + RETURN_STR(message); } /* }}} */ @@ -437,7 +434,9 @@ void resourcebundle_register_class( TSRMLS_D ) } ResourceBundle_object_handlers = std_object_handlers; + ResourceBundle_object_handlers.offset = XtOffsetOf(ResourceBundle_object, zend); ResourceBundle_object_handlers.clone_obj = NULL; /* ICU ResourceBundle has no clone implementation */ + ResourceBundle_object_handlers.dtor_obj = ResourceBundle_object_destroy; ResourceBundle_object_handlers.read_dimension = resourcebundle_array_get; ResourceBundle_object_handlers.count_elements = resourcebundle_array_count; diff --git a/ext/intl/resourcebundle/resourcebundle_class.h b/ext/intl/resourcebundle/resourcebundle_class.h index 8da3ed9d47..7cb015a8df 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.h +++ b/ext/intl/resourcebundle/resourcebundle_class.h @@ -25,17 +25,22 @@ #include "intl_error.h" typedef struct { - zend_object zend; intl_error error; UResourceBundle *me; UResourceBundle *child; + zend_object zend; } ResourceBundle_object; +static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_object *obj) { + return (ResourceBundle_object *)((char*)(obj) - XtOffsetOf(ResourceBundle_object, zend)); +} +#define Z_INTL_RESOURCEBUNDLE_P(zv) php_intl_resourcebundle_fetch_object(Z_OBJ_P(zv)) + #define RESOURCEBUNDLE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(ResourceBundle, rb) -#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(ResourceBundle, rb) +#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb) #define RESOURCEBUNDLE_METHOD_FETCH_OBJECT \ - INTL_METHOD_FETCH_OBJECT(ResourceBundle, rb); \ + INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \ if (RESOURCEBUNDLE_OBJECT(rb) == NULL) { \ intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, \ "Found unconstructed ResourceBundle", 0 TSRMLS_CC); \ diff --git a/ext/intl/resourcebundle/resourcebundle_iterator.c b/ext/intl/resourcebundle/resourcebundle_iterator.c index 78236fda5d..9cde48967a 100644 --- a/ext/intl/resourcebundle/resourcebundle_iterator.c +++ b/ext/intl/resourcebundle/resourcebundle_iterator.c @@ -41,12 +41,11 @@ static void resourcebundle_iterator_read( ResourceBundle_iterator *iterator TSRM if (iterator->is_table) { iterator->currentkey = estrdup( ures_getKey( rb->child ) ); } - MAKE_STD_ZVAL( iterator->current ); - resourcebundle_extract_value( iterator->current, rb TSRMLS_CC ); + resourcebundle_extract_value( &iterator->current, rb TSRMLS_CC ); } else { // zend_throw_exception( spl_ce_OutOfRangeException, "Running past end of ResourceBundle", 0 TSRMLS_CC); - iterator->current = NULL; + ZVAL_UNDEF(&iterator->current); } } /* }}} */ @@ -56,9 +55,9 @@ static void resourcebundle_iterator_invalidate( zend_object_iterator *iter TSRML { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; - if (iterator->current) { + if (!Z_ISUNDEF(iterator->current)) { zval_ptr_dtor( &iterator->current ); - iterator->current = NULL; + ZVAL_UNDEF(&iterator->current); } if (iterator->currentkey) { efree( iterator->currentkey ); @@ -71,7 +70,7 @@ static void resourcebundle_iterator_invalidate( zend_object_iterator *iter TSRML static void resourcebundle_iterator_dtor( zend_object_iterator *iter TSRMLS_DC ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; - zval *object = (zval *)iterator->intern.data; + zval *object = &iterator->intern.data; resourcebundle_iterator_invalidate( iter TSRMLS_CC ); @@ -90,13 +89,13 @@ static int resourcebundle_iterator_has_more( zend_object_iterator *iter TSRMLS_D /* }}} */ /* {{{ resourcebundle_iterator_current */ -static void resourcebundle_iterator_current( zend_object_iterator *iter, zval ***data TSRMLS_DC ) +static zval *resourcebundle_iterator_current( zend_object_iterator *iter TSRMLS_DC ) { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; - if (!iterator->current) { + if (Z_ISUNDEF(iterator->current)) { resourcebundle_iterator_read( iterator TSRMLS_CC); } - *data = &iterator->current; + return &iterator->current; } /* }}} */ @@ -105,12 +104,12 @@ static void resourcebundle_iterator_key( zend_object_iterator *iter, zval *key T { ResourceBundle_iterator *iterator = (ResourceBundle_iterator *) iter; - if (!iterator->current) { + if (Z_ISUNDEF(iterator->current)) { resourcebundle_iterator_read( iterator TSRMLS_CC); } if (iterator->is_table) { - ZVAL_STRING(key, iterator->currentkey, 1); + ZVAL_STRING(key, iterator->currentkey); } else { ZVAL_LONG(key, iterator->i); } @@ -152,15 +151,15 @@ static zend_object_iterator_funcs resourcebundle_iterator_funcs = { /* {{{ resourcebundle_get_iterator */ zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref TSRMLS_DC ) { - ResourceBundle_object *rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC ); + ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P(object ); ResourceBundle_iterator *iterator = emalloc( sizeof( ResourceBundle_iterator ) ); if (byref) { php_error( E_ERROR, "ResourceBundle does not support writable iterators" ); } - Z_ADDREF_P(object); - iterator->intern.data = (void *) object; + zend_iterator_init(&iterator->intern TSRMLS_CC); + ZVAL_COPY(&iterator->intern.data, object); iterator->intern.funcs = &resourcebundle_iterator_funcs; iterator->subject = rb; @@ -171,7 +170,7 @@ zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *o iterator->is_table = (ures_getType( rb->me ) == URES_TABLE); iterator->length = ures_getSize( rb->me ); - iterator->current = NULL; + ZVAL_UNDEF(&iterator->current); iterator->currentkey = NULL; iterator->i = 0; diff --git a/ext/intl/resourcebundle/resourcebundle_iterator.h b/ext/intl/resourcebundle/resourcebundle_iterator.h index 90dba86d80..01a66650b9 100644 --- a/ext/intl/resourcebundle/resourcebundle_iterator.h +++ b/ext/intl/resourcebundle/resourcebundle_iterator.h @@ -26,7 +26,7 @@ typedef struct { ResourceBundle_object *subject; zend_bool is_table; long length; - zval *current; + zval current; char *currentkey; long i; } ResourceBundle_iterator; diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp index fa08af8503..40d1c99289 100644 --- a/ext/intl/timezone/timezone_class.cpp +++ b/ext/intl/timezone/timezone_class.cpp @@ -60,9 +60,8 @@ U_CFUNC void timezone_object_construct(const TimeZone *zone, zval *object, int o * Convert from TimeZone to DateTimeZone object */ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, - const char *func TSRMLS_DC) + const char *func, zval *ret TSRMLS_DC) { - zval *ret = NULL; UnicodeString id; char *message = NULL; php_timezone_obj *tzobj; @@ -76,9 +75,8 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, goto error; } - MAKE_STD_ZVAL(ret); object_init_ex(ret, php_date_get_timezone_ce()); - tzobj = (php_timezone_obj *)zend_objects_get_address(ret TSRMLS_CC); + tzobj = Z_PHPTIMEZONE_P(ret); if (id.compare(0, 3, UnicodeString("GMT", sizeof("GMT")-1, US_INV)) == 0) { /* The DateTimeZone constructor doesn't support offset time zones, @@ -88,31 +86,35 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, //convert offset from milliseconds to minutes tzobj->tzi.utc_offset = -1 * timeZone->getRawOffset() / (60 * 1000); } else { + char *str; + int str_len; /* Call the constructor! */ - Z_TYPE(arg) = IS_STRING; - if (intl_charFromString(id, &Z_STRVAL(arg), &Z_STRLEN(arg), - &INTL_ERROR_CODE(*outside_error)) == FAILURE) { + if (intl_charFromString(id, &str, &str_len, &INTL_ERROR_CODE(*outside_error)) == FAILURE) { spprintf(&message, 0, "%s: could not convert id to UTF-8", func); intl_errors_set(outside_error, INTL_ERROR_CODE(*outside_error), message, 1 TSRMLS_CC); goto error; } - zend_call_method_with_1_params(&ret, NULL, NULL, "__construct", - NULL, &arg); + ZVAL_STRINGL(&arg, str, str_len); + //??? + efree(str); + zend_call_method_with_1_params(ret, NULL, NULL, "__construct", NULL, &arg); if (EG(exception)) { spprintf(&message, 0, "%s: DateTimeZone constructor threw exception", func); intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); - zend_object_store_ctor_failed(ret TSRMLS_CC); + zend_object_store_ctor_failed(Z_OBJ_P(ret) TSRMLS_CC); + zval_ptr_dtor(&arg); goto error; } + zval_ptr_dtor(&arg); } if (0) { error: if (ret) { - zval_ptr_dtor(&ret); + zval_ptr_dtor(ret); } ret = NULL; } @@ -120,34 +122,31 @@ error: if (message) { efree(message); } - if (Z_TYPE(arg) == IS_STRING) { - zval_dtor(&arg); - } return ret; } /* }}} */ /* {{{ timezone_process_timezone_argument * TimeZone argument processor. outside_error may be NULL (for static functions/constructors) */ -U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone, +U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, intl_error *outside_error, const char *func TSRMLS_DC) { - zval local_zv_tz = zval_used_for_init, - *local_zv_tz_p = &local_zv_tz; + zval local_zv_tz = zval_used_for_init; char *message = NULL; TimeZone *timeZone; - if (zv_timezone == NULL || Z_TYPE_PP(zv_timezone) == IS_NULL) { + if (zv_timezone == NULL || Z_TYPE_P(zv_timezone) == IS_NULL) { timelib_tzinfo *tzinfo = get_timezone_info(TSRMLS_C); - ZVAL_STRING(&local_zv_tz, tzinfo->name, 0); - zv_timezone = &local_zv_tz_p; + ZVAL_STRING(&local_zv_tz, tzinfo->name); + zv_timezone = &local_zv_tz; + } else { + ZVAL_UNDEF(&local_zv_tz); } - if (Z_TYPE_PP(zv_timezone) == IS_OBJECT && - instanceof_function(Z_OBJCE_PP(zv_timezone), TimeZone_ce_ptr TSRMLS_CC)) { - TimeZone_object *to = (TimeZone_object*)zend_objects_get_address( - *zv_timezone TSRMLS_CC); + if (Z_TYPE_P(zv_timezone) == IS_OBJECT && + instanceof_function(Z_OBJCE_P(zv_timezone), TimeZone_ce_ptr TSRMLS_CC)) { + TimeZone_object *to = Z_INTL_TIMEZONE_P(zv_timezone); if (to->utimezone == NULL) { spprintf(&message, 0, "%s: passed IntlTimeZone is not " "properly constructed", func); @@ -155,6 +154,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone, intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); efree(message); } + zval_dtor(&local_zv_tz); return NULL; } timeZone = to->utimezone->clone(); @@ -164,14 +164,15 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone, intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1 TSRMLS_CC); efree(message); } + zval_dtor(&local_zv_tz); return NULL; } - } else if (Z_TYPE_PP(zv_timezone) == IS_OBJECT && - instanceof_function(Z_OBJCE_PP(zv_timezone), php_date_get_timezone_ce() TSRMLS_CC)) { + } else if (Z_TYPE_P(zv_timezone) == IS_OBJECT && + instanceof_function(Z_OBJCE_P(zv_timezone), php_date_get_timezone_ce() TSRMLS_CC)) { - php_timezone_obj *tzobj = (php_timezone_obj *)zend_objects_get_address( - *zv_timezone TSRMLS_CC); + php_timezone_obj *tzobj = Z_PHPTIMEZONE_P(zv_timezone); + zval_dtor(&local_zv_tz); return timezone_convert_datetimezone(tzobj->type, tzobj, 0, outside_error, func TSRMLS_CC); } else { @@ -179,7 +180,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone, gottenId; UErrorCode status = U_ZERO_ERROR; /* outside_error may be NULL */ convert_to_string_ex(zv_timezone); - if (intl_stringFromChar(id, Z_STRVAL_PP(zv_timezone), Z_STRLEN_PP(zv_timezone), + if (intl_stringFromChar(id, Z_STRVAL_P(zv_timezone), Z_STRLEN_P(zv_timezone), &status) == FAILURE) { spprintf(&message, 0, "%s: Time zone identifier given is not a " "valid UTF-8 string", func); @@ -187,6 +188,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone, intl_errors_set(outside_error, status, message, 1 TSRMLS_CC); efree(message); } + zval_dtor(&local_zv_tz); return NULL; } timeZone = TimeZone::createTimeZone(id); @@ -196,41 +198,43 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone, intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1 TSRMLS_CC); efree(message); } + zval_dtor(&local_zv_tz); return NULL; } if (timeZone->getID(gottenId) != id) { spprintf(&message, 0, "%s: no such time zone: '%s'", - func, Z_STRVAL_PP(zv_timezone)); + func, Z_STRVAL_P(zv_timezone)); if (message) { intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); efree(message); } + zval_dtor(&local_zv_tz); delete timeZone; return NULL; } } + + zval_dtor(&local_zv_tz); return timeZone; } /* }}} */ /* {{{ clone handler for TimeZone */ -static zend_object_value TimeZone_clone_obj(zval *object TSRMLS_DC) +static zend_object *TimeZone_clone_obj(zval *object TSRMLS_DC) { TimeZone_object *to_orig, *to_new; - zend_object_value ret_val; + zend_object *ret_val; intl_error_reset(NULL TSRMLS_CC); - to_orig = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + to_orig = Z_INTL_TIMEZONE_P(object); intl_error_reset(TIMEZONE_ERROR_P(to_orig) TSRMLS_CC); ret_val = TimeZone_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); - to_new = (TimeZone_object*)zend_object_store_get_object_by_handle( - ret_val.handle TSRMLS_CC); + to_new = php_intl_timezone_fetch_object(ret_val); - zend_objects_clone_members(&to_new->zo, ret_val, - &to_orig->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC); + zend_objects_clone_members(&to_new->zo, &to_orig->zo TSRMLS_CC); if (to_orig->utimezone != NULL) { TimeZone *newTimeZone; @@ -238,14 +242,14 @@ static zend_object_value TimeZone_clone_obj(zval *object TSRMLS_DC) newTimeZone = to_orig->utimezone->clone(); to_new->should_delete = 1; if (!newTimeZone) { - char *err_msg; + zend_string *err_msg; intl_errors_set_code(TIMEZONE_ERROR_P(to_orig), U_MEMORY_ALLOCATION_ERROR TSRMLS_CC); intl_errors_set_custom_msg(TIMEZONE_ERROR_P(to_orig), "Could not clone IntlTimeZone", 0 TSRMLS_CC); err_msg = intl_error_get_message(TIMEZONE_ERROR_P(to_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 { to_new->utimezone = newTimeZone; } @@ -263,8 +267,8 @@ static int TimeZone_compare_objects(zval *object1, zval *object2 TSRMLS_DC) { TimeZone_object *to1, *to2; - to1 = (TimeZone_object*)zend_object_store_get_object(object1 TSRMLS_CC); - to2 = (TimeZone_object*)zend_object_store_get_object(object2 TSRMLS_CC); + to1 = Z_INTL_TIMEZONE_P(object1); + to2 = Z_INTL_TIMEZONE_P(object2); if (to1->utimezone == NULL || to2->utimezone == NULL) { zend_throw_exception(NULL, "Comparison with at least one unconstructed " @@ -295,7 +299,7 @@ static HashTable *TimeZone_get_debug_info(zval *object, int *is_temp TSRMLS_DC) array_init_size(&zv, 4); - to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + to = Z_INTL_TIMEZONE_P(object); tz = to->utimezone; if (tz == NULL) { @@ -342,17 +346,16 @@ static void TimeZone_object_init(TimeZone_object *to TSRMLS_DC) /* }}} */ /* {{{ TimeZone_objects_dtor */ -static void TimeZone_objects_dtor(zend_object *object, - zend_object_handle handle TSRMLS_DC) +static void TimeZone_objects_dtor(zend_object *object TSRMLS_DC) { - zend_objects_destroy_object(object, handle TSRMLS_CC); + zend_objects_destroy_object(object TSRMLS_CC); } /* }}} */ /* {{{ TimeZone_objects_free */ static void TimeZone_objects_free(zend_object *object TSRMLS_DC) { - TimeZone_object* to = (TimeZone_object*) object; + TimeZone_object* to = php_intl_timezone_fetch_object(object); if (to->utimezone && to->should_delete) { delete to->utimezone; @@ -361,37 +364,23 @@ static void TimeZone_objects_free(zend_object *object TSRMLS_DC) intl_error_reset(TIMEZONE_ERROR_P(to) TSRMLS_CC); zend_object_std_dtor(&to->zo TSRMLS_CC); - - efree(to); } /* }}} */ /* {{{ TimeZone_object_create */ -static zend_object_value TimeZone_object_create(zend_class_entry *ce TSRMLS_DC) +static zend_object *TimeZone_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; TimeZone_object* intern; - intern = (TimeZone_object*)ecalloc(1, sizeof(TimeZone_object)); + intern = (TimeZone_object*)ecalloc(1, sizeof(TimeZone_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 TimeZone_object_init(intern TSRMLS_CC); - retval.handle = zend_objects_store_put( - intern, - (zend_objects_store_dtor_t) TimeZone_objects_dtor, - (zend_objects_free_object_storage_t) TimeZone_objects_free, - NULL TSRMLS_CC); - - retval.handlers = &TimeZone_handlers; + intern->zo.handlers = &TimeZone_handlers; - return retval; + return &intern->zo; } /* }}} */ @@ -509,9 +498,13 @@ U_CFUNC void timezone_register_IntlTimeZone_class(TSRMLS_D) memcpy(&TimeZone_handlers, zend_get_std_object_handlers(), sizeof TimeZone_handlers); + TimeZone_handlers.offset = XtOffsetOf(TimeZone_object, zo); TimeZone_handlers.clone_obj = TimeZone_clone_obj; TimeZone_handlers.compare_objects = TimeZone_compare_objects; TimeZone_handlers.get_debug_info = TimeZone_get_debug_info; + TimeZone_handlers.dtor_obj = TimeZone_objects_dtor; + TimeZone_handlers.free_obj = TimeZone_objects_free; + /* Declare 'IntlTimeZone' class constants */ #define TIMEZONE_DECL_LONG_CONST(name, val) \ diff --git a/ext/intl/timezone/timezone_class.h b/ext/intl/timezone/timezone_class.h index a638f6dbf4..71de20c09e 100644 --- a/ext/intl/timezone/timezone_class.h +++ b/ext/intl/timezone/timezone_class.h @@ -32,8 +32,6 @@ typedef void TimeZone; #endif typedef struct { - zend_object zo; - // error handling intl_error err; @@ -42,8 +40,15 @@ typedef struct { //whether to delete the timezone on object free zend_bool should_delete; + + zend_object zo; } TimeZone_object; +static inline TimeZone_object *php_intl_timezone_fetch_object(zend_object *obj) { + return (TimeZone_object *)((char*)(obj) - XtOffsetOf(TimeZone_object, zo)); +} +#define Z_INTL_TIMEZONE_P(zv) php_intl_timezone_fetch_object(Z_OBJ_P(zv)) + #define TIMEZONE_ERROR(to) (to)->err #define TIMEZONE_ERROR_P(to) &(TIMEZONE_ERROR(to)) @@ -51,7 +56,7 @@ typedef struct { #define TIMEZONE_ERROR_CODE_P(co) &(INTL_ERROR_CODE(TIMEZONE_ERROR(to))) #define TIMEZONE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(TimeZone, to) -#define TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(TimeZone, to) +#define TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_TIMEZONE, to) #define TIMEZONE_METHOD_FETCH_OBJECT\ TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; \ if (to->utimezone == NULL) { \ @@ -59,8 +64,8 @@ typedef struct { RETURN_FALSE; \ } -zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, const char *func TSRMLS_DC); -TimeZone *timezone_process_timezone_argument(zval **zv_timezone, intl_error *error, const char *func TSRMLS_DC); +zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, const char *func, zval *ret TSRMLS_DC); +TimeZone *timezone_process_timezone_argument(zval *zv_timezone, intl_error *error, const char *func TSRMLS_DC); void timezone_object_construct(const TimeZone *zone, zval *object, int owned TSRMLS_DC); diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp index 9ca6b44c89..bef69ba539 100644 --- a/ext/intl/timezone/timezone_methods.cpp +++ b/ext/intl/timezone/timezone_methods.cpp @@ -84,7 +84,7 @@ U_CFUNC PHP_FUNCTION(intltz_from_date_time_zone) RETURN_NULL(); } - tzobj = (php_timezone_obj *)zend_objects_get_address(zv_timezone TSRMLS_CC); + tzobj = Z_PHPTIMEZONE_P(zv_timezone); if (!tzobj->initialized) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_from_date_time_zone: DateTimeZone object is unconstructed", @@ -145,54 +145,52 @@ U_CFUNC PHP_FUNCTION(intltz_get_unknown) U_CFUNC PHP_FUNCTION(intltz_create_enumeration) { - zval **arg = NULL; + zval *arg = NULL; StringEnumeration *se = NULL; intl_error_reset(NULL TSRMLS_CC); /* double indirection to have the zend engine destroy the new zval that * results from separation */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Z", &arg) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &arg) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_enumeration: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } - if (arg == NULL || Z_TYPE_PP(arg) == IS_NULL) { + if (arg == NULL || Z_TYPE_P(arg) == IS_NULL) { se = TimeZone::createEnumeration(); - } else if (Z_TYPE_PP(arg) == IS_LONG) { + } else if (Z_TYPE_P(arg) == IS_LONG) { int_offset: - if (Z_LVAL_PP(arg) < (long)INT32_MIN || - Z_LVAL_PP(arg) > (long)INT32_MAX) { + if (Z_LVAL_P(arg) < (long)INT32_MIN || + Z_LVAL_P(arg) > (long)INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_enumeration: value is out of range", 0 TSRMLS_CC); RETURN_FALSE; } else { - se = TimeZone::createEnumeration((int32_t) Z_LVAL_PP(arg)); + se = TimeZone::createEnumeration((int32_t) Z_LVAL_P(arg)); } - } else if (Z_TYPE_PP(arg) == IS_DOUBLE) { + } else if (Z_TYPE_P(arg) == IS_DOUBLE) { double_offset: convert_to_long_ex(arg); goto int_offset; - } else if (Z_TYPE_PP(arg) == IS_OBJECT || Z_TYPE_PP(arg) == IS_STRING) { + } else if (Z_TYPE_P(arg) == IS_OBJECT || Z_TYPE_P(arg) == IS_STRING) { long lval; double dval; convert_to_string_ex(arg); - switch (is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &lval, &dval, 0)) { + switch (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &lval, &dval, 0)) { case IS_DOUBLE: SEPARATE_ZVAL(arg); - zval_dtor(*arg); - Z_TYPE_PP(arg) = IS_DOUBLE; - Z_DVAL_PP(arg) = dval; + zval_dtor(arg); + ZVAL_DOUBLE(arg, dval); goto double_offset; case IS_LONG: SEPARATE_ZVAL(arg); - zval_dtor(*arg); - Z_TYPE_PP(arg) = IS_LONG; - Z_LVAL_PP(arg) = lval; + zval_dtor(arg); + ZVAL_LONG(arg, lval); goto int_offset; } /* else call string version */ - se = TimeZone::createEnumeration(Z_STRVAL_PP(arg)); + se = TimeZone::createEnumeration(Z_STRVAL_P(arg)); } else { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_enumeration: invalid argument type", 0 TSRMLS_CC); @@ -317,11 +315,14 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id) TimeZone::getCanonicalID(id, result, isSystemID, status); INTL_CHECK_STATUS(status, "intltz_get_canonical_id: error obtaining canonical ID"); - intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), - result.getBuffer(), result.length(), &status); + char *str; + int str_len; + intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), &status); INTL_CHECK_STATUS(status, "intltz_get_canonical_id: could not convert time zone id to UTF-16"); - Z_TYPE_P(return_value) = IS_STRING; + RETVAL_STRINGL(str, str_len); + //???? + efree(str); if (is_systemid) { /* by-ref argument passed */ zval_dtor(is_systemid); @@ -355,7 +356,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_region) int32_t region_len = TimeZone::getRegion(id, outbuf, sizeof(outbuf), status); INTL_CHECK_STATUS(status, "intltz_get_region: Error obtaining region"); - RETURN_STRINGL(outbuf, region_len, 1); + RETURN_STRINGL(outbuf, region_len); } #endif @@ -374,7 +375,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_tz_data_version) INTL_CHECK_STATUS(status, "intltz_get_tz_data_version: " "Error obtaining time zone data version"); - RETURN_STRING(res, 1); + RETURN_STRING(res); } U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) @@ -401,11 +402,15 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id) } const UnicodeString result = TimeZone::getEquivalentID(id, (int32_t)index); - intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), - result.getBuffer(), result.length(), &status); + char *str; + int str_len; + + intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), &status); INTL_CHECK_STATUS(status, "intltz_get_equivalent_id: " "could not convert resulting time zone id to UTF-16"); - Z_TYPE_P(return_value) = IS_STRING; + RETVAL_STRINGL(str, str_len); + //???? + efree(str); } U_CFUNC PHP_FUNCTION(intltz_get_id) @@ -431,7 +436,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_id) id_us.getBuffer(), id_us.length(), TIMEZONE_ERROR_CODE_P(to)); INTL_METHOD_CHECK_STATUS(to, "intltz_get_id: Could not convert id to UTF-8"); - RETURN_STRINGL(id, id_len, 0); + RETURN_STRINGL(id, id_len); + //??? + efree(id); } U_CFUNC PHP_FUNCTION(intltz_use_daylight_time) @@ -513,7 +520,7 @@ U_CFUNC PHP_FUNCTION(intltz_has_same_rules) RETURN_FALSE; } TIMEZONE_METHOD_FETCH_OBJECT; - other_to = (TimeZone_object *) zend_object_store_get_object(other_object TSRMLS_CC); + other_to = Z_INTL_TIMEZONE_P(other_object); if (other_to->utimezone == NULL) { intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR, "intltz_has_same_rules: The second IntlTimeZone is unconstructed", 0 TSRMLS_CC); @@ -569,12 +576,15 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name) to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type, Locale::createFromName(locale_str), result); - intl_convert_utf16_to_utf8(&Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), - result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to)); + char *str; + int str_len; + intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to)); INTL_METHOD_CHECK_STATUS(to, "intltz_get_display_name: " "could not convert resulting time zone id to UTF-16"); - Z_TYPE_P(return_value) = IS_STRING; + RETVAL_STRINGL(str, str_len); + //???? + efree(str); } U_CFUNC PHP_FUNCTION(intltz_get_dst_savings) @@ -595,6 +605,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_dst_savings) U_CFUNC PHP_FUNCTION(intltz_to_date_time_zone) { + zval tmp; TIMEZONE_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), @@ -607,7 +618,7 @@ U_CFUNC PHP_FUNCTION(intltz_to_date_time_zone) TIMEZONE_METHOD_FETCH_OBJECT; zval *ret = timezone_convert_to_datetimezone(to->utimezone, - &TIMEZONE_ERROR(to), "intltz_to_date_time_zone" TSRMLS_CC); + &TIMEZONE_ERROR(to), "intltz_to_date_time_zone", &tmp TSRMLS_CC); if (ret) { RETURN_ZVAL(ret, 1, 1); @@ -628,7 +639,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_code) } /* Fetch the object (without resetting its last error code ). */ - to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + to = Z_INTL_TIMEZONE_P(object); if (to == NULL) RETURN_FALSE; @@ -637,7 +648,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_code) U_CFUNC PHP_FUNCTION(intltz_get_error_message) { - const char* message = NULL; + zend_string* message = NULL; TIMEZONE_METHOD_INIT_VARS if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -649,11 +660,11 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_message) /* Fetch the object (without resetting its last error code ). */ - to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC); + to = Z_INTL_TIMEZONE_P(object); if (to == NULL) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message(TIMEZONE_ERROR_P(to) TSRMLS_CC); - RETURN_STRING(message, 0); + RETURN_STR(message); } diff --git a/ext/intl/transliterator/transliterator_class.c b/ext/intl/transliterator/transliterator_class.c index 9891b35f4c..80572ca347 100644 --- a/ext/intl/transliterator/transliterator_class.c +++ b/ext/intl/transliterator/transliterator_class.c @@ -98,53 +98,38 @@ static void transliterator_object_destroy( Transliterator_object* to TSRMLS_DC ) /* {{{ Transliterator_objects_dtor */ static void Transliterator_objects_dtor( - void *object, - zend_object_handle handle TSRMLS_DC ) + zend_object *object TSRMLS_DC ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object( object TSRMLS_CC ); } /* }}} */ /* {{{ Transliterator_objects_free */ static void Transliterator_objects_free( zend_object *object TSRMLS_DC ) { - Transliterator_object* to = (Transliterator_object*) object; + Transliterator_object* to = php_intl_transliterator_fetch_object(object); zend_object_std_dtor( &to->zo TSRMLS_CC ); transliterator_object_destroy( to TSRMLS_CC ); - - efree( to ); } /* }}} */ /* {{{ Transliterator_object_create */ -static zend_object_value Transliterator_object_create( +static zend_object *Transliterator_object_create( zend_class_entry *ce TSRMLS_DC ) { - zend_object_value retval; Transliterator_object* intern; - intern = ecalloc( 1, sizeof( Transliterator_object ) ); + intern = ecalloc( 1, sizeof( Transliterator_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 transliterator_object_init( intern TSRMLS_CC ); - retval.handle = zend_objects_store_put( - intern, - Transliterator_objects_dtor, - (zend_objects_free_object_storage_t) Transliterator_objects_free, - NULL TSRMLS_CC ); - - retval.handlers = &Transliterator_handlers; + intern->zo.handlers = &Transliterator_handlers; - return retval; + return &intern->zo; } /* }}} */ @@ -153,20 +138,19 @@ static zend_object_value Transliterator_object_create( */ /* {{{ clone handler for Transliterator */ -static zend_object_value Transliterator_clone_obj( zval *object TSRMLS_DC ) +static zend_object *Transliterator_clone_obj( zval *object TSRMLS_DC ) { Transliterator_object *to_orig, *to_new; - zend_object_value ret_val; + zend_object *ret_val; intl_error_reset( NULL TSRMLS_CC ); - to_orig = zend_object_store_get_object( object TSRMLS_CC ); + to_orig = Z_INTL_TRANSLITERATOR_P( object ); intl_error_reset( INTL_DATA_ERROR_P( to_orig ) TSRMLS_CC ); ret_val = Transliterator_ce_ptr->create_object( Z_OBJCE_P( object ) TSRMLS_CC ); - to_new = zend_object_store_get_object_by_handle( ret_val.handle TSRMLS_CC ); + to_new = php_intl_transliterator_fetch_object( ret_val ); - zend_objects_clone_members( &to_new->zo, ret_val, - &to_orig->zo, Z_OBJ_HANDLE_P( object ) TSRMLS_CC ); + zend_objects_clone_members( &to_new->zo, &to_orig->zo TSRMLS_CC ); if( to_orig->utrans != NULL ) { @@ -179,13 +163,13 @@ static zend_object_value Transliterator_clone_obj( zval *object TSRMLS_DC ) if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to_orig ) ) ) goto err; - Z_OBJVAL( tempz ) = ret_val; + ZVAL_OBJ(&tempz, ret_val); transliterator_object_construct( &tempz, utrans, TRANSLITERATOR_ERROR_CODE_P( to_orig ) TSRMLS_CC ); if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to_orig ) ) ) { - char *err_msg; + zend_string *err_msg; err: if( utrans != NULL ) @@ -198,8 +182,8 @@ err: "Could not clone transliterator", 0 TSRMLS_CC ); err_msg = intl_error_get_message( TRANSLITERATOR_ERROR_P( to_orig ) TSRMLS_CC ); - php_error_docref( NULL TSRMLS_CC, E_ERROR, "%s", err_msg ); - efree( err_msg ); /* if it's changed into a warning */ + php_error_docref( NULL TSRMLS_CC, E_ERROR, "%s", err_msg->val ); + STR_FREE( err_msg ); /* if it's changed into a warning */ /* do not destroy tempz; we need to return something */ } } @@ -214,19 +198,7 @@ err: } /* }}} */ -#if PHP_VERSION_ID >= 50399 -# define TRANSLITERATOR_PROPERTY_HANDLER_PROLOG \ - zval tmp_member; \ - if( Z_TYPE_P( member ) != IS_STRING ) \ - { \ - tmp_member = *member; \ - zval_copy_ctor( &tmp_member ); \ - convert_to_string( &tmp_member ); \ - member = &tmp_member; \ - key = NULL; \ - } -#else -# define TRANSLITERATOR_PROPERTY_HANDLER_PROLOG \ +#define TRANSLITERATOR_PROPERTY_HANDLER_PROLOG \ zval tmp_member; \ if( Z_TYPE_P( member ) != IS_STRING ) \ { \ @@ -234,24 +206,19 @@ err: zval_copy_ctor( &tmp_member ); \ convert_to_string( &tmp_member ); \ member = &tmp_member; \ + cache_slot = -1; \ } -#endif #define TRANSLITERATOR_PROPERTY_HANDLER_EPILOG \ - if( member == &tmp_member ) \ + if( member == &tmp_member ) \ { \ zval_dtor( &tmp_member ); \ } /* {{{ get_property_ptr_ptr handler */ -#if PHP_VERSION_ID < 50399 -static zval **Transliterator_get_property_ptr_ptr( zval *object, zval *member TSRMLS_DC ) -#else -static zval **Transliterator_get_property_ptr_ptr( zval *object, zval *member, int type, - const struct _zend_literal *key TSRMLS_DC ) -#endif +static zval *Transliterator_get_property_ptr_ptr( zval *object, zval *member, int type, zend_uint cache_slot TSRMLS_DC ) { - zval **retval; + zval *retval; TRANSLITERATOR_PROPERTY_HANDLER_PROLOG; @@ -262,11 +229,7 @@ static zval **Transliterator_get_property_ptr_ptr( zval *object, zval *member, i } else { -#if PHP_VERSION_ID < 50399 - retval = std_object_handlers.get_property_ptr_ptr( object, member TSRMLS_CC ); -#else - retval = std_object_handlers.get_property_ptr_ptr( object, member, type, key TSRMLS_CC ); -#endif + retval = std_object_handlers.get_property_ptr_ptr( object, member, type, cache_slot TSRMLS_CC ); } TRANSLITERATOR_PROPERTY_HANDLER_EPILOG; @@ -276,12 +239,7 @@ static zval **Transliterator_get_property_ptr_ptr( zval *object, zval *member, i /* }}} */ /* {{{ read_property handler */ -#if PHP_VERSION_ID < 50399 -static zval *Transliterator_read_property( zval *object, zval *member, int type TSRMLS_DC ) /* {{{ */ -#else -static zval *Transliterator_read_property( zval *object, zval *member, int type, - const struct _zend_literal *key TSRMLS_DC ) /* {{{ */ -#endif +static zval *Transliterator_read_property( zval *object, zval *member, int type, zend_uint cache_slot, zval *rv TSRMLS_DC ) { zval *retval; @@ -296,11 +254,7 @@ static zval *Transliterator_read_property( zval *object, zval *member, int type, } else { -#if PHP_VERSION_ID < 50399 - retval = std_object_handlers.read_property( object, member, type TSRMLS_CC ); -#else - retval = std_object_handlers.read_property( object, member, type, key TSRMLS_CC ); -#endif + retval = std_object_handlers.read_property( object, member, type, cache_slot, rv TSRMLS_CC ); } TRANSLITERATOR_PROPERTY_HANDLER_EPILOG; @@ -311,12 +265,8 @@ static zval *Transliterator_read_property( zval *object, zval *member, int type, /* }}} */ /* {{{ write_property handler */ -#if PHP_VERSION_ID < 50399 -static void Transliterator_write_property( zval *object, zval *member, zval *value TSRMLS_DC ) -#else static void Transliterator_write_property( zval *object, zval *member, zval *value, - const struct _zend_literal *key TSRMLS_DC ) -#endif + zend_uint cache_slot TSRMLS_DC ) { TRANSLITERATOR_PROPERTY_HANDLER_PROLOG; @@ -328,11 +278,7 @@ static void Transliterator_write_property( zval *object, zval *member, zval *val } else { -#if PHP_VERSION_ID < 50399 - std_object_handlers.write_property( object, member, value TSRMLS_CC ); -#else - std_object_handlers.write_property( object, member, value, key TSRMLS_CC ); -#endif + std_object_handlers.write_property( object, member, value, cache_slot TSRMLS_CC ); } TRANSLITERATOR_PROPERTY_HANDLER_EPILOG; @@ -403,6 +349,9 @@ void transliterator_register_Transliterator_class( TSRMLS_D ) Transliterator_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC ); memcpy( &Transliterator_handlers, zend_get_std_object_handlers(), sizeof Transliterator_handlers ); + Transliterator_handlers.offset = XtOffsetOf(Transliterator_object, zo); + Transliterator_handlers.dtor_obj = Transliterator_objects_dtor; + Transliterator_handlers.free_obj = Transliterator_objects_free; Transliterator_handlers.clone_obj = Transliterator_clone_obj; Transliterator_handlers.get_property_ptr_ptr = Transliterator_get_property_ptr_ptr; Transliterator_handlers.read_property = Transliterator_read_property; diff --git a/ext/intl/transliterator/transliterator_class.h b/ext/intl/transliterator/transliterator_class.h index 5ca50ed2f4..a99c2ced16 100644 --- a/ext/intl/transliterator/transliterator_class.h +++ b/ext/intl/transliterator/transliterator_class.h @@ -25,15 +25,20 @@ #include typedef struct { - zend_object zo; - // error handling intl_error err; // ICU transliterator UTransliterator* utrans; + + zend_object zo; } Transliterator_object; +static inline Transliterator_object *php_intl_transliterator_fetch_object(zend_object *obj) { + return (Transliterator_object *)((char*)(obj) - XtOffsetOf(Transliterator_object, zo)); +} +#define Z_INTL_TRANSLITERATOR_P(zv) php_intl_transliterator_fetch_object(Z_OBJ_P(zv)) + #define TRANSLITERATOR_FORWARD UTRANS_FORWARD #define TRANSLITERATOR_REVERSE UTRANS_REVERSE @@ -44,7 +49,7 @@ typedef struct { #define TRANSLITERATOR_ERROR_CODE_P( co ) &(INTL_ERROR_CODE(TRANSLITERATOR_ERROR( co ))) #define TRANSLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS( Transliterator, to ) -#define TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT( Transliterator, to ) +#define TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT( INTL_TRANSLITERATOR, to ) #define TRANSLITERATOR_METHOD_FETCH_OBJECT\ TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ if( to->utrans == NULL ) \ diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c index 4b77508ff0..25edd005ef 100644 --- a/ext/intl/transliterator/transliterator_methods.c +++ b/ext/intl/transliterator/transliterator_methods.c @@ -185,7 +185,7 @@ PHP_FUNCTION( transliterator_create_from_rules ) smart_str parse_error_str; parse_error_str = intl_parse_error_to_string( &parse_error ); spprintf( &msg, 0, "transliterator_create_from_rules: unable to " - "create ICU transliterator from rules (%s)", parse_error_str.c ); + "create ICU transliterator from rules (%s)", parse_error_str.s? parse_error_str.s->val : "" ); smart_str_free( &parse_error_str ); if( msg != NULL ) { @@ -309,17 +309,18 @@ PHP_FUNCTION( transliterator_transliterate ) uresult_len; long start = 0, limit = -1; - int success = 0, - temp_trans = 0; + int success = 0; + zval tmp_object; TRANSLITERATOR_METHOD_INIT_VARS; object = getThis(); + ZVAL_UNDEF(&tmp_object); if( object == NULL ) { /* in non-OOP version, accept both a transliterator and a string */ - zval **arg1; - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "Zs|ll", + zval *arg1; + if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "zs|ll", &arg1, &str, &str_len, &start, &limit ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -327,29 +328,28 @@ PHP_FUNCTION( transliterator_transliterate ) RETURN_FALSE; } - if( Z_TYPE_PP( arg1 ) == IS_OBJECT && - instanceof_function( Z_OBJCE_PP( arg1 ), Transliterator_ce_ptr TSRMLS_CC ) ) + if( Z_TYPE_P( arg1 ) == IS_OBJECT && + instanceof_function( Z_OBJCE_P( arg1 ), Transliterator_ce_ptr TSRMLS_CC ) ) { - object = *arg1; + object = arg1; } else { /* not a transliterator object as first argument */ int res; - if(Z_TYPE_PP( arg1 ) != IS_STRING ) + if(Z_TYPE_P( arg1 ) != IS_STRING ) { SEPARATE_ZVAL( arg1 ); - convert_to_string( *arg1 ); + convert_to_string( arg1 ); } - ALLOC_INIT_ZVAL( object ); - temp_trans = 1; - res = create_transliterator( Z_STRVAL_PP( arg1 ), Z_STRLEN_PP( arg1 ), + object = &tmp_object; + res = create_transliterator( Z_STRVAL_P( arg1 ), Z_STRLEN_P( arg1 ), TRANSLITERATOR_FORWARD, object TSRMLS_CC ); if( res == FAILURE ) { - char *message = intl_error_get_message( NULL TSRMLS_CC ); + zend_string *message = intl_error_get_message( NULL TSRMLS_CC ); php_error_docref0( NULL TSRMLS_CC, E_WARNING, "Could not create " - "transliterator with ID \"%s\" (%s)", Z_STRVAL_PP( arg1 ), message ); - efree( message ); + "transliterator with ID \"%s\" (%s)", Z_STRVAL_P( arg1 ), message->val ); + STR_FREE( message ); /* don't set U_ILLEGAL_ARGUMENT_ERROR to allow fetching of inner error */ goto cleanup; } @@ -463,8 +463,7 @@ cleanup: RETVAL_FALSE; } - if (temp_trans ) - zval_ptr_dtor( &object ); + zval_ptr_dtor( &tmp_object ); } /* }}} */ @@ -494,7 +493,7 @@ PHP_FUNCTION( transliterator_get_error_code ) } /* Fetch the object (without resetting its last error code ). */ - to = zend_object_store_get_object( object TSRMLS_CC ); + to = Z_INTL_TRANSLITERATOR_P( object ); if (to == NULL ) RETURN_FALSE; @@ -509,7 +508,7 @@ PHP_FUNCTION( transliterator_get_error_code ) */ PHP_FUNCTION( transliterator_get_error_message ) { - const char* message = NULL; + zend_string* message = NULL; TRANSLITERATOR_METHOD_INIT_VARS if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -523,13 +522,13 @@ PHP_FUNCTION( transliterator_get_error_message ) /* Fetch the object (without resetting its last error code ). */ - to = zend_object_store_get_object( object TSRMLS_CC ); + to = Z_INTL_TRANSLITERATOR_P( object ); if (to == NULL ) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message( TRANSLITERATOR_ERROR_P( to ) TSRMLS_CC ); - RETURN_STRING( message, 0 ); + RETURN_STR( message ); } /* }}} */