aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-01-26 21:12:54 +0100
committerMike Pall <mike>2011-01-26 21:14:38 +0100
commitde0781d610595da2e57fb17d867926ba214e54fa (patch)
tree38d40093b339ae45a52b05242a8db1f43f31131b /src
parent0622ad9adc8b0e1b1c576277fe41ba6a203389c6 (diff)
downloadluajit-de0781d610595da2e57fb17d867926ba214e54fa.tar.gz
luajit-de0781d610595da2e57fb17d867926ba214e54fa.tar.bz2
luajit-de0781d610595da2e57fb17d867926ba214e54fa.zip
FFI: Allow cdata indexing with integer cdata.
Diffstat (limited to 'src')
-rw-r--r--src/lj_cdata.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lj_cdata.c b/src/lj_cdata.c
index 1d0aea85..9033d492 100644
--- a/src/lj_cdata.c
+++ b/src/lj_cdata.c
@@ -71,6 +71,7 @@ CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp,
71{ 71{
72 uint8_t *p = (uint8_t *)cdataptr(cd); 72 uint8_t *p = (uint8_t *)cdataptr(cd);
73 CType *ct = ctype_get(cts, cd->typeid); 73 CType *ct = ctype_get(cts, cd->typeid);
74 ptrdiff_t idx;
74 75
75 /* Resolve reference for cdata object. */ 76 /* Resolve reference for cdata object. */
76 if (ctype_isref(ct->info)) { 77 if (ctype_isref(ct->info)) {
@@ -88,8 +89,8 @@ collect_attrib:
88 lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ 89 lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */
89 90
90 if (tvisnum(key)) { /* Numeric key. */ 91 if (tvisnum(key)) { /* Numeric key. */
91 ptrdiff_t idx = LJ_64 ? (ptrdiff_t)numV(key) : 92 idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key));
92 (ptrdiff_t)lj_num2int(numV(key)); 93 integer_key:
93 if (ctype_ispointer(ct->info)) { 94 if (ctype_ispointer(ct->info)) {
94 CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */ 95 CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */
95 if (sz != CTSIZE_INVALID) { 96 if (sz != CTSIZE_INVALID) {
@@ -101,6 +102,15 @@ collect_attrib:
101 return ct; 102 return ct;
102 } 103 }
103 } 104 }
105 } else if (tviscdata(key)) { /* Integer cdata key. */
106 GCcdata *cdk = cdataV(key);
107 CType *ctk = ctype_raw(cts, cdk->typeid);
108 if (ctype_isenum(ctk->info)) ctk = ctype_child(cts, ctk);
109 if (ctype_isinteger(ctk->info)) {
110 lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ctk,
111 (uint8_t *)&idx, cdataptr(cdk), 0);
112 goto integer_key;
113 }
104 } else if (tvisstr(key)) { /* String key. */ 114 } else if (tvisstr(key)) { /* String key. */
105 GCstr *name = strV(key); 115 GCstr *name = strV(key);
106 if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ 116 if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */