Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Aug 1, 2025

Switch to use Q_GLOBAL_STATIC to avoid relocation on CMake object library.

Log:

Summary by Sourcery

Bug Fixes:

  • Replace static unique_ptr with Q_GLOBAL_STATIC for ICU LocaleDisplayNames caching to fix unsupported relocation on arm64.

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 1, 2025

Reviewer's Guide

Replaces the static std::unique_ptr-based caching of ICU LocaleDisplayNames with a Q_GLOBAL_STATIC-based global holder to avoid unsupported relocations on arm64, and updates includes accordingly.

Class diagram for DisplayNamesHolder and globalDisplayNames changes

classDiagram
    class DisplayNamesHolder {
        +DisplayNamesHolder()
        +~DisplayNamesHolder()
        icu::LocaleDisplayNames* displayNames
    }
    class globalDisplayNames {
        <<Q_GLOBAL_STATIC>>
        +DisplayNamesHolder* operator()()
    }
    DisplayNamesHolder <.. globalDisplayNames : holds
Loading

Class diagram for removal of unique_ptr-based caching

classDiagram
    class getDisplayNames {
        - static std::unique_ptr<icu::LocaleDisplayNames> displayNames
        + icu::LocaleDisplayNames* getDisplayNames()
    }
    getDisplayNames --|> DisplayNamesHolder : now uses
Loading

File-Level Changes

Change Details Files
Switch from static std::unique_ptr to Q_GLOBAL_STATIC for LocaleDisplayNames caching
  • Introduced DisplayNamesHolder struct with constructor/destructor managing displayNames pointer
  • Declared globalDisplayNames instance using Q_GLOBAL_STATIC macro
  • Updated getDisplayNames() to return displayNames from the global holder
src/shared-utils/dcclocale.cpp
Updated includes for global static usage
  • Added include for
  • Removed unused include
src/shared-utils/dcclocale.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

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 @BLumia - I've reviewed your changes - here's some feedback:

  • Terminate the Q_GLOBAL_STATIC(DisplayNamesHolder, globalDisplayNames) macro invocation with a semicolon to ensure valid syntax.
  • Use a smart pointer (std::unique_ptr) inside DisplayNamesHolder instead of manually deleting the raw pointer for safer resource management.
  • Add a null check for the result of createInstance to guard against potential nullptr access.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Terminate the Q_GLOBAL_STATIC(DisplayNamesHolder, globalDisplayNames) macro invocation with a semicolon to ensure valid syntax.
- Use a smart pointer (std::unique_ptr) inside DisplayNamesHolder instead of manually deleting the raw pointer for safer resource management.
- Add a null check for the result of createInstance to guard against potential nullptr access.

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.

BLumia added 2 commits August 1, 2025 11:06
Switch to use Q_GLOBAL_STATIC to avoid relocation on CMake obeject
library.

Log:
@github-actions
Copy link

github-actions bot commented Aug 1, 2025

TAG Bot

TAG: 6.1.40
EXISTED: no
DISTRIBUTION: unstable

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码注释:在dcclocale.cpp文件中,新增的DisplayNamesHolder结构体和Q_GLOBAL_STATIC宏的使用没有相应的注释说明其用途和作用。建议添加注释以便其他开发者理解。

  2. 代码风格DisplayNamesHolder结构体的成员变量displayNames前有一个多余的空格,建议保持代码风格的一致性,移除这个空格。

  3. 线程安全性Q_GLOBAL_STATIC宏在多线程环境下是线程安全的,但是如果有其他线程修改icu::LocaleDisplayNames实例,需要确保线程安全。如果getDisplayNames函数可能会被多个线程同时调用,建议在函数内部添加适当的同步机制。

  4. 代码可读性getDisplayNames函数的返回类型可以改为std::unique_ptr<icu::LocaleDisplayNames>,这样可以更清晰地表达返回的是一个智能指针,而不是裸指针。

  5. 代码重构:如果getDisplayNames函数在多个地方被调用,可以考虑将其改为一个静态成员函数,这样可以避免每次调用时都创建一个新的DisplayNamesHolder实例。

  6. 错误处理:在getDisplayNames函数中,如果icu::LocaleDisplayNames::createInstance失败,应该有相应的错误处理机制,比如返回一个空指针或者抛出异常。

  7. 依赖性QGlobalStatic宏的使用依赖于Qt库,如果项目中有其他不使用Qt的分支,这个宏可能会导致编译错误。建议检查项目的依赖关系,确保所有分支都能正常编译。

  8. 版本控制:在debian/changelog文件中,新增了一个修复项,但是没有对应的bug追踪链接或者问题描述。建议添加更多的上下文信息,以便其他开发者理解这个修复的背景和影响。

以上是针对代码审查提出的改进意见,希望能够对你有所帮助。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, caixr23

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

@BLumia BLumia merged commit 3ae8952 into linuxdeepin:master Aug 1, 2025
16 of 18 checks passed
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