Conversation
…ease, net send
Fixes the 8 issues found by the FakeFish project (fakelua-pitfalls):
- P0-1: mysql callbacks now accept inline closures (VarClosure*) in
addition to global function names; invalid callback types throw a
loud "bad argument" instead of being silently dropped by
CVarToString("").
- P0-2: all early-return paths in Query/StmtPrepare/StmtExecute now
fire the callback with an error. Contract: every conn:query() call
results in exactly one callback.
- P1-3: file-level numeric locals with reassignment points are no
longer emitted as C const (which broke JIT compilation with
"cannot assign to variable with const-qualified type"). Never-
reassigned file constants keep the const optimization.
- P1-4: in-flight query on the same connection is queued instead of
erroring; new pool:with(fn) lease API auto-returns the connection
even when fn throws.
- P1-5: json.encode({}) now produces [] (pure-array heuristic);
new json.encode_array() for strict array-shaped encoding.
- P1-6: sends issued inside dispatch callbacks are queued and pumped
by the tick after dispatch completes; send failures log WARN.
- P2-7: result rows convert values by column type (int/float columns
return numbers instead of strings); result table layout documented.
- P2-8: tick pump order and callback-context rules documented in
native READMEs (zh/en), incl. the allowed/forbidden operation matrix.
exception.const_reassign test updated: it asserted the P1-3 bug
(compile failure); now expects successful compilation per the new
semantics. New regression tests for all the above.
This branch has not been deployed
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.
背景
FakeFish(fakelua 的真实项目方)在实战中发现 8 个问题,文档见 fakefish 仓库
docs/fakelua-pitfalls.md。本 PR 逐一修复,共 21 个文件(+776/-86)。修复清单
P0-1
conn:query回调传内联闭包被静默丢弃(最严重)connect/query/stmt_prepare/stmt_execute)现在支持内联闭包(VarClosure*),闭包可捕获上下文;全局函数名字符串继续支持。bad argument,不再静默丢弃。ResultCallback { name, closure },派发时闭包走DispatchCallClosure(arena 分配无 GC,裸指针安全)。P0-2 查询失败时部分错误路径完全没有回调
Query/StmtPrepare/StmtExecute的所有提前 return 路径统一设置错误并派发回调。P1-3 模块级标量多赋值点被 JIT 标 const 导致编译失败
ir.global_reassigned_vars,经file_level_init_exps_判定绑定归属,对遮蔽免疫),CGen 对其发射非 const 的static int64_t。static const优化(infer.test_global_const_int验证不回退)。exception.const_reassign原本断言的就是这个 bug(期待编译失败),已按新语义更新为期待编译成功。P1-4 连接池无租约语义导致永久泄漏
pool:with(fn)租约 API:取连接传给fn(conn),正常返回或抛错都自动归还。P1-5
json.encode空 table 产出{}而非[][];非空仍要求 1..N 连续整数键。json.encode_array()严格通道:非数组形 table 直接报错。P1-6 回调上下文多重静默限制
IoContext::InDispatch())中的send改为入队、由本轮 tick 派发完后统一泵出(事件驱动改轮询驱动),消除平台相关的静默丢弃;发送失败记 WARN 日志。P2-7 MySQL 结果值全为字符串、格式未文档化
P2-8 tick 泵序与嵌套回调延迟无文档
测试
integration_*(本机无服务器,环境性),exception.const_reassign已按新语义修复。pool:with、JIT const 多赋值点、json 空 table 与encode_array、net 回调内 send。兼容性说明
json.encode({})行为从"{}"变为"[]"(本 PR 的目的);需要空对象的场景请使用带字符串键的表或自行处理。tonumber(v)对 number 原样返回,既有代码兼容。