projects/aports·blob master · refs

80 lines · 2.9 KiB

1Patch-Source: https://github.com/krakjoe/apcu/commit/90899684be91c4f750512c2f840f487286ecb807
2From 90899684be91c4f750512c2f840f487286ecb807 Mon Sep 17 00:00:00 2001
3From: Andy Postnikov <[email protected]>
4Date: Sat, 25 Jul 2026 20:10:30 +0200
5Subject: [PATCH] Simplify console output helpers to macros over
6 php_error_docref
7
8Replace the APC_PRINT_FUNCTION macro that generated four exported
9apc_error/apc_warning/apc_notice/apc_debug functions with thin variadic
10macros in apc.h that forward directly to php_error_docref(), and drop the
11generator block from apc.c entirely.
12
13This also fixes the build against PHP 8.6-dev: php/php-src@0a12b3e8268
14removed the params argument from php_verror(), which the old
15APC_PRINT_FUNCTION body called. Forwarding to php_error_docref() instead
16sidesteps php_verror() altogether and works on all supported versions.
17
18Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
19---
20 apc.c | 21 ---------------------
21 apc.h | 14 ++++++++++----
22 2 files changed, 10 insertions(+), 25 deletions(-)
23
24diff --git a/apc.c b/apc.c
25index e2d039ca..c6f4f16f 100644
26--- a/apc.c
27+++ b/apc.c
28@@ -34,27 +34,6 @@
29 #include "apc_globals.h"
30 #include "php.h"
31
32-/* console display functions */
33-#define APC_PRINT_FUNCTION(name, verbosity) \
34- void apc_##name(const char *format, ...) \
35- { \
36- va_list args; \
37- \
38- va_start(args, format); \
39- php_verror(NULL, "", verbosity, format, args); \
40- va_end(args); \
41- }
42-
43-APC_PRINT_FUNCTION(error, E_ERROR)
44-APC_PRINT_FUNCTION(warning, E_WARNING)
45-APC_PRINT_FUNCTION(notice, E_NOTICE)
46-
47-#ifdef APC_DEBUG
48-APC_PRINT_FUNCTION(debug, E_NOTICE)
49-#else
50-void apc_debug(const char *format, ...) {}
51-#endif
52-
53 HashTable* apc_flip_hash(HashTable *hash) {
54 zval data, *entry;
55 HashTable *new_hash;
56diff --git a/apc.h b/apc.h
57index 8bbe3971..cd9fa585 100644
58--- a/apc.h
59+++ b/apc.h
60@@ -78,10 +78,16 @@
61 #endif
62
63 /* console display functions */
64-PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
65-PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
66-PHP_APCU_API void apc_notice(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
67-PHP_APCU_API void apc_debug(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
68+#define apc_error(...) php_error_docref(NULL, E_ERROR, __VA_ARGS__)
69+#define apc_warning(...) php_error_docref(NULL, E_WARNING, __VA_ARGS__)
70+#define apc_notice(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__)
71+
72+#ifdef APC_DEBUG
73+# define apc_debug(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__)
74+#else
75+/* if (0) keeps compile-time format checking at zero runtime cost */
76+# define apc_debug(...) do { if (0) php_error_docref(NULL, E_NOTICE, __VA_ARGS__); } while (0)
77+#endif
78
79 /* apc_flip_hash flips keys and values for faster searching */
80 PHP_APCU_API HashTable* apc_flip_hash(HashTable *hash);