Skip to content

fix(wayland): 导出模块够不着的八个 static inline 函数 - #330

Merged
Sunrisepeak merged 1 commit into
mainfrom
fix/wayland-static-inline
Aug 31, 2026
Merged

fix(wayland): 导出模块够不着的八个 static inline 函数#330
Sunrisepeak merged 1 commit into
mainfrom
fix/wayland-static-inline

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

缺口

static inline 是内部链接,C++ 禁止从模块导出。这个 fork 一直知道这个坑 —— 它为 wayland-scanner 生成的包装专门做了 inline 副本,注释里写得很清楚 —— 但漏掉了两个手写头文件里的:

头文件 函数 归属模块
wayland-server-core.h wl_signal_init/_add/_get/_emit freedesktop.wayland.server
wayland-util.h wl_fixed_to/from_double/int freedesktop.wayland.client

不是边角:每一次 wlroots 监听注册都是 wl_signal_add(&x->events.y, &l),所以走模块路线写不了合成器;wl_fixed_t 是协议里每个亚像素坐标的载体(指针移动、触摸、数位板),所以处理不了输入事件

⚠️ 为什么一直没发现

这个包的测试从没调用过其中任何一个。 缺口是从外面被问出来的 —— 我写了一个最小 wlroots 合成器,编不过:

error: 'wl_signal_add' was not declared in this scope

同一类问题在 freedesktop.cairo(少 cairo_t)和 displayinfo(少 295 个枚举量)上都出现过,发现方式完全一样:自己的测试问不出来,别的包在真实用途里能。

做法,以及两个只有 clang 会说的坑

原来的 inline 副本手法在这里不适用:这两个头必须进 global module fragment(其它声明要用它们的类型),所以 static 定义已经可见,purview 里同名定义就是重定义。做法是先把 static 原件改名让开,再用真名定义并导出。

  • struct wl_signal * 不能写。 elaborated-type-specifier 会在模块里重新声明该类型:declaration of 'wl_signal' in module ... follows declaration in the global moduleGCC 静默接受。
  • wl_fixed_* 不能放进 freedesktop.wayland.util 那个模块是和头文件配对设计的(只出宏和模板,零个 using ::),它自己的测试就写着 #include <wayland-util.h> + import。加同名实体会让每次调用 call to 'wl_fixed_from_int' is ambiguous。也没有同时放进 server —— 两个模块各自的实体,对同时 import 两者的 TU 一样是二义。

三个模块同时 import 已实测,两条工具链都通过。

验证

  • 索引示例 tests/examples/wayland 现在真的调用这八个 —— 再塌陷就是编译错误
  • fork 五个成员 × 两条工具链全绿
  • 资产 wayland-1.26.0-mcpp4.tar.gz,sha256 9bce2cc0…,两个镜像一致,六个描述符同步

`static inline` 是内部链接,C++ 禁止从模块导出。这个 fork 一直知道这个坑 ——
它为 wayland-scanner 生成的包装专门做了 `inline` 副本 —— 但漏掉了两个手写头:

    wayland-server-core.h   wl_signal_init/_add/_get/_emit  -> .server
    wayland-util.h          wl_fixed_to/from_double/int     -> .client

这不是边角。每一次 wlroots 监听注册都是 wl_signal_add(&x->events.y, &l),所以
**走模块路线写不了合成器**;wl_fixed_t 是协议里每个亚像素坐标的载体(指针移动、
触摸、数位板),所以**处理不了输入事件**。

⚠️ 一直没发现,因为这个包的测试从没调用过其中任何一个。缺口是从**外面**被问出
来的 —— 一个最小 wlroots 合成器编不过。同一类问题在 freedesktop.cairo(少
cairo_t)和 displayinfo(少 295 个枚举量)上都出现过,发现方式完全一样:
**自己的测试问不出来,别的包在真实用途里能。**

索引示例现在真的调用这八个 —— 再塌陷就是编译错误。

资产:wayland-1.26.0-mcpp4.tar.gz,sha256 9bce2cc0…,两个镜像一致。
六个描述符同步。gcc 16.1 / llvm 22.1 双绿。
@Sunrisepeak
Sunrisepeak merged commit 05834b8 into main Aug 31, 2026
11 checks passed
@Sunrisepeak
Sunrisepeak deleted the fix/wayland-static-inline branch August 31, 2026 16:38
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.

1 participant