Allow selection of single-number vs. dual-number mode in Makefile.
[luajit-2.0.git] / src / lj_udata.c
blob869f31f8af4987039eb1f08bd4f5d7a5309cc647
1 /*
2 ** Userdata handling.
3 ** Copyright (C) 2005-2011 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));