1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 2.00 of the Zend license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.zend.com/license/2_00.txt. |
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@php.net> |
16 | Zeev Suraski <zeev@php.net> |
17 +----------------------------------------------------------------------+
18 */
19
20 #ifndef ZEND_CONSTANTS_H
21 #define ZEND_CONSTANTS_H
22
23 #include "zend_globals.h"
24
25 #define CONST_CS 0 /* No longer used -- always case sensitive */
26 #define CONST_PERSISTENT (1<<0) /* Persistent */
27 #define CONST_NO_FILE_CACHE (1<<1) /* Can't be saved in file cache */
28 #define CONST_DEPRECATED (1<<2) /* Deprecated */
29 #define CONST_OWNED (1<<3) /* constant should be destroyed together with class */
30
31 #define PHP_USER_CONSTANT 0x7fffff /* a constant defined in user space */
32
33 typedef struct _zend_constant {
34 zval value;
35 zend_string *name;
36 zend_string *filename;
37 } zend_constant;
38
39 #define ZEND_CONSTANT_FLAGS(c) \
40 (Z_CONSTANT_FLAGS((c)->value) & 0xff)
41
42 #define ZEND_CONSTANT_MODULE_NUMBER(c) \
43 (Z_CONSTANT_FLAGS((c)->value) >> 8)
44
45 #define ZEND_CONSTANT_SET_FLAGS(c, _flags, _module_number) do { \
46 Z_CONSTANT_FLAGS((c)->value) = \
47 ((_flags) & 0xff) | ((_module_number) << 8); \
48 } while (0)
49
50 #define REGISTER_NULL_CONSTANT(name, flags) zend_register_null_constant((name), sizeof(name)-1, (flags), module_number)
51 #define REGISTER_BOOL_CONSTANT(name, bval, flags) zend_register_bool_constant((name), sizeof(name)-1, (bval), (flags), module_number)
52 #define REGISTER_LONG_CONSTANT(name, lval, flags) zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), module_number)
53 #define REGISTER_DOUBLE_CONSTANT(name, dval, flags) zend_register_double_constant((name), sizeof(name)-1, (dval), (flags), module_number)
54 #define REGISTER_STRING_CONSTANT(name, str, flags) zend_register_string_constant((name), sizeof(name)-1, (str), (flags), module_number)
55 #define REGISTER_STRINGL_CONSTANT(name, str, len, flags) zend_register_stringl_constant((name), sizeof(name)-1, (str), (len), (flags), module_number)
56
57 #define REGISTER_NS_NULL_CONSTANT(ns, name, flags) zend_register_null_constant(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, (flags), module_number)
58 #define REGISTER_NS_BOOL_CONSTANT(ns, name, bval, flags) zend_register_bool_constant(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, (bval), (flags), module_number)
59 #define REGISTER_NS_LONG_CONSTANT(ns, name, lval, flags) zend_register_long_constant(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, (lval), (flags), module_number)
60 #define REGISTER_NS_DOUBLE_CONSTANT(ns, name, dval, flags) zend_register_double_constant(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, (dval), (flags), module_number)
61 #define REGISTER_NS_STRING_CONSTANT(ns, name, str, flags) zend_register_string_constant(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, (str), (flags), module_number)
62 #define REGISTER_NS_STRINGL_CONSTANT(ns, name, str, len, flags) zend_register_stringl_constant(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, (str), (len), (flags), module_number)
63
64 #define REGISTER_MAIN_NULL_CONSTANT(name, flags) zend_register_null_constant((name), sizeof(name)-1, (flags), 0)
65 #define REGISTER_MAIN_BOOL_CONSTANT(name, bval, flags) zend_register_bool_constant((name), sizeof(name)-1, (bval), (flags), 0)
66 #define REGISTER_MAIN_LONG_CONSTANT(name, lval, flags) zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), 0)
67 #define REGISTER_MAIN_DOUBLE_CONSTANT(name, dval, flags) zend_register_double_constant((name), sizeof(name)-1, (dval), (flags), 0)
68 #define REGISTER_MAIN_STRING_CONSTANT(name, str, flags) zend_register_string_constant((name), sizeof(name)-1, (str), (flags), 0)
69 #define REGISTER_MAIN_STRINGL_CONSTANT(name, str, len, flags) zend_register_stringl_constant((name), sizeof(name)-1, (str), (len), (flags), 0)
70
71 BEGIN_EXTERN_C()
72 void clean_module_constants(int module_number);
73 void free_zend_constant(zval *zv);
74 void zend_startup_constants(void);
75 void zend_register_standard_constants(void);
76 ZEND_API bool zend_verify_const_access(zend_class_constant *c, zend_class_entry *ce);
77 ZEND_API zval *zend_get_constant(zend_string *name);
78 ZEND_API zend_constant *zend_get_constant_ptr(zend_string *name);
79 ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len);
80 ZEND_API zval *zend_get_constant_ex(zend_string *name, zend_class_entry *scope, uint32_t flags);
81 ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *constant_name, zend_class_entry *scope, uint32_t flags);
82 ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, bool bval, int flags, int module_number);
83 ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number);
84 ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number);
85 ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number);
86 ZEND_API void zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
87 ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
88 ZEND_API zend_result zend_register_constant(zend_constant *c);
89 #ifdef ZTS
90 void zend_copy_constants(HashTable *target, HashTable *source);
91 #endif
92
93 ZEND_API zend_constant *_zend_get_special_const(const char *name, size_t name_len);
94
zend_get_special_const(const char * name,size_t name_len)95 static zend_always_inline zend_constant *zend_get_special_const(
96 const char *name, size_t name_len) {
97 if (name_len == 4 || name_len == 5) {
98 return _zend_get_special_const(name, name_len);
99 }
100 return NULL;
101 }
102
103 END_EXTERN_C()
104
105 #define ZEND_CONSTANT_DTOR free_zend_constant
106
107 #endif
108