diff options
Diffstat (limited to 'src/lj_cdata.c')
-rw-r--r-- | src/lj_cdata.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/lj_cdata.c b/src/lj_cdata.c index 10d9423d..a827d1ec 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c | |||
@@ -35,7 +35,7 @@ GCcdata *lj_cdata_newv(lua_State *L, CTypeID id, CTSize sz, CTSize align) | |||
35 | uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata); | 35 | uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata); |
36 | uintptr_t almask = (1u << align) - 1u; | 36 | uintptr_t almask = (1u << align) - 1u; |
37 | GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata)); | 37 | GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata)); |
38 | lua_assert((char *)cd - p < 65536); | 38 | lj_assertL((char *)cd - p < 65536, "excessive cdata alignment"); |
39 | cdatav(cd)->offset = (uint16_t)((char *)cd - p); | 39 | cdatav(cd)->offset = (uint16_t)((char *)cd - p); |
40 | cdatav(cd)->extra = extra; | 40 | cdatav(cd)->extra = extra; |
41 | cdatav(cd)->len = sz; | 41 | cdatav(cd)->len = sz; |
@@ -76,8 +76,8 @@ void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd) | |||
76 | } else if (LJ_LIKELY(!cdataisv(cd))) { | 76 | } else if (LJ_LIKELY(!cdataisv(cd))) { |
77 | CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid); | 77 | CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid); |
78 | CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR; | 78 | CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR; |
79 | lua_assert(ctype_hassize(ct->info) || ctype_isfunc(ct->info) || | 79 | lj_assertG(ctype_hassize(ct->info) || ctype_isfunc(ct->info) || |
80 | ctype_isextern(ct->info)); | 80 | ctype_isextern(ct->info), "free of ctype without a size"); |
81 | lj_mem_free(g, cd, sizeof(GCcdata) + sz); | 81 | lj_mem_free(g, cd, sizeof(GCcdata) + sz); |
82 | } else { | 82 | } else { |
83 | lj_mem_free(g, memcdatav(cd), sizecdatav(cd)); | 83 | lj_mem_free(g, memcdatav(cd), sizecdatav(cd)); |
@@ -115,7 +115,7 @@ CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp, | |||
115 | 115 | ||
116 | /* Resolve reference for cdata object. */ | 116 | /* Resolve reference for cdata object. */ |
117 | if (ctype_isref(ct->info)) { | 117 | if (ctype_isref(ct->info)) { |
118 | lua_assert(ct->size == CTSIZE_PTR); | 118 | lj_assertCTS(ct->size == CTSIZE_PTR, "ref is not pointer-sized"); |
119 | p = *(uint8_t **)p; | 119 | p = *(uint8_t **)p; |
120 | ct = ctype_child(cts, ct); | 120 | ct = ctype_child(cts, ct); |
121 | } | 121 | } |
@@ -126,7 +126,8 @@ collect_attrib: | |||
126 | if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; | 126 | if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; |
127 | ct = ctype_child(cts, ct); | 127 | ct = ctype_child(cts, ct); |
128 | } | 128 | } |
129 | lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ | 129 | /* Interning rejects refs to refs. */ |
130 | lj_assertCTS(!ctype_isref(ct->info), "bad ref of ref"); | ||
130 | 131 | ||
131 | if (tvisint(key)) { | 132 | if (tvisint(key)) { |
132 | idx = (ptrdiff_t)intV(key); | 133 | idx = (ptrdiff_t)intV(key); |
@@ -212,7 +213,8 @@ collect_attrib: | |||
212 | static void cdata_getconst(CTState *cts, TValue *o, CType *ct) | 213 | static void cdata_getconst(CTState *cts, TValue *o, CType *ct) |
213 | { | 214 | { |
214 | CType *ctt = ctype_child(cts, ct); | 215 | CType *ctt = ctype_child(cts, ct); |
215 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); | 216 | lj_assertCTS(ctype_isinteger(ctt->info) && ctt->size <= 4, |
217 | "only 32 bit const supported"); /* NYI */ | ||
216 | /* Constants are already zero-extended/sign-extended to 32 bits. */ | 218 | /* Constants are already zero-extended/sign-extended to 32 bits. */ |
217 | if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) | 219 | if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) |
218 | setnumV(o, (lua_Number)(uint32_t)ct->size); | 220 | setnumV(o, (lua_Number)(uint32_t)ct->size); |
@@ -233,13 +235,14 @@ int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp) | |||
233 | } | 235 | } |
234 | 236 | ||
235 | /* Get child type of pointer/array/field. */ | 237 | /* Get child type of pointer/array/field. */ |
236 | lua_assert(ctype_ispointer(s->info) || ctype_isfield(s->info)); | 238 | lj_assertCTS(ctype_ispointer(s->info) || ctype_isfield(s->info), |
239 | "pointer or field expected"); | ||
237 | sid = ctype_cid(s->info); | 240 | sid = ctype_cid(s->info); |
238 | s = ctype_get(cts, sid); | 241 | s = ctype_get(cts, sid); |
239 | 242 | ||
240 | /* Resolve reference for field. */ | 243 | /* Resolve reference for field. */ |
241 | if (ctype_isref(s->info)) { | 244 | if (ctype_isref(s->info)) { |
242 | lua_assert(s->size == CTSIZE_PTR); | 245 | lj_assertCTS(s->size == CTSIZE_PTR, "ref is not pointer-sized"); |
243 | sp = *(uint8_t **)sp; | 246 | sp = *(uint8_t **)sp; |
244 | sid = ctype_cid(s->info); | 247 | sid = ctype_cid(s->info); |
245 | s = ctype_get(cts, sid); | 248 | s = ctype_get(cts, sid); |
@@ -266,12 +269,13 @@ void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual) | |||
266 | } | 269 | } |
267 | 270 | ||
268 | /* Get child type of pointer/array/field. */ | 271 | /* Get child type of pointer/array/field. */ |
269 | lua_assert(ctype_ispointer(d->info) || ctype_isfield(d->info)); | 272 | lj_assertCTS(ctype_ispointer(d->info) || ctype_isfield(d->info), |
273 | "pointer or field expected"); | ||
270 | d = ctype_child(cts, d); | 274 | d = ctype_child(cts, d); |
271 | 275 | ||
272 | /* Resolve reference for field. */ | 276 | /* Resolve reference for field. */ |
273 | if (ctype_isref(d->info)) { | 277 | if (ctype_isref(d->info)) { |
274 | lua_assert(d->size == CTSIZE_PTR); | 278 | lj_assertCTS(d->size == CTSIZE_PTR, "ref is not pointer-sized"); |
275 | dp = *(uint8_t **)dp; | 279 | dp = *(uint8_t **)dp; |
276 | d = ctype_child(cts, d); | 280 | d = ctype_child(cts, d); |
277 | } | 281 | } |
@@ -286,7 +290,8 @@ void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual) | |||
286 | d = ctype_child(cts, d); | 290 | d = ctype_child(cts, d); |
287 | } | 291 | } |
288 | 292 | ||
289 | lua_assert(ctype_hassize(d->info) && !ctype_isvoid(d->info)); | 293 | lj_assertCTS(ctype_hassize(d->info), "store to ctype without size"); |
294 | lj_assertCTS(!ctype_isvoid(d->info), "store to void type"); | ||
290 | 295 | ||
291 | if (((d->info|qual) & CTF_CONST)) { | 296 | if (((d->info|qual) & CTF_CONST)) { |
292 | err_const: | 297 | err_const: |