Bug 136602 - XPCPtr should be converted into an all purpose smart pointer for os_objects
Summary: XPCPtr should be converted into an all purpose smart pointer for os_objects
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-06 12:40 PDT by Sam Weinig
Modified: 2014-09-07 14:36 PDT (History)
4 users (show)

See Also:


Attachments
Patch (38.68 KB, patch)
2014-09-06 12:43 PDT, Sam Weinig
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2014-09-06 12:40:32 PDT
XPCPtr should be converted into an all purpose smart pointer for os_objects
Comment 1 Sam Weinig 2014-09-06 12:43:21 PDT
Created attachment 237742 [details]
Patch
Comment 2 Darin Adler 2014-09-06 17:26:28 PDT
Comment on attachment 237742 [details]
Patch

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

Generally I’d like to see this more similar to RefPtr, maybe even sharing code somehow. If we made ref/deref free functions instead of member functions, I think we’d be able to share a single class template. But why don’t I feel that way about RetainPtr? Too many special features? Hard to say.

> Source/WTF/wtf/OSObjectPtr.h:89
> +    OSObjectPtr(AdoptOSObject, T ptr)

For PassRefPtr we made this private and made adoptRef a friend. Might want that here too.

> Source/WTF/wtf/OSObjectPtr.h:118
> +    OSObjectPtr& operator=(const OSObjectPtr& other)

I like the swap style we use in RefPtr better.

Also, missing the move assignment operator.

> Source/WTF/wtf/OSObjectPtr.h:124
>          T ptr = m_ptr;

No need for this local variable. It’s fine to release before assigning m_ptr, since we have already retained optr. That’s what we do in the nullptr specialization below, in fact.

> Source/WTF/wtf/OSObjectPtr.h:133
> +    OSObjectPtr& operator=(std::nullptr_t)

With all the inlining, I’m surprised we need a specialization for nullptr.
Comment 3 Sam Weinig 2014-09-07 10:56:13 PDT
(In reply to comment #2)
> (From update of attachment 237742 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=237742&action=review
> 
> Generally I’d like to see this more similar to RefPtr, maybe even sharing code somehow. If we made ref/deref free functions instead of member functions, I think we’d be able to share a single class template. But why don’t I feel that way about RetainPtr? Too many special features? Hard to say.
> 
> > Source/WTF/wtf/OSObjectPtr.h:89
> > +    OSObjectPtr(AdoptOSObject, T ptr)
> 
> For PassRefPtr we made this private and made adoptRef a friend. Might want that here too.
> 
> > Source/WTF/wtf/OSObjectPtr.h:118
> > +    OSObjectPtr& operator=(const OSObjectPtr& other)
> 
> I like the swap style we use in RefPtr better.
> 
> Also, missing the move assignment operator.
> 
> > Source/WTF/wtf/OSObjectPtr.h:124
> >          T ptr = m_ptr;
> 
> No need for this local variable. It’s fine to release before assigning m_ptr, since we have already retained optr. That’s what we do in the nullptr specialization below, in fact.
> 
> > Source/WTF/wtf/OSObjectPtr.h:133
> > +    OSObjectPtr& operator=(std::nullptr_t)
> 
> With all the inlining, I’m surprised we need a specialization for nullptr.

Thanks for the review.  Given that I am mostly just moving this class, I am going to make these changes in a follow up.
Comment 4 Sam Weinig 2014-09-07 10:56:38 PDT
Committed r173367: <http://trac.webkit.org/changeset/173367>
Comment 5 Sam Weinig 2014-09-07 14:36:29 PDT
Feedback is being address in bug 136613.