aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-01-23 14:23:21 +0100
committerMike Pall <mike>2011-01-23 14:23:21 +0100
commit72b3fff72f6bb9cf5796bbcd50e9a490d4e02b4b (patch)
tree5ee063bd3f5af95dddda47f30c67adfe5bc0e5ad /src
parentf529d22869429d458c5382cf6787f213d7bd5296 (diff)
downloadluajit-72b3fff72f6bb9cf5796bbcd50e9a490d4e02b4b.tar.gz
luajit-72b3fff72f6bb9cf5796bbcd50e9a490d4e02b4b.tar.bz2
luajit-72b3fff72f6bb9cf5796bbcd50e9a490d4e02b4b.zip
FFI: Simplify initializer rules. Clarify docs.
Diffstat (limited to 'src')
-rw-r--r--src/lj_cconv.c9
-rw-r--r--src/lj_cconv.h2
-rw-r--r--src/lj_crecord.c3
3 files changed, 4 insertions, 10 deletions
diff --git a/src/lj_cconv.c b/src/lj_cconv.c
index ac6374ed..d4578f88 100644
--- a/src/lj_cconv.c
+++ b/src/lj_cconv.c
@@ -679,17 +679,12 @@ static void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,
679** This is true if an aggregate is to be initialized with a value. 679** This is true if an aggregate is to be initialized with a value.
680** Valarrays are treated as values here so ct_tv handles (V|C, I|F). 680** Valarrays are treated as values here so ct_tv handles (V|C, I|F).
681*/ 681*/
682int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o) 682int lj_cconv_multi_init(CType *d, TValue *o)
683{ 683{
684 if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info))) 684 if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info)))
685 return 0; /* Destination is not an aggregate. */ 685 return 0; /* Destination is not an aggregate. */
686 if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info))) 686 if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info)))
687 return 0; /* Initializer is not a value. */ 687 return 0; /* Initializer is not a value. */
688 if (tviscdata(o)) {
689 CTInfo info = lj_ctype_rawref(cts, cdataV(o)->typeid)->info;
690 if (ctype_isrefarray(info) || ctype_isstruct(info))
691 return 0; /* Initializer is not a value. */
692 }
693 return 1; /* Otherwise the initializer is a value. */ 688 return 1; /* Otherwise the initializer is a value. */
694} 689}
695 690
@@ -699,7 +694,7 @@ void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
699{ 694{
700 if (len == 0) 695 if (len == 0)
701 memset(dp, 0, sz); 696 memset(dp, 0, sz);
702 else if (len == 1 && !lj_cconv_multi_init(cts, d, o)) 697 else if (len == 1 && !lj_cconv_multi_init(d, o))
703 lj_cconv_ct_tv(cts, d, dp, o, 0); 698 lj_cconv_ct_tv(cts, d, dp, o, 0);
704 else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */ 699 else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */
705 cconv_array_init(cts, d, sz, dp, o, len); 700 cconv_array_init(cts, d, sz, dp, o, len);
diff --git a/src/lj_cconv.h b/src/lj_cconv.h
index acc09af9..494f9d4e 100644
--- a/src/lj_cconv.h
+++ b/src/lj_cconv.h
@@ -58,7 +58,7 @@ LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);
58LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, 58LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,
59 uint8_t *dp, TValue *o, CTInfo flags); 59 uint8_t *dp, TValue *o, CTInfo flags);
60LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); 60LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);
61LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o); 61LJ_FUNC int lj_cconv_multi_init(CType *d, TValue *o);
62LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, 62LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
63 uint8_t *dp, TValue *o, MSize len); 63 uint8_t *dp, TValue *o, MSize len);
64 64
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index c6577975..681c5029 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -566,8 +566,7 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
566 CType *d = ctype_raw(cts, id); 566 CType *d = ctype_raw(cts, id);
567 TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL); 567 TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL);
568 J->base[0] = trcd; 568 J->base[0] = trcd;
569 if (J->base[1] && !J->base[2] && 569 if (J->base[1] && !J->base[2] && !lj_cconv_multi_init(d, &rd->argv[1])) {
570 !lj_cconv_multi_init(cts, d, &rd->argv[1])) {
571 goto single_init; 570 goto single_init;
572 } else if (ctype_isarray(d->info)) { 571 } else if (ctype_isarray(d->info)) {
573 CType *dc = ctype_rawchild(cts, d); /* Array element type. */ 572 CType *dc = ctype_rawchild(cts, d); /* Array element type. */