Skip to content

[opt] 优化 ek_list.h 中api#16

Merged
00lllooolll00 merged 1 commit into
masterfrom
develop/nn
Apr 3, 2026
Merged

[opt] 优化 ek_list.h 中api#16
00lllooolll00 merged 1 commit into
masterfrom
develop/nn

Conversation

@00lllooolll00

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings April 3, 2026 13:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the ek_list.h linked-list API to use new naming (foreach, insert_*, is_empty) and updates in-tree usage (HAL drivers) and documentation accordingly.

Changes:

  • Renamed list traversal macros to ek_list_foreach / ek_list_foreach_safe.
  • Renamed list insertion helpers to ek_list_insert_head / ek_list_insert_tail and adjusted internal helpers.
  • Updated HAL registration/find implementations and L2_Core/readme.md examples to the new API names.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
L2_Core/utils/inc/ek_list.h Renames core list APIs/macros and internal helpers.
L2_Core/readme.md Updates documentation examples to match renamed list APIs.
L2_Core/hal/src/ek_hal_uart.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_tim.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_tick.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_spi.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_pwm.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_ltdc.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_i2c.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_gpio.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_dma2d.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_dma.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_dac.c Updates device list registration + iteration to new list APIs.
L2_Core/hal/src/ek_hal_adc.c Updates device list registration + iteration to new list APIs.
Comments suppressed due to low confidence (2)

L2_Core/utils/inc/ek_list.h:94

  • _ek_list_insert 以单下划线开头,属于实现保留标识符(global scope 下以 '_' 开头的标识符为实现保留),放在公共头文件里可能与编译器/库实现发生命名冲突。建议改为不以下划线开头的内部命名(例如 ek_list_insert_internal 等),并同步更新调用处。
__EK_STATIC_INLINE void _ek_list_insert(ek_list_node_t *new_node, ek_list_node_t *prev, ek_list_node_t *next)
{
    prev->next = new_node;
    new_node->next = next;
    new_node->prev = prev;
    next->prev = new_node;
}

L2_Core/utils/inc/ek_list.h:125

  • 同上:_ek_list_remove 以单下划线开头,公共头文件中使用实现保留标识符存在潜在命名冲突风险。建议更换为不以下划线开头的内部命名,并同步更新调用处。
__EK_STATIC_INLINE void _ek_list_remove(ek_list_node_t *prev, ek_list_node_t *next)
{
    next->prev = prev;
    prev->next = next;
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

#define ek_list_iterate_safe(pos, n, head) \
#define ek_list_foreach_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next)

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

ek_list_iterate/ek_list_iterate_safe 被直接改名为 ek_list_foreach/ek_list_foreach_safe,旧宏在头文件中不再提供,会导致任何依赖旧 API 的外部代码直接编译失败。建议至少保留旧名字作为兼容别名(可加弃用标记/注释),或在版本/变更说明中明确这是破坏性变更。

Suggested change
/**
* @brief 兼容旧 API 的遍历别名
* @note 新代码请优先使用 ek_list_foreach
*/
#define ek_list_iterate(pos, head) ek_list_foreach(pos, head)
/**
* @brief 兼容旧 API 的安全遍历别名
* @note 新代码请优先使用 ek_list_foreach_safe
*/
#define ek_list_iterate_safe(pos, n, head) ek_list_foreach_safe(pos, n, head)

Copilot uses AI. Check for mistakes.
Comment on lines +146 to 149
__EK_STATIC_INLINE bool ek_list_is_empty(ek_list_node_t *head)
{
return head->next == head;
}

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

ek_list_empty 被改为 ek_list_is_empty,不仅是破坏性改动,也与仓库内其它容器命名不一致(例如 ek_ringbuf_emptyek_stack_empty)。建议保留 ek_list_empty 作为兼容别名,或继续沿用 _empty 命名以保持一致性。

Copilot uses AI. Check for mistakes.
@00lllooolll00 00lllooolll00 merged commit 3321565 into master Apr 3, 2026
12 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.

2 participants