Repository navigation
runtime-c: 删除 kvlangStrbuf,改一次性有界格式化 - #393
Merged
Merged
Conversation
Contributor
Author
交接:与 #390 语义冲突,交由 coding 决定收口方式本 PR 在 #390( 本 PR 删除了 rebase 后的临时分支未推送、未 force-push,远程分支仍停在原提交;本地已切回
(顺带: |
Strbuf 可增长、可清空、可复用——它把「字符串怎么拼」变成了一个带生命周期和容量策略
的对象。但 runtime 里每一处用法都是「拼一次 → 用 → 扔」,没有任何调用点需要复用;
这个缓冲只是在每个调用处引入三字段状态和一条 malloc 失败路径。
删掉它,换成三个一次性函数(新增 runtime/src/strutil.c):
- kvlangKeyFmt(buf, cap, fmt, ...):有界写入调用方栈缓冲;超长或格式化错误**直接
abort,绝不截断**——截断会静默产出一个错的 key,比崩更糟
- kvlangAstr(fmt, ...) / kvlangAstrN(s, n):一次性堆字符串,调用方 free;OOM abort
- kvlangDie(fmt, ...):统一 panic 出口,noreturn
所有 keytree 函数的 out 参数从 `kvlangStrbuf_t *` 改成 `(char *out, size_t cap)`——
签名直接表达「调用方给的缓冲有多大」,不再有隐藏扩容。
- runtime/src/strbuf.c 删除;新增 strutil.c(CMake 走 `src/*.c` GLOB,构建文件无需改)
- keytree.c / kvcpu.c / runtime.c / vthread.c / xvalue.c / rwir*.c / rwirext.c /
myrwircaps.c / runtime_internal.h / const.h 全量改签名与调用点(-650/+479)
- spec/05-runtime语义/09-cruntime与后端abi.kv:内部模块清单 strbuf.c → strutil.c
- runtime/tests/test_crash_resume.c 跟改
验证:
- `make runtime` 构建通过
- `ctest`:7/9 通过。param_address_{shm,fs} 失败,但用临时 clone 在**重构前的 HEAD
(9dbe650)** 上复跑同样失败——既有问题,非本次引入(CI 只 `make runtime` 不跑
ctest,所以一直没暴露)
- tutorial fs 后端:PASS:222 FAIL:0 SKIP:1,无回归
Co-Authored-By: Claude Code <noreply@anthropic.com>
rebase 到 #390 后:dispatch.c 的 JSON/错误拼接与 keytree 的 delegation 路径
同步改为 parts_t 精确拼接 + kvlangAstr,未保留任何 strbuf 调用。
miaobyte
force-pushed
the
refactor/drop-strbuf
branch
from
October 19, 2026 08:15
5b10c4f to
46441e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Strbuf 可增长、可清空、可复用——它把「字符串怎么拼」变成了一个带生命周期和容量策略的对象。但 runtime 里每一处用法都是「拼一次 → 用 → 扔」,没有任何调用点需要复用;这个缓冲只是在每个调用处引入三字段状态和一条 malloc 失败路径。
删掉它,换成三个一次性函数(新增
runtime/src/strutil.c):kvlangKeyFmt(buf, cap, fmt, ...):有界写入调用方栈缓冲;超长或格式化错误直接 abort,绝不截断——截断会静默产出一个错的 key,比崩更糟kvlangAstr(fmt, ...)/kvlangAstrN(s, n):一次性堆字符串,调用方 free;OOM abortkvlangDie(fmt, ...):统一 panic 出口,noreturn所有 keytree 函数的 out 参数从
kvlangStrbuf_t *改成(char *out, size_t cap)——签名直接表达「调用方给的缓冲有多大」,不再有隐藏扩容。改动面
runtime/src/strbuf.c删除;新增strutil.c(CMake 走src/*.cGLOB,构建文件无需改)keytree.c/kvcpu.c/runtime.c/vthread.c/xvalue.c/rwir*.c/rwirext.c/myrwircaps.c/runtime_internal.h/const.h全量改签名与调用点(-650/+479)05-runtime语义/09-cruntime与后端abi.kv:内部模块清单strbuf.c→strutil.cruntime/tests/test_crash_resume.c跟改验证
make runtime构建通过ctest:7/9 通过。param_address_{shm,fs}失败,但用临时 clone 在**重构前的 HEAD(9dbe650)**上复跑同样失败——既有问题,非本次引入(CI 只make runtime、不跑 ctest,所以一直没暴露)🤖 Generated with Claude Code