[Vala] Trouble filling a char array in a struct
- From: Jan-Jaap van der Geer <jjvdgeer inbox com>
- To: vala-list gnome org
- Subject: [Vala] Trouble filling a char array in a struct
- Date: Tue, 18 Oct 2011 22:45:46 +0200
I have a struct in C looking something like this:
typedef struct f f;
typedef struct b b;
struct b
{ char name[12];
};
struct f
{ b bar;
};
The vapi looks like this:
[CCode (cname = "f")]
public struct Foo
{
[CCode (cname = "bar")]
public unowned Bar Bar;
}
[CCode (cname = "b")]
public struct Bar
{
[CCode (cname = "name")]
public unowned char Name[12];
}
Pre Vala 0.13.2 I had code like this:
var foo = Foo();
Memory.copy(foo.Bar.Name, "foobar", 12);
This worked fine, as can be seen in the generated C:
f foo = {0};
memset (&foo, 0, sizeof (f));
memcpy (foo.bar.name, "foobar", (gsize) 12);
(aren't the {0} and the memset() doing the same thing?)
However, since 0.13.2 it generates the following C:
f foo = {0};
f _tmp0_;
b _tmp1_;
memset (&foo, 0, sizeof (f));
_tmp0_ = foo;
_tmp1_ = _tmp0_.bar;
memcpy (_tmp1_.name, "foobar", (gsize) 12);
This copies the struct and copies the character array into the
copy, and then the copy is discarded. So it has no effect. And a
lot of copying doesn't seem to efficient either.
I tried a variant but this fails as well:
var foo = Foo();
var bar = Bar();
Memory.copy(bar.Name, "foobar", 12);
foo.Bar = bar;
A for-loop setting every byte does work, but it seems quite
inefficient to do it like that...
Any good solutions?
Cheers,
Jan-Jaap
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]