GNOME Bugzilla – Bug 724809
Fail to unset contact favorite
Last modified: 2014-02-21 00:27:14 UTC
Calling the function: folks_favourite_details_change_is_favourite(details, FALSE, ...) does not remove the persona favorite attribute.
After some investigation I found where the problem is. The function: private void _remove_attribute (E.Contact contact, string attr_name) { unowned VCardAttribute? attr = contact.get_attribute (attr_name) ; if (attr != null) { contact.remove_attribute ((!)attr); //e_vcard_remove_attribute(contact, attr); } } is generating a wrong c code: static void _edsf_persona_store_remove_attribute (EdsfPersonaStore* self, EContact* contact, const gchar* attr_name) { EVCardAttribute* attr = NULL; EContact* _tmp0_ = NULL; const gchar* _tmp1_ = NULL; EVCardAttribute* _tmp2_ = NULL; EVCardAttribute* _tmp3_ = NULL; g_return_if_fail (self != NULL); g_return_if_fail (contact != NULL); g_return_if_fail (attr_name != NULL); _tmp0_ = contact; _tmp1_ = attr_name; _tmp2_ = e_vcard_get_attribute ((EVCard*) _tmp0_, _tmp1_); attr = _tmp2_; _tmp3_ = attr; if (_tmp3_ != NULL) { EContact* _tmp4_ = NULL; EVCardAttribute* _tmp5_ = NULL; EVCardAttribute* _tmp6_ = NULL; _tmp4_ = contact; _tmp5_ = attr; _tmp6_ = __vala_EVCardAttribute_copy0 ((EVCardAttribute*) _tmp5_); e_vcard_remove_attribute ((EVCard*) _tmp4_, _tmp6_); } } Note that the genereted code is creating a copy of the attribute before call the function "e_vcard_remove_attribute" which is wrong.
Created attachment 269817 [details] [review] Fix the bug calling the external function
Created attachment 269819 [details] [review] Fix the bug using remove_attributes which uses the attribute name
This problem comes down to: 1. the EVCardAttribute* passed in to e_vcard_remove_attribute() needs to be the original pointer, not a pointer to a copy of the original 2. Vala works on a copy because that argument is transfer=full and it doesn't want to lose access to it once the call to e_vcard_remove_attribute() is done. I think this is mostly eds's fault because freeing an argument is convenient in C (if you know exactly that that's going to happen) but obviously gives the caller less control. We can't change the EDS API for this and I don't know if this is fixable in a clean way in Vala, so I think the best option is to fix this in Folks itself.
Review of attachment 269819 [details] [review]: Please replace the other instance in this file of EVCard.remove_attribute(attr) with EVCard.remove_attributes(null, attr_name) and push to master.
Review of attachment 269817 [details] [review]: I'd much prefer to not do it this way as it's unconventional and better handled by the other patch.
Created attachment 269851 [details] [review] replace all call of remove_attribute
(In reply to comment #5) > Review of attachment 269819 [details] [review]: > > Please replace the other instance in this file of EVCard.remove_attribute(attr) > with EVCard.remove_attributes(null, attr_name) and push to master. I have pushed a new patch, I do not think I have permission to push to master.
Review of attachment 269851 [details] [review]: I made some minor changes (including using the attribute name instead of the attribute itself for the second function call) and pushed to master. Thanks again! commit 87e037787476ba645ced4b8d6a406b32f7dbfae0 Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com> Date: Thu Feb 20 18:21:27 2014 -0300 Replaced use of EVCard.remove_attribute to EVCard.remove_attributes. https://bugzilla.gnome.org/show_bug.cgi?id=724809 NEWS | 1 + backends/eds/lib/edsf-persona-store.vala | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-)