diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_cconv.c | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/src/lj_cconv.c b/src/lj_cconv.c index f68f86a4..06e3160f 100644 --- a/src/lj_cconv.c +++ b/src/lj_cconv.c | |||
@@ -373,28 +373,6 @@ copyval: /* Copy value. */ | |||
373 | 373 | ||
374 | /* -- C type to TValue conversion ----------------------------------------- */ | 374 | /* -- C type to TValue conversion ----------------------------------------- */ |
375 | 375 | ||
376 | /* Copy value to new cdata. Strip attributes and qualifiers. */ | ||
377 | static GCcdata *cconv_copyval(CTState *cts, CTypeID id, void *sp) | ||
378 | { | ||
379 | CType *ct = ctype_raw(cts, id); | ||
380 | CTInfo info = ct->info; | ||
381 | CTSize size = ct->size; | ||
382 | GCcdata *cd; | ||
383 | lua_assert(ctype_isnum(info) || ctype_isenum(info) || | ||
384 | ctype_isptr(info) || ctype_isvalarray(info)); | ||
385 | if (LJ_UNLIKELY((info & CTF_QUAL))) { /* Any qualifiers to strip? */ | ||
386 | if (ctype_isarray(info)) { | ||
387 | CType *cct = ctype_child(cts, ct); | ||
388 | id = lj_ctype_intern(cts, (cct->info & ~CTF_QUAL), cct->size); | ||
389 | info = ((info & ~CTMASK_CID) + id); | ||
390 | } | ||
391 | id = lj_ctype_intern(cts, (info & ~CTF_QUAL), size); | ||
392 | } | ||
393 | cd = lj_cdata_new(cts, id, size); | ||
394 | memcpy(cdataptr(cd), sp, size); | ||
395 | return cd; | ||
396 | } | ||
397 | |||
398 | /* Convert C type to TValue. Caveat: expects to get the raw CType! */ | 376 | /* Convert C type to TValue. Caveat: expects to get the raw CType! */ |
399 | void lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, | 377 | void lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, |
400 | TValue *o, uint8_t *sp) | 378 | TValue *o, uint8_t *sp) |
@@ -423,8 +401,15 @@ void lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, | |||
423 | /* Create reference. */ | 401 | /* Create reference. */ |
424 | setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid)); | 402 | setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid)); |
425 | } else { | 403 | } else { |
404 | GCcdata *cd; | ||
405 | CTSize sz; | ||
426 | copyval: /* Copy value. */ | 406 | copyval: /* Copy value. */ |
427 | setcdataV(cts->L, o, cconv_copyval(cts, sid, sp)); | 407 | sz = s->size; |
408 | lua_assert(sz != CTSIZE_INVALID); | ||
409 | /* Attributes are stripped, qualifiers are kept (but mostly ignored). */ | ||
410 | cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz); | ||
411 | setcdataV(cts->L, o, cd); | ||
412 | memcpy(cdataptr(cd), sp, sz); | ||
428 | } | 413 | } |
429 | } | 414 | } |
430 | 415 | ||