diff options
author | Mike Pall <mike> | 2011-10-11 20:56:57 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2011-10-11 20:58:04 +0200 |
commit | 120c3adbff2acbbee5932f28345cde292ef044ec (patch) | |
tree | 769cfa3b9280480187ce4946adce09dcd6735504 /src | |
parent | 4a144625c90db7497dd3fce79b97be39ef0af773 (diff) | |
download | luajit-120c3adbff2acbbee5932f28345cde292ef044ec.tar.gz luajit-120c3adbff2acbbee5932f28345cde292ef044ec.tar.bz2 luajit-120c3adbff2acbbee5932f28345cde292ef044ec.zip |
FFI: Record loads/stores to external variables in namespaces.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib_ffi.c | 8 | ||||
-rw-r--r-- | src/lj_crecord.c | 17 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 582e9bf7..82942e44 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
@@ -325,7 +325,7 @@ static TValue *ffi_clib_index(lua_State *L) | |||
325 | return lj_clib_index(L, cl, strV(o+1)); | 325 | return lj_clib_index(L, cl, strV(o+1)); |
326 | } | 326 | } |
327 | 327 | ||
328 | LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index) | 328 | LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index 1) |
329 | { | 329 | { |
330 | TValue *tv = ffi_clib_index(L); | 330 | TValue *tv = ffi_clib_index(L); |
331 | if (tviscdata(tv)) { | 331 | if (tviscdata(tv)) { |
@@ -335,7 +335,9 @@ LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index) | |||
335 | if (ctype_isextern(s->info)) { | 335 | if (ctype_isextern(s->info)) { |
336 | CTypeID sid = ctype_cid(s->info); | 336 | CTypeID sid = ctype_cid(s->info); |
337 | void *sp = *(void **)cdataptr(cd); | 337 | void *sp = *(void **)cdataptr(cd); |
338 | if (lj_cconv_tv_ct(cts, ctype_raw(cts, sid), sid, L->top-1, sp)) | 338 | CType *ct = ctype_raw(cts, sid); |
339 | if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); | ||
340 | if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp)) | ||
339 | lj_gc_check(L); | 341 | lj_gc_check(L); |
340 | return 1; | 342 | return 1; |
341 | } | 343 | } |
@@ -344,7 +346,7 @@ LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index) | |||
344 | return 1; | 346 | return 1; |
345 | } | 347 | } |
346 | 348 | ||
347 | LJLIB_CF(ffi_clib___newindex) | 349 | LJLIB_CF(ffi_clib___newindex) LJLIB_REC(clib_index 0) |
348 | { | 350 | { |
349 | TValue *tv = ffi_clib_index(L); | 351 | TValue *tv = ffi_clib_index(L); |
350 | TValue *o = L->base+2; | 352 | TValue *o = L->base+2; |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 96b62efe..c688caa3 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
@@ -1031,6 +1031,7 @@ void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd) | |||
1031 | CType *ct; | 1031 | CType *ct; |
1032 | CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); | 1032 | CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); |
1033 | cTValue *tv = lj_tab_getstr(cl->cache, name); | 1033 | cTValue *tv = lj_tab_getstr(cl->cache, name); |
1034 | rd->nres = rd->data; | ||
1034 | if (id && tv && !tvisnil(tv)) { | 1035 | if (id && tv && !tvisnil(tv)) { |
1035 | /* Specialize to the symbol name and make the result a constant. */ | 1036 | /* Specialize to the symbol name and make the result a constant. */ |
1036 | emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name)); | 1037 | emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name)); |
@@ -1041,7 +1042,21 @@ void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd) | |||
1041 | else | 1042 | else |
1042 | J->base[0] = lj_ir_kint(J, (int32_t)ct->size); | 1043 | J->base[0] = lj_ir_kint(J, (int32_t)ct->size); |
1043 | } else if (ctype_isextern(ct->info)) { | 1044 | } else if (ctype_isextern(ct->info)) { |
1044 | lj_trace_err(J, LJ_TRERR_BADTYPE); /* NYI: access extern variables. */ | 1045 | CTypeID sid = ctype_cid(ct->info); |
1046 | void *sp = *(void **)cdataptr(cdataV(tv)); | ||
1047 | TRef ptr; | ||
1048 | ct = ctype_raw(cts, sid); | ||
1049 | if (rd->data && ctype_isenum(ct->info)) ct = ctype_child(cts, ct); | ||
1050 | if (LJ_64 && !checkptr32(sp)) | ||
1051 | ptr = lj_ir_kintp(J, (uintptr_t)sp); | ||
1052 | else | ||
1053 | ptr = lj_ir_kptr(J, sp); | ||
1054 | if (rd->data) { | ||
1055 | J->base[0] = crec_tv_ct(J, ct, sid, ptr); | ||
1056 | } else { | ||
1057 | J->needsnap = 1; | ||
1058 | crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]); | ||
1059 | } | ||
1045 | } else { | 1060 | } else { |
1046 | J->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA); | 1061 | J->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA); |
1047 | } | 1062 | } |