xref: /PHP-7.4/Zend/zend_map_ptr.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: Dmitry Stogov <dmitry@php.net>                              |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef ZEND_MAP_PTR_H
20 #define ZEND_MAP_PTR_H
21 
22 #include "zend_portability.h"
23 
24 #define ZEND_MAP_PTR_KIND_PTR           0
25 #define ZEND_MAP_PTR_KIND_PTR_OR_OFFSET 1
26 
27 //#if defined(ZTS) || defined(TSRM_WIN32)
28 # define ZEND_MAP_PTR_KIND ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
29 //#else
30 //# define ZEND_MAP_PTR_KIND ZEND_MAP_PTR_KIND_PTR
31 //#endif
32 
33 #if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
34 # define ZEND_MAP_PTR(ptr) \
35 	ptr ## __ptr
36 # define ZEND_MAP_PTR_DEF(type, name) \
37 	type * ZEND_MAP_PTR(name)
38 # define ZEND_MAP_PTR_GET(ptr) \
39 	(*(ZEND_MAP_PTR(ptr)))
40 # define ZEND_MAP_PTR_SET(ptr, val) do { \
41 		(*(ZEND_MAP_PTR(ptr))) = (val); \
42 	} while (0)
43 # define ZEND_MAP_PTR_INIT(ptr, val) do { \
44 		ZEND_MAP_PTR(ptr) = (val); \
45 	} while (0)
46 # define ZEND_MAP_PTR_NEW(ptr) do { \
47 		ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
48 	} while (0)
49 #elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
50 # define ZEND_MAP_PTR(ptr) \
51 	ptr ## __ptr
52 # define ZEND_MAP_PTR_DEF(type, name) \
53 	type * ZEND_MAP_PTR(name)
54 # define ZEND_MAP_PTR_IS_OFFSET(ptr) \
55 	(((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L)
56 # define ZEND_MAP_PTR_OFFSET2PTR(ptr) \
57 	((void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1))
58 # define ZEND_MAP_PTR_PTR2OFFSET(ptr) \
59 	((void*)((uintptr_t)(((char*)(ptr)) - ((char*)CG(map_ptr_base))) | 1L))
60 # define ZEND_MAP_PTR_GET(ptr) \
61 	(ZEND_MAP_PTR_IS_OFFSET(ptr) ? \
62 		*(ZEND_MAP_PTR_OFFSET2PTR(ptr)) : \
63 		(void*)(*(ZEND_MAP_PTR(ptr))))
64 # define ZEND_MAP_PTR_SET(ptr, val) do { \
65 		if (ZEND_MAP_PTR_IS_OFFSET(ptr)) { \
66 			*(ZEND_MAP_PTR_OFFSET2PTR(ptr)) = (val); \
67 		} else { \
68 			*(ZEND_MAP_PTR(ptr)) = (val); \
69 		} \
70 	} while (0)
71 # define ZEND_MAP_PTR_INIT(ptr, val) do { \
72 		ZEND_MAP_PTR(ptr) = (val); \
73 	} while (0)
74 # define ZEND_MAP_PTR_NEW(ptr) do { \
75 		ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
76 	} while (0)
77 #else
78 # error "Unknown ZEND_MAP_PTR_KIND"
79 #endif
80 
81 ZEND_API void  zend_map_ptr_reset(void);
82 ZEND_API void *zend_map_ptr_new(void);
83 ZEND_API void  zend_map_ptr_extend(size_t last);
84 
85 #endif /* ZEND_MAP_PTR_H */
86