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 657346 - Support property getters/setters for SimpleTypes
Support property getters/setters for SimpleTypes
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Structs
0.35.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 694140 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-08-25 16:41 UTC by Nathan Summers
Modified: 2017-02-25 07:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Pass SimpleTypes by-val in getter (2.50 KB, patch)
2011-08-25 16:41 UTC, Nathan Summers
none Details | Review
codegen: Property setters for SimpleTypes (7.81 KB, patch)
2011-08-25 16:42 UTC, Nathan Summers
none Details | Review
Unit tests and last chunk of "pass SimpleTypes by val in getter" (3.01 KB, patch)
2011-12-18 11:38 UTC, Nikolay Orlyuk
none Details | Review
codegen: Fix instance parameter for property setter in SimpleType structs (2.37 KB, patch)
2017-02-24 14:17 UTC, Rico Tzschichholz
committed Details | Review

Description Nathan Summers 2011-08-25 16:41:08 UTC
Created attachment 194713 [details] [review]
codegen: Pass SimpleTypes by-val in getter

The code generator currently doesn't support properties for SimpleTypes very well.  Even though SimpleTypes are supposed to be passed by value, it passes them to the getter/setter by reference.  Furthermore, there was no way in the setters to specify the value that the SimpleType should be set to.  These patches fix both issues.
Comment 1 Nathan Summers 2011-08-25 16:42:15 UTC
Created attachment 194714 [details] [review]
codegen: Property setters for SimpleTypes
Comment 2 Luca Bruno 2011-08-30 08:21:10 UTC
Author: Luca Bruno <lucabru@src.gnome.org>
Date:   Fri Jun 24 01:11:51 2011 -0400

    codegen: Fix definition of property getter for SimpleType structs
    
    Based on patch by Nathan Summers.
    
    Partially fixes bug 657346.

For setters, we want to forbid them in simpletype structs.
Comment 3 Nikolay Orlyuk 2011-12-18 11:38:34 UTC
Created attachment 203789 [details] [review]
Unit tests and last chunk of "pass SimpleTypes by val in getter"

As I can see patch made by Nathan Summers was partially merged into master. But in current state at least first chunk fixes declaration of all property accessors (not only getter) causing loosing of sync between declaration (and implementation) generated code and caller code for set accessors.
See unit-test in patch that reveals that situation.
I belive changes in patch makes set_func to be called with by-val passing of instance.
Note that this code makes assumption that SimpleType struct should never be used with "g_object_set". But getter already does the same as I understand and passes by-val instance to "g_object_get".
Comment 4 Nikolay Orlyuk 2012-06-04 22:53:24 UTC
(In reply to comment #2)
> Author: Luca Bruno <lucabru@src.gnome.org>
> Date:   Fri Jun 24 01:11:51 2011 -0400
> 
>     codegen: Fix definition of property getter for SimpleType structs
> 
>     Based on patch by Nathan Summers.
> 
>     Partially fixes bug 657346.
> 
> For setters, we want to forbid them in simpletype structs.
Why? That's a pretty nice feature that allows to make nice bindings for objects like file descriptors (fd.sig = SIGIO), window handlers (in freeglut for example) etc.
As for me there is no much difference between getter and setter.

Is this issue is abandoned?
Comment 5 Christian Dywan 2012-07-10 11:10:48 UTC
The difference is that you don't have any control over the setter. You can't be notified of changes, there's no memory management.
Comment 6 Nikolay Orlyuk 2012-07-10 21:51:45 UTC
(In reply to comment #5)
> The difference is that you don't have any control over the setter. You can't be
> notified of changes, there's no memory management.
What kind of control?.. [SimpleType] is passed by value, but place where setter is called sends it by pointer (even that body of setter expects value). I thought that this kind of structs is similar to value types in C#. They are pretty useful for making bindings for abstract types that hides the fact of pointer (i.e. instead of "myobj_t *myobj_new()" this helps to build bindings for "myval_t myval_default()").
Difference between getter and setter - is semantic, I think. Rather than possibility to update value passed by value. Even if you'll allow to update that value (by changing setter body generation) you'll loose those changes after returning from function that did received that value.

Code that was generated for setter - is exactly what I expected. And it would be nice to hear view point of someone who thinks differently and expects something different from setter of SimpleType.
Comment 7 Rico Tzschichholz 2017-02-24 14:11:57 UTC
*** Bug 694140 has been marked as a duplicate of this bug. ***
Comment 8 Rico Tzschichholz 2017-02-24 14:17:13 UTC
Created attachment 346641 [details] [review]
codegen: Fix instance parameter for property setter in SimpleType structs

Add test-case and fix code generator for call to the setter to pass
instance as a value rather than as a pointer to value.

Based on patches by Nathan Summers.
Comment 9 Rico Tzschichholz 2017-02-25 07:51:18 UTC
commit f4182fc69849eb735c8dd1083bd2322071aaa79b
Author: Nikolay Orlyuk <virkony@gmail.com>
Date:   Tue Feb 19 02:35:29 2013 +0200

    codegen: Fix instance parameter for property setter in SimpleType structs
    
    Add test-case and fix code generator for call to the setter to pass
    instance as a value rather than as a pointer to value.
    
    Based on patches by Nathan Summers.