Bug 122883 - [WK2] Convert SeccompFilters to using unique_ptr instead of OwnPtr/PassOwnPtr
Summary: [WK2] Convert SeccompFilters to using unique_ptr instead of OwnPtr/PassOwnPtr
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sergio Correia (qrwteyrutiyoup)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-15 22:29 PDT by Sergio Correia (qrwteyrutiyoup)
Modified: 2013-10-31 12:48 PDT (History)
6 users (show)

See Also:


Attachments
Patch (15.17 KB, patch)
2013-10-15 22:31 PDT, Sergio Correia (qrwteyrutiyoup)
no flags Details | Formatted Diff | Diff
=v2 (15.10 KB, patch)
2013-10-18 12:48 PDT, Sergio Correia (qrwteyrutiyoup)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergio Correia (qrwteyrutiyoup) 2013-10-15 22:29:35 PDT
[WK2] Convert SeccompFilters to using unique_ptr instead of OwnPtr/PassOwnPtr
Comment 1 Sergio Correia (qrwteyrutiyoup) 2013-10-15 22:31:02 PDT
Created attachment 214340 [details]
Patch
Comment 2 Anders Carlsson 2013-10-16 08:12:23 PDT
Comment on attachment 214340 [details]
Patch

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

Patch looks good, but please remove the unnecessary std::move calls.

> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60
> +        return std::move(open);

No need to use std::move here. Returning a move-only object will automatically move the object.

> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:93
> +    return std::move(open);

Ditto.

> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:105
> +    return std::move(open);

Ditto.

> Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp:76
> +    return std::move(syscall);

Ditto.

> Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp:98
> +    return std::move(result);

Ditto.
Comment 3 Sergio Correia (qrwteyrutiyoup) 2013-10-16 20:24:20 PDT
Comment on attachment 214340 [details]
Patch

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

>> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60
>> +        return std::move(open);
> 
> No need to use std::move here. Returning a move-only object will automatically move the object.

It seems to be needed for this class: 

[ 82%] Building CXX object Source/WebKit2/CMakeFiles/WebKit2.dir/Shared/linux/SeccompFilters/OpenSyscall.cpp.o
/home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp: In static member function 'static std::unique_ptr<WebKit::Syscall> WebKit::OpenSyscall::createFromOpenatContext(mcontext_t*)':
/home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60:16: error: invalid conversion from 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >' to 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >&&' [-fpermissive]
In file included from /usr/include/c++/4.8.1/memory:81:0,
                 from /home/sergio/projects/webkit/Source/WTF/wtf/StdLibExtras.h:30,
                 from /home/sergio/projects/webkit/Source/WTF/wtf/FastMalloc.h:28,
                 from /home/sergio/projects/webkit/Source/WebKit2/config.h:87,
                 from /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:26:
/usr/include/c++/4.8.1/bits/unique_ptr.h:169:2: error:   initializing argument 1 of 'std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Up = WebKit::OpenSyscall; _Ep = std::default_delete<WebKit::OpenSyscall>; <template-parameter-2-3> = void; _Tp = WebKit::Syscall; _Dp = std::default_delete<WebKit::Syscall>]' [-fpermissive]
/home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60:16: error: cannot convert 'open' from type 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >' to type 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >&&'
Comment 4 Anders Carlsson 2013-10-16 20:28:41 PDT
Comment on attachment 214340 [details]
Patch

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

>>> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60
>>> +        return std::move(open);
>> 
>> No need to use std::move here. Returning a move-only object will automatically move the object.
> 
> It seems to be needed for this class: 
> 
> [ 82%] Building CXX object Source/WebKit2/CMakeFiles/WebKit2.dir/Shared/linux/SeccompFilters/OpenSyscall.cpp.o
> /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp: In static member function 'static std::unique_ptr<WebKit::Syscall> WebKit::OpenSyscall::createFromOpenatContext(mcontext_t*)':
> /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60:16: error: invalid conversion from 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >' to 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >&&' [-fpermissive]
> In file included from /usr/include/c++/4.8.1/memory:81:0,
>                  from /home/sergio/projects/webkit/Source/WTF/wtf/StdLibExtras.h:30,
>                  from /home/sergio/projects/webkit/Source/WTF/wtf/FastMalloc.h:28,
>                  from /home/sergio/projects/webkit/Source/WebKit2/config.h:87,
>                  from /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:26:
> /usr/include/c++/4.8.1/bits/unique_ptr.h:169:2: error:   initializing argument 1 of 'std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Up = WebKit::OpenSyscall; _Ep = std::default_delete<WebKit::OpenSyscall>; <template-parameter-2-3> = void; _Tp = WebKit::Syscall; _Dp = std::default_delete<WebKit::Syscall>]' [-fpermissive]
> /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60:16: error: cannot convert 'open' from type 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >' to type 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >&&'

Wait, why does OpenSyscall::createFromOpenatContext return a PassOwnPtr?
Comment 5 Sergio Correia (qrwteyrutiyoup) 2013-10-18 12:17:23 PDT
Comment on attachment 214340 [details]
Patch

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

