refactor: replace private access hacks with accessor pattern#383
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces prior #define private/protected public access hacks with a template-based private accessor pattern (friend-injection via explicit instantiation), and migrates a few production call sites to use the new accessors.
Changes:
- Added
src/private/dprivateaccessor_p.hproviding macros/templates to access private members/methods without redefining access specifiers. - Updated XDG icon proxy engine to call previously-private
XdgIconLoader/XdgIconLoaderEngineAPIs via accessor tags/macros. - Updated Treeland platform window interface to hook
QWindow::eventwithout#define protected public, and updatedDFontManagerto readQFont::d->dpivia accessor.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util/private/xdgiconproxyengine.cpp | Replaces direct private calls/field access with accessor macros (Qt5/Qt6-conditional). |
| src/util/private/diconproxyengine.cpp | Removes #define private public include hack around xdgiconloader_p.h. |
| src/util/dfontmanager.cpp | Replaces QFont::d access hack with accessor-based private member access. |
| src/private/dprivateaccessor_p.h | Introduces the reusable private accessor pattern (templates + macros). |
| src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp | Replaces protected access hack for QWindow::event with accessor-based member pointer retrieval. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c486e80 to
09bf9f0
Compare
Add CI workflows to verify the project builds correctly on both Arch Linux (latest) and Deepin crimson. This helps catch any platform-specific compilation issues introduced by the accessor pattern refactor.
Remove all '#define private/protected public' hacks and replace them with a proper C++ template-based private accessor pattern using explicit template instantiation (friend injection trick), mirroring the approach used in linuxdeepin/treeland#875. Adds src/util/dprivateaccessor_p.h with Accessor/AccessorImpl templates and D_DECLARE_PRIVATE_MEMBER, D_PRIVATE_MEMBER macros. All helpers live at global scope so ADL correctly resolves the friend-injected get() function.
deepin pr auto review这份代码提交主要做了两件事:
整体来看,这是一个质量非常高的提交,特别是用标准合规的技术替代了破坏类的访问控制宏,值得称赞。但经过仔细审查,仍有一些语法逻辑、代码性能、安全性和工程质量方面的细节需要改进。 以下是详细的审查意见: 一、 语法与逻辑1. CI 工作流:步骤顺序导致潜在的构建失败
2. C++ 模板:友元注入在命名空间作用域的潜在风险
3. C++ 语法:
二、 代码性能1. CI 工作流:Deepin 构建缺乏缓存机制
2. C++ 运行期:访问器函数的零开销保证
三、 代码安全1. CI 安全:APT 仓库使用
2. C++ 安全:消除了
四、 代码质量与工程规范1. CI 规范:Arch Linux CI 缺乏触发条件限制
2. C++ 宏规范:
3. C++ 代码整洁:
4. 版权声明更新
总结核心 C++ 逻辑的重构( |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, zccrs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Remove all '#define private/protected public' hacks and replace them with a proper C++ template-based private accessor pattern using explicit template instantiation (friend injection trick), mirroring the approach used in linuxdeepin/treeland#875.
Add src/private/dprivateaccessor_p.h with Accessor/AccessorImpl templates and D_DECLARE_PRIVATE_MEMBER, D_DECLARE_PRIVATE_METHOD, D_DECLARE_PRIVATE_CONST_METHOD, D_PRIVATE_MEMBER, D_PRIVATE_CALL macros. All helpers are in global namespace so ADL correctly finds the friend-injected get() function.