Skip to content

Commit

Permalink
Implement add_utf8_property_* API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zmievski committed Oct 17, 2006
1 parent 96c2372 commit 2602e49
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Zend/zend_API.c
Expand Up @@ -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;
Expand Down
126 changes: 126 additions & 0 deletions Zend/zend_API.h
Expand Up @@ -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);

Expand Down

0 comments on commit 2602e49

Please sign in to comment.