Bug 162267 - [GTK] Clean up DataObjectGtk handling
Summary: [GTK] Clean up DataObjectGtk handling
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2016-09-20 06:09 PDT by Carlos Garcia Campos
Modified: 2016-09-20 23:19 PDT (History)
6 users (show)

See Also:


Attachments
Patch (48.11 KB, patch)
2016-09-20 06:34 PDT, Carlos Garcia Campos
mcatanzaro: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2016-09-20 06:09:03 PDT
In some cases the ownership of DataObjectGtk instances is not clear enough, and we have hacks to avoid memory leaks because of that.
Comment 1 Carlos Garcia Campos 2016-09-20 06:34:57 PDT
Created attachment 289342 [details]
Patch
Comment 2 WebKit Commit Bot 2016-09-20 06:37:16 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 3 Michael Catanzaro 2016-09-20 10:30:31 PDT
Comment on attachment 289342 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=289342&action=review

> Source/WebCore/platform/gtk/PasteboardHelper.cpp:295
> +        TemporaryChange<DataObjectGtk*> change(settingClipboardDataObject, const_cast<DataObjectGtk*>(&dataObject));

Why is this function receiving a const DataObjectGtk*? Why were you unable to get rid of this const_cast?

> Source/WebKit2/Shared/gtk/PasteboardContent.cpp:36
> +PasteboardContent::PasteboardContent(const WebCore::DataObjectGtk& data)
> +    : dataObject(const_cast<WebCore::DataObjectGtk&>(data))

Again, why is the parameter const? What call site cannot be fixed?
Comment 4 Carlos Garcia Campos 2016-09-20 23:17:40 PDT
(In reply to comment #3)
> Comment on attachment 289342 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=289342&action=review
> 
> > Source/WebCore/platform/gtk/PasteboardHelper.cpp:295
> > +        TemporaryChange<DataObjectGtk*> change(settingClipboardDataObject, const_cast<DataObjectGtk*>(&dataObject));
> 
> Why is this function receiving a const DataObjectGtk*? Why were you unable
> to get rid of this const_cast?
> 
> > Source/WebKit2/Shared/gtk/PasteboardContent.cpp:36
> > +PasteboardContent::PasteboardContent(const WebCore::DataObjectGtk& data)
> > +    : dataObject(const_cast<WebCore::DataObjectGtk&>(data))
> 
> Again, why is the parameter const? What call site cannot be fixed?

Both are special cases. You can't create smart pointers from const references/pointers, but in these particular cases the object is going to be const, the only change we are going to do to the object is taking a reference, and RefCounted::ref() is const indeed. So we can't fix the callers, because it's correct to receive consts, but we cast to allow creating a Ref<> that we know we are ot going to modify.
Comment 5 Carlos Garcia Campos 2016-09-20 23:19:42 PDT
Committed r206197: <http://trac.webkit.org/changeset/206197>