mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-22 09:58:10 +00:00
feat: 适配 LuaJIT 2.1 (luajit_2.1 分支)
- lib/lua 替换为完整 LuaJIT 2.1 仓库(Makefile+src+dynasm, 官方结构)
- 构建系统改造: lib/lua/CMakeLists.txt 改为调用 LuaJIT 自带 make
(BUILDMODE=static CFLAGS=-fPIC) 产出 libluajit.a; 顶层链接该静态库
并加 -Wl,-E 导出符号(静态链 LuaJIT 必需)
- 补充 lua.hpp 转发头兼容桥接层 'lua/lua.hpp' include 路径
- 桥接层沿用 5.1 方案: Registry 存 iopath / luaL_tolstring 兜底 /
typed interop 无 integer 子类型(LUA_VERSION_NUM=501)
- [关键修复] lua_remove 栈越界 bug(各版本共有, LuaJIT 下显性崩溃):
* unload_lib: ref 记录的是 gettop+1, 实际移除应用 ref-1
* clean(): 原逐个 remove 循环恒越界且多次移除后索引偏移,
属死代码(末尾 settop(L,0) 已清栈), 直接删除
该 bug 在 Lua 5.4 中被隐式容忍, 在 LuaJIT 的 GC finalizer 中
表现为 lj_gc_finalize_cdata 段错误
- 测试跨版本断言同步(自 5.1.5)
- 验证: GTest 44/44 通过
This commit is contained in:
62
lib/lua/src/lj_vmevent.h
Normal file
62
lib/lua/src/lj_vmevent.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
** VM event handling.
|
||||
** Copyright (C) 2005-2026 Mike Pall. See Copyright Notice in luajit.h
|
||||
*/
|
||||
|
||||
#ifndef _LJ_VMEVENT_H
|
||||
#define _LJ_VMEVENT_H
|
||||
|
||||
#include "lj_obj.h"
|
||||
|
||||
/* Registry key for VM event handler table. */
|
||||
#define LJ_VMEVENTS_REGKEY "_VMEVENTS"
|
||||
#define LJ_VMEVENTS_HSIZE 4
|
||||
|
||||
#define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7))
|
||||
#define VMEVENT_HASH(ev) ((int)(ev) & ~7)
|
||||
#define VMEVENT_HASHIDX(h) ((int)(h) << 3)
|
||||
#define VMEVENT_NOCACHE 255
|
||||
|
||||
#define VMEVENT_DEF(name, hash) \
|
||||
LJ_VMEVENT_##name##_, \
|
||||
LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3)
|
||||
|
||||
/* VM event IDs. */
|
||||
typedef enum {
|
||||
VMEVENT_DEF(BC, 0x00003883),
|
||||
VMEVENT_DEF(TRACE, 0x12d91467),
|
||||
VMEVENT_DEF(RECORD, 0x1284bf4f),
|
||||
VMEVENT_DEF(TEXIT, 0x129df2b0),
|
||||
VMEVENT_DEF(ERRFIN, 0x12d93888),
|
||||
LJ_VMEVENT__MAX
|
||||
} VMEvent;
|
||||
|
||||
#ifdef LUAJIT_DISABLE_VMEVENT
|
||||
#define lj_vmevent_send(g, ev, args) UNUSED(g)
|
||||
#define lj_vmevent_send_(g, ev, args, post) UNUSED(g)
|
||||
#else
|
||||
#define lj_vmevent_send(g, ev, args) \
|
||||
if ((g)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
|
||||
lua_State *V = vmthread(g); \
|
||||
ptrdiff_t argbase = lj_vmevent_prepare(V, LJ_VMEVENT_##ev); \
|
||||
if (argbase) { \
|
||||
args \
|
||||
lj_vmevent_call(V, argbase); \
|
||||
} \
|
||||
}
|
||||
#define lj_vmevent_send_(g, ev, args, post) \
|
||||
if ((g)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
|
||||
lua_State *V = vmthread(g); \
|
||||
ptrdiff_t argbase = lj_vmevent_prepare(V, LJ_VMEVENT_##ev); \
|
||||
if (argbase) { \
|
||||
args \
|
||||
lj_vmevent_call(V, argbase); \
|
||||
post \
|
||||
} \
|
||||
}
|
||||
|
||||
LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev);
|
||||
LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user