diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_udata.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lj_udata.c b/src/lj_udata.c new file mode 100644 index 00000000..863889c9 --- /dev/null +++ b/src/lj_udata.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | ** Userdata handling. | ||
3 | ** Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #define lj_udata_c | ||
7 | #define LUA_CORE | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | #include "lj_gc.h" | ||
11 | #include "lj_udata.h" | ||
12 | |||
13 | GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env) | ||
14 | { | ||
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->len = sz; | ||
20 | /* NOBARRIER: The GCudata is new (marked white). */ | ||
21 | setgcrefnull(ud->metatable); | ||
22 | setgcref(ud->env, obj2gco(env)); | ||
23 | /* Chain to userdata list (after main thread). */ | ||
24 | setgcrefr(ud->nextgc, mainthread(g)->nextgc); | ||
25 | setgcref(mainthread(g)->nextgc, obj2gco(ud)); | ||
26 | return ud; | ||
27 | } | ||
28 | |||
29 | void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud) | ||
30 | { | ||
31 | lj_mem_free(g, ud, sizeudata(ud)); | ||
32 | } | ||
33 | |||