Skip to content

Revert "chore: temporary disable TreelandUserConfig smart pointer"#678

Merged
zccrs merged 1 commit intolinuxdeepin:masterfrom
wineee:revert
Jan 29, 2026
Merged

Revert "chore: temporary disable TreelandUserConfig smart pointer"#678
zccrs merged 1 commit intolinuxdeepin:masterfrom
wineee:revert

Conversation

@wineee
Copy link
Member

@wineee wineee commented Jan 5, 2026

This reverts commit 779832f.

Summary by Sourcery

Enhancements:

  • Switch Helper::m_config back to a std::unique_ptr-managed TreelandUserConfig instance and adjust its construction and access accordingly.

@deepin-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Re-wraps Helper::m_config in a std::unique_ptr, updating its initialization, reassignment, and accessor to use smart-pointer semantics instead of raw pointers.

Class diagram for Helper using std_unique_ptr_TreelandUserConfig

classDiagram
    class Helper {
        - static Helper* m_instance
        - std_unique_ptr~TreelandUserConfig~ m_config
        - std_unique_ptr~TreelandConfig~ m_globalConfig
        - Treeland_Treeland* m_treeland
        - FpsDisplayManager* m_fpsManager
        + Helper(QObject* parent)
        + static Helper* instance()
        + TreelandUserConfig* config()
        + TreelandConfig* globalConfig()
        + void init(Treeland_Treeland* treeland)
    }

    class TreelandUserConfig {
        + static TreelandUserConfig* createByName(QString serviceName, QString interfaceName, QString path)
    }

    class TreelandConfig {
        + static std_unique_ptr~TreelandConfig~ create(QString serviceName, QString interfaceName)
    }

    class Treeland_Treeland
    class FpsDisplayManager
    class QObject

    Helper --> TreelandUserConfig : owns via std_unique_ptr
    Helper --> TreelandConfig : owns via std_unique_ptr
    Helper --> Treeland_Treeland
    Helper --> FpsDisplayManager
    Helper --> QObject : inherits
Loading

File-Level Changes

Change Details Files
Manage TreelandUserConfig in Helper via std::unique_ptr instead of a raw pointer.
  • Change Helper::m_config type from TreelandUserConfig* to std::unique_ptr.
  • Initialize m_config using m_config.reset(TreelandUserConfig::createByName(...)) in the constructor instead of direct assignment.
  • Update the lambda in Helper::init to recreate m_config via reset(...) when the current user changes.
  • Adjust Helper::config() to return m_config.get() instead of the smart pointer itself.
src/seat/helper.h
src/seat/helper.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-bot
Copy link

deepin-bot bot commented Jan 15, 2026

TAG Bot

New tag: 0.8.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #691

@wineee wineee marked this pull request as ready for review January 29, 2026 06:51
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/seat/helper.cpp:215-220` </location>
<code_context>

     Q_ASSERT(!m_config);
-    m_config = TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
+    m_config.reset(TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
                                               "org.deepin.dde.treeland",
-                                              "/dde"); // will update user path in Helper::init
</code_context>

<issue_to_address>
**issue (bug_risk):** Resetting the unique_ptr may invalidate external raw pointers to the config.

With the raw pointer, reassigning `m_config` leaked the old instance but didn’t invalidate any cached raw pointers. Using `std::unique_ptr::reset()` now correctly deletes the old config, so any code that has stored a `Helper::config()` pointer will end up with a dangling pointer after `updateCurrentUser`. Callers should not cache this pointer long-term, or `config()` should expose a safer API (e.g., reference or handle) that makes ownership and lifetime explicit.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +215 to 220
m_config.reset(TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
"org.deepin.dde.treeland",
"/dde"); // will update user path in Helper::init
"/dde")); // will update user path in Helper::init
m_globalConfig.reset(TreelandConfig::create("org.deepin.dde.treeland",
QString()));

Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Resetting the unique_ptr may invalidate external raw pointers to the config.

With the raw pointer, reassigning m_config leaked the old instance but didn’t invalidate any cached raw pointers. Using std::unique_ptr::reset() now correctly deletes the old config, so any code that has stored a Helper::config() pointer will end up with a dangling pointer after updateCurrentUser. Callers should not cache this pointer long-term, or config() should expose a safer API (e.g., reference or handle) that makes ownership and lifetime explicit.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wineee, zccrs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zccrs zccrs merged commit bf3be27 into linuxdeepin:master Jan 29, 2026
8 checks passed
@wineee wineee deleted the revert branch February 3, 2026 07:08
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.

3 participants