<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>127246</bug_id>
          
          <creation_ts>2014-01-19 01:37:11 -0800</creation_ts>
          <short_desc>[GLIB] GVariant floating references are not correctly handled by GRefPtr</short_desc>
          <delta_ts>2014-01-20 06:44:09 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Gtk</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>125990</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Garcia Campos">cgarcia</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>aperez</cc>
    
    <cc>benjamin</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>commit-queue</cc>
    
    <cc>gustavo</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>969583</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2014-01-19 01:37:11 -0800</bug_when>
    <thetext>GRefPtr should always use g_variant_ref_sink to deal with GVariant floating references. In case of full references, g_variant_ref_sink calls g_variant_ref, so it&apos;s safe to use it always.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969584</commentid>
    <comment_count>1</comment_count>
      <attachid>221582</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2014-01-19 01:40:40 -0800</bug_when>
    <thetext>Created attachment 221582
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969589</commentid>
    <comment_count>2</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2014-01-19 08:05:31 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; GRefPtr should always use g_variant_ref_sink to deal with GVariant floating references. In case of full references, g_variant_ref_sink calls g_variant_ref, so it&apos;s safe to use it always.

Being this the case, if I am understanding GRefPtr correctly then we should
never use adoptGRef() for GVariants, because it does *not* sink the floating
reference or add a reference. If that&apos;s the case it would be good to add
a specialization of the adoptGRef() template to make code that uses it
work properly with GVariants. I see two possible ways:

 a. Specialize adoptGRef&lt;GVariant&gt;() to *not* pass GRefPtrAdopt as second
    argument. This would make adoptGRef() sink the floating reference:

      template&lt;&gt; GRefPtr&lt;GVariant&gt; adoptGRef(GVariant* p) {
          return GRefPtr&lt;GVariant&gt;(p);
      }

 b. Make the compiler stop with error when using adoptGRef&lt;GVariant&gt;().
    For example using a “static_assert” depending on the type used for
    GRefPtr. This would prevent using adoptGRef() for GVariants. For
    example the following would cause compiler errors when instantiating
    adoptGRef() for GVariants:

      // In general, adoptGRef() can be used for any type.
      template &lt;typename T&gt; class GRefPtr {
          // ...
          static const bool canUseAdoptGRef = true;
      };

      // But not for GVariant, so specialize the value of the flag.
      template &lt;&gt; class GRefPtr&lt;GVariant&gt; {
          static const bool canUseAdoptGRef = false;
      };

      template &lt;typename T&gt; GRefPtr&lt;T&gt; adoptGRef(T* p) {
          static_assert(GRefPtr&lt;T&gt;::canUseAdoptGRef,
                        &quot;Can&apos;t use adoptGRef() for this type&quot;);
          return GRefPtr&lt;T&gt;(p, GRefPtrAdopt);
      }

Probably option (a) is the less intrusive, and it would avoid having to go
through the existing code chasing the existing uses of adoptGRef(). WDYT?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969594</commentid>
    <comment_count>3</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2014-01-19 09:16:48 -0800</bug_when>
    <thetext>You might want to adopt a full reference. We don&apos;t want to use adoptGRef with GVariants having a floating reference</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969611</commentid>
    <comment_count>4</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2014-01-19 11:08:05 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; You might want to adopt a full reference. We don&apos;t want to use adoptGRef with GVariants having a floating reference

Then, could you please add something like the solution outlined in (b)
to make it a compiler error to use adoptGRef() on a GVariant? That would
prevent all of us of making the mistake.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969733</commentid>
    <comment_count>5</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2014-01-19 23:45:56 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; You might want to adopt a full reference. We don&apos;t want to use adoptGRef with GVariants having a floating reference
&gt; 
&gt; Then, could you please add something like the solution outlined in (b)
&gt; to make it a compiler error to use adoptGRef() on a GVariant? That would
&gt; prevent all of us of making the mistake.

