Unicode support for PHP constants

This commit is contained in:
Dmitry Stogov 2005-09-08 11:10:34 +00:00
parent d1cf2c5ffe
commit 49c3b14f53
7 changed files with 13 additions and 9 deletions

View File

@ -558,7 +558,7 @@ ZEND_FUNCTION(defined)
}
convert_to_text_ex(var);
if (zend_get_constant(Z_UNIVAL_PP(var), Z_UNILEN_PP(var), &c TSRMLS_CC)) {
if (zend_u_get_constant(Z_TYPE_PP(var), Z_UNIVAL_PP(var), Z_UNILEN_PP(var), &c TSRMLS_CC)) {
zval_dtor(&c);
RETURN_TRUE;
} else {

View File

@ -214,19 +214,18 @@ ZEND_API void zend_register_string_constant(char *name, uint name_len, char *str
}
ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC)
ZEND_API int zend_u_get_constant(zend_uchar type, void *name, uint name_len, zval *result TSRMLS_DC)
{
zend_constant *c;
int retval = 1;
char *lookup_name;
char *colon;
zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
if ((UG(unicode) && (colon = (char*)u_memchr((UChar*)name, ':', name_len)) && ((UChar*)colon)[1] == ':') ||
(!UG(unicode) && (colon = memchr(name, ':', name_len)) && colon[1] == ':')) {
/* class constant */
zend_class_entry **ce = NULL, *scope;
int class_name_len = UG(unicode)?((colon-name)/sizeof(UChar)):colon-name;
int class_name_len = UG(unicode)?((colon-(char*)name)/sizeof(UChar)):colon-(char*)name;
int const_name_len = name_len - class_name_len - 2;
char *constant_name = colon + (UG(unicode)?UBYTES(2):2);
zval **ret_constant;
@ -310,6 +309,10 @@ ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC
return retval;
}
ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC)
{
return zend_u_get_constant(IS_STRING, name, name_len, result TSRMLS_CC);
}
ZEND_API int zend_u_register_constant(zend_uchar type, zend_constant *c TSRMLS_DC)
{

View File

@ -55,6 +55,7 @@ int zend_shutdown_constants(TSRMLS_D);
void zend_register_standard_constants(TSRMLS_D);
void clean_non_persistent_constants(TSRMLS_D);
ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC);
ZEND_API int zend_u_get_constant(zend_uchar type, void *name, uint name_len, zval *result TSRMLS_DC);
ZEND_API void zend_register_long_constant(char *name, uint name_len, long lval, int flags, int module_number TSRMLS_DC);
ZEND_API void zend_register_double_constant(char *name, uint name_len, double dval, int flags, int module_number TSRMLS_DC);
ZEND_API void zend_register_string_constant(char *name, uint name_len, char *strval, int flags, int module_number TSRMLS_DC);

View File

@ -439,7 +439,7 @@ ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC)
refcount = p->refcount;
is_ref = p->is_ref;
if (!zend_get_constant(Z_UNIVAL_P(p), Z_UNILEN_P(p), &const_value TSRMLS_CC)) {
if (!zend_u_get_constant(UG(unicode)?IS_UNICODE:IS_STRING, Z_UNIVAL_P(p), Z_UNILEN_P(p), &const_value TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %v - assumed '%v'",
Z_UNIVAL_P(p),
Z_UNIVAL_P(p));
@ -478,7 +478,7 @@ ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC)
zend_hash_move_forward(p->value.ht);
continue;
}
if (!zend_get_constant(str_index, str_index_len-1, &const_value TSRMLS_CC)) {
if (!zend_u_get_constant(UG(unicode)?IS_UNICODE:IS_STRING, str_index, str_index_len-1, &const_value TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %v - assumed '%v'", str_index, str_index);
zend_hash_move_forward(p->value.ht);
continue;

View File

@ -2552,7 +2552,7 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, CONST|UNUSED, CONST)
}
}
*/
if (!zend_get_constant(Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
if (!zend_u_get_constant(Z_TYPE(opline->op2.u.constant), Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %R - assumed '%R'",
Z_TYPE(opline->op2.u.constant),
Z_UNIVAL(opline->op2.u.constant),

View File

@ -15334,7 +15334,7 @@ static int ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARG
}
}
*/
if (!zend_get_constant(Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
if (!zend_u_get_constant(Z_TYPE((opline->op2.u.constant)), Z_UNIVAL(opline->op2.u.constant), Z_UNILEN(opline->op2.u.constant), &EX_T(opline->result.u.var).tmp_var TSRMLS_CC)) {
zend_error(E_NOTICE, "Use of undefined constant %R - assumed '%R'",
Z_TYPE(opline->op2.u.constant),
Z_UNIVAL(opline->op2.u.constant),

View File

@ -1273,7 +1273,7 @@ PHP_FUNCTION(constant)
}
convert_to_string_ex(const_name);
if (!zend_get_constant(Z_STRVAL_PP(const_name), Z_STRLEN_PP(const_name), return_value TSRMLS_CC)) {
if (!zend_u_get_constant(Z_TYPE_PP(const_name), Z_STRVAL_PP(const_name), Z_STRLEN_PP(const_name), return_value TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find constant %s", Z_STRVAL_PP(const_name));
RETURN_NULL();
}