summaryrefslogtreecommitdiff
path: root/src/lib_ffi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_ffi.c')
-rw-r--r--src/lib_ffi.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index 89baa356..42d71153 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -157,14 +157,13 @@ static int ffi_arith_ptr(lua_State *L, CTState *cts, FFIArith *fa, MMS mm)
157 return 1; 157 return 1;
158 } 158 }
159 } 159 }
160 if (!((mm == MM_add || mm == MM_sub) && 160 if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(fa->ct[1]->info)))
161 ctype_isnum(fa->ct[1]->info))) return 0; 161 return 0;
162 lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), fa->ct[1], 162 lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), fa->ct[1],
163 (uint8_t *)&idx, fa->p[1], 0); 163 (uint8_t *)&idx, fa->p[1], 0);
164 if (mm == MM_sub) idx = -idx; 164 if (mm == MM_sub) idx = -idx;
165 } else if (mm == MM_add && 165 } else if (mm == MM_add && ctype_isnum(ctp->info) &&
166 (ctype_isptr(fa->ct[1]->info) || ctype_isrefarray(fa->ct[1]->info))) { 166 (ctype_isptr(fa->ct[1]->info) || ctype_isrefarray(fa->ct[1]->info))) {
167 if (!ctype_isnum(ctp->info)) return 0;
168 /* Swap pointer and index. */ 167 /* Swap pointer and index. */
169 ctp = fa->ct[1]; pp = fa->p[1]; 168 ctp = fa->ct[1]; pp = fa->p[1];
170 lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), fa->ct[0], 169 lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), fa->ct[0],
@@ -264,8 +263,10 @@ static int ffi_arith(lua_State *L)
264 FFIArith fa; 263 FFIArith fa;
265 MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq); 264 MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq);
266 if (ffi_checkarith(L, cts, &fa)) { 265 if (ffi_checkarith(L, cts, &fa)) {
267 if (ffi_arith_int64(L, cts, &fa, mm) || ffi_arith_ptr(L, cts, &fa, mm)) 266 if (ffi_arith_int64(L, cts, &fa, mm) || ffi_arith_ptr(L, cts, &fa, mm)) {
267 copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */
268 return 1; 268 return 1;
269 }
269 } 270 }
270 /* NYI: per-cdata metamethods. */ 271 /* NYI: per-cdata metamethods. */
271 { 272 {
@@ -319,7 +320,7 @@ LJLIB_CF(ffi_meta___newindex) LJLIB_REC(cdata_index 1)
319} 320}
320 321
321/* The following functions must be in contiguous ORDER MM. */ 322/* The following functions must be in contiguous ORDER MM. */
322LJLIB_CF(ffi_meta___eq) 323LJLIB_CF(ffi_meta___eq) LJLIB_REC(cdata_arith MM_eq)
323{ 324{
324 return ffi_arith(L); 325 return ffi_arith(L);
325} 326}
@@ -329,12 +330,12 @@ LJLIB_CF(ffi_meta___len)
329 return ffi_arith(L); 330 return ffi_arith(L);
330} 331}
331 332
332LJLIB_CF(ffi_meta___lt) 333LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt)
333{ 334{
334 return ffi_arith(L); 335 return ffi_arith(L);
335} 336}
336 337
337LJLIB_CF(ffi_meta___le) 338LJLIB_CF(ffi_meta___le) LJLIB_REC(cdata_arith MM_le)
338{ 339{
339 return ffi_arith(L); 340 return ffi_arith(L);
340} 341}