3 ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
15 /* Get C data pointer. */
16 static LJ_AINLINE
void *cdata_getptr(void *p
, CTSize sz
)
18 if (LJ_64
&& sz
== 4) { /* Support 32 bit pointers on 64 bit targets. */
19 return ((void *)(uintptr_t)*(uint32_t *)p
);
21 lua_assert(sz
== CTSIZE_PTR
);
26 /* Set C data pointer. */
27 static LJ_AINLINE
void cdata_setptr(void *p
, CTSize sz
, const void *v
)
29 if (LJ_64
&& sz
== 4) { /* Support 32 bit pointers on 64 bit targets. */
30 *(uint32_t *)p
= (uint32_t)(uintptr_t)v
;
32 lua_assert(sz
== CTSIZE_PTR
);
33 *(void **)p
= (void *)v
;
37 /* Allocate fixed-size C data object. */
38 static LJ_AINLINE GCcdata
*lj_cdata_new(CTState
*cts
, CTypeID id
, CTSize sz
)
42 CType
*ct
= ctype_raw(cts
, id
);
43 lua_assert((ctype_hassize(ct
->info
) ? ct
->size
: CTSIZE_PTR
) == sz
);
45 cd
= (GCcdata
*)lj_mem_newgco(cts
->L
, sizeof(GCcdata
) + sz
);
47 cd
->ctypeid
= ctype_check(cts
, id
);
51 /* Variant which works without a valid CTState. */
52 static LJ_AINLINE GCcdata
*lj_cdata_new_(lua_State
*L
, CTypeID id
, CTSize sz
)
54 GCcdata
*cd
= (GCcdata
*)lj_mem_newgco(L
, sizeof(GCcdata
) + sz
);
60 LJ_FUNC GCcdata
*lj_cdata_newref(CTState
*cts
, const void *pp
, CTypeID id
);
61 LJ_FUNC GCcdata
*lj_cdata_newv(CTState
*cts
, CTypeID id
, CTSize sz
,
64 LJ_FUNC
void LJ_FASTCALL
lj_cdata_free(global_State
*g
, GCcdata
*cd
);
65 LJ_FUNCA TValue
* LJ_FASTCALL
lj_cdata_setfin(lua_State
*L
, GCcdata
*cd
);
67 LJ_FUNC CType
*lj_cdata_index(CTState
*cts
, GCcdata
*cd
, cTValue
*key
,
68 uint8_t **pp
, CTInfo
*qual
);
69 LJ_FUNC
int lj_cdata_get(CTState
*cts
, CType
*s
, TValue
*o
, uint8_t *sp
);
70 LJ_FUNC
void lj_cdata_set(CTState
*cts
, CType
*d
, uint8_t *dp
, TValue
*o
,