From: Andrei Zmievski Date: Tue, 17 Oct 2006 17:56:42 +0000 (+0000) Subject: Implement add_utf8_property_* API. X-Git-Tag: RELEASE_1_0_0RC1~1269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2602e49e65ac3ded0edef36f35ebaaafbe6ac4f6;p=php Implement add_utf8_property_* API. --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 29bf9d30ff..e24e5b92f1 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1709,6 +1709,18 @@ ZEND_API int add_property_zval_ex(zval *arg, char *key, uint key_len, zval *valu return SUCCESS; } +ZEND_API int add_utf8_property_zval_ex(zval *arg, char *key, uint key_len, zval *value) +{ + zval *z_key; + + MAKE_STD_ZVAL(z_key); + ZVAL_UTF8_STRINGL(z_key, key, key_len-1, ZSTR_DUPLICATE); + + Z_OBJ_HANDLER_P(arg, write_property)(arg, z_key, value TSRMLS_CC); + zval_ptr_dtor(&z_key); + return SUCCESS; +} + ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC) { int name_len; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 8922f3899e..818b466782 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -897,6 +897,132 @@ ZEND_API int add_utf8_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *va #define add_utf8_assoc_text(__arg, __key, __str, __duplicate) add_utf8_assoc_test_ex(__arg, __key, strlen(__key)+1, __str, __duplicate) #define add_utf8_assoc_textl(__arg, __key, __str, __length, __duplicate) add_utf8_assoc_textl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate) +ZEND_API int add_utf8_property_zval_ex(zval *arg, char *key, uint key_len, zval *value); + +#define add_utf8_property_null_ex(arg, key, key_len) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_NULL(___tmp); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_long_ex(arg, key, key_len, n) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_LONG(___tmp, n); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_bool_ex(arg, key, key_len, b) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_BOOL(___tmp, b); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_resource_ex(arg, key, key_len, r) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_RESOURCE(___tmp, r); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_double_ex(arg, key, key_len, d) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_DOUBLE(___tmp, d); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_stringl_ex(arg, key, key_len, str, length, duplicate) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_STRINGL(___tmp, str, length, duplicate); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_unicode_ex(arg, key, key_len, str, duplicate) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_UNICODE(___tmp, str, duplicate); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_unicodel_ex(arg, key, key_len, str, length, duplicate) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_UNICODEL(___tmp, str, length, duplicate); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_zstr_ex(arg, key, key_len, type, str, duplicate) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_ZSTR(___tmp, str, type, duplicate); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_zstrl_ex(arg, key, key_len, type, str, length, duplicate) do { \ + zval *___tmp; \ + MAKE_STD_ZVAL(___tmp); \ + ZVAL_ZSTRL(___tmp, str, length, type, duplicate); \ + add_utf8_property_zval_ex(arg, key, key_len, ___tmp); \ + zval_ptr_dtor(&___tmp); /* write_property will add 1 to refcount */ \ + } while (0) +#define add_utf8_property_text_ex(arg, key, key_len, str, duplicate) do { \ + if (UG(unicode)) { \ + add_utf8_property_unicode_ex(arg, key, key_len, (str).u, duplicate); \ + } else { \ + add_utf8_property_string_ex(arg, key, key_len, (str).s, duplicate); \ + } \ + } while (0) +#define add_utf8_property_textl_ex(arg, key, key_len, str, length, duplicate) do { \ + if (UG(unicode)) { \ + add_utf8_property_unicodel_ex(arg, key, key_len, (str).u, length, duplicate); \ + } else { \ + add_utf8_property_stringl_ex(arg, key, key_len, (str).s, length, duplicate); \ + } \ + } while (0) + +#define add_utf8_property_ascii_stringl_ex(arg, key, key_len, str, length, flags) do { \ + if (UG(unicode)) { \ + UChar *___u_str = zend_ascii_to_unicode((str), (length)+1 ZEND_FILE_LINE_CC); \ + if ((flags) & ZSTR_AUTOFREE) { \ + efree(str); \ + } \ + add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, length, 0); \ + } else { \ + add_utf8_property_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \ + } \ + } while (0) +#define add_utf8_property_rt_stringl_ex(arg, key, key_len, str, length, flags) do { \ + if (UG(unicode)) { \ + UErrorCode ___status = U_ZERO_ERROR; \ + UChar *___u_str; \ + int ___u_len; \ + zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \ + if ((flags) & ZSTR_AUTOFREE) { \ + efree(str); \ + } \ + add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \ + } else { \ + add_utf8_property_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \ + } \ + } while (0) +#define add_utf8_property_utf8_stringl_ex(arg, key, key_len, str, length, flags) do { \ + if (UG(unicode)) { \ + UErrorCode ___status = U_ZERO_ERROR; \ + UChar *___u_str; \ + int ___u_len; \ + zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \ + if ((flags) & ZSTR_AUTOFREE) { \ + efree(str); \ + } \ + add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \ + } else { \ + add_utf8_property_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \ + } \ + } while (0) ZEND_API int add_u_assoc_zval_ex(zval *arg, zend_uchar type, zstr key, uint key_len, zval *value);