refactor: replace private access hacks with accessor pattern#315
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
There was a problem hiding this comment.
Pull request overview
This PR removes the #define private/protected public access hack in the platform theme plugin and replaces it with a “private accessor” pattern based on explicit template instantiation ([temp.explicit]/12), and adds CI workflows to build in Deepin/Arch container environments.
Changes:
- Introduce
dprivateaccessor_p.hmacros to access private/static Qt internals without preprocessor access hacks. - Update
qdeepintheme.cppto use the new accessor macros forQHighDpiScalingprivate statics across Qt versions. - Add GitHub Actions workflows for Deepin crimson and Arch Linux container builds.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
platformthemeplugin/qdeepintheme.cpp |
Replaces direct private static access with D_PRIVATE_STATIC_MEMBER(...) accessor usage. |
platformthemeplugin/dprivateaccessor_p.h |
Adds the explicit-instantiation-based private member accessor infrastructure. |
platformthemeplugin/CMakeLists.txt |
Registers the new private accessor header in the plugin headers list. |
.github/workflows/qt5integration-deepin-build.yml |
Adds a Deepin crimson container build workflow producing .deb artifacts. |
.github/workflows/qt5integration-archlinux-build.yml |
Adds an Arch container build workflow producing an installation zip artifact. |
Comments suppressed due to low confidence (2)
platformthemeplugin/dprivateaccessor_p.h:53
dtk_private_detail::access()is declaredconstexprbut callsget(t), which is notconstexprhere. With C++17 this typically makes the function ill-formed (aconstexprfunction can’t call a non-constexprfunction). Either removeconstexprfromaccess()or make the friendget(Tag)declaration/definitionconstexpras well.
namespace dtk_private_detail {
template<typename Tag>
inline constexpr typename Tag::MemberPtr access(Tag t) noexcept { return get(t); }
}
.github/workflows/qt5integration-deepin-build.yml:51
apt-get install -y --allow-unauthenticated wlr-protocols || trueboth bypasses package authentication and masks installation failures. If the package is optional, prefer checking availability explicitly and keep signature verification enabled; otherwise, remove--allow-unauthenticatedand the unconditional|| trueso failures are actionable.
set -euxo pipefail
apt-get install -y --allow-unauthenticated wlr-protocols || true
cd /tmp
git clone --depth=1 https://github.com/linuxdeepin/treeland-protocols.git
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| set -euxo pipefail | ||
| echo "deb [trusted=yes] http://mirrors.kernel.org/deepin/beige/ crimson main commercial community" > /etc/apt/sources.list | ||
| echo "deb-src [trusted=yes] http://mirrors.kernel.org/deepin/beige/ crimson main commercial community" >> /etc/apt/sources.list | ||
| rm -rf /etc/apt/sources.list.d |
There was a problem hiding this comment.
The Deepin crimson repository does not distribute a GPG signing key publicly, so [trusted=yes] is required. This only affects the isolated CI sandbox environment and has no impact on production deployments.
| jobs: | ||
| container: | ||
| runs-on: ubuntu-latest | ||
| container: archlinux:latest |
There was a problem hiding this comment.
Arch Linux is a rolling release; pinning to a timestamped image causes partial-upgrade breakage (pacman does not support partial upgrades). archlinux:latest ensures a consistent package state, which is the correct approach for Arch CI.
9ef30a8 to
563c066
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 platformthemeplugin/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你好!我是CodeGeeX。我已经仔细审查了你提供的Git Diff,该变更主要包含两部分:一是新增了两个GitHub Actions CI工作流(Arch Linux和Deepin),二是引入了一个利用C++显式模板实例化技术来访问Qt私有成员的宏工具集,以替代破坏性的 总体来说,这是一个质量很高的提交,特别是用符合C++标准的方式替换 1. 代码逻辑与语法1.1 宏定义末尾缺少分号在 // 当前代码
template struct Qt5IntegrationPrivateAccessorImpl<TagName, &ClassName::MemberName>
// 建议修改为
template struct Qt5IntegrationPrivateAccessorImpl<TagName, &ClassName::MemberName>;原因:虽然C++中显式模板实例化声明 1.2 宏定义中使用了保留标识符在 using MemberPtr = MemberType ClassName::*;建议:如果 2. 代码性能2.1 频繁的静态成员访问开销在 D_PRIVATE_STATIC_MEMBER(QHighDpiScaling_m_logicalDpi_tag{}).first = dpi.first;
// ...
D_PRIVATE_STATIC_MEMBER(QHighDpiScaling_m_logicalDpi_tag{}).second = dpi.second;分析: auto& logicalDpi = D_PRIVATE_STATIC_MEMBER(QHighDpiScaling_m_logicalDpi_tag{});
if (dpi.first > 0) {
logicalDpi.first = dpi.first;
} else if (qIsNull(dpi.first)) {
logicalDpi.first = qGuiApp->primaryScreen()->handle()->logicalDpi().first;
}
// ... 同理 second3. 代码安全与健壮性3.1
|
Use C++ [temp.explicit]/12 explicit instantiation to bypass access control instead of #define private/protected public hacks.