Skip to content

Commit

Permalink
Fixed ZEND_MAP_PTR_KIND_PTR (it is not used)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Aug 23, 2021
1 parent 476c333 commit 116fa65
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ ZEND_API void zend_alloc_ce_cache(zend_string *type_name)
/* We use the refcount to keep map_ptr of corresponding type */
uint32_t ret;
do {
ret = (uint32_t)(uintptr_t)zend_map_ptr_new();
ret = ZEND_MAP_PTR_NEW_OFFSET();
} while (ret <= 2);
GC_ADD_FLAGS(type_name, IS_STR_CLASS_NAME_MAP_PTR);
GC_SET_REFCOUNT(type_name, ret);
Expand Down
43 changes: 18 additions & 25 deletions Zend/zend_map_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,24 @@
//# define ZEND_MAP_PTR_KIND ZEND_MAP_PTR_KIND_PTR
//#endif

#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
# define ZEND_MAP_PTR(ptr) \
#define ZEND_MAP_PTR(ptr) \
ptr ## __ptr
# define ZEND_MAP_PTR_DEF(type, name) \
#define ZEND_MAP_PTR_DEF(type, name) \
type * ZEND_MAP_PTR(name)
#define ZEND_MAP_PTR_OFFSET2PTR(offset) \
((void**)((char*)CG(map_ptr_base) + offset))
#define ZEND_MAP_PTR_PTR2OFFSET(ptr) \
((void*)(((char*)(ptr)) - ((char*)CG(map_ptr_base))))
#define ZEND_MAP_PTR_INIT(ptr, val) do { \
ZEND_MAP_PTR(ptr) = (val); \
} while (0)
#define ZEND_MAP_PTR_NEW(ptr) do { \
ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
} while (0)

#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
# define ZEND_MAP_PTR_NEW_OFFSET() \
((uint32_t)(uintptr_t)ZEND_MAP_PTR_PTR2OFFSET(zend_map_ptr_new()))
# define ZEND_MAP_PTR_GET(ptr) \
(*(ZEND_MAP_PTR(ptr)))
# define ZEND_MAP_PTR_GET_IMM(ptr) \
Expand All @@ -44,30 +57,16 @@
} while (0)
# define ZEND_MAP_PTR_SET_IMM(ptr, val) \
ZEND_MAP_PTR_SET(ptr, val)
# define ZEND_MAP_PTR_INIT(ptr, val) do { \
ZEND_MAP_PTR(ptr) = (val); \
} while (0)
# define ZEND_MAP_PTR_NEW(ptr) do { \
ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
} while (0)
# define ZEND_MAP_PTR_REAL_BASE(base) \
(base)
# define ZEND_MAP_PTR_SET_REAL_BASE(base, ptr) do { \
base = (ptr); \
} while (0)
# define ZEND_MAP_PTR_OFFSET2PTR(offset) \
((void**)((char*)CG(map_ptr_base) + offset))
#elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
# define ZEND_MAP_PTR(ptr) \
ptr ## __ptr
# define ZEND_MAP_PTR_DEF(type, name) \
type * ZEND_MAP_PTR(name)
# define ZEND_MAP_PTR_NEW_OFFSET() \
((uint32_t)(uintptr_t)zend_map_ptr_new())
# define ZEND_MAP_PTR_IS_OFFSET(ptr) \
(((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L)
# define ZEND_MAP_PTR_OFFSET2PTR(offset) \
((void**)((char*)CG(map_ptr_base) + offset))
# define ZEND_MAP_PTR_PTR2OFFSET(ptr) \
((void*)(((char*)(ptr)) - ((char*)CG(map_ptr_base))))
# define ZEND_MAP_PTR_GET(ptr) \
(*(ZEND_MAP_PTR_IS_OFFSET(ptr) ? \
ZEND_MAP_PTR_OFFSET2PTR((uintptr_t)ZEND_MAP_PTR(ptr)) : \
Expand All @@ -85,12 +84,6 @@
void **__p = ZEND_MAP_PTR_OFFSET2PTR((uintptr_t)ZEND_MAP_PTR(ptr)); \
*__p = (val); \
} while (0)
# define ZEND_MAP_PTR_INIT(ptr, val) do { \
ZEND_MAP_PTR(ptr) = (val); \
} while (0)
# define ZEND_MAP_PTR_NEW(ptr) do { \
ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
} while (0)
# define ZEND_MAP_PTR_REAL_BASE(base) \
((void*)(((uintptr_t)(base)) + 1))
# define ZEND_MAP_PTR_SET_REAL_BASE(base, ptr) do { \
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/zend_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name)
if ((GC_FLAGS(type_name) & GC_IMMUTABLE)
&& (GC_FLAGS(type_name) & IS_STR_PERMANENT)) {
do {
ret = (uint32_t)(uintptr_t)zend_map_ptr_new();
ret = ZEND_MAP_PTR_NEW_OFFSET();
} while (ret <= 2);
GC_SET_REFCOUNT(type_name, ret);
GC_ADD_FLAGS(type_name, IS_STR_CLASS_NAME_MAP_PTR);
Expand Down

0 comments on commit 116fa65

Please sign in to comment.