From 90899684be91c4f750512c2f840f487286ecb807 Mon Sep 17 00:00:00 2001 From: Andy Postnikov Date: Sat, 25 Jul 2026 20:10:30 +0200 Subject: [PATCH] Simplify console output helpers to macros over php_error_docref Replace the APC_PRINT_FUNCTION macro that generated four exported apc_error/apc_warning/apc_notice/apc_debug functions with thin variadic macros in apc.h that forward directly to php_error_docref(), and drop the generator block from apc.c entirely. This also fixes the build against PHP 8.6-dev: php/php-src@0a12b3e8268 removed the params argument from php_verror(), which the old APC_PRINT_FUNCTION body called. Forwarding to php_error_docref() instead sidesteps php_verror() altogether and works on all supported versions. Co-Authored-By: Claude Opus 4.8 (1M context) --- apc.c | 21 --------------------- apc.h | 14 ++++++++++---- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/apc.c b/apc.c index e2d039ca..c6f4f16f 100644 --- a/apc.c +++ b/apc.c @@ -34,27 +34,6 @@ #include "apc_globals.h" #include "php.h" -/* console display functions */ -#define APC_PRINT_FUNCTION(name, verbosity) \ - void apc_##name(const char *format, ...) \ - { \ - va_list args; \ - \ - va_start(args, format); \ - php_verror(NULL, "", verbosity, format, args); \ - va_end(args); \ - } - -APC_PRINT_FUNCTION(error, E_ERROR) -APC_PRINT_FUNCTION(warning, E_WARNING) -APC_PRINT_FUNCTION(notice, E_NOTICE) - -#ifdef APC_DEBUG -APC_PRINT_FUNCTION(debug, E_NOTICE) -#else -void apc_debug(const char *format, ...) {} -#endif - HashTable* apc_flip_hash(HashTable *hash) { zval data, *entry; HashTable *new_hash; diff --git a/apc.h b/apc.h index 8bbe3971..cd9fa585 100644 --- a/apc.h +++ b/apc.h @@ -78,10 +78,16 @@ #endif /* console display functions */ -PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); -PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); -PHP_APCU_API void apc_notice(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); -PHP_APCU_API void apc_debug(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); +#define apc_error(...) php_error_docref(NULL, E_ERROR, __VA_ARGS__) +#define apc_warning(...) php_error_docref(NULL, E_WARNING, __VA_ARGS__) +#define apc_notice(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__) + +#ifdef APC_DEBUG +# define apc_debug(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__) +#else +/* if (0) keeps compile-time format checking at zero runtime cost */ +# define apc_debug(...) do { if (0) php_error_docref(NULL, E_NOTICE, __VA_ARGS__); } while (0) +#endif /* apc_flip_hash flips keys and values for faster searching */ PHP_APCU_API HashTable* apc_flip_hash(HashTable *hash);