-
Notifications
You must be signed in to change notification settings - Fork 29
Refactor/coder create #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis change refactors the Brotli PHP extension by introducing a unified Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PHP_Extension
participant Brotli_Lib
User->>PHP_Extension: Request compression/decompression
PHP_Extension->>PHP_Extension: Initialize php_brotli_context
alt Compression
PHP_Extension->>PHP_Extension: php_brotli_context_create_encoder
else Decompression
PHP_Extension->>PHP_Extension: php_brotli_context_create_decoder
end
PHP_Extension->>Brotli_Lib: Perform compression/decompression using context
Brotli_Lib-->>PHP_Extension: Return result
PHP_Extension-->>User: Return processed data
Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
brotli.c (1)
111-143
:⚠️ Potential issueCheck return values of
BrotliEncoderSetParameter
to avoid silent failureThe three
BrotliEncoderSetParameter
calls may legitimately fail (e.g. if Brotli adds range checks in future versions).
Right now failure is ignored, leaving the context in an indeterminate state and leaking the freshly created encoder instance.- BrotliEncoderSetParameter(ctx->encoder, BROTLI_PARAM_QUALITY, quality); - BrotliEncoderSetParameter(ctx->encoder, BROTLI_PARAM_LGWIN, lgwin); - BrotliEncoderSetParameter(ctx->encoder, BROTLI_PARAM_MODE, mode); + if (!BrotliEncoderSetParameter(ctx->encoder, BROTLI_PARAM_QUALITY, quality) || + !BrotliEncoderSetParameter(ctx->encoder, BROTLI_PARAM_LGWIN, lgwin) || + !BrotliEncoderSetParameter(ctx->encoder, BROTLI_PARAM_MODE, mode)) { + BrotliEncoderDestroyInstance(ctx->encoder); + ctx->encoder = NULL; + return FAILURE; + }Fail‐fast behaviour makes caller-side error handling reliable and prevents memory leaks.
🧹 Nitpick comments (2)
brotli.c (2)
89-98
: Consider tracking buffer capacity & improving documentationGreat to see the unified context struct – it will remove a lot of duplicated plumbing.
Two small suggestions:
output
is treated as a grow-able buffer in several places (erealloc
, pointer arithmetics). Storing an additionalsize_t output_capacity
(or re-usingavailable_out
) inside the struct would make it easier to reason about the currently allocated size and would guard against accidental overruns.A short comment on the lifetime semantics of each pointer (e.g. “owned by context / borrowed from caller”) will help future maintainers, especially now that the same struct is shared by encoder and decoder paths.
100-109
:php_brotli_context_init()
– zero the entire struct in one goManually assigning every member works, but using
memset(ctx, 0, sizeof(*ctx))
at the top of this helper would:
- keep the function correct if new fields are added later,
- avoid the risk of missing a member, and
- produce identical machine code after optimisation.
Not critical, yet a one-liner makes the intent unmistakable.
static void php_brotli_context_init(php_brotli_context *ctx) { - ctx->encoder = NULL; - ctx->decoder = NULL; - ctx->available_in = 0; - ctx->next_in = NULL; - ctx->available_out = 0; - ctx->next_out = NULL; - ctx->output = NULL; + memset(ctx, 0, sizeof(*ctx)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
brotli.c
(8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
- GitHub Check: ci (7.1-alpine, ghcr.io/kjdev/php, linux/amd64)
- GitHub Check: ci (8.1-zts-alpine, system, apcu, php, linux/amd64)
- GitHub Check: ci (7.2-alpine, ghcr.io/kjdev/php, linux/amd64)
- GitHub Check: ci (7.4-alpine, ghcr.io/kjdev/php, linux/amd64)
- GitHub Check: ci (8.3-alpine, apcu, php, linux/386)
- GitHub Check: ci (8.2-zts-alpine, php, linux/amd64)
- GitHub Check: ci (8.3-zts-alpine, system, apcu, php, linux/amd64)
- GitHub Check: ci (8.4-alpine, system, apcu, php, linux/amd64)
- GitHub Check: ci (8.2-zts-alpine, apcu, php, linux/amd64)
- GitHub Check: ci (8.3-zts-alpine, php, linux/amd64)
- GitHub Check: ci (8.2-alpine, php, linux/amd64)
- GitHub Check: ci (8.4-alpine, php, linux/amd64)
- GitHub Check: ci (8.2, x86, ts, vs16, true)
- GitHub Check: ci (8.2, x86, ts, vs16, false)
- GitHub Check: ci (8.2, x86, nts, vs16, true)
- GitHub Check: ci (8.3, x64, ts, vs16, true)
- GitHub Check: ci (8.3, x86, ts, vs16, false)
- GitHub Check: ci (8.4, x64, ts, vs17, true)
- GitHub Check: ci (8.4, x86, nts, vs17, true)
🔇 Additional comments (5)
brotli.c (5)
230-235
: Good guard around encoder initialisation in output handlerThe new call to
php_brotli_context_create_encoder()
simplifies output-handler setup and correctly aborts on failure – nice!
303-305
: Restart branch mirrors start-up logic correctlyRe-initialising the context after a CLEAN event via the same helper keeps both branches consistent – looks good.
780-782
: Stream opener — parameter propagation is soundBoth the write (compress) and read (decompress) paths now rely on the consolidated helpers. Error handling propagates
FAILURE
back to the caller and cleans up the partially-initialised stream; behaviour is identical to the old code. 👍Also applies to: 791-792
1181-1187
: Incremental compress init passes user-supplied mode verbatimThe wrapper correctly forwards
mode
to the helper; with the stricter validation added earlier this remains safe.
1351-1355
: Incremental uncompress init keeps parity with compress initDecoder context creation is now symmetric with the encoder path – no issues spotted.
Summary by CodeRabbit