8000 Immutable clases and op_arrays by dstogov · Pull Request #3608 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

Immutable clases and op_arrays #3608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Hide offset encoding magic in ZEND_MAP_PTR_IS_OFFSET(), ZEND_MAP_PTR_…
…OFFSET2PTR() and ZEND_MAP_PTR_PTR2OFFSET() macros.
  • Loading branch information
dstogov committed Oct 17, 2018
commit 8dadca8864e66de70a24bdf1181bcf7dd8fb27d7
2 changes: 1 addition & 1 deletion Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ ZEND_API void *zend_map_ptr_new(void)
#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
return ptr;
#elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
return (void*)((CG(map_ptr_last) * sizeof(void*)) - (sizeof(void*) - 1));
return ZEND_MAP_PTR_PTR2OFFSET(ptr);
#else
# error "Unknown ZEND_MAP_PTR_KIND"
#endif
Expand Down
14 changes: 10 additions & 4 deletions Zend/zend_map_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@
ptr ## __ptr
# define ZEND_MAP_PTR_DEF(type, name) \
type * ZEND_MAP_PTR(name)
# define ZEND_MAP_PTR_IS_OFFSET(ptr) \
(((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L)
# define ZEND_MAP_PTR_OFFSET2PTR(ptr) \
((void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1))
# define ZEND_MAP_PTR_PTR2OFFSET(ptr) \
((void*)((uintptr_t)(((char*)(ptr)) - ((char*)CG(map_ptr_base))) | 1L))
# define ZEND_MAP_PTR_GET(ptr) \
((((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L) ? \
*(void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1) : \
(ZEND_MAP_PTR_IS_OFFSET(ptr) ? \
*(ZEND_MAP_PTR_OFFSET2PTR(ptr)) : \
(void*)(*(ZEND_MAP_PTR(ptr))))
# define ZEND_MAP_PTR_SET(ptr, val) do { \
if (((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L) { \
*(void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1) = (val); \
if (ZEND_MAP_PTR_IS_OFFSET(ptr)) { \
*(ZEND_MAP_PTR_OFFSET2PTR(ptr)) = (val); \
} else { \
*(ZEND_MAP_PTR(ptr)) = (val); \
} \
Expand Down
0