Skip to content

Commit b457c69

Browse files
andypostclaude
andcommitted
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) <noreply@anthropic.com>
1 parent bc9e296 commit b457c69

2 files changed

Lines changed: 10 additions & 25 deletions

File tree

apc.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,6 @@
3434
#include "apc_globals.h"
3535
#include "php.h"
3636

37-
/* console display functions */
38-
#define APC_PRINT_FUNCTION(name, verbosity) \
39-
void apc_##name(const char *format, ...) \
40-
{ \
41-
va_list args; \
42-
\
43-
va_start(args, format); \
44-
php_verror(NULL, "", verbosity, format, args); \
45-
va_end(args); \
46-
}
47-
48-
APC_PRINT_FUNCTION(error, E_ERROR)
49-
APC_PRINT_FUNCTION(warning, E_WARNING)
50-
APC_PRINT_FUNCTION(notice, E_NOTICE)
51-
52-
#ifdef APC_DEBUG
53-
APC_PRINT_FUNCTION(debug, E_NOTICE)
54-
#else
55-
void apc_debug(const char *format, ...) {}
56-
#endif
57-
5837
HashTable* apc_flip_hash(HashTable *hash) {
5938
zval data, *entry;
6039
HashTable *new_hash;

apc.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@
7878
#endif
7979

8080
/* console display functions */
81-
PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
82-
PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
83-
PHP_APCU_API void apc_notice(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
84-
PHP_APCU_API void apc_debug(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
81+
#define apc_error(...) php_error_docref(NULL, E_ERROR, __VA_ARGS__)
82+
#define apc_warning(...) php_error_docref(NULL, E_WARNING, __VA_ARGS__)
83+
#define apc_notice(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__)
84+
85+
#ifdef APC_DEBUG
86+
# define apc_debug(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__)
87+
#else
88+
/* if (0) keeps compile-time format checking at zero runtime cost */
89+
# define apc_debug(...) do { if (0) php_error_docref(NULL, E_NOTICE, __VA_ARGS__); } while (0)
90+
#endif
8591

8692
/* apc_flip_hash flips keys and values for faster searching */
8793
PHP_APCU_API HashTable* apc_flip_hash(HashTable *hash);

0 commit comments

Comments
 (0)