1999-04-07 18:10:10 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2007-01-01 09:29:37 +00:00
|
|
|
| Copyright (c) 1998-2007 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-07 18:10:10 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 15:16:21 +00:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
2006-02-21 08:00:39 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 15:16:21 +00:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-07-16 14:58:16 +00:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
1999-04-07 18:10:10 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-01 01:49:15 +00:00
|
|
|
/* $Id$ */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_constants.h"
|
2003-06-15 15:34:00 +00:00
|
|
|
#include "zend_execute.h"
|
1999-04-07 18:10:10 +00:00
|
|
|
#include "zend_variables.h"
|
|
|
|
#include "zend_operators.h"
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
void free_zend_constant(zend_constant *c) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2002-06-22 13:52:07 +00:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
1999-04-07 18:10:10 +00:00
|
|
|
zval_dtor(&c->value);
|
|
|
|
}
|
2006-02-21 20:12:43 +00:00
|
|
|
free(c->name.v);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
void copy_zend_constant(zend_constant *c) /* {{{ */
|
1999-07-14 16:00:47 +00:00
|
|
|
{
|
2006-02-22 10:02:15 +00:00
|
|
|
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);
|
|
|
|
}
|
2000-02-13 22:15:06 +00:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
|
|
|
zval_copy_ctor(&c->value);
|
|
|
|
}
|
1999-07-14 16:00:47 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-07-14 16:00:47 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
void zend_copy_constants(HashTable *target, HashTable *source) /* {{{ */
|
1999-07-14 16:00:47 +00:00
|
|
|
{
|
|
|
|
zend_constant tmp_constant;
|
|
|
|
|
2000-02-05 15:11:24 +00:00
|
|
|
zend_hash_copy(target, source, (copy_ctor_func_t) copy_zend_constant, &tmp_constant, sizeof(zend_constant));
|
1999-07-14 16:00:47 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-07-14 16:00:47 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
static int clean_non_persistent_constant(zend_constant *c TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2006-03-13 11:13:55 +00:00
|
|
|
return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
|
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
2006-03-13 11:13:55 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
static int clean_non_persistent_constant_full(zend_constant *c TSRMLS_DC) /* {{{ */
|
2006-03-13 11:13:55 +00:00
|
|
|
{
|
2006-03-14 11:24:30 +00:00
|
|
|
return (c->flags & CONST_PERSISTENT) ? 0 : 1;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
static int clean_module_constant(zend_constant *c, int *module_number TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
if (c->module_number == *module_number) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
void clean_module_constants(int module_number TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2001-07-31 04:53:54 +00:00
|
|
|
zend_hash_apply_with_argument(EG(zend_constants), (apply_func_arg_t) clean_module_constant, (void *) &module_number TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
int zend_startup_constants(TSRMLS_D) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2003-06-02 12:13:11 +00:00
|
|
|
EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2005-08-11 23:35:03 +00:00
|
|
|
if (zend_u_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1, UG(unicode))==FAILURE) {
|
1999-07-14 16:00:47 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-07-14 16:00:47 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
void zend_register_standard_constants(TSRMLS_D) /* {{{ */
|
1999-07-14 16:00:47 +00:00
|
|
|
{
|
1999-04-07 18:10:10 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
|
2005-09-15 16:19:48 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
|
1999-04-07 18:10:10 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
|
1999-07-22 22:17:49 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
|
2003-11-18 09:25:04 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
|
1999-07-22 22:17:49 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
|
2000-04-19 13:15:13 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
|
1999-07-22 22:17:49 +00:00
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
|
|
|
|
|
2006-03-23 22:00:42 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_STOP", ZEND_CONV_ERROR_STOP, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_SKIP", ZEND_CONV_ERROR_SKIP, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_SUBST", ZEND_CONV_ERROR_SUBST, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_UNICODE", ZEND_CONV_ERROR_ESCAPE_UNICODE, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_ICU", ZEND_CONV_ERROR_ESCAPE_ICU, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_JAVA", ZEND_CONV_ERROR_ESCAPE_JAVA, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_XML_DEC", ZEND_CONV_ERROR_ESCAPE_XML_DEC, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_XML_HEX", ZEND_CONV_ERROR_ESCAPE_XML_HEX, CONST_PERSISTENT | CONST_CS);
|
2005-08-11 23:35:03 +00:00
|
|
|
|
2006-03-26 01:48:33 +00:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("FROM_UNICODE", ZEND_FROM_UNICODE, CONST_PERSISTENT | CONST_CS);
|
|
|
|
REGISTER_MAIN_LONG_CONSTANT("TO_UNICODE", ZEND_TO_UNICODE, CONST_PERSISTENT | CONST_CS);
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
/* true/false constants */
|
|
|
|
{
|
|
|
|
zend_constant c;
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2006-02-20 19:03:43 +00:00
|
|
|
Z_TYPE(c.value) = IS_BOOL;
|
2006-03-15 09:04:48 +00:00
|
|
|
c.flags = CONST_PERSISTENT | CONST_CT_SUBST;
|
1999-04-07 18:10:10 +00:00
|
|
|
c.module_number = 0;
|
|
|
|
|
2006-02-21 20:12:43 +00:00
|
|
|
c.name.s = zend_strndup(ZEND_STRL("TRUE"));
|
1999-12-31 13:56:59 +00:00
|
|
|
c.name_len = sizeof("TRUE");
|
2006-02-20 19:03:43 +00:00
|
|
|
Z_LVAL(c.value) = 1;
|
|
|
|
Z_TYPE(c.value) = IS_BOOL;
|
2001-07-27 10:10:39 +00:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2006-02-21 20:12:43 +00:00
|
|
|
c.name.s = zend_strndup(ZEND_STRL("FALSE"));
|
1999-12-31 13:56:59 +00:00
|
|
|
c.name_len = sizeof("FALSE");
|
2006-02-20 19:03:43 +00:00
|
|
|
Z_LVAL(c.value) = 0;
|
|
|
|
Z_TYPE(c.value) = IS_BOOL;
|
2001-07-27 10:10:39 +00:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-12-28 12:05:48 +00:00
|
|
|
|
2006-03-15 09:04:48 +00:00
|
|
|
c.name.s = zend_strndup(ZEND_STRL("NULL"));
|
|
|
|
c.name_len = sizeof("NULL");
|
|
|
|
Z_TYPE(c.value) = IS_NULL;
|
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
|
|
|
|
|
|
|
c.flags = CONST_PERSISTENT;
|
|
|
|
|
2006-02-21 20:12:43 +00:00
|
|
|
c.name.s = zend_strndup(ZEND_STRL("ZEND_THREAD_SAFE"));
|
2000-06-26 18:15:33 +00:00
|
|
|
c.name_len = sizeof("ZEND_THREAD_SAFE");
|
2006-02-20 19:03:43 +00:00
|
|
|
Z_LVAL(c.value) = ZTS_V;
|
|
|
|
Z_TYPE(c.value) = IS_BOOL;
|
2001-07-27 10:10:39 +00:00
|
|
|
zend_register_constant(&c TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
int zend_shutdown_constants(TSRMLS_D) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_hash_destroy(EG(zend_constants));
|
2003-06-02 12:13:11 +00:00
|
|
|
free(EG(zend_constants));
|
1999-04-07 18:10:10 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
void clean_non_persistent_constants(TSRMLS_D) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2001-10-23 01:23:36 +00:00
|
|
|
if (EG(full_tables_cleanup)) {
|
2006-03-13 11:13:55 +00:00
|
|
|
zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
|
2001-10-23 01:23:36 +00:00
|
|
|
} else {
|
|
|
|
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API void zend_register_long_constant(char *name, uint name_len, long lval, int flags, int module_number TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_constant c;
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2006-11-17 10:48:53 +00:00
|
|
|
if (UG(unicode)) {
|
|
|
|
c.name.u = malloc(UBYTES(name_len));
|
|
|
|
u_charsToUChars(name, c.name.u, name_len);
|
|
|
|
c.name_len = name_len;
|
|
|
|
} else {
|
|
|
|
c.name.s = zend_strndup(name, name_len-1);
|
|
|
|
c.name_len = name_len;
|
|
|
|
}
|
2006-02-20 19:03:43 +00:00
|
|
|
Z_TYPE(c.value) = IS_LONG;
|
|
|
|
Z_LVAL(c.value) = lval;
|
1999-04-07 18:10:10 +00:00
|
|
|
c.flags = flags;
|
|
|
|
c.module_number = module_number;
|
2006-11-17 10:48:53 +00:00
|
|
|
zend_u_register_constant(ZEND_STR_TYPE, &c TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API void zend_register_double_constant(char *name, uint name_len, double dval, int flags, int module_number TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_constant c;
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2006-11-17 10:48:53 +00:00
|
|
|
if (UG(unicode)) {
|
|
|
|
c.name.u = malloc(UBYTES(name_len));
|
|
|
|
u_charsToUChars(name, c.name.u, name_len);
|
|
|
|
c.name_len = name_len;
|
|
|
|
} else {
|
|
|
|
c.name.s = zend_strndup(name, name_len-1);
|
|
|
|
c.name_len = name_len;
|
|
|
|
}
|
2006-02-20 19:03:43 +00:00
|
|
|
Z_TYPE(c.value) = IS_DOUBLE;
|
|
|
|
Z_DVAL(c.value) = dval;
|
1999-04-07 18:10:10 +00:00
|
|
|
c.flags = flags;
|
|
|
|
c.module_number = module_number;
|
2006-11-17 10:48:53 +00:00
|
|
|
zend_u_register_constant(ZEND_STR_TYPE, &c TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API void zend_register_stringl_constant(char *name, uint name_len, char *strval, uint strlen, int flags, int module_number TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_constant c;
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2006-11-17 10:48:53 +00:00
|
|
|
if (UG(unicode)) {
|
|
|
|
c.name.u = malloc(UBYTES(name_len));
|
|
|
|
u_charsToUChars(name, c.name.u, name_len);
|
|
|
|
c.name_len = name_len;
|
|
|
|
Z_TYPE(c.value) = IS_UNICODE;
|
|
|
|
if (flags & CONST_PERSISTENT) {
|
|
|
|
Z_USTRVAL(c.value) = malloc(UBYTES(strlen+1));
|
|
|
|
} else {
|
|
|
|
Z_USTRVAL(c.value) = emalloc(UBYTES(strlen+1));
|
|
|
|
}
|
|
|
|
u_charsToUChars(strval, Z_USTRVAL(c.value), strlen+1);
|
|
|
|
Z_USTRLEN(c.value) = strlen;
|
|
|
|
if (!(flags & CONST_PERSISTENT)) {
|
|
|
|
efree(strval);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.name.s = zend_strndup(name, name_len-1);
|
|
|
|
c.name_len = name_len;
|
|
|
|
Z_TYPE(c.value) = IS_STRING;
|
|
|
|
Z_STRVAL(c.value) = strval;
|
|
|
|
Z_STRLEN(c.value) = strlen;
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
c.flags = flags;
|
|
|
|
c.module_number = module_number;
|
2006-11-17 10:48:53 +00:00
|
|
|
zend_u_register_constant(ZEND_STR_TYPE, &c TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API void zend_register_string_constant(char *name, uint name_len, char *strval, int flags, int module_number TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2001-07-27 10:10:39 +00:00
|
|
|
zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number TSRMLS_CC);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API int zend_u_get_constant(zend_uchar type, zstr name, uint name_len, zval *result, zend_class_entry *scope TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
zend_constant *c;
|
2002-06-19 04:13:12 +00:00
|
|
|
int retval = 1;
|
2006-02-21 20:12:43 +00:00
|
|
|
zstr lookup_name;
|
|
|
|
zstr colon;
|
2003-06-15 13:58:50 +00:00
|
|
|
|
2007-07-27 09:04:12 +00:00
|
|
|
if ((UG(unicode) && (colon.u = u_memrchr(name.u, ':', name_len)) && colon.u > name.u && *(colon.u-1) == ':') ||
|
|
|
|
(!UG(unicode) && (colon.s = zend_memrchr(name.s, ':', name_len))&& colon.s > name.s && *(colon.s-1) == ':')) {
|
2003-06-15 13:58:50 +00:00
|
|
|
/* class constant */
|
2006-10-18 16:34:25 +00:00
|
|
|
zend_class_entry **ce = NULL;
|
2007-07-27 09:04:12 +00:00
|
|
|
int class_name_len = UG(unicode)?colon.u-name.u-1:colon.s-name.s-1;
|
2003-06-15 13:58:50 +00:00
|
|
|
int const_name_len = name_len - class_name_len - 2;
|
2006-02-21 20:12:43 +00:00
|
|
|
zstr constant_name, class_name;
|
2003-06-15 13:58:50 +00:00
|
|
|
zval **ret_constant;
|
2006-02-21 20:12:43 +00:00
|
|
|
|
|
|
|
if (UG(unicode)) {
|
2007-07-27 09:04:12 +00:00
|
|
|
constant_name.u = colon.u + 1;
|
2006-02-21 20:12:43 +00:00
|
|
|
} else {
|
2007-07-27 09:04:12 +00:00
|
|
|
constant_name.s = colon.s + 1;
|
2006-02-21 20:12:43 +00:00
|
|
|
}
|
2003-06-16 10:16:50 +00:00
|
|
|
|
2006-10-18 16:34:25 +00:00
|
|
|
if (!scope) {
|
|
|
|
if (EG(in_execution)) {
|
|
|
|
scope = EG(scope);
|
|
|
|
} else {
|
|
|
|
scope = CG(active_class_entry);
|
|
|
|
}
|
2003-06-16 10:16:50 +00:00
|
|
|
}
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2005-08-11 23:35:03 +00:00
|
|
|
if (UG(unicode)) {
|
2006-02-21 20:12:43 +00:00
|
|
|
class_name.u = eustrndup(name.u, class_name_len);
|
2005-08-11 23:35:03 +00:00
|
|
|
} else {
|
2006-02-21 20:12:43 +00:00
|
|
|
class_name.s = estrndup(name.s, class_name_len);
|
2005-08-11 23:35:03 +00:00
|
|
|
}
|
2004-07-01 16:28:32 +00:00
|
|
|
|
2005-08-11 23:35:03 +00:00
|
|
|
if (class_name_len == sizeof("self")-1 &&
|
|
|
|
ZEND_U_EQUAL(type, class_name, class_name_len, "self", sizeof("self")-1)) {
|
2003-06-30 20:22:35 +00:00
|
|
|
if (scope) {
|
2003-06-16 10:16:50 +00:00
|
|
|
ce = &scope;
|
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
|
|
|
|
retval = 0;
|
|
|
|
}
|
2006-02-21 08:00:39 +00:00
|
|
|
} else if (class_name_len == sizeof("parent")-1 &&
|
2005-08-11 23:35:03 +00:00
|
|
|
ZEND_U_EQUAL(type, class_name, class_name_len, "parent", sizeof("parent")-1)) {
|
2006-02-21 08:00:39 +00:00
|
|
|
if (!scope) {
|
2003-06-16 10:16:50 +00:00
|
|
|
zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
|
2006-02-21 08:00:39 +00:00
|
|
|
} else if (!scope->parent) {
|
|
|
|
zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
|
2003-06-16 10:16:50 +00:00
|
|
|
} else {
|
|
|
|
ce = &scope->parent;
|
|
|
|
}
|
2003-06-15 13:58:50 +00:00
|
|
|
} else {
|
2005-08-11 23:35:03 +00:00
|
|
|
if (zend_u_lookup_class(type, class_name, class_name_len, &ce TSRMLS_CC) != SUCCESS) {
|
2003-06-15 13:58:50 +00:00
|
|
|
retval = 0;
|
2007-07-27 09:04:12 +00:00
|
|
|
if ((UG(unicode) && (colon.u = u_memrchr(class_name.u, ':', class_name_len)) && colon.u > class_name.u && *(colon.u-1) == ':') ||
|
|
|
|
(!UG(unicode) && (colon.s = zend_memrchr(class_name.s, ':', class_name_len))&& colon.s > class_name.s && *(colon.s-1) == ':')) {
|
|
|
|
zend_class_entry **pce;
|
|
|
|
zstr lcname;
|
|
|
|
unsigned int lcname_len;
|
|
|
|
|
|
|
|
if (UG(unicode)) {
|
|
|
|
colon.u++;
|
|
|
|
lcname_len = class_name_len - (colon.u - class_name.u);
|
|
|
|
} else {
|
|
|
|
colon.s++;
|
|
|
|
lcname_len = class_name_len - (colon.s - class_name.s);
|
|
|
|
}
|
|
|
|
lcname = zend_u_str_case_fold(type, colon, lcname_len, 0, &lcname_len);
|
|
|
|
if (zend_u_hash_find(CG(class_table), type, lcname, lcname_len+1, (void**)&ce) == SUCCESS &&
|
|
|
|
(*ce)->type == ZEND_INTERNAL_CLASS) {
|
|
|
|
retval = 1;
|
|
|
|
}
|
|
|
|
efree(lcname.v);
|
|
|
|
}
|
2003-06-15 13:58:50 +00:00
|
|
|
}
|
2003-06-16 10:16:50 +00:00
|
|
|
}
|
2003-06-15 13:58:50 +00:00
|
|
|
|
2003-06-30 20:22:35 +00:00
|
|
|
if (retval && ce) {
|
2005-08-11 23:35:03 +00:00
|
|
|
if (zend_u_hash_find(&((*ce)->constants_table), type, constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
|
2003-06-16 10:16:50 +00:00
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-04 08:24:32 +00:00
|
|
|
zend_error(E_ERROR, "Class '%R' not found", type, class_name);
|
2003-06-16 10:16:50 +00:00
|
|
|
retval = 0;
|
2003-06-15 13:58:50 +00:00
|
|
|
}
|
2007-06-04 08:24:32 +00:00
|
|
|
efree(class_name.v);
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2003-06-30 20:22:35 +00:00
|
|
|
if (retval) {
|
2007-07-27 16:29:25 +00:00
|
|
|
zval_update_constant_ex(ret_constant, (void*)1, *ce TSRMLS_CC);
|
2003-06-15 13:58:50 +00:00
|
|
|
*result = **ret_constant;
|
|
|
|
zval_copy_ctor(result);
|
|
|
|
}
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2003-06-15 13:58:50 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2005-08-11 23:35:03 +00:00
|
|
|
if (zend_u_hash_find(EG(zend_constants), type, name, name_len+1, (void **) &c) == FAILURE) {
|
2006-02-20 19:03:43 +00:00
|
|
|
unsigned int lookup_name_len;
|
2005-08-11 23:35:03 +00:00
|
|
|
|
|
|
|
lookup_name = zend_u_str_case_fold(type, name, name_len, 1, &lookup_name_len);
|
2006-02-21 08:00:39 +00:00
|
|
|
|
2005-08-11 23:35:03 +00:00
|
|
|
if (zend_u_hash_find(EG(zend_constants), type, lookup_name, lookup_name_len+1, (void **) &c)==SUCCESS) {
|
2006-02-21 20:12:43 +00:00
|
|
|
if ((c->flags & CONST_CS) && memcmp(c->name.v, name.v, UG(unicode)?UBYTES(name_len):name_len)!=0) {
|
2002-06-19 04:13:12 +00:00
|
|
|
retval=0;
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
} else {
|
2007-06-28 00:01:58 +00:00
|
|
|
if (!EG(in_execution)) {
|
|
|
|
retval = 0;
|
2007-06-28 20:19:58 +00:00
|
|
|
} else if (name_len == sizeof(ZEND_HALT_CONSTANT_NAME)-1 && ZEND_U_EQUAL(type, name, name_len, ZEND_HALT_CONSTANT_NAME, sizeof(ZEND_HALT_CONSTANT_NAME)-1)) {
|
2007-06-28 00:01:58 +00:00
|
|
|
char *cfilename;
|
|
|
|
zstr haltname;
|
|
|
|
int len, clen;
|
|
|
|
cfilename = zend_get_executed_filename(TSRMLS_C);
|
|
|
|
clen = strlen(cfilename);
|
|
|
|
/* check for __COMPILER_HALT_OFFSET__ */
|
2007-06-28 20:27:35 +00:00
|
|
|
zend_mangle_property_name(&haltname.s, &len, ZEND_HALT_CONSTANT_NAME,
|
2007-06-28 20:19:58 +00:00
|
|
|
sizeof(ZEND_HALT_CONSTANT_NAME) - 1, cfilename, clen, 0);
|
2007-06-28 00:01:58 +00:00
|
|
|
if (zend_u_hash_find(EG(zend_constants), IS_STRING, haltname, len+1, (void **) &c) == SUCCESS) {
|
|
|
|
retval=1;
|
|
|
|
} else {
|
|
|
|
retval=0;
|
|
|
|
}
|
|
|
|
pefree(haltname.s, 0);
|
|
|
|
} else {
|
|
|
|
retval=0;
|
|
|
|
}
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2006-02-21 20:12:43 +00:00
|
|
|
efree(lookup_name.v);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2001-12-01 08:33:48 +00:00
|
|
|
|
2002-06-19 04:13:12 +00:00
|
|
|
if (retval) {
|
|
|
|
*result = c->value;
|
|
|
|
zval_copy_ctor(result);
|
2003-07-27 12:03:54 +00:00
|
|
|
result->refcount = 1;
|
|
|
|
result->is_ref = 0;
|
2002-06-19 04:13:12 +00:00
|
|
|
}
|
2001-12-01 08:33:48 +00:00
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC) /* {{{ */
|
2005-09-08 11:10:34 +00:00
|
|
|
{
|
2006-10-18 16:34:25 +00:00
|
|
|
return zend_u_get_constant(IS_STRING, ZSTR(name), name_len, result, NULL TSRMLS_CC);
|
2005-09-08 11:10:34 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API int zend_u_register_constant(zend_uchar type, zend_constant *c TSRMLS_DC) /* {{{ */
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
2006-02-20 19:03:43 +00:00
|
|
|
unsigned int lookup_name_len;
|
2006-02-21 20:12:43 +00:00
|
|
|
zstr lookup_name;
|
|
|
|
zstr name;
|
2000-07-28 09:44:46 +00:00
|
|
|
int ret = SUCCESS;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
|
|
|
#if 0
|
2001-08-11 15:56:40 +00:00
|
|
|
printf("Registering constant for module %d\n", c->module_number);
|
1999-04-07 18:10:10 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-19 04:13:12 +00:00
|
|
|
if (!(c->flags & CONST_CS)) {
|
2003-06-01 16:20:23 +00:00
|
|
|
/* keep in mind that c->name_len already contains the '\0' */
|
2005-08-11 23:35:03 +00:00
|
|
|
name = lookup_name = zend_u_str_case_fold(type, c->name, c->name_len-1, 1, &lookup_name_len);
|
|
|
|
lookup_name_len++;
|
2003-05-21 22:57:51 +00:00
|
|
|
} else {
|
2005-08-11 23:35:03 +00:00
|
|
|
lookup_name_len = c->name_len;
|
2004-05-26 21:01:37 +00:00
|
|
|
name = c->name;
|
2006-02-26 11:57:14 +00:00
|
|
|
lookup_name = NULL_ZSTR;
|
2003-05-21 22:57:51 +00:00
|
|
|
}
|
2002-06-19 04:13:12 +00:00
|
|
|
|
2007-06-28 20:19:58 +00:00
|
|
|
if (EG(in_execution) && lookup_name_len == sizeof(ZEND_HALT_CONSTANT_NAME) && ZEND_U_EQUAL(type, name, lookup_name_len-1, ZEND_HALT_CONSTANT_NAME, sizeof(ZEND_HALT_CONSTANT_NAME)-1)) {
|
2007-06-28 00:01:58 +00:00
|
|
|
zend_error(E_NOTICE,"Constant %R already defined", type, name);
|
|
|
|
if (lookup_name.v) {
|
|
|
|
efree(lookup_name.v);
|
|
|
|
}
|
|
|
|
ret = FAILURE;
|
|
|
|
}
|
2005-08-11 23:35:03 +00:00
|
|
|
if (zend_u_hash_add(EG(zend_constants), type, name, lookup_name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
|
2005-08-15 14:39:18 +00:00
|
|
|
zend_error(E_NOTICE,"Constant %R already defined", type, name);
|
2006-02-21 20:12:43 +00:00
|
|
|
free(c->name.v);
|
2002-06-22 13:52:07 +00:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
2001-08-14 15:22:34 +00:00
|
|
|
zval_dtor(&c->value);
|
|
|
|
}
|
2000-07-28 09:44:46 +00:00
|
|
|
ret = FAILURE;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2006-02-21 20:12:43 +00:00
|
|
|
if (lookup_name.v) {
|
|
|
|
efree(lookup_name.v);
|
2004-05-26 21:01:37 +00:00
|
|
|
}
|
2000-07-28 09:44:46 +00:00
|
|
|
return ret;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2007-07-11 11:19:58 +00:00
|
|
|
ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC) /* {{{ */
|
2005-08-11 23:35:03 +00:00
|
|
|
{
|
2006-02-22 10:02:15 +00:00
|
|
|
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);
|
|
|
|
}
|
2005-08-11 23:35:03 +00:00
|
|
|
}
|
2007-07-11 11:19:58 +00:00
|
|
|
/* }}} */
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2003-02-01 01:49:15 +00:00
|
|
|
* indent-tabs-mode: t
|
1999-04-07 18:10:10 +00:00
|
|
|
* End:
|
|
|
|
*/
|