]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Fix auto-deref of pointers to structs.
authorMike Pall <mike>
Wed, 15 Dec 2010 18:47:01 +0000 (19:47 +0100)
committerMike Pall <mike>
Wed, 15 Dec 2010 18:48:20 +0000 (19:48 +0100)
src/lj_cdata.c
src/lj_crecord.c

index 29380cbcccbd7cfc4f68bfe6057d395482f5d89b..a763908d02d42ae025b698ffcf4c8e75591c6c34 100644 (file)
@@ -78,6 +78,7 @@ CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp,
     ct = ctype_child(cts, ct);
   }
 
+collect_attrib:
   /* Skip attributes and collect qualifiers. */
   while (ctype_isattrib(ct->info)) {
     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,
   } else if (tvisstr(key)) {  /* String key. */
     GCstr *name = strV(key);
     if (ctype_isptr(ct->info)) {  /* Automatically perform '->'. */
-      CType *cct = ctype_child(cts, ct);
-      if (ctype_isstruct(cct->info)) {
+      if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) {
        p = (uint8_t *)cdata_getptr(p, ct->size);
-       ct = cct;
-       goto index_struct;
+       ct = ctype_child(cts, ct);
+       goto collect_attrib;
       }
     } if (ctype_isstruct(ct->info)) {
       CTSize ofs;
-      CType *fct;
-    index_struct:
-      fct = lj_ctype_getfield(cts, ct, name, &ofs);
+      CType *fct = lj_ctype_getfield(cts, ct, name, &ofs);
       if (fct) {
        *pp = p + ofs;
        return fct;
index 0d8c02a5adb1965bb4371598061b1e5cdeb4aad6..3ee39ecec6f4367192c6b088143cf82ac7bf6c6e 100644 (file)
@@ -363,9 +363,17 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
     GCstr *name = strV(&rd->argv[1]);
     /* Always specialize to the field name. */
     emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));
-    if (ctype_isstruct(ct->info)) {
+    if (ctype_isptr(ct->info)) {  /* Automatically perform '->'. */
+      CType *cct = ctype_rawchild(cts, ct);
+      if (ctype_isstruct(cct->info)) {
+        ct = cct;
+        goto index_struct;
+      }
+    } else if (ctype_isstruct(ct->info)) {
       CTSize fofs;
-      CType *fct = lj_ctype_getfield(cts, ct, name, &fofs);
+      CType *fct;
+index_struct:
+      fct = lj_ctype_getfield(cts, ct, name, &fofs);
       if (fct) {
        if (ctype_isconstval(fct->info)) {
          if (fct->size >= 0x80000000u &&