Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Issue 599313003: Add nullptr support to scoped_ptr. (Closed)

Created:
6 years, 2 months ago by danakj
Modified:
6 years, 2 months ago
Reviewers:
jamesr, brettw, Nico, dcheng
CC:
chromium-reviews, erikwright+watch_chromium.org, gavinp+memory_chromium.org, Ryan Sleevi
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Project:
chromium
Visibility:
Public.

Description

Add nullptr support to scoped_ptr. This adds support to use nullptr to construct, assign, or return a scoped_ptr<T> and scoped_ptr<T[]>. Support for this requires the use of a move-only constructor. The changes are: - Add a constructor that takes decltype(nullptr) as a parameter. This allows behaviour such as scoped_ptr<T>(nullptr), but also allows a function with return type scoped_ptr<T> to "return nullptr;" instead of "return scoped_ptr<T>();". - Add an operator=(decltype(nullptr)) that resets the scoped_ptr to empty and deletes anything it held. - Add/Modify a constructor to take a scoped_ptr<U,E>&& parameter for constructing a scoped_ptr from another using move-only semantics. This piece is critical for allowing the function returning nullptr to be assigned to some other scoped_ptr at the callsite. In particular, take the following code: scoped_ptr<T> Function() { return nullptr; } scoped_ptr<T> var = Function(); In this case the constructor which takes a nullptr allows Function() to be written, but not to be used. The move-only constructor allows the assignment from Function() to var. See "C++11 feature proposal: Move-only constructors" on chromium-dev for more explanation why. The scoped_ptr<T> class already had a constructor which took scoped_ptr<U,E> as an argument, so this was changed to be scoped_ptr<U,E>&& instead. The scoped_ptr<T[]> class had no such constructor, so a scoped_ptr&& constructor was added. These match the constructors found on the unique_ptr class. - Remove the RValue type and the contructor that constructs a scoped_ptr from an RValue. Change Pass() to return a scoped_ptr&& instead of a scoped_ptr::RValue, to avoid the type conversion and remove some complexity. This is done with a new emulation macro that still provides Pass() and makes the type go down the MoveOnlyType path in base::Callback code. This adds base_unittests to demonstrate and use these changes. The use of Pass() remains unchanged until std::move() is written or allowed. At that time std::move() could be used instead of Pass. R=brettw@chromium.org, jamesr@chromium.org Committed: https://crrev.com/2299e91d3508f8d5d18ef990cf6024ea4371250a Cr-Commit-Position: refs/heads/master@{#297072} Committed: https://crrev.com/a9527ce329c38d945e46773f1592a4939cf62b99 Cr-Commit-Position: refs/heads/master@{#297116}

Patch Set 1 #

Total comments: 6

Patch Set 2 : nullptr: jamesr-review #

Patch Set 3 : nullptr: no-RValue #

Patch Set 4 : nullptr: Pass-is-std::move #

Patch Set 5 : nullptr: addtestsforconversion #

Total comments: 2

Patch Set 6 : nullptr: backtothefuture #

Total comments: 2

Patch Set 7 : nullptr: testfix #

Total comments: 1

Patch Set 8 : nullptr: use-new-array-to-create-array #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+122 lines, -39 lines) Patch
M base/memory/scoped_ptr.h View 1 3 4 5 17 chunks +68 lines, -39 lines 0 comments Download
M base/memory/scoped_ptr_unittest.cc View 1 2 3 4 5 6 7 2 chunks +54 lines, -0 lines 1 comment Download

Messages

