summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2012-10-08 17:14:18 +0200
committerMike Pall <mike>2012-10-08 17:15:28 +0200
commitda682b0e9184d4db7e8e477c682947d106790240 (patch)
treeea38a32325107a9cb8047880712d13e6dd12fa5d /src
parentc681e009c0c5cba5622b863b914c19cfbf6cc147 (diff)
downloadluajit-da682b0e9184d4db7e8e477c682947d106790240.tar.gz
luajit-da682b0e9184d4db7e8e477c682947d106790240.tar.bz2
luajit-da682b0e9184d4db7e8e477c682947d106790240.zip
FFI: Add support for copy constructors.
Diffstat (limited to 'src')
-rw-r--r--src/lj_cconv.c6
-rw-r--r--src/lj_cconv.h2
-rw-r--r--src/lj_crecord.c3
3 files changed, 7 insertions, 4 deletions
diff --git a/src/lj_cconv.c b/src/lj_cconv.c
index f33ed56d..b81b4e90 100644
--- a/src/lj_cconv.c
+++ b/src/lj_cconv.c
@@ -718,12 +718,14 @@ static void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,
718** This is true if an aggregate is to be initialized with a value. 718** This is true if an aggregate is to be initialized with a value.
719** Valarrays are treated as values here so ct_tv handles (V|C, I|F). 719** Valarrays are treated as values here so ct_tv handles (V|C, I|F).
720*/ 720*/
721int lj_cconv_multi_init(CType *d, TValue *o) 721int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o)
722{ 722{
723 if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info))) 723 if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info)))
724 return 0; /* Destination is not an aggregate. */ 724 return 0; /* Destination is not an aggregate. */
725 if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info))) 725 if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info)))
726 return 0; /* Initializer is not a value. */ 726 return 0; /* Initializer is not a value. */
727 if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d)
728 return 0; /* Source and destination are identical aggregates. */
727 return 1; /* Otherwise the initializer is a value. */ 729 return 1; /* Otherwise the initializer is a value. */
728} 730}
729 731
@@ -733,7 +735,7 @@ void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
733{ 735{
734 if (len == 0) 736 if (len == 0)
735 memset(dp, 0, sz); 737 memset(dp, 0, sz);
736 else if (len == 1 && !lj_cconv_multi_init(d, o)) 738 else if (len == 1 && !lj_cconv_multi_init(cts, d, o))
737 lj_cconv_ct_tv(cts, d, dp, o, 0); 739 lj_cconv_ct_tv(cts, d, dp, o, 0);
738 else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */ 740 else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */
739 cconv_array_init(cts, d, sz, dp, o, len); 741 cconv_array_init(cts, d, sz, dp, o, len);
diff --git a/src/lj_cconv.h b/src/lj_cconv.h
index c53a7cf8..fd5da555 100644
--- a/src/lj_cconv.h
+++ b/src/lj_cconv.h
@@ -61,7 +61,7 @@ LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);
61LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, 61LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,
62 uint8_t *dp, TValue *o, CTInfo flags); 62 uint8_t *dp, TValue *o, CTInfo flags);
63LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); 63LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);
64LJ_FUNC int lj_cconv_multi_init(CType *d, TValue *o); 64LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);
65LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, 65LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
66 uint8_t *dp, TValue *o, MSize len); 66 uint8_t *dp, TValue *o, MSize len);
67 67
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index 99303310..fbb5d79a 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -654,7 +654,8 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
654 TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL); 654 TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL);
655 cTValue *fin; 655 cTValue *fin;
656 J->base[0] = trcd; 656 J->base[0] = trcd;
657 if (J->base[1] && !J->base[2] && !lj_cconv_multi_init(d, &rd->argv[1])) { 657 if (J->base[1] && !J->base[2] &&
658 !lj_cconv_multi_init(cts, d, &rd->argv[1])) {
658 goto single_init; 659 goto single_init;
659 } else if (ctype_isarray(d->info)) { 660 } else if (ctype_isarray(d->info)) {
660 CType *dc = ctype_rawchild(cts, d); /* Array element type. */ 661 CType *dc = ctype_rawchild(cts, d); /* Array element type. */