|
| 1 | +From 95f9ab828f95c6ca5877e584ead109189d0cec61 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Andy Postnikov <apostnikov@gmail.com> |
| 3 | +Date: Thu, 30 Apr 2026 20:43:38 +0200 |
| 4 | +Subject: [PATCH] Replace XtOffsetOf() with offsetof() for PHP 8.6 |
| 5 | + |
| 6 | +PHP 8.6 removed XtOffsetOf(), which was an alias for the standard C |
| 7 | +offsetof() macro. Replace all usages in apc_cache.h and apc_iterator |
| 8 | +with offsetof() directly. |
| 9 | + |
| 10 | +Ref: https://github.com/php/php-src/commit/7114314c5a96c362b95663f7e7c9184586721f58 |
| 11 | +--- |
| 12 | + apc_cache.h | 2 +- |
| 13 | + apc_iterator.c | 2 +- |
| 14 | + apc_iterator.h | 2 +- |
| 15 | + 3 files changed, 3 insertions(+), 3 deletions(-) |
| 16 | + |
| 17 | +diff --git a/apc_cache.h b/apc_cache.h |
| 18 | +index 36e81123..1db9b29c 100644 |
| 19 | +--- a/apc_cache.h |
| 20 | ++++ b/apc_cache.h |
| 21 | +@@ -295,7 +295,7 @@ static inline void apc_cache_runlock(apc_cache_t *cache) { |
| 22 | + } |
| 23 | + |
| 24 | + /* APC_ENTRY_SIZE takes into account the trailing key-string + terminating 0-byte */ |
| 25 | +-#define APC_ENTRY_SIZE(key_len) (ZEND_MM_ALIGNED_SIZE(XtOffsetOf(apc_cache_entry_t, key.val) + key_len + 1)) |
| 26 | ++#define APC_ENTRY_SIZE(key_len) (ZEND_MM_ALIGNED_SIZE(offsetof(apc_cache_entry_t, key.val) + key_len + 1)) |
| 27 | + |
| 28 | + /* ENTRYAT and ENTRYOF are used to convert between offsets and pointers to cache entries. |
| 29 | + * Both expect the presence of cache->header that points to the cache header in the |
| 30 | +diff --git a/apc_iterator.c b/apc_iterator.c |
| 31 | +index 535a9df7..cb7edc3b 100644 |
| 32 | +--- a/apc_iterator.c |
| 33 | ++++ b/apc_iterator.c |
| 34 | +@@ -548,7 +548,7 @@ int apc_iterator_init(int module_number) { |
| 35 | + |
| 36 | + apc_iterator_object_handlers.clone_obj = NULL; |
| 37 | + apc_iterator_object_handlers.free_obj = apc_iterator_free; |
| 38 | +- apc_iterator_object_handlers.offset = XtOffsetOf(apc_iterator_t, obj); |
| 39 | ++ apc_iterator_object_handlers.offset = offsetof(apc_iterator_t, obj); |
| 40 | + |
| 41 | + return SUCCESS; |
| 42 | + } |
| 43 | +diff --git a/apc_iterator.h b/apc_iterator.h |
| 44 | +index d38a5a35..362dcb43 100644 |
| 45 | +--- a/apc_iterator.h |
| 46 | ++++ b/apc_iterator.h |
| 47 | +@@ -69,7 +69,7 @@ typedef struct _apc_iterator_t { |
| 48 | + zend_object obj; |
| 49 | + } apc_iterator_t; |
| 50 | + |
| 51 | +-#define apc_iterator_fetch_from(o) ((apc_iterator_t*)((char*)o - XtOffsetOf(apc_iterator_t, obj))) |
| 52 | ++#define apc_iterator_fetch_from(o) ((apc_iterator_t*)((char*)o - offsetof(apc_iterator_t, obj))) |
| 53 | + #define apc_iterator_fetch(z) apc_iterator_fetch_from(Z_OBJ_P(z)) |
| 54 | + |
| 55 | + typedef struct _apc_iterator_item_t { |
| 56 | +From d29e907791502af89a7996930f8dce5fd8efe4a1 Mon Sep 17 00:00:00 2001 |
| 57 | +From: Andy Postnikov <apostnikov@gmail.com> |
| 58 | +Date: Fri, 10 Apr 2026 02:28:52 +0200 |
| 59 | +Subject: [PATCH] Fix build against PHP 8.6 (EMPTY_SWITCH_DEFAULT_CASE removed) |
| 60 | + |
| 61 | +Replace EMPTY_SWITCH_DEFAULT_CASE() with ZEND_UNREACHABLE() in |
| 62 | +apc_persist.c and add a fallback definition for PHP < 8.0 in apc.h, |
| 63 | +matching php-src debug/release behavior. |
| 64 | + |
| 65 | +Modernize Windows CI to use php/php-windows-builder which handles |
| 66 | +packaging and artifact upload automatically. Add PHP 8.6 to Ubuntu CI. |
| 67 | + |
| 68 | +Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> |
| 69 | +--- |
| 70 | + .github/workflows/config.yml | 53 ++++++++---------------------------- |
| 71 | + apc.h | 10 +++++++ |
| 72 | + apc_persist.c | 6 ++-- |
| 73 | + 3 files changed, 26 insertions(+), 43 deletions(-) |
| 74 | + |
| 75 | +diff --git a/apc.h b/apc.h |
| 76 | +index 6e725d04..8bbe3971 100644 |
| 77 | +--- a/apc.h |
| 78 | ++++ b/apc.h |
| 79 | +@@ -67,6 +67,16 @@ |
| 80 | + #include "php.h" |
| 81 | + #include "main/php_streams.h" |
| 82 | + |
| 83 | ++/* ZEND_UNREACHABLE() was added in PHP 8.0. Provide fallback for PHP 7.x. |
| 84 | ++ * Remove this block when APCu drops support for PHP < 8.0. */ |
| 85 | ++#if PHP_VERSION_ID < 80000 |
| 86 | ++# if ZEND_DEBUG |
| 87 | ++# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); ZEND_ASSUME(0);} while (0) |
| 88 | ++# else |
| 89 | ++# define ZEND_UNREACHABLE() ZEND_ASSUME(0) |
| 90 | ++# endif |
| 91 | ++#endif |
| 92 | ++ |
| 93 | + /* console display functions */ |
| 94 | + PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); |
| 95 | + PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); |
| 96 | +diff --git a/apc_persist.c b/apc_persist.c |
| 97 | +index e322b8d2..531695f3 100644 |
| 98 | +--- a/apc_persist.c |
| 99 | ++++ b/apc_persist.c |
| 100 | +@@ -244,7 +244,8 @@ static zend_bool apc_persist_calc_zval(apc_persist_context_t *ctxt, const zval * |
| 101 | + case IS_RESOURCE: |
| 102 | + apc_warning("Cannot store resources in apcu cache"); |
| 103 | + return 0; |
| 104 | +- EMPTY_SWITCH_DEFAULT_CASE() |
| 105 | ++ default: |
| 106 | ++ ZEND_UNREACHABLE(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | +@@ -450,7 +451,8 @@ static void apc_persist_copy_zval_impl(apc_persist_context_t *ctxt, zval *zv) { |
| 111 | + if (!ptr) ptr = apc_persist_copy_ref(ctxt, Z_REF_P(zv)); |
| 112 | + ZVAL_REF(zv, ptr); |
| 113 | + return; |
| 114 | +- EMPTY_SWITCH_DEFAULT_CASE() |
| 115 | ++ default: |
| 116 | ++ ZEND_UNREACHABLE(); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | +From 90899684be91c4f750512c2f840f487286ecb807 Mon Sep 17 00:00:00 2001 |
| 121 | +From: Andy Postnikov <apostnikov@gmail.com> |
| 122 | +Date: Sat, 25 Jul 2026 20:10:30 +0200 |
| 123 | +Subject: [PATCH] Simplify console output helpers to macros over |
| 124 | + php_error_docref |
| 125 | + |
| 126 | +Replace the APC_PRINT_FUNCTION macro that generated four exported |
| 127 | +apc_error/apc_warning/apc_notice/apc_debug functions with thin variadic |
| 128 | +macros in apc.h that forward directly to php_error_docref(), and drop the |
| 129 | +generator block from apc.c entirely. |
| 130 | + |
| 131 | +This also fixes the build against PHP 8.6-dev: php/php-src@0a12b3e8268 |
| 132 | +removed the params argument from php_verror(), which the old |
| 133 | +APC_PRINT_FUNCTION body called. Forwarding to php_error_docref() instead |
| 134 | +sidesteps php_verror() altogether and works on all supported versions. |
| 135 | + |
| 136 | +Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |
| 137 | +--- |
| 138 | + apc.c | 21 --------------------- |
| 139 | + apc.h | 14 ++++++++++---- |
| 140 | + 2 files changed, 10 insertions(+), 25 deletions(-) |
| 141 | + |
| 142 | +diff --git a/apc.c b/apc.c |
| 143 | +index e2d039c..c6f4f16 100644 |
| 144 | +--- a/apc.c |
| 145 | ++++ b/apc.c |
| 146 | +@@ -34,27 +34,6 @@ |
| 147 | + #include "apc_globals.h" |
| 148 | + #include "php.h" |
| 149 | + |
| 150 | +-/* console display functions */ |
| 151 | +-#define APC_PRINT_FUNCTION(name, verbosity) \ |
| 152 | +- void apc_##name(const char *format, ...) \ |
| 153 | +- { \ |
| 154 | +- va_list args; \ |
| 155 | +- \ |
| 156 | +- va_start(args, format); \ |
| 157 | +- php_verror(NULL, "", verbosity, format, args); \ |
| 158 | +- va_end(args); \ |
| 159 | +- } |
| 160 | +- |
| 161 | +-APC_PRINT_FUNCTION(error, E_ERROR) |
| 162 | +-APC_PRINT_FUNCTION(warning, E_WARNING) |
| 163 | +-APC_PRINT_FUNCTION(notice, E_NOTICE) |
| 164 | +- |
| 165 | +-#ifdef APC_DEBUG |
| 166 | +-APC_PRINT_FUNCTION(debug, E_NOTICE) |
| 167 | +-#else |
| 168 | +-void apc_debug(const char *format, ...) {} |
| 169 | +-#endif |
| 170 | +- |
| 171 | + HashTable* apc_flip_hash(HashTable *hash) { |
| 172 | + zval data, *entry; |
| 173 | + HashTable *new_hash; |
| 174 | +diff --git a/apc.h b/apc.h |
| 175 | +index 8bbe397..cd9fa58 100644 |
| 176 | +--- a/apc.h |
| 177 | ++++ b/apc.h |
| 178 | +@@ -78,10 +78,16 @@ |
| 179 | + #endif |
| 180 | + |
| 181 | + /* console display functions */ |
| 182 | +-PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); |
| 183 | +-PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); |
| 184 | +-PHP_APCU_API void apc_notice(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); |
| 185 | +-PHP_APCU_API void apc_debug(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); |
| 186 | ++#define apc_error(...) php_error_docref(NULL, E_ERROR, __VA_ARGS__) |
| 187 | ++#define apc_warning(...) php_error_docref(NULL, E_WARNING, __VA_ARGS__) |
| 188 | ++#define apc_notice(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__) |
| 189 | ++ |
| 190 | ++#ifdef APC_DEBUG |
| 191 | ++# define apc_debug(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__) |
| 192 | ++#else |
| 193 | ++/* if (0) keeps compile-time format checking at zero runtime cost */ |
| 194 | ++# define apc_debug(...) do { if (0) php_error_docref(NULL, E_NOTICE, __VA_ARGS__); } while (0) |
| 195 | ++#endif |
| 196 | + |
| 197 | + /* apc_flip_hash flips keys and values for faster searching */ |
| 198 | + PHP_APCU_API HashTable* apc_flip_hash(HashTable *hash); |
| 199 | +-- |
| 200 | +2.55.0 |
| 201 | + |
0 commit comments