Skip to content

Conversation

@deepin-ci-robot
Copy link
Contributor

Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#531

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@deepin-ci-robot
Copy link
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#531
@deepin-ci-robot
Copy link
Contributor Author

deepin pr auto review

代码审查报告

1. 整体评估

本次代码变更主要是对DTK(Deepin Tool Kit)核心模块的重构,主要涉及版本管理、配置系统和工具链的改进。整体来看,代码结构更加清晰,线程安全性有所增强,但存在一些可以改进的地方。

2. 语法和逻辑问题

2.1 版本管理逻辑

CMakeLists.txt 中:

option(DTK5 "Build DTK5." ON)
if(DTK5)
    set(DTK_VERSION_MAJOR "5")
    set(DTK_NAME_SUFFIX "") # Empty name suffix for DTK5 products.
else()
    set(DTK_VERSION_MAJOR "6")
    set(DTK_NAME_SUFFIX "6")
endif()

问题:版本判断逻辑不够清晰,缺少对其他版本的支持。

建议

  1. 添加版本验证逻辑,确保只支持5和6版本
  2. 添加版本兼容性检查
  3. 考虑使用更灵活的版本控制方案

2.2 配置文件生成

tools/dconfig2cpp/main.cpp 中:

headerStream << "#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)\n"
             << "#include <QProperty>\n"
             << "#endif\n";
headerStream << "#include <QEvent>\n";

问题:条件编译的顺序可能导致某些情况下头文件包含顺序不正确。

建议:将公共头文件放在条件编译之前。

3. 代码质量问题

3.1 命名一致性

在多个文件中存在命名不一致的问题:

  • DTK_VERSION_MAJORDTK_NAME_SUFFIX 的使用不一致
  • 某些地方使用 DTK5 选项,某些地方直接使用 DTK_VERSION_MAJOR

建议

  1. 统一使用 DTK_VERSION_MAJORDTK_NAME_SUFFIX 作为主要版本标识
  2. 确保所有相关文件使用相同的命名约定

3.2 代码重复

dconfig_org_deepin_dtk_preference.hpp 和其他生成的头文件中存在大量重复代码:

inline void updateProperty(const QString &key, const QVariant &v) {
    if (key == QStringLiteral("autoDisplayFeature")) {
        // ... 大量重复代码
    }
    // ... 更多重复代码
}

建议

  1. 考虑使用模板或宏来减少重复代码
  2. 将通用逻辑提取到基类中

4. 性能问题

4.1 原子操作使用

在多个文件中频繁使用原子操作:

QAtomicPointer<DTK_CORE_NAMESPACE::DConfig> m_config = nullptr;
QAtomicInteger<int> m_status = static_cast<int>(Data::Status::Invalid);

问题:过度使用原子操作可能导致不必要的性能开销。

建议

  1. 评估原子操作的使用场景,确保只在真正需要的地方使用
  2. 考虑使用读写锁等替代方案,减少原子操作的开销

4.2 字符串处理

tools/dconfig2cpp/main.cpp 中:

QString p_key3 { QStringLiteral(u"\u0067\u006c\u006f\u0062\u0061\u006c") };

问题:使用Unicode转义序列可能导致不必要的性能开销。

建议:直接使用普通字符串字面量,除非有特殊需求。

5. 安全性问题

5.1 线程安全

dconfig_org_deepin_dtk_preference.hpp 中:

QMetaObject::invokeMethod(worker, [safeData, backend, name, appId, subpath, isGeneric, worker]() mutable {
    delete worker;
    worker = nullptr;
    // ...
});

问题:lambda中使用mutable关键字,可能导致线程安全问题。

建议

  1. 避免在lambda中使用mutable,除非绝对必要
  2. 确保所有共享数据的访问都是线程安全的

5.2 内存管理

在多个文件中存在复杂的内存管理逻辑:

~dconfig_org_deepin_dtk_preference() {
    int oldStatus = m_data->m_status.fetchAndStoreOrdered(static_cast<int>(Data::Status::Destroyed));
    m_data->m_userConfig = nullptr;
    if (oldStatus == static_cast<int>(Data::Status::Succeeded)) {
        auto config = m_data->m_config.loadRelaxed();
        Q_ASSERT(config);
        config->deleteLater();
        // m_data will be deleted by config's destroyed signal
    } else if (oldStatus == static_cast<int>(Data::Status::Failed) ||
               oldStatus == static_cast<int>(Data::Status::Invalid)) {
        m_data->deleteLater();
    }
}

问题:复杂的析构逻辑可能导致内存泄漏或双重释放。

建议

  1. 简化内存管理逻辑
  2. 考虑使用智能指针替代原始指针
  3. 添加内存泄漏检测机制

6. 改进建议

6.1 版本管理

# 改进后的版本管理
set(DTK_SUPPORTED_VERSIONS "5;6")
set(DTK_DEFAULT_VERSION "5")

set(DTK_VERSION "${DTK_DEFAULT_VERSION}" CACHE STRING "DTK version to build")
set_property(CACHE DTK_VERSION PROPERTY STRINGS ${DTK_SUPPORTED_VERSIONS})

if(NOT DTK_VERSION IN_LIST DTK_SUPPORTED_VERSIONS)
    message(FATAL_ERROR "Unsupported DTK version: ${DTK_VERSION}. Supported versions: ${DTK_SUPPORTED_VERSIONS}")
endif()

if(DTK_VERSION STREQUAL "5")
    set(DTK_NAME_SUFFIX "")
else()
    set(DTK_NAME_SUFFIX "${DTK_VERSION}")
endif()

6.2 线程安全改进

// 改进后的线程安全实现
class DConfigHolder {
public:
    DConfigHolder() = default;
    ~DConfigHolder() {
        QWriteLocker locker(&m_lock);
        m_config.reset();
    }
    
    void setConfig(DTK_CORE_NAMESPACE::DConfig* config) {
        QWriteLocker locker(&m_lock);
        m_config.reset(config);
    }
    
    DTK_CORE_NAMESPACE::DConfig* config() const {
        QReadLocker locker(&m_lock);
        return m_config.get();
    }
    
private:
    mutable QReadWriteLock m_lock;
    QScopedPointer<DTK_CORE_NAMESPACE::DConfig> m_config;
};

6.3 内存管理改进

// 使用智能指针改进内存管理
class dconfig_org_deepin_dtk_preference : public QObject {
    Q_OBJECT
public:
    explicit dconfig_org_deepin_dtk_preference(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend,
                        const QString &name, const QString &appId, const QString &subpath,
                        bool isGeneric, QObject *parent)
        : QObject(parent)
        , m_data(std::make_unique<Data>(this)) {
        // ...
    }
    
    ~dconfig_org_deepin_dtk_preference() {
        // 简化的析构逻辑
        if (m_data) {
            m_data->cleanup();
        }
    }
    
private:
    std::unique_ptr<Data> m_data;
};

7. 总结

本次代码变更在版本管理和线程安全性方面有所改进,但仍存在以下主要问题:

  1. 版本管理逻辑不够清晰,需要更灵活的版本控制方案
  2. 代码重复较多,需要进一步重构
  3. 线程安全实现复杂,存在潜在风险
  4. 内存管理逻辑复杂,可能导致内存泄漏

建议优先解决线程安全和内存管理问题,然后逐步重构代码以减少重复。同时,考虑引入更现代的C++特性(如智能指针)来简化资源管理。

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

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.

2 participants