Bug 136613

Summary: Make OSObjectPtr a bit more like RefPtr
Product: WebKit Reporter: Sam Weinig <sam>
Component: New BugsAssignee: Sam Weinig <sam>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cmarcelo, commit-queue, darin, koivisto, mitz, thorton
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 136636    
Bug Blocks:    
Attachments:
Description Flags
Patch darin: review+

Description Sam Weinig 2014-09-07 14:33:24 PDT
Make OSObjectPtr a bit more like RefPtr
Comment 1 Sam Weinig 2014-09-07 14:35:49 PDT
Created attachment 237757 [details]
Patch
Comment 2 Sam Weinig 2014-09-07 14:36:56 PDT
This bug is for addressing the feedback in https://bugs.webkit.org/show_bug.cgi?id=136613.
Comment 3 Sam Weinig 2014-09-07 14:39:27 PDT
Two things I didn't do were:
- Remove the specialization for nullptr as I don't trust compilers :).
- Made it share code with RefPtr, as that would be a much bigger task.
Comment 4 Darin Adler 2014-09-07 18:01:07 PDT
(In reply to comment #3)
> - Remove the specialization for nullptr as I don't trust compilers :).

But you didn’t add one for RefPtr. You trust compilers only with a class that we use extensively across the entire project, not with a class that’s far less often used?
Comment 5 Darin Adler 2014-09-07 18:03:08 PDT
Comment on attachment 237757 [details]
Patch

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

> Source/WTF/wtf/OSObjectPtr.h:52
>  struct AdoptOSObject { };

Now that this is not part of the public API of OSObjectPtr, could make this struct a private member of the OSObjectPtr class. Would be tidier.

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

Unwanted const here prevents the patch from compiling.
Comment 6 Sam Weinig 2014-09-08 10:15:26 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > - Remove the specialization for nullptr as I don't trust compilers :).
> 
> But you didn’t add one for RefPtr. You trust compilers only with a class that we use extensively across the entire project, not with a class that’s far less often used?

I'm writing some test code to figure out if it really is the same. When I finish that experiment, I will either add the code to RefPtr, or remove it from OSObjectPtr.
Comment 7 Sam Weinig 2014-09-08 10:16:09 PDT
(In reply to comment #5)
> (From update of attachment 237757 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=237757&action=review
> 
> > Source/WTF/wtf/OSObjectPtr.h:52
> >  struct AdoptOSObject { };
> 
> Now that this is not part of the public API of OSObjectPtr, could make this struct a private member of the OSObjectPtr class. Would be tidier.

Will fix.

> 
> > Source/WTF/wtf/OSObjectPtr.h:122
> > +    OSObjectPtr& operator=(const OSObjectPtr&& other)
> 
> Unwanted const here prevents the patch from compiling.

Do'h.
Comment 8 Sam Weinig 2014-09-08 10:26:44 PDT
Committed r173383: <http://trac.webkit.org/changeset/173383>
Comment 9 Tim Horton 2014-09-08 10:38:20 PDT
Hopeful build fix in http://trac.webkit.org/changeset/173384
Comment 10 WebKit Commit Bot 2014-09-08 11:00:50 PDT
Re-opened since this is blocked by bug 136636
Comment 11 Antti Koivisto 2014-09-26 08:25:13 PDT
How is this better than just having adoptOSObject() function for RetainPtr? That's what I was doing before discovering this and it seemed to work fine.
Comment 12 Sam Weinig 2014-09-26 13:44:36 PDT
(In reply to comment #11)
> How is this better than just having adoptOSObject() function for RetainPtr? That's what I was doing before discovering this and it seemed to work fine.

It's not. And I will be rolling this out pretty soon.
Comment 13 Antti Koivisto 2014-09-27 00:10:03 PDT
This seemed to work on all platforms:

+    template<typename T> inline RetainPtr<T> adoptSystem(T ptr)
+    {
+#if OS_OBJECT_USE_OBJC
+        return adoptNS(ptr);
+#else
+        return adoptCF(ptr);
+#endif
+    }
+
Comment 14 Sam Weinig 2014-10-03 17:37:46 PDT
(In reply to comment #13)
> This seemed to work on all platforms:
> 
> +    template<typename T> inline RetainPtr<T> adoptSystem(T ptr)
> +    {
> +#if OS_OBJECT_USE_OBJC
> +        return adoptNS(ptr);
> +#else
> +        return adoptCF(ptr);
> +#endif
> +    }
> +

Actually, I don't believe this actually works.  In 32-bit, OS-objects are not objective-c objects, but also not CFObjects, so they can't be CFRetain()/CFReleased().  I think we are going to need to stick with OSObjectPtr for now.