Skip to content

feat: add unique_resource #16

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

feat: add unique_resource #16

wants to merge 1 commit into from

Conversation

sjinks
Copy link
Owner

@sjinks sjinks commented Mar 12, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new resource management utility, unique_resource, for safe and automatic resource cleanup with custom deleters.
    • Added a factory function for creating unique_resource instances that only take ownership if the resource is valid.
  • Documentation

    • Expanded README with details, usage examples, and API documentation for unique_resource.
  • Examples

    • Added an example demonstrating unique_resource for managing files and sockets.
  • Tests

    • Added comprehensive unit tests for unique_resource covering creation, ownership transfer, release, reset, and exception safety.
  • Chores

    • Updated build and configuration files to support new examples and tests.
    • Adjusted code quality checks for examples and tests.

@sjinks sjinks self-assigned this Mar 12, 2025
Copy link

github-actions bot commented Mar 12, 2025

Test Results

  5 files    5 suites   37s ⏱️
 44 tests  44 ✅ 0 💤 0 ❌
220 runs  220 ✅ 0 💤 0 ❌

Results for commit 6c5a909.

♻️ This comment has been updated with latest results.

@sjinks sjinks force-pushed the add-unqiue_resource branch from 70f88bf to 594c628 Compare March 12, 2025 01:39
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 89.53488% with 9 lines in your changes missing coverage. Please review.

Project coverage is 84.71%. Comparing base (11c8203) to head (6c5a909).

Files with missing lines Patch % Lines
src/unique_resource.h 89.53% 0 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #16      +/-   ##
==========================================
+ Coverage   78.87%   84.71%   +5.84%     
==========================================
  Files           1        2       +1     
  Lines          71      157      +86     
  Branches       15       23       +8     
==========================================
+ Hits           56      133      +77     
- Partials       15       24       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sjinks sjinks force-pushed the add-unqiue_resource branch 5 times, most recently from a336c28 to 18a6066 Compare March 12, 2025 17:02
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
64.6% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@sjinks sjinks force-pushed the add-unqiue_resource branch from 18a6066 to 6c5a909 Compare June 24, 2025 08:37
Copy link

sonarqubecloud bot commented Jun 24, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
64.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sjinks
Copy link
Owner Author

sjinks commented Jul 29, 2025

@coderabbitai summary

@sjinks
Copy link
Owner Author

sjinks commented Jul 29, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jul 29, 2025

✅ Actions performed

Summary regeneration triggered.

Copy link

coderabbitai bot commented Jul 29, 2025

Warning

Rate limit exceeded

@sjinks has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 11c8203 and 6c5a909.

📒 Files selected for processing (9)
  • .github/workflows/ci-vcpkg.yml (0 hunks)
  • README.md (4 hunks)
  • examples/.clang-tidy (1 hunks)
  • examples/CMakeLists.txt (1 hunks)
  • examples/unique_resource.cpp (1 hunks)
  • src/unique_resource.h (1 hunks)
  • test/.clang-tidy (1 hunks)
  • test/CMakeLists.txt (1 hunks)
  • test/unique_resource.cpp (1 hunks)

Walkthrough

A new resource management utility, unique_resource, is introduced, including its implementation, documentation, example usage, and comprehensive unit tests. The build system and documentation are updated to support and showcase this addition. Minor configuration changes are made to Clang-Tidy and CI workflow files, with no impact on existing functionality or exported interfaces except for the new utility.

Changes

Cohort / File(s) Change Summary
Resource Management Utility Implementation
src/unique_resource.h
Adds the unique_resource template class and make_unique_resource_checked factory, providing a generic RAII wrapper for resource handles with custom deleters, including full move semantics and exception safety.
Documentation and Examples
README.md, examples/unique_resource.cpp
Updates documentation to describe and demonstrate unique_resource, adds example usage for file and socket management, and details API and usage patterns.
Build System Updates
examples/CMakeLists.txt, test/CMakeLists.txt
Adds the new example and test files for unique_resource to the build configuration as new targets and sources.
Unit Tests for unique_resource
test/unique_resource.cpp
Introduces a comprehensive test suite for unique_resource, covering construction, move semantics, release/reset, exception safety, and pointer-like access.
Clang-Tidy Configuration
examples/.clang-tidy, test/.clang-tidy
Adds a clang-tidy config to examples enabling cppcoreguidelines-owning-memory and disables this check in test.
CI Workflow Cleanup
.github/workflows/ci-vcpkg.yml
Removes a commented-out macOS Xcode version fix step; no effect on workflow logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant unique_resource
    participant Resource
    participant Deleter

    User->>unique_resource: Construct with Resource, Deleter
    unique_resource->>Resource: Store handle
    unique_resource->>Deleter: Store deleter

    User->>unique_resource: Use resource via get(), operator*
    User->>unique_resource: release() / reset() / destruction
    alt Resource owned
        unique_resource->>Deleter: Call deleter(resource)
        Deleter-->>Resource: Release/dispose
    else Resource released
        unique_resource-->>Deleter: No action
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

