diff options
| author | Mike Pall <mike> | 2012-05-23 22:19:05 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2012-05-23 22:20:27 +0200 |
| commit | 3a43ea50843e4f6db73b8edf637dfd209ffbe2ab (patch) | |
| tree | d939ba39e95c0463fd12bad5963a0b50564a47a5 | |
| parent | f3197046b801b20e28a2b9acc6fb0ee4f51f9f2f (diff) | |
| download | luajit-3a43ea50843e4f6db73b8edf637dfd209ffbe2ab.tar.gz luajit-3a43ea50843e4f6db73b8edf637dfd209ffbe2ab.tar.bz2 luajit-3a43ea50843e4f6db73b8edf637dfd209ffbe2ab.zip | |
FFI: Equality comparisons never raise an error.
| -rw-r--r-- | doc/ext_ffi_semantics.html | 5 | ||||
| -rw-r--r-- | src/lj_carith.c | 4 | ||||
| -rw-r--r-- | src/lj_crecord.c | 16 |
3 files changed, 19 insertions, 6 deletions
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html index 2dbe41e9..304befa7 100644 --- a/doc/ext_ffi_semantics.html +++ b/doc/ext_ffi_semantics.html | |||
| @@ -724,6 +724,11 @@ of them is an <tt>uint64_t</tt>, the other side is converted to an | |||
| 724 | both sides are converted to an <tt>int64_t</tt> and a signed | 724 | both sides are converted to an <tt>int64_t</tt> and a signed |
| 725 | comparison is performed.</li> | 725 | comparison is performed.</li> |
| 726 | 726 | ||
| 727 | <li><b>Comparisons for equality/inequality</b> never raise an error. | ||
| 728 | Even incompatible pointers can be compared for equality by address. Any | ||
| 729 | other incompatible comparison (also with non-cdata objects) treats the | ||
| 730 | two sides as unequal.</li> | ||
| 731 | |||
| 727 | </ul> | 732 | </ul> |
| 728 | 733 | ||
| 729 | <h3 id="cdata_key">cdata objects as table keys</h3> | 734 | <h3 id="cdata_key">cdata objects as table keys</h3> |
diff --git a/src/lj_carith.c b/src/lj_carith.c index 56708bf6..583a3876 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c | |||
| @@ -205,6 +205,10 @@ static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm) | |||
| 205 | if (!tv) { | 205 | if (!tv) { |
| 206 | const char *repr[2]; | 206 | const char *repr[2]; |
| 207 | int i; | 207 | int i; |
| 208 | if (mm == MM_eq) { /* Equality checks never raise an error. */ | ||
| 209 | setboolV(L->top-1, 0); | ||
| 210 | return 1; | ||
| 211 | } | ||
| 208 | for (i = 0; i < 2; i++) { | 212 | for (i = 0; i < 2; i++) { |
| 209 | if (ca->ct[i]) | 213 | if (ca->ct[i]) |
| 210 | repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL)); | 214 | repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL)); |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 81ab3540..74d62d6c 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -1073,13 +1073,17 @@ static void crec_arith_meta(jit_State *J, CTState *cts, RecordFFData *rd) | |||
| 1073 | tv = lj_ctype_meta(cts, argv2cdata(J, J->base[1], &rd->argv[1])->typeid, | 1073 | tv = lj_ctype_meta(cts, argv2cdata(J, J->base[1], &rd->argv[1])->typeid, |
| 1074 | (MMS)rd->data); | 1074 | (MMS)rd->data); |
| 1075 | } | 1075 | } |
| 1076 | if (tv && tvisfunc(tv)) { | 1076 | if (tv) { |
| 1077 | J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; | 1077 | if (tvisfunc(tv)) { |
| 1078 | rd->nres = -1; /* Pending tailcall. */ | 1078 | J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; |
| 1079 | } else { | 1079 | rd->nres = -1; /* Pending tailcall. */ |
| 1080 | /* NYI: non-function metamethods. */ | 1080 | return; |
| 1081 | lj_trace_err(J, LJ_TRERR_BADTYPE); | 1081 | } /* NYI: non-function metamethods. */ |
| 1082 | } else if ((MMS)rd->data == MM_eq) { | ||
| 1083 | J->base[0] = TREF_FALSE; | ||
| 1084 | return; | ||
| 1082 | } | 1085 | } |
| 1086 | lj_trace_err(J, LJ_TRERR_BADTYPE); | ||
| 1083 | } | 1087 | } |
| 1084 | 1088 | ||
| 1085 | void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | 1089 | void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) |
