]> git.saurik.com Git - cycript.git/commitdiff
Add workaround for zero-sized struct (and use it).
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 30 Dec 2015 04:15:00 +0000 (20:15 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 30 Dec 2015 04:15:00 +0000 (20:15 -0800)
Analyze.cpp
sig/ffi_type.cpp

index 1eac8a0d57f25ee0b44c3e982ddc51f199588788..b98e027ccbba3a844f9cfc5840cd5cf021b75f95 100644 (file)
@@ -127,6 +127,8 @@ std::ostream &operator <<(std::ostream &out, const CYCXPosition<clang_get_Locati
 }
 
 struct CYKey {
+    unsigned priority_ = 0;
+
     std::string code_;
     unsigned flags_;
 };
@@ -293,6 +295,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
     CYCXString spelling(cursor);
     std::string name(spelling);
     std::ostringstream value;
+    unsigned priority(2);
     unsigned flags(0);
 
     /*CXSourceLocation location(clang_getCursorLocation(cursor));
@@ -364,10 +367,10 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
         } break;
 
         case CXCursor_StructDecl: {
-            if (!clang_isCursorDefinition(cursor))
-                goto skip;
             if (spelling[0] == '\0')
                 goto skip;
+            if (!clang_isCursorDefinition(cursor))
+                priority = 1;
 
             std::ostringstream types;
             std::ostringstream names;
@@ -453,8 +456,11 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
 
     {
         CYKey &key(baton.keys[name]);
-        key.code_ = value.str();
-        key.flags_ = flags;
+        if (key.priority_ < priority) {
+            key.priority_ = priority;
+            key.code_ = value.str();
+            key.flags_ = flags;
+        }
     }
 
   skip:
index e114db876e18f21abac0a377ec04b1a7313c8574..5c16db323e34b29498a66b65c87e26f5f3971d66 100644 (file)
@@ -158,10 +158,17 @@ ffi_type *Aggregate::GetFFI(CYPool &pool) const {
     ffi->alignment = 0;
     ffi->type = FFI_TYPE_STRUCT;
 
-    ffi->elements = new(pool) ffi_type *[signature.count + 1];
-    for (size_t index(0); index != signature.count; ++index)
-        ffi->elements[index] = signature.elements[index].type->GetFFI(pool);
-    ffi->elements[signature.count] = NULL;
+    if (signature.count == 0) {
+        // https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01286.html
+        ffi->elements = new(pool) ffi_type *[2];
+        ffi->elements[0] = &ffi_type_void;
+        ffi->elements[1] = NULL;
+    } else {
+        ffi->elements = new(pool) ffi_type *[signature.count + 1];
+        for (size_t index(0); index != signature.count; ++index)
+            ffi->elements[index] = signature.elements[index].type->GetFFI(pool);
+        ffi->elements[signature.count] = NULL;
+    }
 
     return ffi;
 }