Using adoptGRef with a GVariant is not a mistake, if the GVariant has a full reference and you want to adopt it. That&apos;s what happens with some methods like g_dbus_proxy_call_sync that return a full reference that you want to adopt. We might check if the GVariant has a floating reference and assert (or warning) in that case, but I don&apos;t think it&apos;s worth it, TBH. You are supposed to know how it works, like with GtkWidget, even when not using smart pointers. If it helps I can document in the wiki how to use initially unowned references with our smart pointers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969735</commentid>
    <comment_count>6</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2014-01-19 23:57:05 -0800</bug_when>
    <thetext>Committed r162306: &lt;http://trac.webkit.org/changeset/162306&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969824</commentid>
    <comment_count>7</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2014-01-20 05:58:50 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; (In reply to comment #3)
&gt; &gt; &gt; You might want to adopt a full reference. We don&apos;t want to use adoptGRef with GVariants having a floating reference
&gt; &gt; 
&gt; &gt; Then, could you please add something like the solution outlined in (b)
&gt; &gt; to make it a compiler error to use adoptGRef() on a GVariant? That would
&gt; &gt; prevent all of us of making the mistake.
&gt; 
&gt; Using adoptGRef with a GVariant is not a mistake, if the GVariant has a full reference and you want to adopt it. That&apos;s what happens with some methods like g_dbus_proxy_call_sync that return a full reference that you want to adopt. We might check if the GVariant has a floating reference and assert (or warning) in that case, but I don&apos;t think it&apos;s worth it, TBH. You are supposed to know how it works, like with GtkWidget, even when not using smart pointers. If it helps I can document in the wiki how to use initially unowned references with our smart pointers.

Ah, understood. I am writing a wiki page explaining how to use GRefPtr
so it is easier for people starting to hack in WebKitGTK+ to use it
properly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>969831</commentid>
    <comment_count>8</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2014-01-20 06:44:09 -0800</bug_when>
    <thetext>(In reply to comment #7)
&gt; (In reply to comment #5)
&gt; &gt; (In reply to comment #4)
&gt; &gt; &gt; (In reply to comment #3)
&gt; &gt; &gt; &gt; You might want to adopt a full reference. We don&apos;t want to use adoptGRef with GVariants having a floating reference
&gt; &gt; &gt; 
&gt; &gt; &gt; Then, could you please add something like the solution outlined in (b)
&gt; &gt; &gt; to make it a compiler error to use adoptGRef() on a GVariant? That would
&gt; &gt; &gt; prevent all of us of making the mistake.
&gt; &gt; 
&gt; &gt; Using adoptGRef with a GVariant is not a mistake, if the GVariant has a full reference and you want to adopt it. That&apos;s what happens with some methods like g_dbus_proxy_call_sync that return a full reference that you want to adopt. We might check if the GVariant has a floating reference and assert (or warning) in that case, but I don&apos;t think it&apos;s worth it, TBH. You are supposed to know how it works, like with GtkWidget, even when not using smart pointers. If it helps I can document in the wiki how to use initially unowned references with our smart pointers.
&gt; 
&gt; Ah, understood. I am writing a wiki page explaining how to use GRefPtr
&gt; so it is easier for people starting to hack in WebKitGTK+ to use it
&gt; properly.

Done: https://trac.webkit.org/wiki/GRefPtr</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>221582</attachid>
            <date>2014-01-19 01:40:40 -0800</date>
            <delta_ts>2014-01-19 10:59:43 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>wtf-floating-variant.diff</filename>
            <type>text/plain</type>
            <size>3407</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XVEYvQ2hhbmdlTG9nIGIvU291cmNlL1dURi9DaGFuZ2VMb2cK
aW5kZXggZDdiYjcxZS4uMTE1YTM5OSAxMDA2NDQKLS0tIGEvU291cmNlL1dURi9DaGFuZ2VMb2cK
KysrIGIvU291cmNlL1dURi9DaGFuZ2VMb2cKQEAgLTEsMyArMSwxNyBAQAorMjAxNC0wMS0xOSAg
Q2FybG9zIEdhcmNpYSBDYW1wb3MgIDxjZ2FyY2lhQGlnYWxpYS5jb20+CisKKyAgICAgICAgW0dM
SUJdIEdWYXJpYW50IGZsb2F0aW5nIHJlZmVyZW5jZXMgYXJlIG5vdCBjb3JyZWN0bHkgaGFuZGxl
ZCBieSBHUmVmUHRyCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNn
aT9pZD0xMjcyNDYKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAg
ICAgICBHUmVmUHRyIHNob3VsZCBhbHdheXMgdXNlIGdfdmFyaWFudF9yZWZfc2luayB0byBkZWFs
IHdpdGggR1ZhcmlhbnQKKyAgICAgICAgZmxvYXRpbmcgcmVmZXJlbmNlcy4gSW4gY2FzZSBvZiBm
dWxsIHJlZmVyZW5jZXMsC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JkSGVscGVy
OjpmaWxsRGF0YU9iamVjdEZyb21Ecm9wRGF0YShHdGtTZWxlY3Rpb25EYXRhKiBkYXRhLCBndWlu
dAogICAgICAgICBpZiAocGllY2VzLnNpemUoKSA+IDEpCiAgICAgICAgICAgICBkYXRhT2JqZWN0
LT5zZXRUZXh0KHBpZWNlc1sxXSk7CiAgICAgfSBlbHNlIGlmICh0YXJnZXQgPT0gdW5rbm93bkF0
b20pIHsKLSAgICAgICAgR1JlZlB0cjxHVmFyaWFudD4gdmFyaWFudCA9IGFkb3B0R1JlZihnX3Zh
cmlhbnRfbmV3X3BhcnNlZChyZWludGVycHJldF9jYXN0PGNvbnN0IGNoYXIqPihndGtfc2VsZWN0
aW9uX2RhdGFfZ2V0X2RhdGEoZGF0YSkpKSk7CisgICAgICAgIEdSZWZQdHI8R1ZhcmlhbnQ+IHZh
cmlhbnQgPSBnX3ZhcmlhbnRfbmV3X3BhcnNlZChyZWludGVycHJldF9jYXN0PGNvbnN0IGNoYXIq
PihndGtfc2VsZWN0aW9uX2RhdGFfZ2V0X2RhdGEoZGF0YSkpKTsKIAogICAgICAgICBHT3duUHRy
PGdjaGFyPiBrZXk7CiAgICAgICAgIEdPd25QdHI8Z2NoYXI+IHZhbHVlOwo=
</data>
<flag name="review"
          id="245530"
          type_id="1"
          status="+"
          setter="mrobinson"
    />
          </attachment>
      

    </bug>

</bugzilla>