Bug 186245 - [Cocoa] Update more code to be more ARC-compatible to prepare for future ARC adoption
Summary: [Cocoa] Update more code to be more ARC-compatible to prepare for future ARC ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-06-03 14:03 PDT by Darin Adler
Modified: 2018-06-05 12:41 PDT (History)
7 users (show)

See Also:


Attachments
Patch (87.97 KB, patch)
2018-06-03 14:34 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (88.12 KB, patch)
2018-06-03 16:37 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-sierra (2.28 MB, application/zip)
2018-06-03 17:48 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews104 for mac-sierra-wk2 (2.83 MB, application/zip)
2018-06-03 17:56 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews114 for mac-sierra (3.01 MB, application/zip)
2018-06-03 18:16 PDT, EWS Watchlist
no flags Details
Patch (88.11 KB, patch)
2018-06-03 21:43 PDT, Darin Adler
dbates: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2018-06-03 14:03:10 PDT
[Cocoa] Update more code to be more ARC-compatible to prepare for future ARC adoption
Comment 1 Darin Adler 2018-06-03 14:34:55 PDT Comment hidden (obsolete)
Comment 2 EWS Watchlist 2018-06-03 14:38:27 PDT Comment hidden (obsolete)
Comment 3 Darin Adler 2018-06-03 16:37:26 PDT Comment hidden (obsolete)
Comment 4 EWS Watchlist 2018-06-03 16:39:17 PDT Comment hidden (obsolete)
Comment 5 EWS Watchlist 2018-06-03 17:48:34 PDT Comment hidden (obsolete)
Comment 6 EWS Watchlist 2018-06-03 17:48:35 PDT Comment hidden (obsolete)
Comment 7 EWS Watchlist 2018-06-03 17:56:01 PDT Comment hidden (obsolete)
Comment 8 EWS Watchlist 2018-06-03 17:56:03 PDT Comment hidden (obsolete)
Comment 9 EWS Watchlist 2018-06-03 18:16:36 PDT Comment hidden (obsolete)
Comment 10 EWS Watchlist 2018-06-03 18:16:37 PDT Comment hidden (obsolete)
Comment 11 Darin Adler 2018-06-03 21:43:43 PDT
Created attachment 341888 [details]
Patch
Comment 12 Daniel Bates 2018-06-03 23:48:05 PDT
Comment on attachment 341888 [details]
Patch

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

> Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:562
> +        NSDictionary *attributes = @{ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA) };

This is ok as-is. Could use auto here.

> Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm:222
> +        NSDictionary* videoDecoderSpecification = @{ (__bridge NSString *)kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder: @YES };

Ditto.

> Source/WebCore/platform/mac/WebCoreNSURLExtras.mm:819
> +    CFURLRef result = CFURLCreateWithBytes(NULL, urlBytes.data(), fragRg.location - 1, kCFStringEncodingUTF8, NULL);

This is ok as-is. NULL => nullptr 

(There are two in this line).

> Source/WebCore/platform/mac/WebCoreNSURLExtras.mm:821
> +        result = CFURLCreateWithBytes(NULL, urlBytes.data(), fragRg.location - 1, kCFStringEncodingISOLatin1, NULL);

Ditto.

> Source/WebCore/platform/mac/WebCoreNSURLExtras.mm:1012
> +    CFURLRef result = CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingUTF8, NULL);

Ditto.

> Source/WebCore/platform/mac/WebCoreNSURLExtras.mm:1014
> +        result = CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingISOLatin1, NULL);

Ditto.

> Source/WebCore/platform/network/mac/ResourceErrorMac.mm:121
> +    : ResourceError((__bridge NSError *)cfError)

This is ok as-is. Could use uniform initializer syntax.
Comment 13 Daniel Bates 2018-06-04 00:05:06 PDT
Comment on attachment 341888 [details]
Patch

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

It’s tempting to comment on how to clean up the surrounding code, but that is not the purpose of this patch :)

> Source/WebCore/bridge/objc/objc_class.mm:53
> +    ObjcClass* aClass = reinterpret_cast<ObjcClass*>(const_cast<void*>(CFDictionaryGetValue(classesByIsA, (__bridge CFTypeRef)isa)));

This is ok as-is. Could use auto here.

> Source/WebCore/platform/mac/PluginBlacklist.mm:172
> +    : m_bundleIDToMinimumSecureVersion(adoptNS([bundleIDToMinimumSecureVersion copy]))

This is ok as-is. Could use uniform initializer syntax in this line and the lines below that are part of the initializer list.

> Source/WebCore/platform/mac/URLMac.mm:57
> +    // Creating a toll-free bridged CFURL, because creation with NSURL methods would not preserve the original string.

Is the comma before “because” necessary? Since you’re touching this function, that is unrelated to this purpose of this patch, we could use a C++ style cast in the return statement.
Comment 14 Darin Adler 2018-06-04 21:08:50 PDT
(In reply to Daniel Bates from comment #13)
> Since you’re touching this
> function, that is unrelated to this purpose of this patch, we could use a
> C++ style cast in the return statement.

I made the other changes you requested, but I will not be changing this return statement for two reasons:

1) I prefer not to use C++ style typecasts for conversions between CF types and NS types because of the need for __bridge and this is a conversion from a CF type to an NS type.

2) The reason I didn’t change this particular line to add a __bridge is that it’s tricky to get it right for ARC and I am waiting until later when I figure out how to do it 100% correctly.

It doesn’t seem helpful for me to change it in any way at this time since I don’t know how to make it right. I limited my changes to ones I am confident are correct for ARC, to make the actual conversion a bit easier so we can focus on the more difficult cases.
Comment 15 Darin Adler 2018-06-04 21:13:45 PDT
Committed r232501: <https://trac.webkit.org/changeset/232501>
Comment 16 Radar WebKit Bug Importer 2018-06-04 21:14:32 PDT
<rdar://problem/40793363>
Comment 17 Daniel Bates 2018-06-04 23:02:54 PDT
(In reply to Darin Adler from comment #14)
> (In reply to Daniel Bates from comment #13)
> > Since you’re touching this
> > function, that is unrelated to this purpose of this patch, we could use a
> > C++ style cast in the return statement.
> 
> I made the other changes you requested, but I will not be changing this
> return statement for two reasons:
> 
> 1) I prefer not to use C++ style typecasts for conversions between CF types
> and NS types because of the need for __bridge and this is a conversion from
> a CF type to an NS type.
> 
> 2) The reason I didn’t change this particular line to add a __bridge is that
> it’s tricky to get it right for ARC and I am waiting until later when I
> figure out how to do it 100% correctly.
> 
> It doesn’t seem helpful for me to change it in any way at this time since I
> don’t know how to make it right. I limited my changes to ones I am confident
> are correct for ARC, to make the actual conversion a bit easier so we can
> focus on the more difficult cases.

Makes sense. Out of curiosity, are you using ARC conversion feature in Xcode to help you with the conversion?
Comment 18 Darin Adler 2018-06-05 12:41:34 PDT
(In reply to Daniel Bates from comment #17)
> Out of curiosity, are you using ARC conversion feature in Xcode
> to help you with the conversion?

I tried. So far it has not been helpful.