|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | Zend Engine | |
| 4 | + +----------------------------------------------------------------------+ |
| 5 | + | Copyright (c) 1998-2018 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@zend.com> | |
| 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_GET(ptr) \ |
| 55 | + ((((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L) ? \ |
| 56 | + *(void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1) : \ |
| 57 | + (void*)(*(ZEND_MAP_PTR(ptr)))) |
| 58 | +# define ZEND_MAP_PTR_SET(ptr, val) do { \ |
| 59 | + if (((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L) { \ |
| 60 | + *(void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1) = (val); \ |
| 61 | + } else { \ |
| 62 | + *(ZEND_MAP_PTR(ptr)) = (val); \ |
| 63 | + } \ |
| 64 | + } while (0) |
| 65 | +# define ZEND_MAP_PTR_INIT(ptr, val) do { \ |
| 66 | + ZEND_MAP_PTR(ptr) = (val); \ |
| 67 | + } while (0) |
| 68 | +# define ZEND_MAP_PTR_NEW(ptr) do { \ |
| 69 | + ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \ |
| 70 | + } while (0) |
| 71 | +#else |
| 72 | +# error "Unknown ZEND_MAP_PTR_KIND" |
| 73 | +#endif |
| 74 | + |
| 75 | +ZEND_API void zend_map_ptr_reset(void); |
| 76 | +ZEND_API void *zend_map_ptr_new(void); |
| 77 | +ZEND_API void zend_map_ptr_extend(size_t last); |
| 78 | + |
| 79 | +#endif /* ZEND_MAP_PTR_H */ |
| 80 | + |
| 81 | +/* |
| 82 | + * Local variables: |
| 83 | + * tab-width: 4 |
| 84 | + * c-basic-offset: 4 |
| 85 | + * indent-tabs-mode: t |
| 86 | + * End: |
| 87 | + * vim600: sw=4 ts=4 fdm=marker |
| 88 | + * vim<600: sw=4 ts=4 |
| 89 | + */ |
0 commit comments