[Vala] Another problem since Vala 0.13.2 - Methods sending blocks to be filled



It seems a lot of my stuff breaks since 0.13.2...

I have a lot of API calls that take in a block of memory, that
subsequently get filled during the call.

Something like this:

C:

  typedef struct foo foo;
  struct foo { int bar; };

extern void get_info (foo *block);


Vapi:

  [CCode (cname = "foo")]
  public struct Foo
  {
    [CCode (cname = "bar")]
    public unowned int Bar;
  }

  [CCode (cname = "get_info")]
  public static void GetInfo (Foo block);

Used like this:

  var foo = Foo();
  GetInfo(foo);
  var bar = foo.Bar;


This used to generate this C code:

  foo foo = {0};
  gint bar;
  memset (&foo, 0, sizeof (foo));
  get_info (&foo);
  bar = foo.bar;

but since 0.13.2 it generates:

  foo foo = {0};
  foo _tmp0_;
  foo _tmp1_;
  gint _tmp2_;
  gint bar;
  memset (&foo, 0, sizeof (foo));
  _tmp0_ = foo;
  get_info (&_tmp0_);
  _tmp1_ = foo;
  _tmp2_ = _tmp1_.bar;
  bar = _tmp2_;

So get_info() is called with a copy of the parameter after which
the original is used to read the values. So it isn't reading the
results of get_info at all.

I could get this to work by changing the vapi to:

  public static void GetInfo (Foo* block);

and calling it by:

  GetInfo(&foo);
  
but:
a) this means lots of changes in my code
b) it seems a step backwards to start using pointers where this
previously was not needed.

Is there a better way?

Cheers,
Jan-Jaap




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