Bug 158269 - Allow RefPtrs of const types
Summary: Allow RefPtrs of const types
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-01 13:39 PDT by Alex Christensen
Modified: 2016-07-14 17:01 PDT (History)
10 users (show)

See Also:


Attachments
Patch (2.51 KB, patch)
2016-06-01 13:41 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (2.50 KB, patch)
2016-06-02 00:56 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (4.85 KB, patch)
2016-06-07 09:42 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2016-06-01 13:39:03 PDT
Allow RefPtrs of const types
Comment 1 Alex Christensen 2016-06-01 13:41:24 PDT
Created attachment 280262 [details]
Patch
Comment 2 Alexey Proskuryakov 2016-06-01 19:34:30 PDT
Comment on attachment 280262 [details]
Patch

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

> Source/WTF/wtf/RefCounted.h:145
> +            delete const_cast<T*>(static_cast<const T*>(this));

Was this change actually needed?
Comment 3 Alex Christensen 2016-06-02 00:56:56 PDT
Created attachment 280315 [details]
Patch
Comment 4 Alex Christensen 2016-06-02 00:57:32 PDT
A change was needed, but the const_cast was not.
Comment 5 Anders Carlsson 2016-06-02 19:52:51 PDT
I wonder if we should make RefPtr do the cast instead.
Comment 6 Alex Christensen 2016-06-02 20:12:39 PDT
This allows you to make a RefPtr<const X> but making a RefPtr<X> from a RefPtr<const X> doesn't work because it sees those types as unrelated.
Comment 7 Darin Adler 2016-06-03 19:53:19 PDT
(In reply to comment #6)
> This allows you to make a RefPtr<const X> but making a RefPtr<X> from a
> RefPtr<const X> doesn't work because it sees those types as unrelated.

I think you mean that making a RefPtr<const X> from a RefPtr<X> doesn’t work. Because that other one should not work!
Comment 8 Darin Adler 2016-06-03 19:54:18 PDT
I’m OK with this change, but I’d like to see test coverage for this in Tools/TestWebKitAPI/Tests/WTF.
Comment 9 Alex Christensen 2016-06-07 09:42:58 PDT
Created attachment 280713 [details]
Patch
Comment 10 Alex Christensen 2016-06-07 09:44:09 PDT
(In reply to comment #7)
> (In reply to comment #6)
> > This allows you to make a RefPtr<const X> but making a RefPtr<X> from a
> > RefPtr<const X> doesn't work because it sees those types as unrelated.
> 
> I think you mean that making a RefPtr<const X> from a RefPtr<X> doesn’t
> work. Because that other one should not work!
Yep, I got those backwards.  I thought I was running into template weirdness when using this, but I added a test and it compiles fine.  I'll fix it if I run into it again and something is actually wrong.
Comment 11 Darin Adler 2016-06-09 20:22:43 PDT
(In reply to comment #5)
> I wonder if we should make RefPtr do the cast instead.

Did you have a reply to Anders about this, Alex?
Comment 12 Brent Fulgham 2016-06-16 15:46:23 PDT
Comment on attachment 280713 [details]
Patch

This seems like a good change, but I'd feel better if Anders or Sam glanced at it before we landed it.
Comment 13 Alex Christensen 2016-06-20 13:26:00 PDT
(In reply to comment #11)
> (In reply to comment #5)
> > I wonder if we should make RefPtr do the cast instead.
> 
> Did you have a reply to Anders about this, Alex?

I prefer this approach because RefCounted changing the ref count and deleting the object when the last ref is gone does not mutate the object itself, but if you implemented your own ref/deref functions that did mutate the object significantly, then you would not want a RefPtr<const YourType> to be possible.
Comment 14 WebKit Commit Bot 2016-07-14 17:01:26 PDT
Comment on attachment 280713 [details]
Patch

Clearing flags on attachment: 280713

Committed r203257: <http://trac.webkit.org/changeset/203257>
Comment 15 WebKit Commit Bot 2016-07-14 17:01:32 PDT
All reviewed patches have been landed.  Closing bug.