RESOLVED FIXED 214654
WTF::Function adoption should be explicit instead of implicit
https://bugs.webkit.org/show_bug.cgi?id=214654
Summary WTF::Function adoption should be explicit instead of implicit
Geoffrey Garen
Reported 2020-07-22 14:15:49 PDT
WTF::Function adoption should be explicit instead of implicit
Attachments
Patch (4.01 KB, patch)
2020-07-22 14:19 PDT, Geoffrey Garen
no flags
Patch (4.72 KB, patch)
2020-07-22 14:56 PDT, Geoffrey Garen
darin: review+
Patch for landing (4.76 KB, patch)
2020-07-22 16:17 PDT, Geoffrey Garen
no flags
Geoffrey Garen
Comment 1 2020-07-22 14:19:11 PDT
Geoffrey Garen
Comment 2 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!
Darin Adler
Comment 3 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?
Geoffrey Garen
Comment 4 2020-07-22 14:27:20 PDT
I don't think there are name conflicts. Would you rename leakImpl() to leak() too?
Darin Adler
Comment 5 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.
Geoffrey Garen
Comment 6 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.
Geoffrey Garen
Comment 7 2020-07-22 14:56:42 PDT
Darin Adler
Comment 8 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.
Geoffrey Garen
Comment 9 2020-07-22 16:17:03 PDT
Created attachment 404992 [details] Patch for landing
EWS
Comment 10 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].
Radar WebKit Bug Importer
Comment 11 2020-07-22 20:34:18 PDT
Note You need to log in before you can comment on or make changes to this bug.