Bug 156904 - Drop [UsePointersEvenForNonNullableObjectArguments] from MediaSource interfaces
Summary: Drop [UsePointersEvenForNonNullableObjectArguments] from MediaSource interfaces
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: youenn fablet
URL:
Keywords:
Depends on:
Blocks: 156844
  Show dependency treegraph
 
Reported: 2016-04-22 02:31 PDT by youenn fablet
Modified: 2016-04-28 10:36 PDT (History)
7 users (show)

See Also:


Attachments
Patch (14.89 KB, patch)
2016-04-22 02:57 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (22.20 KB, patch)
2016-04-25 05:52 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-yosemite (790.17 KB, application/zip)
2016-04-25 07:19 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews106 for mac-yosemite-wk2 (969.09 KB, application/zip)
2016-04-25 07:22 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews115 for mac-yosemite (879.32 KB, application/zip)
2016-04-25 07:37 PDT, Build Bot
no flags Details
Rebasing some tests (24.74 KB, patch)
2016-04-25 08:01 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (27.89 KB, patch)
2016-04-26 07:45 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (20.09 KB, patch)
2016-04-27 02:33 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2016-04-22 02:31:15 PDT
Drop [UsePointersEvenForNonNullableObjectArguments] from MediaSource interfaces
Comment 1 youenn fablet 2016-04-22 02:57:28 PDT
Created attachment 277035 [details]
Patch
Comment 2 Chris Dumez 2016-04-22 09:29:28 PDT
Comment on attachment 277035 [details]
Patch

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

> Source/WebCore/Modules/mediasource/MediaSource.cpp:522
> +    // FIXME: In case type is null, we should probably throw a TypeError.

Yes, this is what the spec says:
https://w3c.github.io/media-source/#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type

Could you please make the fix in this patch? Changing the exception type should be safe compatibility-size.

