dee

Merge lp:~mhr3/dee/no-magic-ref-stealing into lp:dee

Proposed by Michal Hruby
Status: Merged
Merged at revision: 302
Proposed branch: lp:~mhr3/dee/no-magic-ref-stealing
Merge into: lp:dee
Diff against target: 96 lines (+16/-9)
3 files modified
dee/dee-filter-model.c (+8/-1)
dee/dee-proxy-model.c (+3/-5)
dee/dee-shared-model.c (+5/-3)
To merge this branch: bzr merge lp:~mhr3/dee/no-magic-ref-stealing
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+80261@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

This looks good in principle. Ilike the less magical ref semantics :-)

It is an API break though - so I think we need to figure out how to
align landing all of this (if we want it in Precise that is)

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

And... *if* we want this in Precise I'd also like to see some tests
for the ref counting logic. lp:gtx that we have an optional dep on has
gtx_assert_last_unref() which is mighty handy for this - alas, as
said, this is only an optional dep... I think we need to talk about
this?

Revision history for this message
Michal Hruby (mhr3) wrote :

I don't think this breaks any public API, it should be completely transparent to the outside world. I'll add some tests to make sure this works properly.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Ok, Michal wins. Without this patch we get:

>>> from gi.repository import Dee
>>> m = Dee.SequenceModel.new()
>>> p = Dee.Peer.new("org.foo")
>>> s = Dee.SharedModel(back_end=m, peer=p)
>>> del m
>>> s.set_schema("s", "i")

(process:6009): dee-CRITICAL **: dee_model_get_schema: assertion `DEE_IS_MODEL (self)' failed

(process:6009): dee-CRITICAL **: dee_model_set_schema_full: assertion `DEE_IS_MODEL (self)' failed
>>>

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dee/dee-filter-model.c'
2--- dee/dee-filter-model.c 2011-07-14 08:50:02 +0000
3+++ dee/dee-filter-model.c 2011-10-24 19:54:23 +0000
4@@ -184,6 +184,11 @@
5 if (priv->on_orig_row_changed_id != 0)
6 g_signal_handler_disconnect (priv->orig_model, priv->on_orig_row_changed_id);
7
8+ if (priv->orig_model)
9+ {
10+ g_object_unref (priv->orig_model);
11+ }
12+
13 G_OBJECT_CLASS (dee_filter_model_parent_class)->finalize (object);
14 }
15
16@@ -199,7 +204,8 @@
17 "creating a DeeFilterModel");
18 return;
19 }
20-
21+
22+ /* This will return a new reference on back-end */
23 g_object_get (object, "back-end", &(priv->orig_model), NULL);
24
25 /* Map the end iter of the orig_model to the end iter of our iter list */
26@@ -360,6 +366,7 @@
27 "back-end", orig_model,
28 "proxy-signals", FALSE,
29 NULL));
30+
31 return self;
32 }
33
34
35=== modified file 'dee/dee-proxy-model.c'
36--- dee/dee-proxy-model.c 2011-03-03 13:13:37 +0000
37+++ dee/dee-proxy-model.c 2011-10-24 19:54:23 +0000
38@@ -284,12 +284,11 @@
39 GParamSpec *pspec)
40 {
41 DeeProxyModelPrivate *priv = DEE_PROXY_MODEL (object)->priv;
42-
43+
44 switch (id)
45 {
46 case PROP_BACK_END:
47- /* Steal ref to the back end model */
48- priv->back_end = g_value_get_object (value);
49+ priv->back_end = g_value_dup_object (value);
50 break;
51 case PROP_PROXY_SIGNALS:
52 priv->proxy_signals = g_value_get_boolean (value);
53@@ -339,8 +338,7 @@
54 /**
55 * DeeProxyModel:back-end:
56 *
57- * The backend model used by this proxy model. The ownership of the ref to
58- * the back end model is transfered to the proxy model.
59+ * The backend model used by this proxy model.
60 **/
61 pspec = g_param_spec_object ("back-end", "Back end",
62 "Back end model",
63
64=== modified file 'dee/dee-shared-model.c'
65--- dee/dee-shared-model.c 2011-07-14 08:50:02 +0000
66+++ dee/dee-shared-model.c 2011-10-24 19:54:23 +0000
67@@ -461,10 +461,9 @@
68 switch (id)
69 {
70 case PROP_PEER:
71- /* Steal ref to peer */
72 if (priv->swarm != NULL)
73 g_object_unref (priv->swarm);
74- priv->swarm = g_value_get_object (value);
75+ priv->swarm = g_value_dup_object (value);
76 break;
77 case PROP_SYNCHRONIZED:
78 g_critical ("Trying to set read only property DeeSharedModel:synchronized");
79@@ -551,7 +550,7 @@
80 obj_class->constructed = dee_shared_model_constructed;
81
82 /**
83- * DeeSharedModel:peer: (transfer full):
84+ * DeeSharedModel:peer:
85 *
86 * The #DeePeer that this model uses to connect to the swarm
87 */
88@@ -1309,6 +1308,9 @@
89 "peer", swarm,
90 NULL);
91
92+ g_object_unref (back_end);
93+ g_object_unref (swarm);
94+
95 return self;
96 }
97

Subscribers

People subscribed via source and target branches

to all changes: