GNOME Bugzilla – Bug 694140
Setter in SimpleType structs receives pointer
Last modified: 2017-02-24 14:11:57 UTC
Created attachment 236689 [details] unit test that reveals problem See attached unit-test (based on on top of master branch). C code generated for it looks like this (only meaningful part left): typedef gint StaticTableEntry; static gchar* static_table_table[4]; StaticTableEntry static_table_get_top (void) { StaticTableEntry result; result = (StaticTableEntry) 0; return result; } const gchar* static_table_entry_get_data (StaticTableEntry self) { const gchar* result; const gchar* _tmp2_; _tmp2_ = static_table_table[(gint) self]; result = _tmp2_; return result; } void static_table_entry_set_data (StaticTableEntry self, const gchar* value) { const gchar* _tmp2_; gchar* _tmp3_; _tmp2_ = value; _tmp3_ = g_strdup (_tmp2_); _g_free0 (static_table_table[(gint) self]); static_table_table[(gint) self] = _tmp3_; } void _vala_main (void) { StaticTableEntry _tmp0_; StaticTableEntry _tmp1_; StaticTableEntry entry; const gchar* _tmp4_; const gchar* _tmp5_; const gchar* _tmp8_; const gchar* _tmp9_; static_table_init (); _tmp0_ = static_table_get_top (); _tmp1_ = _tmp0_; entry = _tmp1_; _tmp4_ = static_table_entry_get_data (entry); _tmp5_ = _tmp4_; _vala_assert (g_strcmp0 (_tmp5_, "black") == 0, "entry.data == \"black\""); static_table_entry_set_data (&entry, "white"); _tmp8_ = static_table_entry_get_data (entry); _tmp9_ = _tmp8_; _vala_assert (g_strcmp0 (_tmp9_, "white") == 0, "entry.data == \"white\""); } Note that "&entry". This doesn't match declaration and doesn't fit well into [SimpleType] idea. Using [SimpleType] setter allows to create bindings for such functions like cpufreq_set_policy (from libcpufreq).
Created attachment 236690 [details] [review] unit test that reveals problem
Created attachment 236691 [details] [review] fix for this issue
*** This bug has been marked as a duplicate of bug 657346 ***