xref: /PHP-7.4/Zend/zend_constants.h (revision 92ac598a)
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				(1<<0)				/* Case Sensitive */
26 #define CONST_PERSISTENT		(1<<1)				/* Persistent */
27 #define CONST_CT_SUBST			(1<<2)				/* Allow compile-time substitution */
28 #define CONST_NO_FILE_CACHE		(1<<3)				/* Can't be saved in file cache */
29 
30 #define	PHP_USER_CONSTANT   0x7fffff /* a constant defined in user space */
31 
32 /* Flag for zend_get_constant_ex(). Must not class with ZEND_FETCH_CLASS_* flags. */
33 #define ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK 0x1000
34 
35 typedef struct _zend_constant {
36 	zval value;
37 	zend_string *name;
38 } zend_constant;
39 
40 #define ZEND_CONSTANT_FLAGS(c) \
41 	(Z_CONSTANT_FLAGS((c)->value) & 0xff)
42 
43 #define ZEND_CONSTANT_MODULE_NUMBER(c) \
44 	(Z_CONSTANT_FLAGS((c)->value) >> 8)
45 
46 #define ZEND_CONSTANT_SET_FLAGS(c, _flags, _module_number) do { \
47 		Z_CONSTANT_FLAGS((c)->value) = \
48 			((_flags) & 0xff) | ((_module_number) << 8); \
49 	} while (0)
50 
51 #define REGISTER_NULL_CONSTANT(name, flags)  zend_register_null_constant((name), sizeof(name)-1, (flags), module_number)
52 #define REGISTER_BOOL_CONSTANT(name, bval, flags)  zend_register_bool_constant((name), sizeof(name)-1, (bval), (flags), module_number)
53 #define REGISTER_LONG_CONSTANT(name, lval, flags)  zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), module_number)
54 #define REGISTER_DOUBLE_CONSTANT(name, dval, flags)  zend_register_double_constant((name), sizeof(name)-1, (dval), (flags), module_number)
55 #define REGISTER_STRING_CONSTANT(name, str, flags)  zend_register_string_constant((name), sizeof(name)-1, (str), (flags), module_number)
56 #define REGISTER_STRINGL_CONSTANT(name, str, len, flags)  zend_register_stringl_constant((name), sizeof(name)-1, (str), (len), (flags), module_number)
57 
58 #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)
59 #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)
60 #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)
61 #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)
62 #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)
63 #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)
64 
65 #define REGISTER_MAIN_NULL_CONSTANT(name, flags)  zend_register_null_constant((name), sizeof(name)-1, (flags), 0)
66 #define REGISTER_MAIN_BOOL_CONSTANT(name, bval, flags)  zend_register_bool_constant((name), sizeof(name)-1, (bval), (flags), 0)
67 #define REGISTER_MAIN_LONG_CONSTANT(name, lval, flags)  zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), 0)
68 #define REGISTER_MAIN_DOUBLE_CONSTANT(name, dval, flags)  zend_register_double_constant((name), sizeof(name)-1, (dval), (flags), 0)
69 #define REGISTER_MAIN_STRING_CONSTANT(name, str, flags)  zend_register_string_constant((name), sizeof(name)-1, (str), (flags), 0)
70 #define REGISTER_MAIN_STRINGL_CONSTANT(name, str, len, flags)  zend_register_stringl_constant((name), sizeof(name)-1, (str), (len), (flags), 0)
71 
72 BEGIN_EXTERN_C()
73 void clean_module_constants(int module_number);
74 void free_zend_constant(zval *zv);
75 int zend_startup_constants(void);
76 int zend_shutdown_constants(void);
77 void zend_register_standard_constants(void);
78 ZEND_API int zend_verify_const_access(zend_class_constant *c, zend_class_entry *ce);
79 ZEND_API zval *zend_get_constant(zend_string *name);
80 ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len);
81 ZEND_API zval *zend_get_constant_ex(zend_string *name, zend_class_entry *scope, uint32_t flags);
82 ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, zend_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, char *strval, int flags, int module_number);
87 ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, char *strval, size_t strlen, int flags, int module_number);
88 ZEND_API int zend_register_constant(zend_constant *c);
89 #ifdef ZTS
90 void zend_copy_constants(HashTable *target, HashTable *sourc);
91 #endif
92 END_EXTERN_C()
93 
94 #define ZEND_CONSTANT_DTOR free_zend_constant
95 
96 #endif
97