Skip to content

Commit

Permalink
fix ffi.nullptr #2
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Jan 16, 2025
1 parent e826b2e commit 6d6ac43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ static struct ctype *ctype_new(lua_State *L, bool keep)
struct ctype *ct = lua_newuserdata(L, sizeof(struct ctype));

ct->type = CTYPE_VOID;
ct->ft = &ffi_type_void;
ct->is_const = false;

luaL_getmetatable(L, CTYPE_MT);
Expand Down Expand Up @@ -2469,8 +2470,16 @@ static void createmetatable(lua_State *L, const char *name, const struct luaL_Re

static void create_nullptr(lua_State *L)
{
struct ctype *ct = ctype_new(L, false);
ctype_to_ptr(L, ct);
struct ctype match = {
.type = CTYPE_VOID,
.ft = &ffi_type_void
};
struct ctype *ct;

ctype_to_ptr(L, &match);

ct = ctype_lookup(L, &match, false);

cdata_ptr_set(cdata_new(L, ct, NULL), NULL);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ ffi.cdef([[
]])

local tests = {
function()
print(ffi.nullptr)
end,
function()
local a = ffi.new('int [10]', {1, 2, 3})
assert(a[0] == 1)
Expand Down

0 comments on commit 6d6ac43

Please sign in to comment.