>>>> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60
>>>> +        return std::move(open);
>>> 
>>> No need to use std::move here. Returning a move-only object will automatically move the object.
>> 
>> It seems to be needed for this class: 
>> 
>> [ 82%] Building CXX object Source/WebKit2/CMakeFiles/WebKit2.dir/Shared/linux/SeccompFilters/OpenSyscall.cpp.o
>> /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp: In static member function 'static std::unique_ptr<WebKit::Syscall> WebKit::OpenSyscall::createFromOpenatContext(mcontext_t*)':
>> /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60:16: error: invalid conversion from 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >' to 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >&&' [-fpermissive]
>> In file included from /usr/include/c++/4.8.1/memory:81:0,
>>                  from /home/sergio/projects/webkit/Source/WTF/wtf/StdLibExtras.h:30,
>>                  from /home/sergio/projects/webkit/Source/WTF/wtf/FastMalloc.h:28,
>>                  from /home/sergio/projects/webkit/Source/WebKit2/config.h:87,
>>                  from /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:26:
>> /usr/include/c++/4.8.1/bits/unique_ptr.h:169:2: error:   initializing argument 1 of 'std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Up = WebKit::OpenSyscall; _Ep = std::default_delete<WebKit::OpenSyscall>; <template-parameter-2-3> = void; _Tp = WebKit::Syscall; _Dp = std::default_delete<WebKit::Syscall>]' [-fpermissive]
>> /home/sergio/projects/webkit/Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60:16: error: cannot convert 'open' from type 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >' to type 'std::unique_ptr<WebKit::OpenSyscall, std::default_delete<WebKit::OpenSyscall> >&&'
> 
> Wait, why does OpenSyscall::createFromOpenatContext return a PassOwnPtr?

I don't see any special reason, other than the fact that Syscall::createFromContext() returns a PassOwnPtr, and these create-from-context calls such as OpenSyscall::createFromOpenatContext() do so as well. It could probably be reworked not to do that. Would you like me to attempt something in that direction?
Comment 6 Anders Carlsson 2013-10-18 12:20:00 PDT
(In reply to comment #5)
> > Wait, why does OpenSyscall::createFromOpenatContext return a PassOwnPtr?
> 
> I don't see any special reason, other than the fact that Syscall::createFromContext() returns a PassOwnPtr, and these create-from-context calls such as OpenSyscall::createFromOpenatContext() do so as well. It could probably be reworked not to do that. Would you like me to attempt something in that direction?

Yes, please make all of these return std::unique_ptr.
Comment 7 Sergio Correia (qrwteyrutiyoup) 2013-10-18 12:26:40 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > > Wait, why does OpenSyscall::createFromOpenatContext return a PassOwnPtr?
> > 
> > I don't see any special reason, other than the fact that Syscall::createFromContext() returns a PassOwnPtr, and these create-from-context calls such as OpenSyscall::createFromOpenatContext() do so as well. It could probably be reworked not to do that. Would you like me to attempt something in that direction?
> 
> Yes, please make all of these return std::unique_ptr.

Wait, there's a minor misunderstanding here. The original patch did that (that was the goal, to convert to using unique_ptr), but you pointed out that I wouldn't need the std::move() because the objects would be moved automatically.
Then I said that I would still need the std::move() calls in OpenSyscall.cpp. The PassOwnPtr you were looking at were from the current code, before conversion. Let me post an updated patch removing the unecessary std::move() calls from Syscall.cpp.
Comment 8 Sergio Correia (qrwteyrutiyoup) 2013-10-18 12:48:52 PDT
Created attachment 214596 [details]
=v2

Removed unecessary std::move() calls in Syscall.cpp.
Comment 9 Darin Adler 2013-10-18 19:16:49 PDT
Comment on attachment 214596 [details]
=v2

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

> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:60
> +        return std::move(open);

No need for std::move here.

> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:93
> +    return std::move(open);

No need for std::move here.

> Source/WebKit2/Shared/linux/SeccompFilters/OpenSyscall.cpp:105
> +    return std::move(open);

No need for std::move here.
Comment 10 Darin Adler 2013-10-18 19:17:19 PDT
(In reply to comment #7)
> Then I said that I would still need the std::move() calls in OpenSyscall.cpp.

Why? I don’t get it?
Comment 11 Sergio Correia (qrwteyrutiyoup) 2013-10-21 18:29:13 PDT
(In reply to comment #10)
> (In reply to comment #7)
> > Then I said that I would still need the std::move() calls in OpenSyscall.cpp.
> 
> Why? I don’t get it?

This question has insights on the issue at hand:
http://stackoverflow.com/questions/17481018/when-is-explicit-move-needed-for-a-return-statement

Basically we need the explicit move in there because the return type is std::unique_ptr<Syscall> and we are returning a std::unique_ptr<OpenSyscall>. The compiler message is this: 

error: invalid conversion from 'std::unique_ptr<WebKit::OpenSyscall>' to 'std::unique_ptr<WebKit::OpenSyscall>&&'
Comment 12 Sergio Correia (qrwteyrutiyoup) 2013-10-31 10:19:52 PDT
Hi Darin/Anders,

could you please take another look at this?
Comment 13 WebKit Commit Bot 2013-10-31 12:48:19 PDT
Comment on attachment 214596 [details]
=v2

Clearing flags on attachment: 214596

Committed r158388: <http://trac.webkit.org/changeset/158388>
Comment 14 WebKit Commit Bot 2013-10-31 12:48:23 PDT
All reviewed patches have been landed.  Closing bug.