cvs: php-src /ext/unicode collator.c php_unicode.h unicode.c ZendEngine2 zend.c zend_globals.h zend_operators.c zend_unicode.c zend_unicode.h

From: Date: Thu, 20 Apr 2006 21:56:43 +0000
Subject: cvs: php-src /ext/unicode collator.c php_unicode.h unicode.c ZendEngine2 zend.c zend_globals.h zend_operators.c zend_unicode.c zend_unicode.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-37878@lists.php.net to get a copy of this message
andrei Thu Apr 20 21:56:43 2006 UTC Modified files: /ZendEngine2 zend.c zend_globals.h zend_operators.c zend_unicode.c zend_unicode.h /php-src/ext/unicode collator.c php_unicode.h unicode.c Log: Move to refcounted implementation of collators.

http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend.c?r1=1.351&r2=1.352&diff_format=u Index: ZendEngine2/zend.c diff -u ZendEngine2/zend.c:1.351 ZendEngine2/zend.c:1.352 --- ZendEngine2/zend.c:1.351 Wed Apr 19 10:29:46 2006 +++ ZendEngine2/zend.c Thu Apr 20 21:56:43 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.c,v 1.351 2006/04/19 10:29:46 dmitry Exp $ */ +/* $Id: zend.c,v 1.352 2006/04/20 21:56:43 andrei Exp $ */ #include "zend.h" #include "zend_extensions.h" @@ -1227,15 +1227,17 @@ ZEND_API void zend_reset_locale_deps(TSRMLS_D) { + UCollator *coll; UErrorCode status = U_ZERO_ERROR; if (UG(default_collator)) { - ucol_close(UG(default_collator)); + zend_collator_destroy(UG(default_collator)); } - UG(default_collator) = ucol_open(UG(default_locale), &status); + coll = ucol_open(UG(default_locale), &status); if (U_FAILURE(status)) { zend_error(E_ERROR, "Could not open collator for locale %s", UG(default_locale)); } + UG(default_collator) = zend_collator_create(coll); } static void init_unicode_request_globals(TSRMLS_D) @@ -1248,7 +1250,7 @@ static void shutdown_unicode_request_globals(TSRMLS_D) { - ucol_close(UG(default_collator)); + zend_collator_destroy(UG(default_collator)); efree(UG(default_locale)); } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_globals.h?r1=1.155&r2=1.156&diff_format=u Index: ZendEngine2/zend_globals.h diff -u ZendEngine2/zend_globals.h:1.155 ZendEngine2/zend_globals.h:1.156 --- ZendEngine2/zend_globals.h:1.155 Fri Mar 31 22:51:37 2006 +++ ZendEngine2/zend_globals.h Thu Apr 20 21:56:43 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_globals.h,v 1.155 2006/03/31 22:51:37 pollita Exp $ */ +/* $Id: zend_globals.h,v 1.156 2006/04/20 21:56:43 andrei Exp $ */ #ifndef ZEND_GLOBALS_H #define ZEND_GLOBALS_H @@ -307,9 +307,9 @@ uint16_t to_error_mode; char *default_locale; - UCollator *default_collator; + zend_collator *default_collator; - HashTable flex_compatible; + HashTable flex_compatible; /* table of flex-compatible encodings */ }; #endif /* ZEND_GLOBALS_H */ http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_operators.c?r1=1.240&r2=1.241&diff_format=u Index: ZendEngine2/zend_operators.c diff -u ZendEngine2/zend_operators.c:1.240 ZendEngine2/zend_operators.c:1.241 --- ZendEngine2/zend_operators.c:1.240 Tue Mar 28 06:30:47 2006 +++ ZendEngine2/zend_operators.c Thu Apr 20 21:56:43 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.c,v 1.240 2006/03/28 06:30:47 andrei Exp $ */ +/* $Id: zend_operators.c,v 1.241 2006/04/20 21:56:43 andrei Exp $ */ #include <ctype.h> @@ -1443,7 +1443,7 @@ op2 = &op2_copy; } - Z_LVAL_P(result) = ucol_strcoll(UG(default_collator), Z_USTRVAL_P(op1), Z_USTRLEN_P(op1), Z_USTRVAL_P(op2), Z_USTRLEN_P(op2)); + Z_LVAL_P(result) = ucol_strcoll(UG(default_collator)->coll, Z_USTRVAL_P(op1), Z_USTRLEN_P(op1), Z_USTRVAL_P(op2), Z_USTRLEN_P(op2)); Z_TYPE_P(result) = IS_LONG; if (use_copy1) { http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_unicode.c?r1=1.20&r2=1.21&diff_format=u Index: ZendEngine2/zend_unicode.c diff -u ZendEngine2/zend_unicode.c:1.20 ZendEngine2/zend_unicode.c:1.21 --- ZendEngine2/zend_unicode.c:1.20 Mon Mar 27 19:15:58 2006 +++ ZendEngine2/zend_unicode.c Thu Apr 20 21:56:43 2006 @@ -677,6 +677,27 @@ } /* }}} */ +zend_collator* zend_collator_create(UCollator *coll) +{ + zend_collator *zcoll = NULL; + + zcoll = emalloc(sizeof(zend_collator)); + zcoll->coll = coll; + zcoll->refcount = 1; + + return zcoll; +} + +void zend_collator_destroy(zend_collator *zcoll) +{ + zcoll->refcount--; + if (zcoll->refcount == 0) { + ucol_close(zcoll->coll); + efree(zcoll); + } +} + + /* * Local variables: * tab-width: 4 http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_unicode.h?r1=1.14&r2=1.15&diff_format=u Index: ZendEngine2/zend_unicode.h diff -u ZendEngine2/zend_unicode.h:1.14 ZendEngine2/zend_unicode.h:1.15 --- ZendEngine2/zend_unicode.h:1.14 Mon Mar 27 06:02:28 2006 +++ ZendEngine2/zend_unicode.h Thu Apr 20 21:56:43 2006 @@ -48,6 +48,12 @@ } zend_conv_direction; +typedef struct _zend_collator { + UCollator *coll; + int refcount; +} zend_collator; + + extern ZEND_API zend_class_entry *unicodeConversionException; @@ -58,6 +64,8 @@ void zend_set_converter_subst_char(UConverter *conv, UChar *subst_char); void zend_register_unicode_exceptions(TSRMLS_D); void zend_update_converters_error_behavior(TSRMLS_D); +zend_collator* zend_collator_create(UCollator *coll); +void zend_collator_destroy(zend_collator *zcoll); /* API functions */ http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/collator.c?r1=1.3&r2=1.4&diff_format=u Index: php-src/ext/unicode/collator.c diff -u php-src/ext/unicode/collator.c:1.3 php-src/ext/unicode/collator.c:1.4 --- php-src/ext/unicode/collator.c:1.3 Tue Mar 28 04:33:29 2006 +++ php-src/ext/unicode/collator.c Thu Apr 20 21:56:43 2006 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: collator.c,v 1.3 2006/03/28 04:33:29 andrei Exp $ */ +/* $Id: collator.c,v 1.4 2006/04/20 21:56:43 andrei Exp $ */ #include "php.h" #include "ext/standard/php_array.h" @@ -42,8 +42,8 @@ typedef struct _php_collator_obj php_collator_obj; struct _php_collator_obj { - zend_object std; - UCollator *col; + zend_object std; + zend_collator *zcoll; }; #define COLLATOR_SET_CONTEXT \ @@ -140,8 +140,8 @@ { php_collator_obj *intern = (php_collator_obj *)object; - if (intern->col) { - ucol_close(intern->col); + if (intern->zcoll) { + zend_collator_destroy(intern->zcoll); } if (intern->std.properties) { @@ -178,10 +178,11 @@ PHP_FUNCTION(collator_create) { php_collator_obj *collatorobj; - UErrorCode error; + UErrorCode status = U_ZERO_ERROR; char *collator_name; int collator_name_len; zval *object; + UCollator *ucoll; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &collator_name, &collator_name_len) == FAILURE) { RETURN_FALSE; @@ -192,8 +193,13 @@ } collator_instantiate(unicode_ce_collator, object TSRMLS_CC); collatorobj = (php_collator_obj *) zend_object_store_get_object(object TSRMLS_CC); - error = U_ZERO_ERROR; - collatorobj->col = ucol_open(collator_name, &error); + ucoll = ucol_open(collator_name, &status); + if (U_FAILURE(status)) { + /* UTODO handle error case properly */ + zend_error(E_ERROR, "Could not open collator for locale %s", UG(default_locale)); + return; + } + collatorobj->zcoll = zend_collator_create(ucoll); } PHP_FUNCTION(collator_compare) @@ -207,7 +213,7 @@ RETURN_FALSE; } collatorobj = (php_collator_obj *) zend_object_store_get_object(object TSRMLS_CC); - RETURN_LONG(ucol_strcoll(collatorobj->col, string1, string1_len, string2, string2_len)); + RETURN_LONG(ucol_strcoll(collatorobj->zcoll->coll, string1, string1_len, string2, string2_len)); } PHP_FUNCTION(collator_sort) @@ -216,7 +222,7 @@ php_collator_obj *collatorobj; zval *array; HashTable *target_hash; - UCollator *orig_collator; + zend_collator *orig_collator; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa/", &object, unicode_ce_collator, &array) == FAILURE) { RETURN_FALSE; @@ -226,7 +232,7 @@ target_hash = HASH_OF(array); php_set_compare_func(SORT_LOCALE_STRING TSRMLS_CC); orig_collator = UG(default_collator); - UG(default_collator) = collatorobj->col; + UG(default_collator) = collatorobj->zcoll; if (zend_hash_sort(target_hash, zend_qsort, php_array_data_compare, 1 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { @@ -245,7 +251,7 @@ RETURN_FALSE; } collatorobj = (php_collator_obj *) zend_object_store_get_object(object TSRMLS_CC); - ucol_setStrength(collatorobj->col, strength); + ucol_setStrength(collatorobj->zcoll->coll, strength); } PHP_FUNCTION(collator_get_strength) @@ -257,7 +263,7 @@ RETURN_FALSE; } collatorobj = (php_collator_obj *) zend_object_store_get_object(object TSRMLS_CC); - RETURN_LONG(ucol_getStrength(collatorobj->col)); + RETURN_LONG(ucol_getStrength(collatorobj->zcoll->coll)); } PHP_FUNCTION(collator_set_attribute) @@ -272,7 +278,7 @@ } collatorobj = (php_collator_obj *) zend_object_store_get_object(object TSRMLS_CC); error = U_ZERO_ERROR; - ucol_setAttribute(collatorobj->col, attribute, value, &error); + ucol_setAttribute(collatorobj->zcoll->coll, attribute, value, &error); RETURN_BOOL(error == U_ZERO_ERROR ? 1 : 0); } @@ -288,9 +294,26 @@ } collatorobj = (php_collator_obj *) zend_object_store_get_object(object TSRMLS_CC); error = U_ZERO_ERROR; - value = ucol_getAttribute(collatorobj->col, attribute, &error); + value = ucol_getAttribute(collatorobj->zcoll->coll, attribute, &error); if (error != U_ZERO_ERROR) { RETURN_FALSE; } RETURN_LONG(value); } + +PHP_FUNCTION(i18n_coll_get_default) +{ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + return; + } + +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/php_unicode.h?r1=1.7&r2=1.8&diff_format=u Index: php-src/ext/unicode/php_unicode.h diff -u php-src/ext/unicode/php_unicode.h:1.7 php-src/ext/unicode/php_unicode.h:1.8 --- php-src/ext/unicode/php_unicode.h:1.7 Wed Mar 29 01:20:43 2006 +++ php-src/ext/unicode/php_unicode.h Thu Apr 20 21:56:43 2006 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_unicode.h,v 1.7 2006/03/29 01:20:43 pollita Exp $ */ +/* $Id: php_unicode.h,v 1.8 2006/04/20 21:56:43 andrei Exp $ */ #ifndef PHP_UNICODE_H #define PHP_UNICODE_H @@ -57,6 +57,7 @@ PHP_FUNCTION(i18n_loc_get_default); PHP_FUNCTION(i18n_loc_set_default); +PHP_FUNCTION(i18n_coll_get_default); PHP_FUNCTION(collator_create); PHP_FUNCTION(collator_compare); PHP_FUNCTION(collator_sort); http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/unicode.c?r1=1.19&r2=1.20&diff_format=u Index: php-src/ext/unicode/unicode.c diff -u php-src/ext/unicode/unicode.c:1.19 php-src/ext/unicode/unicode.c:1.20 --- php-src/ext/unicode/unicode.c:1.19 Wed Mar 29 01:20:43 2006 +++ php-src/ext/unicode/unicode.c Thu Apr 20 21:56:43 2006 @@ -15,10 +15,9 @@ +----------------------------------------------------------------------+ */ -/* $Id: unicode.c,v 1.19 2006/03/29 01:20:43 pollita Exp $ */ +/* $Id: unicode.c,v 1.20 2006/04/20 21:56:43 andrei Exp $ */ #include "php_unicode.h" -#if HAVE_UNICODE #include "zend_unicode.h" void php_register_unicode_iterators(TSRMLS_D); @@ -236,6 +235,7 @@ zend_function_entry unicode_functions[] = { PHP_FE(i18n_loc_get_default, NULL) PHP_FE(i18n_loc_set_default, NULL) + PHP_FE(i18n_coll_get_default, NULL) PHP_FE(unicode_decode, NULL) PHP_FE(unicode_semantics, NULL) PHP_FE(unicode_encode, NULL) @@ -318,8 +318,6 @@ /* }}} */ -#endif /* HAVE_UNICODE */ - /* * Local variables:
« previous php.cvs (#37878) next »