nodejs / nodejs/node

Remove FFI type aliases while it's still experimental

未关闭
#64,848 7 条评论 6 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request ffi
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

What is the problem this feature will solve?

node:ffi was introduced with synonyms for the same types

i8, int8
u8, uint8, bool, char
i16, int16
u16, uint16
i32, int32
u32, uint32
i64, int64
u64, uint64
f32, float
f64, double
pointer, ptr
string, str
buffer
arraybuffer

While this may be convenient for folks that are familiar with the different names, it also adds mental overhead - developers need to confirm if 'char' and 'u8' mean the same thing or are subtly different.

There were a few bugs that are kindof related to this

  • when ffi.types.FLOAT_32 was added it's value was float32 which wasn't a supported alias, so now there's three ways to spell float 32.
  • buffer and arraybuffer are also synonyms but are different lines in the docs
  • char is listed on the same lines as u8 and bool but it is not a synonym (it varies by platform)

cc @nodejs/ffi

What is the feature you are proposing to solve the problem?

We should remove each synonym and keep one spelling for each distinct type.
I'm not opinionated on which spelling we prefer, I think the uint8 style agrees with ffi.types and the access helpers (getUint8).

We should do this now while the module is experimental. WE can always add more names in the future, but removing them after the module is stable is harder.

What alternatives have you considered?
  • we could do nothing and live with the synonyms
  • we could deprecate and print a warning when the non-preferred aliases are used

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 node:ffi 入口点开始,盘点类型别名、ffi.types 名称、访问辅助函数和文档引用。issue 中尚未决定首选拼写,因此在继续之前先检查现有的 API 约定。完成的标准是每个不同的类型只有一种拼写,并且相关文档和行为一致地反映此次移除。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
backend
Issue 类型
重构
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。