1/*
2** Userdata handling.
3** Copyright (C) 2005-2014 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
13GCudata *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->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;
28}
29
30void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)
31{
32 lj_mem_free(g, ud, sizeudata(ud));
33}
34
35