Skip to content

Commit 7155662

Browse files
authored
Fix C++ build (#24786)
1 parent b8c55c5 commit 7155662

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎Zend/zend_portability.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ extern "C++" {
5858
/* Make the atomic types used by Zend available to C++ extensions. */
5959
using std::atomic_bool;
6060
using std::atomic_int;
61+
using std::atomic_thread_fence;
62+
using std::memory_order_acquire;
6163
}
6264
#else
6365
# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L

‎Zend/zend_types.h‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,16 @@ static zend_always_inline uint32_t zend_gc_delref_ex(zend_refcounted_h *p, uint3
963963
/* Fast class cache */
964964
static zend_always_inline bool zstr_has_ce_cache(const zend_string *s)
965965
{
966-
static_assert(sizeof(_Atomic uint32_t) == sizeof(uint32_t), "atomic size");
967-
static_assert(alignof(_Atomic uint32_t) == alignof(uint32_t), "atomic align");
968-
static_assert(ATOMIC_INT_LOCK_FREE == 2, "not always lock-free");
966+
#if defined(__cplusplus) || !defined(ATOMIC_INT_LOCK_FREE) || ATOMIC_INT_LOCK_FREE != 2
967+
uint32_t type_info = *(const volatile uint32_t *)&GC_TYPE_INFO(s);
968+
atomic_thread_fence(memory_order_acquire);
969+
#else
970+
static_assert(sizeof(_Atomic(uint32_t)) == sizeof(uint32_t), "atomic size");
971+
static_assert(alignof(_Atomic(uint32_t)) == alignof(uint32_t), "atomic align");
972+
973+
uint32_t type_info = atomic_load_explicit((_Atomic(uint32_t) *)&GC_TYPE_INFO(s), memory_order_acquire);
974+
#endif
969975

970-
uint32_t type_info = atomic_load_explicit((_Atomic uint32_t *)&GC_TYPE_INFO(s), memory_order_acquire);
971976
return (type_info & (IS_STR_CLASS_NAME_MAP_PTR << GC_FLAGS_SHIFT)) != 0;
972977
}
973978

0 commit comments

Comments
 (0)