Bug 214654 - WTF::Function adoption should be explicit instead of implicit
Summary: WTF::Function adoption should be explicit instead of implicit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-22 14:15 PDT by Geoffrey Garen
Modified: 2022-02-28 03:35 PST (History)
11 users (show)

See Also:


Attachments
Patch (4.01 KB, patch)
2020-07-22 14:19 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (4.72 KB, patch)
2020-07-22 14:56 PDT, Geoffrey Garen
darin: review+
Details | Formatted Diff | Diff
Patch for landing (4.76 KB, patch)
2020-07-22 16:17 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2020-07-22 14:15:49 PDT
WTF::Function adoption should be explicit instead of implicit
Comment 1 Geoffrey Garen 2020-07-22 14:19:11 PDT
Created attachment 404961 [details]
Patch
Comment 2 Geoffrey Garen 2020-07-22 14:20:25 PDT
If someone can figure out the template fu to automatically deduce the function type in adoptImpl, that would be great!
Comment 3 Darin Adler 2020-07-22 14:25:04 PDT
Comment on attachment 404961 [details]
Patch

Does it really need to be name adoptImpl and not just adopt? Are there name conflicts?
Comment 4 Geoffrey Garen 2020-07-22 14:27:20 PDT
I don't think there are name conflicts.

Would you rename leakImpl() to leak() too?
Comment 5 Darin Adler 2020-07-22 14:33:54 PDT
I am increasingly unsure about this.

Why should WTF::Function adoption be explicit?

In other cases, we do that because we are concerned about object lifetime. Like a raw pointer being adopted by a std::unique_ptr. Does that apply here.

I don’t think "impl" is the correct term for a C++ function.
Comment 6 Geoffrey Garen 2020-07-22 14:38:16 PDT
Yes, this is all about the lifetime of the unique_ptr that holds the functor. leakImpl() leaks the unique_ptr and adopt takes ownership of the pointer.
Comment 7 Geoffrey Garen 2020-07-22 14:56:42 PDT
Created attachment 404971 [details]
Patch
Comment 8 Darin Adler 2020-07-22 15:33:22 PDT
Comment on attachment 404971 [details]
Patch

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

> Source/WTF/wtf/Function.h:125
> +template <typename T> inline Function<T> adopt(typename Function<T>::Impl* impl)

I think you want to write something more like this:

    template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::CallableWrapperBase<Out, In...>* pointer)

That should allow you to use adopt() without template arguments.
Comment 9 Geoffrey Garen 2020-07-22 16:17:03 PDT
Created attachment 404992 [details]
Patch for landing
Comment 10 EWS 2020-07-22 20:33:29 PDT
Committed r264743: <https://trac.webkit.org/changeset/264743>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 404992 [details].
Comment 11 Radar WebKit Bug Importer 2020-07-22 20:34:18 PDT
<rdar://problem/65970781>