Bug 177803 - Fix MSVC build with ENCRYPTED_MEDIA enabled
Summary: Fix MSVC build with ENCRYPTED_MEDIA enabled
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Don Olmstead
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-10-03 01:35 PDT by Yoshiaki Jitsukawa
Modified: 2021-02-08 16:11 PST (History)
18 users (show)

See Also:


Attachments
Patch (10.28 KB, patch)
2017-10-03 01:41 PDT, Yoshiaki Jitsukawa
no flags Details | Formatted Diff | Diff
compiler error log for MediaKeySession.cpp (2.44 KB, text/plain)
2017-10-03 22:29 PDT, Yoshiaki Jitsukawa
no flags Details
Patch (12.72 KB, patch)
2017-10-09 16:07 PDT, Yoshiaki Jitsukawa
no flags Details | Formatted Diff | Diff
Patch (10.22 KB, patch)
2021-02-08 11:06 PST, Don Olmstead
achristensen: review+
Details | Formatted Diff | Diff
Patch (12.96 KB, patch)
2021-02-08 14:56 PST, Don Olmstead
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yoshiaki Jitsukawa 2017-10-03 01:35:16 PDT
Both MSVC 2015 and 2017 fail to compile MediaKeySession.cpp and CDMClearKey.cpp.
Comment 1 Yoshiaki Jitsukawa 2017-10-03 01:41:47 PDT
Created attachment 322502 [details]
Patch
Comment 2 Yoshiaki Jitsukawa 2017-10-03 01:58:02 PDT
MSVC fails to compile lambda capture lists like this:
 [this, weakThis = m_weakPtrFactory.createWeakPtr(*this), promise = WTFMove(promise)]
so with the patch weakThis is created outside of the capture list.
Comment 3 Alex Christensen 2017-10-03 19:58:27 PDT
That ought to work.  It's valid C++14.  What is the error when compiling these files without this change?
Comment 4 Chris Dumez 2017-10-03 20:06:04 PDT
Yes, this should build fine. Those changes do not look good. Are you building without c++14 support enabled?
Comment 5 Yoshiaki Jitsukawa 2017-10-03 22:29:14 PDT
Created attachment 322632 [details]
compiler error log for MediaKeySession.cpp

For example I'm getting the attached errors when compiling MediaKeySession.cpp even with /std:c++14 option.
Comment 6 Alex Christensen 2017-10-04 13:25:45 PDT
Comment on attachment 322502 [details]
Patch

I think we need to find a better solution than this.
Comment 7 Yoshiaki Jitsukawa 2017-10-04 14:41:44 PDT
(In reply to Alex Christensen from comment #6)
> Comment on attachment 322502 [details]
> Patch
> 
> I think we need to find a better solution than this.

I agree to that. Thank you!
Comment 8 Zan Dobersek 2017-10-05 01:15:29 PDT
Try adding a simple private `createWeakPtr()` method on the MediaKeySession class, and call that in the lambda's capture list:

> WeakPtr<MediaKeySession> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }

The build error seems to indicate a compiler bug in how the `*this` object is deduced in the capture list. I also wonder whether capturing `weakThis = m_weakPtrFactory.createWeakPtr(*this)` before the plain `this` pointer would have any effect.
Comment 9 Yoshiaki Jitsukawa 2017-10-05 02:20:17 PDT
(In reply to Zan Dobersek from comment #8)
> Try adding a simple private `createWeakPtr()` method on the MediaKeySession
> class, and call that in the lambda's capture list:
> 
> > WeakPtr<MediaKeySession> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }
> 
> The build error seems to indicate a compiler bug in how the `*this` object
> is deduced in the capture list. I also wonder whether capturing `weakThis =
> m_weakPtrFactory.createWeakPtr(*this)` before the plain `this` pointer would
> have any effect.

Thanks, let me try those.
Comment 10 Yoshiaki Jitsukawa 2017-10-09 16:07:08 PDT
Created attachment 323238 [details]
Patch
Comment 11 Yoshiaki Jitsukawa 2017-10-09 16:19:29 PDT
(In reply to Zan Dobersek from comment #8)
> Try adding a simple private `createWeakPtr()` method on the MediaKeySession
> class, and call that in the lambda's capture list:
> 
> > WeakPtr<MediaKeySession> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }
> 
> The build error seems to indicate a compiler bug in how the `*this` object
> is deduced in the capture list. I also wonder whether capturing `weakThis =
> m_weakPtrFactory.createWeakPtr(*this)` before the plain `this` pointer would
> have any effect.

Both of them didn't work and it seems that there's something wrong with deduction
in nested lambda so I attached another patch to create a weak ptr at the outermost
capture list.
Comment 12 Alex Christensen 2017-10-10 12:39:52 PDT
Comment on attachment 323238 [details]
Patch

