Object returned inside switch argument goes out of scope before evaluation
Submitted by Jim Nelson
Link to original bug (#703818)
Description
If a function returns an object (doesn't matter if it descends from Object) and the function is called as an argument to a switch statement, the object is unref'd before the switch-case block completes.
Minimal test case:
class Xyzzy : Object {
public string foo { get; private set; }
public Xyzzy(string foo) {
this.foo = foo;
}
}
Xyzzy x(string str) {
return new Xyzzy(str);
}
void main(string[] args) {
switch (x("abc").foo) {
case "abc":
stdout.printf("found\n");
break;
default:
stdout.printf("not found\n");
break;
}
}
x("abc").foo is "abc", but in the C code, the object is unref'd before evaluating the case blocks:
_tmp0_ = x ("abc");
_tmp1_ = _tmp0_;
_tmp2_ = xyzzy_get_foo (_tmp1_);
_tmp3_ = _tmp2_;
_tmp4_ = _tmp3_;
** _g_object_unref0 (_tmp1_);
_tmp5_ = _tmp4_;
** _tmp7_ = (NULL == _tmp5_) ? 0 : g_quark_from_string (_tmp5_);
if (_tmp7_ == ((0 != _tmp6_label0) ? _tmp6_label0 : (_tmp6_label0 =
Lines with "**" are of interest here.
Version: 0.20.x
Edited by Rico Tzschichholz