Skip to content

refactor: change use php_brotli_context in brotli_uncompress() #67

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

kjdev
Copy link
Owner

@kjdev kjdev commented May 13, 2025

Summary by CodeRabbit

  • Refactor

    • Improved internal handling of Brotli decoder creation and management for more consistent error reporting and streamlined decompression operations.
  • Bug Fixes

    • Enhanced error messages when decompression fails, providing clearer feedback to users.

Copy link

coderabbitai bot commented May 13, 2025

Walkthrough

The decoder creation process in the Brotli extension was refactored by introducing a new function that accepts an error-handling parameter, consolidating decoder initialization and parameter setting. Existing functions were updated to use the new context-based decoder management, and error reporting was made more flexible and consistent.

Changes

File(s) Change Summary
brotli.c Replaced php_brotli_context_create_decoder with php_brotli_context_create_decoder_ex accepting a fail flag; added a macro for backward compatibility; refactored uncompress functions to use the new context-based decoder creation and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant BrotliContext
    participant Decoder

    Caller->>BrotliContext: php_brotli_context_create_decoder_ex(ctx, fail)
    BrotliContext->>Decoder: Create and configure decoder
    alt Decoder creation fails
        BrotliContext->>Caller: Emit warning (format depends on fail), return FAILURE
    else Decoder creation succeeds
        BrotliContext->>Caller: Return SUCCESS
    end

    Caller->>BrotliContext: Use context for decompression (brotli_uncompress, etc.)
    BrotliContext->>Decoder: Stream decompression
    Caller->>BrotliContext: Close context (cleanup)
Loading

Possibly related PRs

  • refactor: php_brotli_context struct #60: Builds on the context struct refactor by extending unified php_brotli_context usage for decoder creation and error handling.
  • refactor: php_brotli_stream_data struct #61: Related to the consolidation of encoder/decoder states and buffers into the unified php_brotli_context.
  • Develop #58: Both PRs refactor Brotli context handling, with this PR focusing on internal decoder logic and the related PR on PHP-level context object representation.

Poem

In the warren where code does flow,
A decoder’s birth now starts to show—
With context clear and errors neat,
Warnings hop in tidy feet.
Rabbits cheer this tidy fix,
For Brotli’s streams are now a mix
Of clever hops and context tricks! 🐇

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4c1ee and 663de30.

📒 Files selected for processing (1)
  • brotli.c (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: kjdev
PR: kjdev/php-ext-brotli#64
File: brotli.c:122-134
Timestamp: 2025-05-02T04:03:47.808Z
Learning: In the php-ext-brotli extension, encoder/decoder resource cleanup is deliberately handled by the caller functions rather than within resource creation functions like `php_brotli_context_create_encoder_ex`. The cleanup is done via `php_brotli_context_close()` which properly destroys any encoder/decoder instances.
brotli.c (1)
Learnt from: kjdev
PR: kjdev/php-ext-brotli#64
File: brotli.c:122-134
Timestamp: 2025-05-02T04:03:47.808Z
Learning: In the php-ext-brotli extension, encoder/decoder resource cleanup is deliberately handled by the caller functions rather than within resource creation functions like `php_brotli_context_create_encoder_ex`. The cleanup is done via `php_brotli_context_close()` which properly destroys any encoder/decoder instances.
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: ci (7.0-alpine, ghcr.io/kjdev/php, linux/amd64)
  • GitHub Check: ci (8.0-alpine, ghcr.io/kjdev/php, linux/amd64)
  • GitHub Check: ci (7.4-alpine, ghcr.io/kjdev/php, linux/amd64)
  • GitHub Check: ci (8.1-alpine, php, linux/amd64)
  • GitHub Check: ci (8.1-alpine, apcu, php, linux/amd64)
  • GitHub Check: ci (8.1, x86, ts, vs16, false)
  • GitHub Check: ci (8.2, x86, nts, vs16, true)
  • GitHub Check: ci (8.2, x64, ts, vs16, true)
  • GitHub Check: ci (8.3, x86, ts, vs16, true)
🔇 Additional comments (4)
brotli.c (4)

213-229: Good refactoring approach with improved error handling flexibility

The introduction of php_brotli_context_create_decoder_ex with a fail parameter is a solid improvement that enables more consistent error handling. This mirrors the existing pattern used by php_brotli_context_create_encoder_ex, making the codebase more uniform.

The conditional prefix in error messages (line 218-219) provides better context depending on where the function is called from, making error messages more relevant to their usage context.


235-236: Good backward compatibility preservation

Adding this macro maintains backward compatibility for existing code that calls the original function. This is a clean approach that follows the same pattern as the encoder functions.


1424-1451: Improved resource management in brotli_uncompress

The refactoring to use the php_brotli_context structure provides better encapsulation and consistent resource handling. This approach consolidates the decoder state management with other context information, making the code more maintainable.

The change aligns with the learned behavior that resource cleanup is handled by the caller functions via php_brotli_context_close().


1472-1475: Consistent error handling in brotli_uncompress_init

Using the new decoder creation function with fail=1 improves error reporting clarity and consistency with the rest of the codebase.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kjdev
Copy link
Owner Author

kjdev commented May 13, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kjdev kjdev merged commit 663de30 into master May 13, 2025
74 checks passed
@kjdev kjdev deleted the refactor/uncompress branch May 13, 2025 03:37
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.

1 participant