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
=== modified file 'src/dee-serializable.c'
--- src/dee-serializable.c 2011-11-30 10:24:47 +0000
+++ src/dee-serializable.c 2012-01-16 08:22:24 +0000
@@ -379,6 +379,8 @@
379379
380 g_variant_builder_add_value (&b, g_variant_new_variant (payload));380 g_variant_builder_add_value (&b, g_variant_new_variant (payload));
381381
382 g_variant_unref (payload);
383
382 return g_variant_builder_end (&b);384 return g_variant_builder_end (&b);
383}385}
384386
@@ -391,18 +393,25 @@
391 * You can recreate a serialized instance by calling dee_serializable_parse()393 * You can recreate a serialized instance by calling dee_serializable_parse()
392 * provided that you know the correct #GType for the serialized instance.394 * provided that you know the correct #GType for the serialized instance.
393 *395 *
394 * Return value: A floating reference to a #GVariant with the serialized data.396 * Return value: (transfer full): A reference to a #GVariant with
395 * The variants type signature is entirely dependent of the397 * the serialized data. The variants type signature is entirely
396 * underlying implementation.398 * dependent of the underlying implementation. Free using
399 * g_variant_unref().
397 */400 */
398GVariant*401GVariant*
399dee_serializable_serialize (DeeSerializable *self)402dee_serializable_serialize (DeeSerializable *self)
400{403{
401 DeeSerializableIface *iface;404 DeeSerializableIface *iface;
405 GVariant *result;
402406
403 g_return_val_if_fail (DEE_IS_SERIALIZABLE (self), NULL);407 g_return_val_if_fail (DEE_IS_SERIALIZABLE (self), NULL);
404408
405 iface = DEE_SERIALIZABLE_GET_IFACE (self);409 iface = DEE_SERIALIZABLE_GET_IFACE (self);
406410
407 return (* iface->serialize) (self);411 result = iface->serialize (self);
412 /* Make sure we return a real reference
413 * FIXME: just use g_variant_take_ref once we depend on glib 2.30 */
414 if (g_variant_is_floating (result)) return g_variant_ref_sink (result);
415
416 return result;
408}417}
409418
=== modified file 'vapi/Dee-1.0-custom.vala'
--- vapi/Dee-1.0-custom.vala 2012-01-04 08:32:53 +0000
+++ vapi/Dee-1.0-custom.vala 2012-01-16 08:22:24 +0000
@@ -23,10 +23,17 @@
23 public void clear (Dee.Model model, Dee.ModelIter iter);23 public void clear (Dee.Model model, Dee.ModelIter iter);
24 }24 }
2525
26 [CCode (type_id = "dee_result_set_get_type ()")]
26 public interface ResultSet {27 public interface ResultSet {
27 [CCode (cname = "_vala_dee_result_set_iterator")]28 [CCode (cname = "_vala_dee_result_set_iterator")]
28 public Dee.ResultSet iterator ();29 public Dee.ResultSet iterator ();
29 [CCode (cname = "_vala_dee_result_set_next_value")]30 [CCode (cname = "_vala_dee_result_set_next_value")]
30 public unowned Dee.ModelIter? next_value ();31 public unowned Dee.ModelIter? next_value ();
31 }32 }
33
34 [CCode (type_id = "dee_serializable_get_type ()")]
35 public interface Serializable : GLib.Object {
36 [CCode (returns_floating_reference = true)]
37 public GLib.Variant externalize ();
38 }
32}39}
3340
=== modified file 'vapi/Dee-1.0.metadata'
--- vapi/Dee-1.0.metadata 2012-01-09 17:07:37 +0000
+++ vapi/Dee-1.0.metadata 2012-01-16 08:22:24 +0000
@@ -22,6 +22,7 @@
22SerializableParseFunc skip=false22SerializableParseFunc skip=false
23Serializable23Serializable
24 .register_parser skip=false24 .register_parser skip=false
25 .externalize skip // we need floating annotation here, see -custom
2526
26SerializableModel27SerializableModel
27 .get_seqnum virtual28 .get_seqnum virtual
2829
=== modified file 'vapi/dee-1.0.vapi'
--- vapi/dee-1.0.vapi 2012-01-09 17:07:37 +0000
+++ vapi/dee-1.0.vapi 2012-01-16 08:22:24 +0000
@@ -239,7 +239,7 @@
239 public abstract GLib.Object load (string resource_name) throws GLib.Error;239 public abstract GLib.Object load (string resource_name) throws GLib.Error;
240 public abstract bool store (Dee.Serializable resource, string resource_name) throws GLib.Error;240 public abstract bool store (Dee.Serializable resource, string resource_name) throws GLib.Error;
241 }241 }
242 [CCode (cheader_filename = "dee.h")]242 [CCode (cheader_filename = "dee.h", type_id = "dee_result_set_get_type ()")]
243 public interface ResultSet : GLib.Object {243 public interface ResultSet : GLib.Object {
244 public abstract unowned Dee.Model get_model ();244 public abstract unowned Dee.Model get_model ();
245 public abstract uint get_n_rows ();245 public abstract uint get_n_rows ();
@@ -255,6 +255,7 @@
255 }255 }
256 [CCode (cheader_filename = "dee.h", type_id = "dee_serializable_get_type ()")]256 [CCode (cheader_filename = "dee.h", type_id = "dee_serializable_get_type ()")]
257 public interface Serializable : GLib.Object {257 public interface Serializable : GLib.Object {
258 [CCode (returns_floating_reference = true)]
258 public GLib.Variant externalize ();259 public GLib.Variant externalize ();
259 public static GLib.Object parse (GLib.Variant data, GLib.Type type);260 public static GLib.Object parse (GLib.Variant data, GLib.Type type);
260 public static GLib.Object parse_external (GLib.Variant data);261 public static GLib.Object parse_external (GLib.Variant data);
@@ -279,7 +280,7 @@
279 public static Dee.Filter new_sort (owned Dee.CompareRowFunc cmp_row);280 public static Dee.Filter new_sort (owned Dee.CompareRowFunc cmp_row);
280 public bool notify (Dee.ModelIter orig_iter, Dee.Model orig_model, Dee.FilterModel filter_model);281 public bool notify (Dee.ModelIter orig_iter, Dee.Model orig_model, Dee.FilterModel filter_model);
281 }282 }
282 [CCode (cheader_filename = "dee.h")]283 [CCode (cheader_filename = "dee.h", has_type_id = false)]
283 public struct ModelReader {284 public struct ModelReader {
284 public weak Dee.ModelReaderFunc reader_func;285 public weak Dee.ModelReaderFunc reader_func;
285 public void* userdata;286 public void* userdata;

Subscribers

People subscribed via source and target branches

to all changes: