GNOME Bugzilla – Bug 657346
Support property getters/setters for SimpleTypes
Last modified: 2017-02-25 07:51:35 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.
Created attachment 194714 [details] [review] codegen: Property setters for SimpleTypes
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.
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".
(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?
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.
(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.
*** Bug 694140 has been marked as a duplicate of this bug. ***
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.
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.