Skip to content

Simplify console output helpers - #630

Merged
madmajestro merged 1 commit into
krakjoe:masterfrom
andypost:simplify-console-helpers
Jul 26, 2026
Merged

Simplify console output helpers#630
madmajestro merged 1 commit into
krakjoe:masterfrom
andypost:simplify-console-helpers

Conversation

@andypost

Copy link
Copy Markdown
Contributor

Simplify console output helpers

Follow-up to #629, per @madmajestro's review suggestion there.

Replaces the APC_PRINT_FUNCTION generator in apc.c — which produced four
exported apc_error / apc_warning / apc_notice / apc_debug functions —
with thin variadic macros in apc.h that forward straight to
php_error_docref():

#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__)

Net −16 lines, and it supersedes #629: the old generator body called
php_verror(), whose signature changed in php/php-src@0a12b3e8268 (params arg
removed) and broke the build against PHP 8.6-dev. Forwarding to
php_error_docref() sidesteps php_verror() entirely and builds on all
supported versions. If this lands, #629 can be closed.

Trade-off: ABI

Pro — simpler (no apc.c code, no va_list/vspprintf/efree
plumbing), one fewer indirection, and format-string checking is preserved via
php_error_docref's own printf attribute. apc_debug also stops evaluating
its arguments when APC_DEBUG is off (do {} while (0)), which is the usual,
slightly-better behaviour.

Con — the four functions were declared PHP_APCU_API, i.e. exported
symbols
; turning them into macros removes them from the ABI. They're internal
console helpers (no in-tree or bc/ caller takes their address or uses them
outside a direct call), so the practical risk is nil — but it is technically a
public-symbol removal, hence a separate PR for you to decide rather than folded
into the #629 build-fix.

Verification

  • All translation units that use these macros compile clean against php-src
    master (new 4-arg php_verror present in main/php.h).
  • Counter-check: pristine master apcu fails the same compile on the
    php_verror argument mismatch — the exact break Fix build against PHP 8.6 (php_verror params argument removed) #629 addresses — confirming
    the fix is real and not a no-op.
  • APC_DEBUG=1 build compiles; no -Wunused fallout from the disabled
    apc_debug.

@andypost

Copy link
Copy Markdown
Contributor Author

Supersedes #629 (the minimal php_verror build-fix). This PR fixes the same PHP 8.6-dev build break and additionally applies @madmajestro's cleanup suggestion from that review. If this is preferred, #629 can be closed; if the ABI removal is unwanted, #629 remains the minimal fix.

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>
@andypost
andypost force-pushed the simplify-console-helpers branch from 22aaf7a to b457c69 Compare July 26, 2026 02:40
@andypost

Copy link
Copy Markdown
Contributor Author

Pushed a small refinement: with APC_DEBUG off, apc_debug is now

do { if (0) php_error_docref(NULL, E_NOTICE, __VA_ARGS__); } while (0)

instead of a bare do {} while (0). The if (0) keeps compile-time -Wformat checking of debug call sites in normal (non-debug) builds at zero runtime cost — verified that a deliberately mismatched format in an apc_debug() call now warns even without --enable-apcu-debug. Previously a bad debug format would only surface in debug builds, which CI doesn't exercise.

@madmajestro madmajestro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

I think this ABI break is more of a theoretical issue. No other PHP extension should rely on APCu logging functions that were quite obviously intended for internal use. Especially since that functionality is also available via php_error_docref() in the PHP core. Not even the apcu-bc extension depends on these functions.

@madmajestro
madmajestro merged commit 9089968 into krakjoe:master Jul 26, 2026
51 checks passed
@andypost
andypost deleted the simplify-console-helpers branch July 26, 2026 12:29
@andypost

Copy link
Copy Markdown
Contributor Author

Thank you, awaiting beta stability of 8.6 now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants