diff options
author | Mike Pall <mike> | 2010-12-15 19:47:01 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-12-15 19:48:20 +0100 |
commit | fbcc925a2d0f64e352d359626c1cb410b2cb5883 (patch) | |
tree | b4f8e7143141f3bace03f54b31b3ddc8d2d7f4d3 | |
parent | badff4ed0ad5ed8650f6fa55ab56e86b990ba397 (diff) | |
download | luajit-fbcc925a2d0f64e352d359626c1cb410b2cb5883.tar.gz luajit-fbcc925a2d0f64e352d359626c1cb410b2cb5883.tar.bz2 luajit-fbcc925a2d0f64e352d359626c1cb410b2cb5883.zip |
FFI: Fix auto-deref of pointers to structs.
-rw-r--r-- | src/lj_cdata.c | 12 | ||||
-rw-r--r-- | src/lj_crecord.c | 12 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/lj_cdata.c b/src/lj_cdata.c index 29380cbc..a763908d 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c | |||
@@ -78,6 +78,7 @@ CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp, | |||
78 | ct = ctype_child(cts, ct); | 78 | ct = ctype_child(cts, ct); |
79 | } | 79 | } |
80 | 80 | ||
81 | collect_attrib: | ||
81 | /* Skip attributes and collect qualifiers. */ | 82 | /* Skip attributes and collect qualifiers. */ |
82 | while (ctype_isattrib(ct->info)) { | 83 | while (ctype_isattrib(ct->info)) { |
83 | if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; | 84 | if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size; |
@@ -102,17 +103,14 @@ CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp, | |||
102 | } else if (tvisstr(key)) { /* String key. */ | 103 | } else if (tvisstr(key)) { /* String key. */ |
103 | GCstr *name = strV(key); | 104 | GCstr *name = strV(key); |
104 | if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ | 105 | if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ |
105 | CType *cct = ctype_child(cts, ct); | 106 | if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) { |
106 | if (ctype_isstruct(cct->info)) { | ||
107 | p = (uint8_t *)cdata_getptr(p, ct->size); | 107 | p = (uint8_t *)cdata_getptr(p, ct->size); |
108 | ct = cct; | 108 | ct = ctype_child(cts, ct); |
109 | goto index_struct; | 109 | goto collect_attrib; |
110 | } | 110 | } |
111 | } if (ctype_isstruct(ct->info)) { | 111 | } if (ctype_isstruct(ct->info)) { |
112 | CTSize ofs; | 112 | CTSize ofs; |
113 | CType *fct; | 113 | CType *fct = lj_ctype_getfield(cts, ct, name, &ofs); |
114 | index_struct: | ||
115 | fct = lj_ctype_getfield(cts, ct, name, &ofs); | ||
116 | if (fct) { | 114 | if (fct) { |
117 | *pp = p + ofs; | 115 | *pp = p + ofs; |
118 | return fct; | 116 | return fct; |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 0d8c02a5..3ee39ece 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
@@ -363,9 +363,17 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd) | |||
363 | GCstr *name = strV(&rd->argv[1]); | 363 | GCstr *name = strV(&rd->argv[1]); |
364 | /* Always specialize to the field name. */ | 364 | /* Always specialize to the field name. */ |
365 | emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name)); | 365 | emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name)); |
366 | if (ctype_isstruct(ct->info)) { | 366 | if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ |
367 | CType *cct = ctype_rawchild(cts, ct); | ||
368 | if (ctype_isstruct(cct->info)) { | ||
369 | ct = cct; | ||
370 | goto index_struct; | ||
371 | } | ||
372 | } else if (ctype_isstruct(ct->info)) { | ||
367 | CTSize fofs; | 373 | CTSize fofs; |
368 | CType *fct = lj_ctype_getfield(cts, ct, name, &fofs); | 374 | CType *fct; |
375 | index_struct: | ||
376 | fct = lj_ctype_getfield(cts, ct, name, &fofs); | ||
369 | if (fct) { | 377 | if (fct) { |
370 | if (ctype_isconstval(fct->info)) { | 378 | if (ctype_isconstval(fct->info)) { |
371 | if (fct->size >= 0x80000000u && | 379 | if (fct->size >= 0x80000000u && |