dee

Merge lp:~mhr3/dee/floating-and-sinking into lp:dee

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 338
Merged at revision: 337
Proposed branch: lp:~mhr3/dee/floating-and-sinking
Merge into: lp:dee
Diff against target: 106 lines (+24/-6)
4 files modified
src/dee-serializable.c (+13/-4)
vapi/Dee-1.0-custom.vala (+7/-0)
vapi/Dee-1.0.metadata (+1/-0)
vapi/dee-1.0.vapi (+3/-2)
To merge this branch: bzr merge lp:~mhr3/dee/floating-and-sinking
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+88644@code.launchpad.net

Description of the change

Since dee_serializable_serialize is a virtual method, it has to return a non-floating reference to make sure it works in all cases without memory leaks.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Agreed with the analysis in bug #916783. Let's get this in.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dee-serializable.c'
2--- src/dee-serializable.c 2011-11-30 10:24:47 +0000
3+++ src/dee-serializable.c 2012-01-16 08:22:24 +0000
4@@ -379,6 +379,8 @@
5
6 g_variant_builder_add_value (&b, g_variant_new_variant (payload));
7
8+ g_variant_unref (payload);
9+
10 return g_variant_builder_end (&b);
11 }
12
13@@ -391,18 +393,25 @@
14 * You can recreate a serialized instance by calling dee_serializable_parse()
15 * provided that you know the correct #GType for the serialized instance.
16 *
17- * Return value: A floating reference to a #GVariant with the serialized data.
18- * The variants type signature is entirely dependent of the
19- * underlying implementation.
20+ * Return value: (transfer full): A reference to a #GVariant with
21+ * the serialized data. The variants type signature is entirely
22+ * dependent of the underlying implementation. Free using
23+ * g_variant_unref().
24 */
25 GVariant*
26 dee_serializable_serialize (DeeSerializable *self)
27 {
28 DeeSerializableIface *iface;
29+ GVariant *result;
30
31 g_return_val_if_fail (DEE_IS_SERIALIZABLE (self), NULL);
32
33 iface = DEE_SERIALIZABLE_GET_IFACE (self);
34
35- return (* iface->serialize) (self);
36+ result = iface->serialize (self);
37+ /* Make sure we return a real reference
38+ * FIXME: just use g_variant_take_ref once we depend on glib 2.30 */
39+ if (g_variant_is_floating (result)) return g_variant_ref_sink (result);
40+
41+ return result;
42 }
43
44=== modified file 'vapi/Dee-1.0-custom.vala'
45--- vapi/Dee-1.0-custom.vala 2012-01-04 08:32:53 +0000
46+++ vapi/Dee-1.0-custom.vala 2012-01-16 08:22:24 +0000
47@@ -23,10 +23,17 @@
48 public void clear (Dee.Model model, Dee.ModelIter iter);
49 }
50
51+ [CCode (type_id = "dee_result_set_get_type ()")]
52 public interface ResultSet {
53 [CCode (cname = "_vala_dee_result_set_iterator")]
54 public Dee.ResultSet iterator ();
55 [CCode (cname = "_vala_dee_result_set_next_value")]
56 public unowned Dee.ModelIter? next_value ();
57 }
58+
59+ [CCode (type_id = "dee_serializable_get_type ()")]
60+ public interface Serializable : GLib.Object {
61+ [CCode (returns_floating_reference = true)]
62+ public GLib.Variant externalize ();
63+ }
64 }
65
66=== modified file 'vapi/Dee-1.0.metadata'
67--- vapi/Dee-1.0.metadata 2012-01-09 17:07:37 +0000
68+++ vapi/Dee-1.0.metadata 2012-01-16 08:22:24 +0000
69@@ -22,6 +22,7 @@
70 SerializableParseFunc skip=false
71 Serializable
72 .register_parser skip=false
73+ .externalize skip // we need floating annotation here, see -custom
74
75 SerializableModel
76 .get_seqnum virtual
77
78=== modified file 'vapi/dee-1.0.vapi'
79--- vapi/dee-1.0.vapi 2012-01-09 17:07:37 +0000
80+++ vapi/dee-1.0.vapi 2012-01-16 08:22:24 +0000
81@@ -239,7 +239,7 @@
82 public abstract GLib.Object load (string resource_name) throws GLib.Error;
83 public abstract bool store (Dee.Serializable resource, string resource_name) throws GLib.Error;
84 }
85- [CCode (cheader_filename = "dee.h")]
86+ [CCode (cheader_filename = "dee.h", type_id = "dee_result_set_get_type ()")]
87 public interface ResultSet : GLib.Object {
88 public abstract unowned Dee.Model get_model ();
89 public abstract uint get_n_rows ();
90@@ -255,6 +255,7 @@
91 }
92 [CCode (cheader_filename = "dee.h", type_id = "dee_serializable_get_type ()")]
93 public interface Serializable : GLib.Object {
94+ [CCode (returns_floating_reference = true)]
95 public GLib.Variant externalize ();
96 public static GLib.Object parse (GLib.Variant data, GLib.Type type);
97 public static GLib.Object parse_external (GLib.Variant data);
98@@ -279,7 +280,7 @@
99 public static Dee.Filter new_sort (owned Dee.CompareRowFunc cmp_row);
100 public bool notify (Dee.ModelIter orig_iter, Dee.Model orig_model, Dee.FilterModel filter_model);
101 }
102- [CCode (cheader_filename = "dee.h")]
103+ [CCode (cheader_filename = "dee.h", has_type_id = false)]
104 public struct ModelReader {
105 public weak Dee.ModelReaderFunc reader_func;
106 public void* userdata;

Subscribers

People subscribed via source and target branches

to all changes: