1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 13:43:27 +08:00
|
|
|
| Copyright (c) 1998-2001 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 13:26:39 +08:00
|
|
|
| This source file is subject to version 0.92 of the Zend license, |
|
1999-07-16 22:58:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-03-06 13:26:39 +08:00
|
|
|
| http://www.zend.com/license/0_92.txt. |
|
1999-07-16 22:58:16 +08: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-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_constants.h"
|
|
|
|
#include "zend_variables.h"
|
|
|
|
#include "zend_operators.h"
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
|
|
|
|
2000-01-18 01:33:37 +08:00
|
|
|
void free_zend_constant(zend_constant *c)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
|
|
|
zval_dtor(&c->value);
|
|
|
|
}
|
|
|
|
free(c->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-15 00:00:47 +08:00
|
|
|
void copy_zend_constant(zend_constant *c)
|
|
|
|
{
|
|
|
|
c->name = zend_strndup(c->name, c->name_len);
|
2000-02-14 06:15:06 +08:00
|
|
|
if (!(c->flags & CONST_PERSISTENT)) {
|
|
|
|
zval_copy_ctor(&c->value);
|
|
|
|
}
|
1999-07-15 00:00:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void zend_copy_constants(HashTable *target, HashTable *source)
|
|
|
|
{
|
|
|
|
zend_constant tmp_constant;
|
|
|
|
|
2000-02-05 23:11:24 +08:00
|
|
|
zend_hash_copy(target, source, (copy_ctor_func_t) copy_zend_constant, &tmp_constant, sizeof(zend_constant));
|
1999-07-15 00:00:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
static int clean_non_persistent_constant(zend_constant *c)
|
|
|
|
{
|
|
|
|
if (c->flags & CONST_PERSISTENT) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int clean_module_constant(zend_constant *c, int *module_number)
|
|
|
|
{
|
|
|
|
if (c->module_number == *module_number) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void clean_module_constants(int module_number)
|
|
|
|
{
|
1999-04-21 11:49:09 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_hash_apply_with_argument(EG(zend_constants), (int (*)(void *,void *)) clean_module_constant, (void *) &module_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-21 01:02:11 +08:00
|
|
|
int zend_startup_constants(ELS_D)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef ZEND_WIN32
|
1999-04-08 02:10:10 +08:00
|
|
|
DWORD dwBuild=0;
|
|
|
|
DWORD dwVersion = GetVersion();
|
|
|
|
DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
|
|
|
|
DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
|
|
|
|
#endif
|
|
|
|
|
1999-07-15 00:00:47 +08:00
|
|
|
EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-07-15 00:00:47 +08:00
|
|
|
if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void zend_register_standard_constants(ELS_D)
|
|
|
|
{
|
1999-04-08 02:10:10 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
|
|
|
|
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-23 06:17:49 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
|
|
|
|
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 21:15:13 +08: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-23 06:17:49 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
|
|
|
|
|
|
|
|
/* true/false constants */
|
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_BOOL;
|
|
|
|
c.flags = CONST_PERSISTENT;
|
|
|
|
c.module_number = 0;
|
|
|
|
|
1999-12-31 21:56:59 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("TRUE"));
|
|
|
|
c.name_len = sizeof("TRUE");
|
1999-04-08 02:10:10 +08:00
|
|
|
c.value.value.lval = 1;
|
|
|
|
c.value.type = IS_BOOL;
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_register_constant(&c ELS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-12-31 21:56:59 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("FALSE"));
|
|
|
|
c.name_len = sizeof("FALSE");
|
1999-04-08 02:10:10 +08:00
|
|
|
c.value.value.lval = 0;
|
|
|
|
c.value.type = IS_BOOL;
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_register_constant(&c ELS_CC);
|
1999-12-28 20:05:48 +08:00
|
|
|
|
2000-06-27 02:15:33 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("ZEND_THREAD_SAFE"));
|
|
|
|
c.name_len = sizeof("ZEND_THREAD_SAFE");
|
|
|
|
c.value.value.lval = ZTS_V;
|
|
|
|
c.value.type = IS_BOOL;
|
|
|
|
zend_register_constant(&c ELS_CC);
|
|
|
|
|
1999-12-31 21:56:59 +08:00
|
|
|
c.name = zend_strndup(ZEND_STRL("NULL"));
|
|
|
|
c.name_len = sizeof("NULL");
|
2000-01-04 21:22:58 +08:00
|
|
|
c.value.type = IS_NULL;
|
1999-12-28 20:05:48 +08:00
|
|
|
zend_register_constant(&c ELS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-22 01:26:37 +08:00
|
|
|
int zend_shutdown_constants(ELS_D)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_hash_destroy(EG(zend_constants));
|
|
|
|
free(EG(zend_constants));
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void clean_non_persistent_constants(void)
|
|
|
|
{
|
1999-04-21 11:49:09 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_hash_apply(EG(zend_constants), (int (*)(void *)) clean_non_persistent_constant);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-22 01:26:37 +08:00
|
|
|
ZEND_API void zend_register_long_constant(char *name, uint name_len, long lval, int flags, int module_number ELS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_LONG;
|
|
|
|
c.value.value.lval = lval;
|
|
|
|
c.flags = flags;
|
|
|
|
c.name = zend_strndup(name,name_len);
|
|
|
|
c.name_len = name_len;
|
|
|
|
c.module_number = module_number;
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_register_constant(&c ELS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-22 01:26:37 +08:00
|
|
|
ZEND_API void zend_register_double_constant(char *name, uint name_len, double dval, int flags, int module_number ELS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_DOUBLE;
|
|
|
|
c.value.value.dval = dval;
|
|
|
|
c.flags = flags;
|
|
|
|
c.name = zend_strndup(name,name_len);
|
|
|
|
c.name_len = name_len;
|
|
|
|
c.module_number = module_number;
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_register_constant(&c ELS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-22 01:26:37 +08:00
|
|
|
ZEND_API void zend_register_stringl_constant(char *name, uint name_len, char *strval, uint strlen, int flags, int module_number ELS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zend_constant c;
|
|
|
|
|
|
|
|
c.value.type = IS_STRING;
|
|
|
|
c.value.value.str.val = strval;
|
|
|
|
c.value.value.str.len = strlen;
|
|
|
|
c.flags = flags;
|
|
|
|
c.name = zend_strndup(name,name_len);
|
|
|
|
c.name_len = name_len;
|
|
|
|
c.module_number = module_number;
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_register_constant(&c ELS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-22 01:26:37 +08:00
|
|
|
ZEND_API void zend_register_string_constant(char *name, uint name_len, char *strval, int flags, int module_number ELS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number ELS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_API int zend_get_constant(char *name, uint name_len, zval *result)
|
|
|
|
{
|
|
|
|
zend_constant *c;
|
|
|
|
char *lookup_name = estrndup(name,name_len);
|
|
|
|
int retval;
|
1999-04-21 11:49:09 +08:00
|
|
|
ELS_FETCH();
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
zend_str_tolower(lookup_name, name_len);
|
|
|
|
|
|
|
|
if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) {
|
|
|
|
if ((c->flags & CONST_CS) && memcmp(c->name, name, name_len)!=0) {
|
|
|
|
retval=0;
|
|
|
|
} else {
|
|
|
|
retval=1;
|
|
|
|
*result = c->value;
|
|
|
|
zval_copy_ctor(result);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
retval=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
efree(lookup_name);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-28 17:44:46 +08:00
|
|
|
ZEND_API int zend_register_constant(zend_constant *c ELS_DC)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
char *lowercase_name = zend_strndup(c->name, c->name_len);
|
2000-07-28 17:44:46 +08:00
|
|
|
int ret = SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("Registering constant for module %d\n",c->module_number);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
zend_str_tolower(lowercase_name, c->name_len);
|
|
|
|
if (zend_hash_add(EG(zend_constants), lowercase_name, c->name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
|
|
|
|
zval_dtor(&c->value);
|
2000-07-28 17:44:46 +08:00
|
|
|
zend_error(E_NOTICE,"Constant %s already defined",lowercase_name);
|
|
|
|
ret = FAILURE;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
free(lowercase_name);
|
2000-07-28 17:44:46 +08:00
|
|
|
return ret;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|