I think this approach looks ok.
Comment 13 Yoshiaki Jitsukawa 2017-10-10 14:23:15 PDT
(In reply to Alex Christensen from comment #12)
> Comment on attachment 323238 [details]
> Patch
> 
> I think this approach looks ok.

Thank you!
Comment 14 WebKit Commit Bot 2017-10-10 14:51:51 PDT
Comment on attachment 323238 [details]
Patch

Clearing flags on attachment: 323238

Committed r223148: <http://trac.webkit.org/changeset/223148>
Comment 15 WebKit Commit Bot 2017-10-10 14:51:52 PDT
All reviewed patches have been landed.  Closing bug.
Comment 16 Radar WebKit Bug Importer 2017-10-10 14:52:51 PDT
<rdar://problem/34920322>
Comment 17 Matt Lewis 2017-10-10 15:58:14 PDT
This caused internal failures. For more information, refer to the reviewer for more details.
Comment 18 Matt Lewis 2017-10-10 15:59:44 PDT
Reverted r223148 for reason:

This caused build failures.

Committed r223153: <http://trac.webkit.org/changeset/223153>
Comment 19 Yoshiaki Jitsukawa 2017-10-23 06:55:57 PDT
(In reply to Matt Lewis from comment #17)
> This caused internal failures. For more information, refer to the reviewer
> for more details.

So would you give me some information to help fix the failures?
Comment 20 Don Olmstead 2021-02-08 11:06:39 PST
Created attachment 419609 [details]
Patch
Comment 21 Alex Christensen 2021-02-08 12:48:36 PST
Comment on attachment 419609 [details]
Patch

The original patch introduced some unused lambda capture 'this' instances:

error:
.../OpenSource/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:357:10: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
.../OpenSource/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:461:10: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
.../OpenSource/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:505:10: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]

What a great reason to delay this patch for 3.5 years.  This version doesn't touch that file, so it should be fine.  If you want to also change CDMClearKey.cpp, just remove 'this' if you can.
Comment 22 Don Olmstead 2021-02-08 14:56:28 PST
Created attachment 419633 [details]
Patch
Comment 23 EWS 2021-02-08 15:53:14 PST
Committed r272557: <https://commits.webkit.org/r272557>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 419633 [details].
Comment 24 Darin Adler 2021-02-08 16:11:36 PST
Comment on attachment 419633 [details]
Patch

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

> Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp:326
> +        m_instanceSession->loadSession(m_sessionType, *sanitizedSessionId, origin, [this, weakThis = makeWeakPtr(*weakThis), promise = WTFMove(promise), sanitizedSessionId = *sanitizedSessionId, identifier = WTFMove(identifier)] (Optional<CDMInstanceSession::KeyStatusVector>&& knownKeys, Optional<double>&& expiration, Optional<CDMInstanceSession::Message>&& message, CDMInstanceSession::SuccessValue succeeded, CDMInstanceSession::SessionLoadFailure failure) mutable {

Is this:

    weakThis = makeWeakPtr(*weakThis)

Different from just writing this:

    weakThis

?

> Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp:438
> +        m_instanceSession->updateLicense(m_sessionId, m_sessionType, sanitizedResponse.releaseNonNull(), [this, weakThis = makeWeakPtr(*weakThis), promise = WTFMove(promise), identifier = WTFMove(identifier)] (bool sessionWasClosed, Optional<CDMInstanceSession::KeyStatusVector>&& changedKeys, Optional<double>&& changedExpiration, Optional<CDMInstanceSession::Message>&& message, CDMInstanceSession::SuccessValue succeeded) mutable {

Ditto.

> Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp:559
> +        m_instanceSession->closeSession(m_sessionId, [this, weakThis = makeWeakPtr(*weakThis), promise = WTFMove(promise), identifier = WTFMove(identifier)] () mutable {

Ditto.

> Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp:603
> +        m_instanceSession->removeSessionData(m_sessionId, m_sessionType, [this, weakThis = makeWeakPtr(*weakThis), promise = WTFMove(promise), identifier = WTFMove(identifier)] (CDMInstanceSession::KeyStatusVector&& keys, Optional<Ref<SharedBuffer>>&& message, CDMInstanceSession::SuccessValue succeeded) mutable {

Ditto.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:490
> +                [weakThis = makeWeakPtr(*weakThis), callback = WTFMove(callback), sessionWasClosed, changedKeys = WTFMove(changedKeys), succeeded] () mutable {

Ditto.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:573
> +                [weakThis = makeWeakPtr(*weakThis), callback = WTFMove(callback), keyStatusVector = WTFMove(keyStatusVector), message = WTFMove(message), success]() mutable {

Ditto.