diff options
| author | Mike Pall <mike> | 2020-05-08 13:50:41 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2020-05-08 13:50:41 +0200 |
| commit | cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0 (patch) | |
| tree | d0194b811af58504b68e91f673e6e27852e82b5d /src | |
| parent | 179cf2eb84fef2b9a524469c3c8cc49363b8fb10 (diff) | |
| download | luajit-cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0.tar.gz luajit-cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0.tar.bz2 luajit-cc4bbec483d3f3250b519ccb7cc22f1a8e6fe6f0.zip | |
FFI: Always fall back to metamethods for cdata length/concat.
Thanks to Egor Skriptunoff.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_ffi.c | 2 | ||||
| -rw-r--r-- | src/lj_carith.c | 11 | ||||
| -rw-r--r-- | src/lj_carith.h | 1 | ||||
| -rw-r--r-- | src/lj_crecord.c | 6 |
4 files changed, 6 insertions, 14 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 5851eea5..c7a26f56 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -193,7 +193,7 @@ LJLIB_CF(ffi_meta___eq) LJLIB_REC(cdata_arith MM_eq) | |||
| 193 | 193 | ||
| 194 | LJLIB_CF(ffi_meta___len) LJLIB_REC(cdata_arith MM_len) | 194 | LJLIB_CF(ffi_meta___len) LJLIB_REC(cdata_arith MM_len) |
| 195 | { | 195 | { |
| 196 | return lj_carith_len(L); | 196 | return ffi_arith(L); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt) | 199 | LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt) |
diff --git a/src/lj_carith.c b/src/lj_carith.c index b33b1f36..530d5ddb 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c | |||
| @@ -263,7 +263,7 @@ int lj_carith_op(lua_State *L, MMS mm) | |||
| 263 | { | 263 | { |
| 264 | CTState *cts = ctype_cts(L); | 264 | CTState *cts = ctype_cts(L); |
| 265 | CDArith ca; | 265 | CDArith ca; |
| 266 | if (carith_checkarg(L, cts, &ca)) { | 266 | if (carith_checkarg(L, cts, &ca) && mm != MM_len && mm != MM_concat) { |
| 267 | if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) { | 267 | if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) { |
| 268 | copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */ | 268 | copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */ |
| 269 | return 1; | 269 | return 1; |
| @@ -272,15 +272,6 @@ int lj_carith_op(lua_State *L, MMS mm) | |||
| 272 | return lj_carith_meta(L, cts, &ca, mm); | 272 | return lj_carith_meta(L, cts, &ca, mm); |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | /* No built-in functionality for length of cdata. */ | ||
| 276 | int lj_carith_len(lua_State *L) | ||
| 277 | { | ||
| 278 | CTState *cts = ctype_cts(L); | ||
| 279 | CDArith ca; | ||
| 280 | carith_checkarg(L, cts, &ca); | ||
| 281 | return lj_carith_meta(L, cts, &ca, MM_len); | ||
| 282 | } | ||
| 283 | |||
| 284 | /* -- 64 bit integer arithmetic helpers ----------------------------------- */ | 275 | /* -- 64 bit integer arithmetic helpers ----------------------------------- */ |
| 285 | 276 | ||
| 286 | #if LJ_32 && LJ_HASJIT | 277 | #if LJ_32 && LJ_HASJIT |
diff --git a/src/lj_carith.h b/src/lj_carith.h index bac3e1a4..207809df 100644 --- a/src/lj_carith.h +++ b/src/lj_carith.h | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | #if LJ_HASFFI | 11 | #if LJ_HASFFI |
| 12 | 12 | ||
| 13 | LJ_FUNC int lj_carith_op(lua_State *L, MMS mm); | 13 | LJ_FUNC int lj_carith_op(lua_State *L, MMS mm); |
| 14 | LJ_FUNC int lj_carith_len(lua_State *L); | ||
| 15 | 14 | ||
| 16 | #if LJ_32 && LJ_HASJIT | 15 | #if LJ_32 && LJ_HASJIT |
| 17 | LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k); | 16 | LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k); |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 99344b79..6e3c36a1 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -1443,8 +1443,10 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
| 1443 | } | 1443 | } |
| 1444 | { | 1444 | { |
| 1445 | TRef tr; | 1445 | TRef tr; |
| 1446 | if (!(tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) && | 1446 | MMS mm = (MMS)rd->data; |
| 1447 | !(tr = crec_arith_ptr(J, sp, s, (MMS)rd->data)) && | 1447 | if ((mm == MM_len || mm == MM_concat || |
| 1448 | (!(tr = crec_arith_int64(J, sp, s, mm)) && | ||
| 1449 | !(tr = crec_arith_ptr(J, sp, s, mm)))) && | ||
| 1448 | !(tr = crec_arith_meta(J, sp, s, cts, rd))) | 1450 | !(tr = crec_arith_meta(J, sp, s, cts, rd))) |
| 1449 | return; | 1451 | return; |
| 1450 | J->base[0] = tr; | 1452 | J->base[0] = tr; |