> Source/WebCore/Modules/mediasource/MediaSource.cpp:526
>      if (type.isNull() || type.isEmpty()) {

if (type.isEmpty()) would suffice
Then
ec = TypeError;

> Source/WebCore/Modules/mediasource/MediaSource.cpp:576
> +    return buffer.ptr();

This function should return a RefPtr<> and here we would just return WTFMove(buffer);

> Source/WebCore/Modules/mediasource/SourceBuffer.h:90
> +    void appendBuffer(ArrayBufferView*, ExceptionCode&);

We really need to fix the bindings generator.

> Source/WebCore/Modules/mediasource/SourceBufferList.cpp:52
> +void SourceBufferList::add(SourceBuffer& buffer)

Should be a Ref<>&&

> Source/WebCore/Modules/mediasource/SourceBufferList.cpp:54
> +    m_list.append(&buffer);

WTFMove(buffer)

Also, could you look to see if making m_list a Vector<Ref<SourceBuffer>> could be done in this patch without too much effort? It would be much nicer.
Comment 3 Darin Adler 2016-04-24 09:49:32 PDT
Comment on attachment 277035 [details]
Patch

I’m going to set review- because I’d like to see another patch with the fixes Chris suggested.
Comment 4 youenn fablet 2016-04-25 05:52:35 PDT
Created attachment 277240 [details]
Patch
Comment 5 youenn fablet 2016-04-25 06:22:49 PDT
(In reply to comment #2)
> Comment on attachment 277035 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=277035&action=review
> 
> > Source/WebCore/Modules/mediasource/MediaSource.cpp:522
> > +    // FIXME: In case type is null, we should probably throw a TypeError.
> 
> Yes, this is what the spec says:
> https://w3c.github.io/media-source/#widl-MediaSource-addSourceBuffer-
> SourceBuffer-DOMString-type
> 
> Could you please make the fix in this patch? Changing the exception type
> should be safe compatibility-size.

The issue is that binding generator should handle this case (null is not a valid value for DOMString).
I fixed that by making type parameter nullable.

> > Source/WebCore/Modules/mediasource/MediaSource.cpp:576
> > +    return buffer.ptr();
> 
> This function should return a RefPtr<> and here we would just return
> WTFMove(buffer);

buffer is now moved before returning.
I kept returning the raw pointer.

> > Source/WebCore/Modules/mediasource/SourceBuffer.h:90
> > +    void appendBuffer(ArrayBufferView*, ExceptionCode&);
> 
> We really need to fix the bindings generator.

Agreed.

> > Source/WebCore/Modules/mediasource/SourceBufferList.cpp:52
> > +void SourceBufferList::add(SourceBuffer& buffer)
> 
> Should be a Ref<>&&

FIXED.

> > Source/WebCore/Modules/mediasource/SourceBufferList.cpp:54
> > +    m_list.append(&buffer);
> 
> WTFMove(buffer)
> 
> Also, could you look to see if making m_list a Vector<Ref<SourceBuffer>>
> could be done in this patch without too much effort? It would be much nicer.

Done.
There are some HashMap<..., RefPtr<>> and Vector<RefPtr<>> that might also be changed to using Ref<> in mediasource/mediastream if possible.
Comment 6 Build Bot 2016-04-25 07:19:19 PDT
Comment on attachment 277240 [details]
Patch

Attachment 277240 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/1217916

New failing tests:
http/tests/media/media-source/mediasource-addsourcebuffer.html
media/media-source/media-source-addsourcebuffer.html
Comment 7 Build Bot 2016-04-25 07:19:23 PDT
Created attachment 277244 [details]
Archive of layout-test-results from ews101 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 8 Build Bot 2016-04-25 07:22:03 PDT
Comment on attachment 277240 [details]
Patch

Attachment 277240 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/1217918

New failing tests:
http/tests/media/media-source/mediasource-addsourcebuffer.html
media/media-source/media-source-addsourcebuffer.html
Comment 9 Build Bot 2016-04-25 07:22:07 PDT
Created attachment 277245 [details]
Archive of layout-test-results from ews106 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 10 Build Bot 2016-04-25 07:37:08 PDT
Comment on attachment 277240 [details]
Patch

Attachment 277240 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/1217929

New failing tests:
http/tests/media/media-source/mediasource-addsourcebuffer.html
media/media-source/media-source-addsourcebuffer.html
Comment 11 Build Bot 2016-04-25 07:37:13 PDT
Created attachment 277246 [details]
Archive of layout-test-results from ews115 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews115  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 12 youenn fablet 2016-04-25 08:01:23 PDT
Created attachment 277248 [details]
Rebasing some tests
Comment 13 Chris Dumez 2016-04-25 09:59:43 PDT
Comment on attachment 277248 [details]
Rebasing some tests

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

> Source/WTF/wtf/Ref.h:189
> +template<typename T, typename U> inline bool operator==(const Ref<T>& a, const Ref<U>& b)

Antti and Andreas do not like this one. They think if there were an operator== it should forward to the underlying type's operator== since this is a reference, not a pointer type.
Comment 14 Chris Dumez 2016-04-25 10:04:14 PDT
Comment on attachment 277248 [details]
Rebasing some tests

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

> Source/WebCore/Modules/mediasource/MediaSource.cpp:575
> +    return result;

This method should be updated to return a RefPtr<> since we transfer ownership to the caller.
Comment 15 youenn fablet 2016-04-25 10:31:28 PDT
(In reply to comment #14)
> Comment on attachment 277248 [details]
> Rebasing some tests
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=277248&action=review
> 
> > Source/WebCore/Modules/mediasource/MediaSource.cpp:575
> > +    return result;
> 
> This method should be updated to return a RefPtr<> since we transfer
> ownership to the caller.

Can you explain the issue?
A "result" ref is kept by m_sourceBuffers.
I wonder whether returning a RefPtr<> will not create unneeded refcounting at the JS binding code?

> Antti and Andreas do not like this one. They think if there were an
> operator== it should forward to the underlying type's operator== since this
> is a reference, not a pointer type.

Good point, I'll check this.
Comment 16 Chris Dumez 2016-04-25 10:46:40 PDT
Comment on attachment 277248 [details]
Rebasing some tests

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

>>> Source/WebCore/Modules/mediasource/MediaSource.cpp:575
>>> +    return result;
>> 
>> This method should be updated to return a RefPtr<> since we transfer ownership to the caller.
> 
> Can you explain the issue?
> A "result" ref is kept by m_sourceBuffers.
> I wonder whether returning a RefPtr<> will not create unneeded refcounting at the JS binding code?

Hmm, given that m_sourceBuffers refs it, I don't feel strongly about it anymore.
Comment 17 youenn fablet 2016-04-26 07:45:56 PDT
Created attachment 277367 [details]
Patch
Comment 18 WebKit Commit Bot 2016-04-26 07:47:25 PDT
Attachment 277367 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/Ref.h:200:  This { should be at the end of the previous line  [whitespace/braces] [4]
ERROR: Source/WTF/wtf/Ref.h:205:  This { should be at the end of the previous line  [whitespace/braces] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/Ref.cpp:165:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/Ref.cpp:170:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/Ref.cpp:175:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Tools/TestWebKitAPI/Tests/WTF/Ref.cpp:180:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
Total errors found: 6 in 17 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 19 Darin Adler 2016-04-26 09:00:46 PDT
Comment on attachment 277367 [details]
Patch

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

> Source/WebCore/Modules/mediasource/SourceBuffer.h:90
> +    void appendBuffer(ArrayBufferView*, ExceptionCode&);

Why does this take a pointer instead of a reference?

> Source/WebCore/Modules/mediasource/SourceBufferList.cpp:60
>      size_t index = m_list.find(buffer);

This does not seem to be what we want.

We want to find the pointer, not find the value. And Vector::find will use == to compare Ref<SourceBuffer> with SourceBuffer&, right? That’s bad in two ways. One, it will churn the reference count on the passed in buffer every time it does a comparison. Two, it will compare the SourceBuffer objects rather than comparing the pointers.

While this patch does add the correct behavior for Ref==Ref comparisons, I don’t think we actually want to use that algorithm in the code here from Vector::find for both of those reasons. And maybe we should not be adding the Ref==Ref operation at this time.

Instead I think we need to write out a loop of our own to do the finding, or add another Vector function that is flexible enough that we can use something other than operator==.

> Source/WebCore/Modules/mediasource/SourceBufferList.h:59
> +    bool contains(SourceBuffer& buffer) { return m_list.find(buffer) != notFound; }

Same issue here.
Comment 20 Darin Adler 2016-04-26 09:27:36 PDT
Comment on attachment 277367 [details]
Patch

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

> Source/WTF/wtf/Ref.h:207
> +template<typename T, typename U> inline auto operator==(const Ref<T>& a, const U& b) -> typename std::enable_if<!CanUseEqual<T, U>::value, bool>::type
> +{
> +    return a.ptr() == &b;
> +}

This is *not* a good idea. We don’t want Ref to silently do a pointer comparison if there is no == operator available to compare the values of the two objects. This is unprecedented behavior that might be convenient, but is subtle and dangerous.

I suggest not adding this to Ref at all, and doing something different to deal with the Vector::find that we want to use to find a pointer in a vector of Ref.

>> Source/WebCore/Modules/mediasource/SourceBufferList.cpp:60
>>      size_t index = m_list.find(buffer);
> 
> This does not seem to be what we want.
> 
> We want to find the pointer, not find the value. And Vector::find will use == to compare Ref<SourceBuffer> with SourceBuffer&, right? That’s bad in two ways. One, it will churn the reference count on the passed in buffer every time it does a comparison. Two, it will compare the SourceBuffer objects rather than comparing the pointers.
> 
> While this patch does add the correct behavior for Ref==Ref comparisons, I don’t think we actually want to use that algorithm in the code here from Vector::find for both of those reasons. And maybe we should not be adding the Ref==Ref operation at this time.
> 
> Instead I think we need to write out a loop of our own to do the finding, or add another Vector function that is flexible enough that we can use something other than operator==.

OK, my comment was wrong. Clearly your override of Ref does a pointer comparison with no reference count churn for SourceBuffer&, so the error lies elsewhere.
Comment 21 Chris Dumez 2016-04-26 09:34:57 PDT
(In reply to comment #20)
> Comment on attachment 277367 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=277367&action=review
> 
> > Source/WTF/wtf/Ref.h:207
> > +template<typename T, typename U> inline auto operator==(const Ref<T>& a, const U& b) -> typename std::enable_if<!CanUseEqual<T, U>::value, bool>::type
> > +{
> > +    return a.ptr() == &b;
> > +}
> 
> This is *not* a good idea. We don’t want Ref to silently do a pointer
> comparison if there is no == operator available to compare the values of the
> two objects. This is unprecedented behavior that might be convenient, but is
> subtle and dangerous.
> 
> I suggest not adding this to Ref at all, and doing something different to
> deal with the Vector::find that we want to use to find a pointer in a vector
> of Ref.
> 
> >> Source/WebCore/Modules/mediasource/SourceBufferList.cpp:60
> >>      size_t index = m_list.find(buffer);
> > 
> > This does not seem to be what we want.
> > 
> > We want to find the pointer, not find the value. And Vector::find will use == to compare Ref<SourceBuffer> with SourceBuffer&, right? That’s bad in two ways. One, it will churn the reference count on the passed in buffer every time it does a comparison. Two, it will compare the SourceBuffer objects rather than comparing the pointers.
> > 
> > While this patch does add the correct behavior for Ref==Ref comparisons, I don’t think we actually want to use that algorithm in the code here from Vector::find for both of those reasons. And maybe we should not be adding the Ref==Ref operation at this time.
> > 
> > Instead I think we need to write out a loop of our own to do the finding, or add another Vector function that is flexible enough that we can use something other than operator==.
> 
> OK, my comment was wrong. Clearly your override of Ref does a pointer
> comparison with no reference count churn for SourceBuffer&, so the error
> lies elsewhere.

Honestly, short-term, I would just keep using RefPtr<> in this Vector.
Comment 22 Darin Adler 2016-04-26 09:36:42 PDT
(In reply to comment #21)
> Honestly, short-term, I would just keep using RefPtr<> in this Vector.

Agreed, I think that’s the best thing to do for now.
Comment 23 Chris Dumez 2016-04-26 09:37:05 PDT
(In reply to comment #21)
> (In reply to comment #20)
> > Comment on attachment 277367 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=277367&action=review
> > 
> > > Source/WTF/wtf/Ref.h:207
> > > +template<typename T, typename U> inline auto operator==(const Ref<T>& a, const U& b) -> typename std::enable_if<!CanUseEqual<T, U>::value, bool>::type
> > > +{
> > > +    return a.ptr() == &b;
> > > +}
> > 
> > This is *not* a good idea. We don’t want Ref to silently do a pointer
> > comparison if there is no == operator available to compare the values of the
> > two objects. This is unprecedented behavior that might be convenient, but is
> > subtle and dangerous.
> > 
> > I suggest not adding this to Ref at all, and doing something different to
> > deal with the Vector::find that we want to use to find a pointer in a vector
> > of Ref.
> > 
> > >> Source/WebCore/Modules/mediasource/SourceBufferList.cpp:60
> > >>      size_t index = m_list.find(buffer);
> > > 
> > > This does not seem to be what we want.
> > > 
> > > We want to find the pointer, not find the value. And Vector::find will use == to compare Ref<SourceBuffer> with SourceBuffer&, right? That’s bad in two ways. One, it will churn the reference count on the passed in buffer every time it does a comparison. Two, it will compare the SourceBuffer objects rather than comparing the pointers.
> > > 
> > > While this patch does add the correct behavior for Ref==Ref comparisons, I don’t think we actually want to use that algorithm in the code here from Vector::find for both of those reasons. And maybe we should not be adding the Ref==Ref operation at this time.
> > > 
> > > Instead I think we need to write out a loop of our own to do the finding, or add another Vector function that is flexible enough that we can use something other than operator==.
> > 
> > OK, my comment was wrong. Clearly your override of Ref does a pointer
> > comparison with no reference count churn for SourceBuffer&, so the error
> > lies elsewhere.
> 
> Honestly, short-term, I would just keep using RefPtr<> in this Vector.

Longer term, I think VectorTraits are meant for things like these?
Comment 24 Darin Adler 2016-04-26 09:42:09 PDT
(In reply to comment #23)
> > Honestly, short-term, I would just keep using RefPtr<> in this Vector.
> 
> Longer term, I think VectorTraits are meant for things like these?

I don’t agree. That defines what every Vector does for a given type. In this case I think it’s an issue of we want to do with the particular Vector that’s the issue, not how all Vector<Ref> should work. Unless we let you allocate a Vector with custom traits.
Comment 25 Chris Dumez 2016-04-26 09:44:11 PDT
(In reply to comment #24)
> (In reply to comment #23)
> > > Honestly, short-term, I would just keep using RefPtr<> in this Vector.
> > 
> > Longer term, I think VectorTraits are meant for things like these?
> 
> I don’t agree. That defines what every Vector does for a given type. In this
> case I think it’s an issue of we want to do with the particular Vector
> that’s the issue, not how all Vector<Ref> should work. Unless we let you
> allocate a Vector with custom traits.

Oh right, I assumed we would let you allocate a Vector with custom traits (like we do for HashMap), but it looks like you're right.
Comment 26 youenn fablet 2016-04-27 01:50:02 PDT
(In reply to comment #20)
> Comment on attachment 277367 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=277367&action=review
> 
> > Source/WTF/wtf/Ref.h:207
> > +template<typename T, typename U> inline auto operator==(const Ref<T>& a, const U& b) -> typename std::enable_if<!CanUseEqual<T, U>::value, bool>::type
> > +{
> > +    return a.ptr() == &b;
> > +}
> 
> This is *not* a good idea. We don’t want Ref to silently do a pointer
> comparison if there is no == operator available to compare the values of the
> two objects. This is unprecedented behavior that might be convenient, but is
> subtle and dangerous.
> 

Agreed, Ref should remain a reference and not try to be more intelligent.

> Honestly, short-term, I would just keep using RefPtr<> in this Vector.

I'll update the patch accordingly.
Comment 27 youenn fablet 2016-04-27 02:33:20 PDT
Created attachment 277463 [details]
Patch
Comment 28 WebKit Commit Bot 2016-04-28 10:36:05 PDT
Comment on attachment 277463 [details]
Patch

Clearing flags on attachment: 277463

Committed r200198: <http://trac.webkit.org/changeset/200198>
Comment 29 WebKit Commit Bot 2016-04-28 10:36:12 PDT
All reviewed patches have been landed.  Closing bug.