[Vala] Incorrect C generated with union containing anonymous struct



I have the following struct:

typedef union foobar foobar;

union foobar
   {  struct
      {  char *bar;
      }
      foo;
   };

This is represented in the vapi like this:

[CCode (cheader_filename = "struct.h")]
namespace StructTest
{
  [CCode (cname = "foo")]
  public struct Foo
  {
    [CCode (cname = "bar")]
    public unowned string bar;
  }

  [CCode (cname = "foobar")]
  public struct Foobar
  {
    [CCode (cname = "foo")]
    public unowned Foo foo;
  }
}

I use it like this:

    var fbar = Foobar();
    Memory.copy (fbar.foo.bar, "tralala", 10);

In Vala 0.13.1 this worked fine and the following code was
generated:

    foobar fbar = {0};
    memset (&fbar, 0, sizeof (foobar));
    memcpy (fbar.foo.bar, "tralala", (gsize) 10);

However, in version 0.13.2 and beyond the following code is
generated:

    foobar fbar = {0};
    foobar _tmp0_;
    foo _tmp1_;
    const gchar* _tmp2_;
    memset (&fbar, 0, sizeof (foobar));
    _tmp0_ = fbar;
    _tmp1_ = _tmp0_.foo;
    _tmp2_ = _tmp1_.bar;
    memcpy (_tmp2_, "tralala", (gsize) 10);

This fails since foo, the variable of _tmp1_ is undefined in C. I
could of course remove the [CCode (cname = "foo")] in the vapi but
that only changes the name to something else that is not known.

Is this a bug? Is there a workaround? Note that the C-code is
beyond my control, so workarounds involving changing the definition
of the struct in C will most probably not work...

Thanks,
Jan-Jaap



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]