Total messages: 55 (9 generated)
danakj
This hasn't been formally allowed yet, but if it were...
6 years, 2 months ago (2014-09-25 01:11:01 UTC) #1
Nico
Out of curiosity: For the third point, would it be possible to change the CPP03_MOVE_EMULATION ...
6 years, 2 months ago (2014-09-25 01:58:42 UTC) #2
danakj
On Sep 24, 2014 9:58 PM, <thakis@chromium.org> wrote: > > Out of curiosity: For the ...
6 years, 2 months ago (2014-09-25 02:22:19 UTC) #3
danakj
One more thought. This move constructor is only needed with our emulation in places where ...
6 years, 2 months ago (2014-09-25 02:44:53 UTC) #4
jamesr
I think in the future we'll want to allow assigning a scoped_ptr<U>&& to a scoped_ptr<T> ...
6 years, 2 months ago (2014-09-25 05:58:09 UTC) #6
danakj
PTAL https://codereview.chromium.org/599313003/diff/1/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/599313003/diff/1/base/memory/scoped_ptr.h#newcode336 base/memory/scoped_ptr.h:336: // IMPLEMENTATION NOTE: C++11 unique_ptr<> keeps this constructor ...
6 years, 2 months ago (2014-09-25 14:47:52 UTC) #7
danakj
https://codereview.chromium.org/599313003/diff/1/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/599313003/diff/1/base/memory/scoped_ptr.h#newcode336 base/memory/scoped_ptr.h:336: // IMPLEMENTATION NOTE: C++11 unique_ptr<> keeps this constructor distinct ...
6 years, 2 months ago (2014-09-25 14:50:19 UTC) #8
jamesr
This lgtm, although I'm not an owner in these parts.
6 years, 2 months ago (2014-09-25 16:14:25 UTC) #9
danakj
brettw: can you OWNERS review? I believe nico is out atm.
6 years, 2 months ago (2014-09-25 16:38:21 UTC) #10
brettw
LGTM. It makes sense, I'm hoping the others did a careful check of the gotchas ...
6 years, 2 months ago (2014-09-25 21:31:52 UTC) #11
danakj
jamesr: PTAL Here's a slightly simpler version, where I was able to remove the RValue ...
6 years, 2 months ago (2014-09-26 02:02:03 UTC) #12
danakj
+ajwong FYI cuz it'll make you happy (I hope)
6 years, 2 months ago (2014-09-26 03:19:58 UTC) #13
jamesr
I preferred patch set 2. static_cast<T&&>(..) is not exactly the same thing as std::move() and ...
6 years, 2 months ago (2014-09-26 04:43:57 UTC) #14
awong
On 2014/09/26 04:43:57, jamesr wrote: > I preferred patch set 2. static_cast<T&&>(..) is not exactly ...
6 years, 2 months ago (2014-09-26 04:51:45 UTC) #15
danakj
On 2014/09/26 04:51:45, awong wrote: > @danakj: Have you matched this up with the unique_ptr<> ...
6 years, 2 months ago (2014-09-26 13:40:46 UTC) #16
danakj
On 2014/09/26 04:43:57, jamesr wrote: > I preferred patch set 2. static_cast<T&&>(..) is not exactly ...
6 years, 2 months ago (2014-09-26 13:57:36 UTC) #17
danakj
To make Pass() exactly the same as std::move(), the test before: { ConDecLogger* logger = ...
6 years, 2 months ago (2014-09-26 14:04:18 UTC) #18
jamesr
I believe I understand patch set 2. I do not understand patch set 5. It's ...
6 years, 2 months ago (2014-09-26 20:22:45 UTC) #22
danakj
Patchset 2 and 5 are identical for users of scoped_ptr, unless they are trying to ...
6 years, 2 months ago (2014-09-26 20:57:53 UTC) #23
jamesr
On 2014/09/26 20:57:53, danakj wrote: > Patchset 2 and 5 are identical for users of ...
6 years, 2 months ago (2014-09-26 21:00:47 UTC) #24
danakj
On 2014/09/26 21:00:47, jamesr wrote: > On 2014/09/26 20:57:53, danakj wrote: > > Patchset 2 ...
6 years, 2 months ago (2014-09-26 21:03:59 UTC) #25
danakj
On 2014/09/26 21:03:59, danakj wrote: > On 2014/09/26 21:00:47, jamesr wrote: > > On 2014/09/26 ...
6 years, 2 months ago (2014-09-26 21:52:37 UTC) #26
jamesr
OK, thank you for investigating. I still prefer PS2.
6 years, 2 months ago (2014-09-26 21:54:11 UTC) #27
danakj
Since I don't think I can convince you of the value of making this more ...
6 years, 2 months ago (2014-09-26 21:55:54 UTC) #28
danakj
On 2014/09/26 21:54:11, jamesr wrote: > OK, thank you for investigating. I still prefer PS2. ...
6 years, 2 months ago (2014-09-26 21:56:19 UTC) #30
jamesr
I think there's some value, but I don't think the value outweighs the risks here. ...
6 years, 2 months ago (2014-09-26 21:58:26 UTC) #31
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/599313003/160001
6 years, 2 months ago (2014-09-26 21:58:35 UTC) #32
jamesr
Sorry unchecking, I want to make sure we understand what's happening in that test.
6 years, 2 months ago (2014-09-26 21:59:10 UTC) #34
danakj
https://codereview.chromium.org/599313003/diff/160001/base/memory/scoped_ptr_unittest.cc File base/memory/scoped_ptr_unittest.cc (left): https://codereview.chromium.org/599313003/diff/160001/base/memory/scoped_ptr_unittest.cc#oldcode409 base/memory/scoped_ptr_unittest.cc:409: EXPECT_FALSE(scoper.get()); On 2014/09/26 21:58:26, jamesr wrote: > does this ...
6 years, 2 months ago (2014-09-26 22:00:09 UTC) #35
danakj
Added back: // This differs from unique_ptr, as Pass() has side effects but std::move() // ...
6 years, 2 months ago (2014-09-26 22:01:25 UTC) #36
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/599313003/180001
6 years, 2 months ago (2014-09-26 22:03:40 UTC) #38
jamesr
https://codereview.chromium.org/599313003/diff/180001/base/memory/scoped_ptr_unittest.cc File base/memory/scoped_ptr_unittest.cc (right): https://codereview.chromium.org/599313003/diff/180001/base/memory/scoped_ptr_unittest.cc#newcode409 base/memory/scoped_ptr_unittest.cc:409: // This differs from unique_ptr, as Pass() has side ...
6 years, 2 months ago (2014-09-26 22:41:03 UTC) #39
danakj
Filed https://code.google.com/p/chromium/issues/detail?id=418297
6 years, 2 months ago (2014-09-26 22:58:20 UTC) #40
commit-bot: I haz the power
Committed patchset #7 (id:180001) as b2a8bf07aab072d48e965c65275257a241ca8354
6 years, 2 months ago (2014-09-26 23:36:26 UTC) #41
commit-bot: I haz the power
Patchset 7 (id:??) landed as https://crrev.com/2299e91d3508f8d5d18ef990cf6024ea4371250a Cr-Commit-Position: refs/heads/master@{#297072}
6 years, 2 months ago (2014-09-26 23:37:21 UTC) #42
dcheng
This is causing several test failures: https://build.chromium.org/p/chromium.memory/builders/Mac%20ASan%2064%20Tests%20(1)/builds/2337: ScopedPtrTest.ScopedPtrWithArray (run #1): [ RUN ] ScopedPtrTest.ScopedPtrWithArray ================================================================= ...
6 years, 2 months ago (2014-09-27 07:33:56 UTC) #44
dcheng
A revert of this CL (patchset #7 id:180001) has been created in https://codereview.chromium.org/603353005/ by dcheng@chromium.org. ...
6 years, 2 months ago (2014-09-27 07:34:58 UTC) #45
danakj
Thanks for the links. On Sat, Sep 27, 2014 at 3:33 AM, <dcheng@chromium.org> wrote: > ...
6 years, 2 months ago (2014-09-27 18:48:12 UTC) #46
jamesr
Hmm, looks like somehow this allowed converting between scoped_ptr<>s with different deleter types.
6 years, 2 months ago (2014-09-27 18:56:52 UTC) #47
dcheng
On 2014/09/27 at 18:56:52, jamesr wrote: > Hmm, looks like somehow this allowed converting between ...
6 years, 2 months ago (2014-09-27 19:07:14 UTC) #48
danakj
Maybe it's https://chromium.googlesource.com/chromium/src/+/ad66334103b9b9a3129e98fc9decbc0c94c9aa11 Ok well I've fixed the new-vs-new[] thing in the last patch set, ...
6 years, 2 months ago (2014-09-27 19:12:13 UTC) #49
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/599313003/200001
6 years, 2 months ago (2014-09-27 19:13:13 UTC) #51
commit-bot: I haz the power
Committed patchset #8 (id:200001) as ae3a5edbe51dceb5c33c63d9dbed8a4c87def403
6 years, 2 months ago (2014-09-27 20:22:20 UTC) #52
commit-bot: I haz the power
Patchset 8 (id:??) landed as https://crrev.com/a9527ce329c38d945e46773f1592a4939cf62b99 Cr-Commit-Position: refs/heads/master@{#297116}
6 years, 2 months ago (2014-09-27 20:22:51 UTC) #53
jamesr
https://codereview.chromium.org/599313003/diff/200001/base/memory/scoped_ptr_unittest.cc File base/memory/scoped_ptr_unittest.cc (right): https://codereview.chromium.org/599313003/diff/200001/base/memory/scoped_ptr_unittest.cc#newcode630 base/memory/scoped_ptr_unittest.cc:630: scoped_ptr<int[]> scoper2(new int[3]); oh, that would explain it! we ...
6 years, 2 months ago (2014-09-27 20:30:36 UTC) #54
eustas
6 years, 2 months ago (2014-09-29 08:15:34 UTC) #55
Message was sent while issue was closed.
A revert of this CL (patchset #8 id:200001) has been created in
https://codereview.chromium.org/604423005/ by eustas@chromium.org.

The reason for reverting is: This patch seems to break ScopedPtrWithArray ASAN
test.

https://build.chromium.org/p/chromium.memory/builders/Mac%20ASan%2064%20Tests....

Powered by Google App Engine
This is Rietveld 408576698