diff options
author | Mike Pall <mike> | 2011-02-27 01:31:22 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-02-27 01:31:22 +0100 |
commit | c031d4b6a06eab94e8d9b837ec6dc257899a4ae1 (patch) | |
tree | 785116fc10de78f3414604fcd9b403a0e63dfa0e /src/lj_cdata.c | |
parent | d437086c5a82cb44ba34d039695aff79e7a1793c (diff) | |
download | luajit-c031d4b6a06eab94e8d9b837ec6dc257899a4ae1.tar.gz luajit-c031d4b6a06eab94e8d9b837ec6dc257899a4ae1.tar.bz2 luajit-c031d4b6a06eab94e8d9b837ec6dc257899a4ae1.zip |
DUALNUM: Handle integer type in FFI.
Diffstat (limited to 'src/lj_cdata.c')
-rw-r--r-- | src/lj_cdata.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lj_cdata.c b/src/lj_cdata.c index af78d05e..ae66b4b5 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c | |||
@@ -88,7 +88,10 @@ collect_attrib: | |||
88 | } | 88 | } |
89 | lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ | 89 | lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ |
90 | 90 | ||
91 | if (tvisnum(key)) { /* Numeric key. */ | 91 | if (tvisint(key)) { |
92 | idx = (ptrdiff_t)intV(key); | ||
93 | goto integer_key; | ||
94 | } else if (tvisnum(key)) { /* Numeric key. */ | ||
92 | idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); | 95 | idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); |
93 | integer_key: | 96 | integer_key: |
94 | if (ctype_ispointer(ct->info)) { | 97 | if (ctype_ispointer(ct->info)) { |
@@ -171,10 +174,10 @@ static void cdata_getconst(CTState *cts, TValue *o, CType *ct) | |||
171 | CType *ctt = ctype_child(cts, ct); | 174 | CType *ctt = ctype_child(cts, ct); |
172 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); | 175 | lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); |
173 | /* Constants are already zero-extended/sign-extended to 32 bits. */ | 176 | /* Constants are already zero-extended/sign-extended to 32 bits. */ |
174 | if (!(ctt->info & CTF_UNSIGNED)) | 177 | if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) |
175 | setintV(o, (int32_t)ct->size); | ||
176 | else | ||
177 | setnumV(o, (lua_Number)(uint32_t)ct->size); | 178 | setnumV(o, (lua_Number)(uint32_t)ct->size); |
179 | else | ||
180 | setintV(o, (int32_t)ct->size); | ||
178 | } | 181 | } |
179 | 182 | ||
180 | /* Get C data value and convert to TValue. */ | 183 | /* Get C data value and convert to TValue. */ |