Skip to content

nups uses objlen but objlen stops at first nil value #5

Description

@Bilgus

A nil upvalue makes lua_objlen stop counting leaving following upvalues nil as well
instead explicitly store ar.nups when the table is created

lmarshal.c#L224
lua_newtable(L);
for (i=1; i <= ar.nups; i++) {
lua_getupvalue(L, -2, i);
lua_rawseti(L, -2, i);
}

should become

lua_createtable(L, ar.nups, 1);
lua_pushinteger(L, ar.nups);
lua_setfield(L, -2, "nups");
for (i=1; i <= ar.nups; i++) {
lua_getupvalue(L, -2, i);
lua_rawseti(L, -2, i);
}

lmarshal.c#L389

mar_decode_table(L, *p, l, idx);
nups = lua_objlen(L, -1);
for (i=1; i <= nups; i++) {
lua_rawgeti(L, -1, i);
lua_setupvalue(L, -3, i);
}

should become

mar_decode_table(L, ld_lpf, field.v_len, idx);
lua_getfield(L, -1, "nups");
nups = lua_tointeger(L, -1);
lua_pop(L, 1);
for (i=1; i <= nups; i++) {
lua_rawgeti(L, -1, i);
lua_setupvalue(L, -3, i);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions