Warn when returning aggregates by value
@pwithnall
Submitted by Philip Withnall Link to original bug (#745002)
Description
g-ir-scanner should warn if C code returns an aggregate by value rather than by reference, since GIR appears to not support this currently. (Or, at least, pygobject appears not to support it and I’m not sure how other bindings could either.)
For example, given functions: cairo_rectangle_int_t *test_func1 (void); cairo_rectangle_int_t test_func2 (void);
The following GIR is generated, where the functions only differ in their c:type parameters:
<return-value transfer-ownership="full">
</return-value>
</function>
<return-value transfer-ownership="full">
</return-value>
</function>
The following Python test then crashes because the return value of func2() is interpreted as a cairo_rectangle_int_t* rather than a cairo_rectangle_int_t: from gi.repository import Test b = Test.func2() print("b: (wrong address): ", b) # wrong address print("b.x: (crash): ", b.x) # crashes
This was previously caught in some modules by using the -Waggregate-return compiler warning, but that’s fallen out of favour because it’s a pain for internal code.