diff options
author | Mike Pall <mike> | 2012-10-08 17:14:18 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2012-10-08 17:15:28 +0200 |
commit | da682b0e9184d4db7e8e477c682947d106790240 (patch) | |
tree | ea38a32325107a9cb8047880712d13e6dd12fa5d /src | |
parent | c681e009c0c5cba5622b863b914c19cfbf6cc147 (diff) | |
download | luajit-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.c | 6 | ||||
-rw-r--r-- | src/lj_cconv.h | 2 | ||||
-rw-r--r-- | src/lj_crecord.c | 3 |
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 | */ |
721 | int lj_cconv_multi_init(CType *d, TValue *o) | 721 | int 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); | |||
61 | LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, | 61 | LJ_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); |
63 | LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); | 63 | LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); |
64 | LJ_FUNC int lj_cconv_multi_init(CType *d, TValue *o); | 64 | LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o); |
65 | LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, | 65 | LJ_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. */ |