Bug 133929

Summary: Add an autorelease() member function to RetainPtr
Product: WebKit Reporter: Anders Carlsson <andersca>
Component: New BugsAssignee: Anders Carlsson <andersca>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cmarcelo, commit-queue, mitz
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch mitz: review+

Description Anders Carlsson 2014-06-15 12:17:32 PDT
Add an autorelease() member function to RetainPtr
Comment 1 Anders Carlsson 2014-06-15 12:19:47 PDT
Created attachment 233145 [details]
Patch
Comment 2 WebKit Commit Bot 2014-06-15 12:21:51 PDT
Attachment 233145 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/RetainPtr.h:171:  Extra space before [  [whitespace/braces] [5]
Total errors found: 1 in 14 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 mitz 2014-06-15 12:28:27 PDT
Comment on attachment 233145 [details]
Patch

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

> Source/WTF/wtf/RetainPtr.h:172
> +#if __has_feature(objc_arc)
> +        return ptr;
> +#else
> +        return [(id)CFMakeCollectable(ptr) autorelease];
> +#endif

Can this be written more concisely as
    return CFBridgingRelease(ptr);
?
Comment 4 Anders Carlsson 2014-06-15 12:30:26 PDT
(In reply to comment #3)
> (From update of attachment 233145 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=233145&action=review
> 
> > Source/WTF/wtf/RetainPtr.h:172
> > +#if __has_feature(objc_arc)
> > +        return ptr;
> > +#else
> > +        return [(id)CFMakeCollectable(ptr) autorelease];
> > +#endif
> 
> Can this be written more concisely as
>     return CFBridgingRelease(ptr);
> ?

Yes, that's the function I was looking for!
Comment 5 Benjamin Poulain 2014-06-15 12:30:53 PDT
Comment on attachment 233145 [details]
Patch

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

> Source/WTF/wtf/RetainPtr.h:171
> +        return [(id)CFMakeCollectable(ptr) autorelease];

We use CFRetain/CFRelease everywhere, shouldn't this be CFAutorelease?
Comment 6 mitz 2014-06-15 12:31:58 PDT
Comment on attachment 233145 [details]
Patch

r=me with CFBridgingRelease.
Comment 7 Anders Carlsson 2014-06-15 12:34:43 PDT
(In reply to comment #5)
> (From update of attachment 233145 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=233145&action=review
> 
> > Source/WTF/wtf/RetainPtr.h:171
> > +        return [(id)CFMakeCollectable(ptr) autorelease];
> 
> We use CFRetain/CFRelease everywhere, shouldn't this be CFAutorelease?

It can't be CFAutorelease because:

1. It's not available on 10.8
2. I don't think it does the right thing for garbage collected Objective-C apps using WebKit.
Comment 8 Anders Carlsson 2014-06-15 16:16:57 PDT
Committed r169995: <http://trac.webkit.org/changeset/169995>
Comment 9 mitz 2014-06-15 20:31:14 PDT
(In reply to comment #8)
> Committed r169995: <http://trac.webkit.org/changeset/169995>

This broke the iOS build with:

In file included from Source/WebCore/bindings/objc/DOM.mm:32:
In file included from Source/WebCore/loader/cache/CachedImage.h:26:
In file included from Source/WebCore/loader/cache/CachedResource.h:29:
In file included from Source/WebCore/platform/network/cf/ResourceError.h:31:
WebKitBuild/Release-iphonesimulator/usr/local/include/wtf/RetainPtr.h:166:16: error: cannot initialize return object of type 'PtrType' (aka 'CGImage *') with an rvalue of type 'id'
Source/WebCore/bindings/objc/DOM.mm:613:68: note: in instantiation of member function 'WTF::RetainPtr<CGImage *>::autorelease' requested here
Comment 10 mitz 2014-06-15 21:10:24 PDT
(In reply to comment #9)
> (In reply to comment #8)
> > Committed r169995: <http://trac.webkit.org/changeset/169995>
> 
> This broke the iOS build with:
> 
> In file included from Source/WebCore/bindings/objc/DOM.mm:32:
> In file included from Source/WebCore/loader/cache/CachedImage.h:26:
> In file included from Source/WebCore/loader/cache/CachedResource.h:29:
> In file included from Source/WebCore/platform/network/cf/ResourceError.h:31:
> WebKitBuild/Release-iphonesimulator/usr/local/include/wtf/RetainPtr.h:166:16: error: cannot initialize return object of type 'PtrType' (aka 'CGImage *') with an rvalue of type 'id'
> Source/WebCore/bindings/objc/DOM.mm:613:68: note: in instantiation of member function 'WTF::RetainPtr<CGImage *>::autorelease' requested here

I tried to fix that in <http://trac.webkit.org/r169999>.