]> granicus.if.org Git - php/commitdiff
Unicode support for PHP constants
authorDmitry Stogov <dmitry@php.net>
Thu, 8 Sep 2005 11:10:34 +0000 (11:10 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 8 Sep 2005 11:10:34 +0000 (11:10 +0000)
Zend/zend_builtin_functions.c
Zend/zend_constants.c
Zend/zend_constants.h
Zend/zend_execute_API.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/standard/basic_functions.c

index 0dd3be64e453ed2816252429d02826dbbcd2a150..3175f9457cf301b405b9848a5425684010dd376d 100644 (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 {
index 1389144abb21ebb65cfa088f30a3052e748d0a25..79d86182201102fd7011d0f1a7fbe87bebf6a965 100644 (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)
 {
index a3ca212d3b62da3bd8767abb474ae507ec7e2f14..41997ea13f3a38c7582fe474225be49093dea426 100644 (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);
index a83769ad624bf787ab77d061e9c2c16c8df8c8b8..99bf1c2d1b851b77c5783946b354e981ff10b2a8 100644 (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;
index b99d79700ffd56e8af7d72f075b23bd12b36ac2a..7b0e62deffc6b38fa45680b8ff9e71971b14d081 100644 (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),
index 8fbeedbdf6672ad5a861b95a42621e7d5a122a6f..d26f6ceb635044747c202e63e151db31efb02f96 100644 (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),
index d8fab087d8ea8b4e1f3fc6278010630ab6f72163..211b52a677dc550934965c52646b16ab0811aa65 100644 (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();
        }