In burrows deep, I code with glee,
A resource guard for you and me!
With unique_resource by my side,
No leaks or handles left to hide.
From files to sockets, all is neat—
My RAII is hard to beat!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-unqiue_resource

🪧 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 generate unit tests to generate unit tests for 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.

Copy link

coderabbitai bot commented Jul 29, 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.

Copy link

coderabbitai bot commented Jul 29, 2025

Note

Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@sjinks sjinks requested a review from Copilot July 29, 2025 19:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new unique_resource utility for universal RAII resource management, providing safe and automatic resource cleanup with custom deleters. The implementation follows the C++ Library Fundamentals Technical Specification pattern for managing resources through handles.

Key changes include:

  • Added a comprehensive unique_resource class template with move semantics and exception safety
  • Implemented factory function make_unique_resource_checked for conditional resource ownership
  • Enhanced documentation and examples demonstrating file and socket management

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/unique_resource.h Core implementation of unique_resource class template with RAII semantics and custom deleters
test/unique_resource.cpp Comprehensive unit tests covering construction, move semantics, assignment, and exception safety
examples/unique_resource.cpp Example demonstrating file and socket resource management
test/CMakeLists.txt Added new test file to build configuration
examples/CMakeLists.txt Added unique_resource example to build system
test/.clang-tidy Disabled owning-memory warnings for test code
examples/.clang-tidy Disabled owning-memory warnings for example code
README.md Updated documentation with unique_resource usage examples and API reference
.github/workflows/ci-vcpkg.yml Removed commented-out AppleClang configuration


/**
* @example unique_resource.cpp
* Example of using `unqiue_resource` and `make_unique_resource_checked`.
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

The word "unqiue_resource" contains a typo. It should be "unique_resource".

Suggested change
* Example of using `unqiue_resource` and `make_unique_resource_checked`.
* Example of using `unique_resource` and `make_unique_resource_checked`.

Copilot uses AI. Check for mistakes.

unique_resource(
Res&& r, Del&& d, dummy_scope_guard dummy
) noexcept(std::is_nothrow_constructible_v<Resource, Res> && std::is_nothrow_constructible_v<Deleter, Del>)
: m_resource(std::forward<Res>(r), dummy), m_deleter(std::forward<Deleter>(d), dummy)
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

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

The deleter is being constructed with std::forward<Deleter>(d) but the parameter type is Del&&, not Deleter&&. This should be std::forward<Del>(d) to properly forward the deleter parameter.

Suggested change
: m_resource(std::forward<Res>(r), dummy), m_deleter(std::forward<Deleter>(d), dummy)
: m_resource(std::forward<Res>(r), dummy), m_deleter(std::forward<Del>(d), dummy)

Copilot uses AI. Check for mistakes.

@sjinks
Copy link
Owner Author

sjinks commented Jul 29, 2025

Copilot-Generated Summary

This pull request introduces the unique_resource utility to the project, enhancing resource management capabilities. It also includes updates to documentation, examples, and build configurations to support this new feature while improving code quality and maintainability.

New Feature: unique_resource

  • Added the unique_resource class, a universal RAII resource handle wrapper for managing resources with custom deleters. This ensures resources are properly released upon scope exit. (README.md, examples/unique_resource.cpp, [1] [2]
  • Introduced the make_unique_resource_checked function for safely creating unique_resource instances. (README.md, examples/unique_resource.cpp, [1] [2]

Documentation Updates

  • Updated README.md to include unique_resource in the list of utilities and provide examples and API details. [1] [2] [3] [4]

Examples and Testing Enhancements

  • Added a new example program, examples/unique_resource.cpp, demonstrating the usage of unique_resource for file and socket management.
  • Updated examples/CMakeLists.txt to include the new example executable.
  • Added unique_resource tests to the test suite by updating test/CMakeLists.txt.

Build and Code Quality Improvements

  • Introduced .clang-tidy configuration in the examples directory to enforce memory ownership guidelines.
  • Updated .clang-tidy configuration in the test directory to include memory ownership checks.

Cleanup

  • Removed commented-out code related to AppleClang setup in .github/workflows/ci-vcpkg.yml, as it is no longer needed.

Copy link

coderabbitai bot commented Jul 29, 2025

UTG Post-Process Complete

No new issues were detected in the generated code and all check runs have completed. The unit test generation process has completed successfully.

Copy link

coderabbitai bot commented Jul 29, 2025

Creating a PR to put the unit tests in...

The changes have been created in this pull request: View PR

@sjinks
Copy link
Owner Author

sjinks commented Jul 29, 2025

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 29, 2025

✅ Actions performed

Full review triggered.

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