eolian_mono: Generate placeholder fields for empty structs
authorLauro Moura <lauromoura@expertisesolutions.com.br>
Fri, 1 Dec 2017 03:43:12 +0000 (00:43 -0300)
committerLauro Moura <lauromoura@expertisesolutions.com.br>
Mon, 4 Dec 2017 18:47:53 +0000 (15:47 -0300)
Mono's JIT fails to generate function pointer for delegates with empty
structs in the signature, leading to those mini-amd64.c crashes on empty
fields.

This commit generates a placeholder IntPtr field in empty structs.

src/bin/eolian_mono/eolian/mono/struct_definition.hh

index 1b5e27c..ee05852 100644 (file)
@@ -50,7 +50,7 @@ struct struct_definition_generator
         .generate(sink, struct_.cxx_name, context))
        return false;
 
-     // iterate enum fiels
+     // iterate struct fields
      for(auto first = std::begin(struct_.fields)
              , last = std::end(struct_.fields); first != last; ++first)
        {
@@ -65,6 +65,16 @@ struct struct_definition_generator
             return false;
        }
 
+     // Check whether this is an extern struct without declared fields in .eo file and generate a
+     // placeholder field if positive.
+     // Mono's JIT is picky when generating function pointer for delegates with empty structs, leading to
+     // those 'mini-amd64.c condition fields not met' crashes.
+     if (struct_.fields.size() == 0)
+       {
+           if (!as_generator("public IntPtr field;\n").generate(sink, nullptr, context))
+             return false;
+       }
+
      if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false;
 
      auto close_namespace = *(lit("} ")) << "\n";