After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 694140 - Setter in SimpleType structs receives pointer
Setter in SimpleType structs receives pointer
Status: RESOLVED DUPLICATE of bug 657346
Product: vala
Classification: Core
Component: Structs
0.18.x
Other Linux
: Normal major
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2013-02-19 01:11 UTC by Nikolay Orlyuk
Modified: 2017-02-24 14:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
unit test that reveals problem (2.18 KB, application/force-download)
2013-02-19 01:11 UTC, Nikolay Orlyuk
  Details
unit test that reveals problem (2.18 KB, patch)
2013-02-19 01:13 UTC, Nikolay Orlyuk
none Details | Review
fix for this issue (1.33 KB, patch)
2013-02-19 01:14 UTC, Nikolay Orlyuk
none Details | Review

Description Nikolay Orlyuk 2013-02-19 01:11:47 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).
Comment 1 Nikolay Orlyuk 2013-02-19 01:13:22 UTC
Created attachment 236690 [details] [review]
unit test that reveals problem
Comment 2 Nikolay Orlyuk 2013-02-19 01:14:20 UTC
Created attachment 236691 [details] [review]
fix for this issue
Comment 3 Rico Tzschichholz 2017-02-24 14:11:57 UTC

*** This bug has been marked as a duplicate of bug 657346 ***