mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-23 18:38:15 +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:
71
lib/lua/src/lj_cconv.h
Normal file
71
lib/lua/src/lj_cconv.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
** C type conversions.
|
||||
** Copyright (C) 2005-2026 Mike Pall. See Copyright Notice in luajit.h
|
||||
*/
|
||||
|
||||
#ifndef _LJ_CCONV_H
|
||||
#define _LJ_CCONV_H
|
||||
|
||||
#include "lj_obj.h"
|
||||
#include "lj_ctype.h"
|
||||
|
||||
#if LJ_HASFFI
|
||||
|
||||
/* Compressed C type index. ORDER CCX. */
|
||||
enum {
|
||||
CCX_B, /* Bool. */
|
||||
CCX_I, /* Integer. */
|
||||
CCX_F, /* Floating-point number. */
|
||||
CCX_C, /* Complex. */
|
||||
CCX_V, /* Vector. */
|
||||
CCX_P, /* Pointer. */
|
||||
CCX_A, /* Refarray. */
|
||||
CCX_S /* Struct/union. */
|
||||
};
|
||||
|
||||
/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */
|
||||
static LJ_AINLINE uint32_t cconv_idx(CTInfo info)
|
||||
{
|
||||
uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */
|
||||
lj_assertX(ctype_type(info) <= CT_MAYCONVERT,
|
||||
"cannot convert ctype %08x", info);
|
||||
#if LJ_64
|
||||
idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u);
|
||||
#else
|
||||
idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u);
|
||||
#endif
|
||||
lj_assertX(idx < 8, "cannot convert ctype %08x", info);
|
||||
return idx;
|
||||
}
|
||||
|
||||
#define cconv_idx2(dinfo, sinfo) \
|
||||
((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo)))
|
||||
|
||||
#define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src)
|
||||
|
||||
/* Conversion flags. */
|
||||
#define CCF_CAST 0x00000001u
|
||||
#define CCF_FROMTV 0x00000002u
|
||||
#define CCF_SAME 0x00000004u
|
||||
#define CCF_IGNQUAL 0x00000008u
|
||||
|
||||
#define CCF_ARG_SHIFT 8
|
||||
#define CCF_ARG(n) ((n) << CCF_ARG_SHIFT)
|
||||
#define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT)
|
||||
|
||||
LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags);
|
||||
LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
|
||||
uint8_t *dp, uint8_t *sp, CTInfo flags);
|
||||
LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
|
||||
TValue *o, uint8_t *sp);
|
||||
LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);
|
||||
LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,
|
||||
uint8_t *dp, TValue *o, CTInfo flags);
|
||||
LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);
|
||||
LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);
|
||||
LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
|
||||
uint8_t *dp, TValue *o, MSize len);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user