SimpleType code generation broken
@sdroege
Submitted by Sebastian Dröge Link to original bug (#610083)
Description
Hi, the code generation for SimpleTypes is broken. Take as example the following:
[SimpleType]
[Immutable]
[CCode (copy_function = "fraction_copy")]
struct Fraction {
public int num;
public int den;
public Fraction copy () {
return Fraction (num, den);
}
public Fraction (int num, int den) {
this.num = num;
this.den = den;
}
public Fraction mult (Fraction other) {
return Fraction (num * other.num, den * other.den);
}
}
Some errors in the generated code are:
void fraction_init (Fraction self, gint num, gint den): This initializes self, but as self is passed by value this has absolutely no effect. It should either be passed by reference for that function or should be returned. Code that uses fraction_init() expect that it returns the initialized instance and that it only takes the num/den parameters and not the self parameter. In fraction_init(), self is simply passed to memset while the address of it should be passed.
I'll try to create a patch for this to work later.
Edited by Rico Tzschichholz