From: Dmitry Stogov Date: Wed, 22 Feb 2006 10:02:15 +0000 (+0000) Subject: Unicode support: fixed internal constants usage and get_defined_constants() X-Git-Tag: RELEASE_1_2~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f4d9fa4a70e84dc52472a24b09f608b5889c6e4;p=php Unicode support: fixed internal constants usage and get_defined_constants() --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 86e1270b0f..23ef30f8ec 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1663,8 +1663,8 @@ ZEND_FUNCTION(get_defined_constants) zval_copy_ctor(const_val); INIT_PZVAL(const_val); - /* FIXME: Unicode support??? */ - add_assoc_zval_ex(modules[module_number], val->name.s, val->name_len, const_val); + add_u_assoc_zval_ex(modules[module_number], UG(unicode)?IS_UNICODE:IS_STRING, val->name, val->name_len, const_val); + bad_module_id: zend_hash_move_forward_ex(EG(zend_constants), &pos); } diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 28684bfba0..2bc0e53dd4 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -38,8 +38,12 @@ void free_zend_constant(zend_constant *c) void copy_zend_constant(zend_constant *c) { - /* FIXME: Unicode support??? */ - c->name.s = zend_strndup(c->name.s, c->name_len - 1); + TSRMLS_FETCH(); + if (UG(unicode)) { + c->name.u = zend_ustrndup(c->name.u, c->name_len - 1); + } else { + c->name.s = zend_strndup(c->name.s, c->name_len - 1); + } if (!(c->flags & CONST_PERSISTENT)) { zval_copy_ctor(&c->value); } @@ -358,7 +362,26 @@ ZEND_API int zend_u_register_constant(zend_uchar type, zend_constant *c TSRMLS_D ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC) { - return zend_u_register_constant(IS_STRING, c TSRMLS_CC); + if (UG(unicode)) { + UChar *ustr; + + if (c->name.s) { + ustr = malloc(UBYTES(c->name_len)); + u_charsToUChars(c->name.s, ustr, c->name_len); + free(c->name.s); + c->name.u = ustr; + } + if (Z_TYPE(c->value) == IS_STRING || Z_TYPE(c->value) == IS_CONSTANT) { + ustr = pemalloc(UBYTES(Z_STRLEN(c->value)+1), c->flags & CONST_PERSISTENT); + u_charsToUChars(Z_STRVAL(c->value), ustr, Z_STRLEN(c->value)+1); + pefree(Z_STRVAL(c->value), c->flags & CONST_PERSISTENT); + Z_USTRVAL(c->value) = ustr; + if (Z_TYPE(c->value) == IS_STRING) Z_TYPE(c->value) = IS_UNICODE; + } + return zend_u_register_constant(IS_UNICODE, c TSRMLS_CC); + } else { + return zend_u_register_constant(IS_STRING, c TSRMLS_CC); + } } /* * Local variables: