DynASM: Lua 5.2 compatibility fixes.
[luajit-2.0.git] / src / lj_udata.c
blob5e11afbe65f53be34bb478d2818443029ead90c4
1 /*
2 ** Userdata handling.
3 ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #define lj_udata_c
7 #define LUA_CORE
9 #include "lj_obj.h"
10 #include "lj_gc.h"
11 #include "lj_udata.h"
13 GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env)
15 GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata);
16 global_State *g = G(L);
17 newwhite(g, ud); /* Not finalized. */
18 ud->gct = ~LJ_TUDATA;
19 ud->udtype = UDTYPE_USERDATA;
20 ud->len = sz;
21 /* NOBARRIER: The GCudata is new (marked white). */
22 setgcrefnull(ud->metatable);
23 setgcref(ud->env, obj2gco(env));
24 /* Chain to userdata list (after main thread). */
25 setgcrefr(ud->nextgc, mainthread(g)->nextgc);
26 setgcref(mainthread(g)->nextgc, obj2gco(ud));
27 return ud;
30 void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)
32 lj_mem_free(g, ud, sizeudata(ud));