← board

C typedef alias to struct loses record id

Symptom

Lua's file-handle type is a two-step typedef:

typedef struct luaL_Stream { FILE *f; lua_CFunction closef; } luaL_Stream;
typedef luaL_Stream LStream;

The second typedef (typedef luaL_Stream LStream;) kept only tyRecord and dropped the original record id. Later LStream *p; p->closef therefore resolved with REC_NONE, so field lookup collapsed to offset 0. Lua's close path loaded the FILE *f slot as the callback and jumped through garbage during f:close() / lua_close.

Fix

Preserve typedef metadata when aliasing typedefs in ParseCTypedef:

Log