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

Issue 11149006: Extend scoped_ptr to be closer to unique_ptr. Support custom deleters, and deleting arrays. (Closed)

Created:
8 years, 2 months ago by awong
Modified:
8 years ago
CC:
chromium-reviews, erikwright+watch_chromium.org, gavinp+memory_chromium.org, gromer, tfarina, dhollowa, kinuko, ananta, hans, scherkus (not reviewing)
Visibility:
Public.

Description

Extend scoped_ptr to be closer to unique_ptr. Support custom deleters, and deleting arrays. This is based on the modifications by "Geoffrey Romer" <gromer@google.com>; to Google's internal version of scoped_ptr<>. All cleaver tricks are his, not mine. :) It brings most of the features of C++11's unique_ptr<> into this class and should eliminate the need for scoped_array<>, scoped_malloc_free<>, and possibly a few other scopers. Please refer to the unique_ptr<> API for documentation. Divergence from unique_ptr<>: 1) DefaultDeleter<T[n]> (sized-arrays) is explicitly disabled because this construct would cause the single-object delete to be called on a pointer to a T[n]. It is impossible to construct a single-object new expression that returns a T[n]*. You can only get this with new[] which should correspond to DefaultDeleter<T[n][]>. This issue has been raised with the C++ LWG as it is possible a unique_ptr<> spec defect. 2) Reference types for Deleters are not supported. This simplifies implementation significantly because there is no need to distinguish between the converting constructor + converting assignment operator and their move constructor + move assignment operator. 4) Move-only Deleters are not supported. Avoids the need to emulate std::forward(). BUG=109874 TBR=dhollowa,kinuko,ananta,hans,scherkus Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=174057

Patch Set 1 #

Patch Set 2 : I think this works. #

Total comments: 8

Patch Set 3 : This actually compiles and looks like it works???!? #

Patch Set 4 : Element[] added, comments cleaned. One friend issue fixed. #

Total comments: 34

Patch Set 5 : scoped_ptf<>: unfriend #

Patch Set 6 : utility -> algorithm. Mac needs it. #

Total comments: 1

Patch Set 7 : Fix forward declare. #

Patch Set 8 : fix callback #

Patch Set 9 : fix unittest #

Total comments: 2

Patch Set 10 : Custom deleter constructor #

Patch Set 11 : Add unittests #

Patch Set 12 : Style fixes. #

Patch Set 13 : proofread #

Patch Set 14 : fix friends #

Patch Set 15 : Fix unittest bug. #

Patch Set 16 : fix reset() to not call deleter on NULL ptr_. Matches unique_ptr<> spec. #

Total comments: 12

Patch Set 17 : Address jyasskin's comments #

Patch Set 18 : remove Pass() from scoped_ptr_impl and don't overuse get_deleter() #

Patch Set 19 : fix cut/paste error #

Total comments: 31

Patch Set 20 : DISALLOW_COPY_AND_ASSIGN + fix comments #

Total comments: 9

Patch Set 21 : disallow T[] conversions more explicitly. #

Patch Set 22 : merged to ToT #

Total comments: 25

Patch Set 23 : address comments #

Patch Set 24 : retry #

Total comments: 2

Patch Set 25 : Address nits. #

Patch Set 26 : fix unittest. #

Patch Set 27 : Clarify size comment. #

Total comments: 10

Patch Set 28 : phix grammer. #

Patch Set 29 : rebased #

Unified diffs Side-by-side diffs Delta from patch set Stats (+774 lines, -106 lines) Patch
M base/callback_internal.h View 1 2 3 4 5 6 7 2 chunks +6 lines, -6 lines 0 comments Download
M base/memory/scoped_ptr.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 9 chunks +380 lines, -89 lines 0 comments Download
M base/memory/scoped_ptr_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 7 chunks +325 lines, -2 lines 0 comments Download
M base/memory/scoped_ptr_unittest.nc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 chunk +53 lines, -1 line 0 comments Download
M chrome/browser/autofill/personal_data_manager.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/sync_file_system/sync_file_system_service.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 chunk +1 line, -1 line 0 comments Download
M chrome_frame/chrome_launcher_utils.h View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M content/browser/speech/speech_recognition_manager_impl.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 chunk +2 lines, -1 line 0 comments Download
M media/base/audio_bus.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +1 line, -1 line 0 comments Download
M media/base/message_loop_factory.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +3 lines, -2 lines 0 comments Download
M media/base/serial_runner.h View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 50 (0 generated)
awong
THIS IS NOT READY FOR A REAL REVIEW
8 years, 2 months ago (2012-10-13 01:05:00 UTC) #1
awong
but I wanted to send a draft to see if there are any early comments. ...
8 years, 2 months ago (2012-10-13 01:05:27 UTC) #2
Jeffrey Yasskin
I haven't gotten all the way through this. https://codereview.chromium.org/11149006/diff/2001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/2001/base/memory/scoped_ptr.h#newcode97 base/memory/scoped_ptr.h:97: #include ...
8 years, 2 months ago (2012-10-13 01:33:29 UTC) #3
awong
Comments addressed. Jeffrey, Ryan: There are a few places where I could really use feedback. ...
8 years, 2 months ago (2012-10-18 02:46:15 UTC) #4
Ryan Sleevi
Before you work too hard on getting it cleaned up - does it work on ...
8 years, 2 months ago (2012-10-18 03:17:10 UTC) #5
awong
2 quick responses before heading to bed. On Wed, Oct 17, 2012 at 8:17 PM, ...
8 years, 2 months ago (2012-10-18 03:50:21 UTC) #6
Jeffrey Yasskin
http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h#newcode176 base/memory/scoped_ptr.h:176: // "move()" function. Do I need to use SFINAE ...
8 years, 2 months ago (2012-10-18 04:14:29 UTC) #7
awong
Comments responded to. Also fixed the safe-bool idiom. After I get it compiling everywhere, I'll ...
8 years, 2 months ago (2012-10-18 18:08:02 UTC) #8
Jeffrey Yasskin
http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h#newcode296 base/memory/scoped_ptr.h:296: // TODO(ajwong): REVIEWER QUESTION: is it cleaner to use ...
8 years, 2 months ago (2012-10-18 18:33:45 UTC) #9
Ryan Sleevi
On 2012/10/18 18:33:45, Jeffrey Yasskin wrote: > http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h > File base/memory/scoped_ptr.h (right): > > http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h#newcode296 ...
8 years, 2 months ago (2012-10-18 18:39:40 UTC) #10
gromer
I'm not at all familiar with the Chromium codebase, so consider my comments advisory. http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h ...
8 years, 2 months ago (2012-10-18 20:45:20 UTC) #11
willchan no longer on Chromium
http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): http://codereview.chromium.org/11149006/diff/14002/base/memory/scoped_ptr.h#newcode404 base/memory/scoped_ptr.h:404: // - it cannot be const-qualified differently from Element. ...
8 years, 2 months ago (2012-10-18 21:28:41 UTC) #12
Jeffrey Yasskin
I defer to Geoffrey on this. He's been much closer to the unique_ptr migration than ...
8 years, 2 months ago (2012-10-18 22:23:16 UTC) #13
Jeffrey Yasskin
Oops, +gromer now. On Thu, Oct 18, 2012 at 3:22 PM, Jeffrey Yasskin <jyasskin@chromium.org> wrote: ...
8 years, 2 months ago (2012-10-18 22:25:24 UTC) #14
tfarina
http://codereview.chromium.org/11149006/diff/23004/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): http://codereview.chromium.org/11149006/diff/23004/base/memory/scoped_ptr.h#newcode281 base/memory/scoped_ptr.h:281: // Constructor. Defaults to initializing with NULL. can you ...
8 years, 1 month ago (2012-11-02 02:12:31 UTC) #15
awong
Hi Thiago, Thanks for the comments. The code is not really ready for review yet, ...
8 years, 1 month ago (2012-11-02 02:46:51 UTC) #16
awong
Finally wrote tests and scrubbed behavior (fixed some bugs too :-/) Jeffrey, Geoffrey, Ryan, do ...
8 years ago (2012-11-27 22:36:15 UTC) #17
awong
FYI, the current implementation causes a ~1% increase in text-segment size on base_unittests so the ...
8 years ago (2012-11-28 01:22:41 UTC) #18
Jeffrey Yasskin
I'm curious to hear what caused the 1% size increase. Unless it's just the extra ...
8 years ago (2012-11-28 06:07:18 UTC) #19
awong
Comments addressed. As for the size increase, I examined the assembly more. Here's some knowns: ...
8 years ago (2012-11-28 10:20:34 UTC) #20
awong
New results: 1) Using a separate default constructor versus a default NULL arg has no ...
8 years ago (2012-11-28 11:01:26 UTC) #21
awong
!@#$#@# Oh good grief. Mystery solved. I've been accidentally compiling -O0. Good call Jeffrey on ...
8 years ago (2012-11-28 11:38:00 UTC) #22
Jeffrey Yasskin
LGTM https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h#newcode176 base/memory/scoped_ptr.h:176: scoped_ptr_impl(scoped_ptr_impl<U, V>* other) Could you DISALLOW_COPY_AND_ASSIGN so there's ...
8 years ago (2012-11-28 22:06:42 UTC) #23
awong
https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h#newcode176 base/memory/scoped_ptr.h:176: scoped_ptr_impl(scoped_ptr_impl<U, V>* other) On 2012/11/28 22:06:42, Jeffrey Yasskin wrote: ...
8 years ago (2012-11-29 01:15:13 UTC) #24
Ryan Sleevi
Initial comments. I've probably missed a few things, so may go through it again once ...
8 years ago (2012-11-29 01:42:25 UTC) #25
Ryan Sleevi
https://codereview.chromium.org/11149006/diff/44004/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/44004/base/memory/scoped_ptr.h#newcode170 base/memory/scoped_ptr.h:170: class scoped_ptr_impl { Have you confirmed what the compile ...
8 years ago (2012-11-29 02:42:27 UTC) #26
gromer
https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h#newcode119 base/memory/scoped_ptr.h:119: // All default single-object deleters can trivially convert to ...
8 years ago (2012-12-04 19:41:18 UTC) #27
Ryan Sleevi
https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h#newcode119 base/memory/scoped_ptr.h:119: // All default single-object deleters can trivially convert to ...
8 years ago (2012-12-04 20:09:51 UTC) #28
gromer
https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h#newcode119 base/memory/scoped_ptr.h:119: // All default single-object deleters can trivially convert to ...
8 years ago (2012-12-04 20:39:26 UTC) #29
awong
Ready for another pass. Overall, I opted to punt on most of the issues raised ...
8 years ago (2012-12-12 02:17:02 UTC) #30
Ryan Sleevi
I'll do a proper read through when my mind is working. I just quickly skimmed ...
8 years ago (2012-12-12 03:37:46 UTC) #31
gromer
https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h#newcode119 base/memory/scoped_ptr.h:119: // All default single-object deleters can trivially convert to ...
8 years ago (2012-12-12 17:29:57 UTC) #32
awong
Comments address. sizeof() test added to unittest and running through trybots now. https://codereview.chromium.org/11149006/diff/40024/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h ...
8 years ago (2012-12-12 21:00:13 UTC) #33
gromer
https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h#newcode163 base/memory/scoped_ptr.h:163: // Never allow someone to delcare something like scoped_ptr<int[10]>. ...
8 years ago (2012-12-14 16:57:26 UTC) #34
awong
https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h#newcode163 base/memory/scoped_ptr.h:163: // Never allow someone to delcare something like scoped_ptr<int[10]>. ...
8 years ago (2012-12-14 20:25:26 UTC) #35
willchan no longer on Chromium
There are enough C++ ninjas (all who know it far better than I) reviewing this ...
8 years ago (2012-12-14 21:07:03 UTC) #36
gromer
https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h#newcode163 base/memory/scoped_ptr.h:163: // Never allow someone to delcare something like scoped_ptr<int[10]>. ...
8 years ago (2012-12-14 21:11:46 UTC) #37
awong
https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h#newcode163 base/memory/scoped_ptr.h:163: // Never allow someone to delcare something like scoped_ptr<int[10]>. ...
8 years ago (2012-12-14 21:18:39 UTC) #38
awong
Last nit addressed. Thanks for all the detailed review and comments so far. I think ...
8 years ago (2012-12-14 23:45:11 UTC) #39
awong
https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h#newcode296 base/memory/scoped_ptr.h:296: // sizeof(scoped_ptr<T>) == sizeof(T*) On 2012/12/14 21:11:46, gromer wrote: ...
8 years ago (2012-12-15 00:19:08 UTC) #40
gromer
lgtm https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/61001/base/memory/scoped_ptr.h#newcode296 base/memory/scoped_ptr.h:296: // sizeof(scoped_ptr<T>) == sizeof(T*) On 2012/12/15 00:19:08, awong ...
8 years ago (2012-12-15 00:21:40 UTC) #41
Ryan Sleevi
LGTM! https://codereview.chromium.org/11149006/diff/76002/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/76002/base/memory/scoped_ptr.h#newcode120 base/memory/scoped_ptr.h:120: // U* is implicitly convertible to T* and ...
8 years ago (2012-12-15 02:24:12 UTC) #42
awong
https://codereview.chromium.org/11149006/diff/76002/base/memory/scoped_ptr.h File base/memory/scoped_ptr.h (right): https://codereview.chromium.org/11149006/diff/76002/base/memory/scoped_ptr.h#newcode120 base/memory/scoped_ptr.h:120: // U* is implicitly convertible to T* and U ...
8 years ago (2012-12-15 02:32:26 UTC) #43
awong
willchan: Wanna do the OWNERS honors? I'll submit after M25 branch cut. On 2012/12/15 02:32:26, ...
8 years ago (2012-12-18 19:59:37 UTC) #44
willchan no longer on Chromium
Please make sure that the changelist description is up to date with everything y'all discussed. ...
8 years ago (2012-12-18 23:01:35 UTC) #45
awong
Updated description with a list of known deficiencies.
8 years ago (2012-12-19 00:03:36 UTC) #46
awong
On 2012/12/19 00:03:36, awong wrote: > Updated description with a list of known deficiencies. TBR ...
8 years ago (2012-12-19 20:56:57 UTC) #47
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/ajwong@chromium.org/11149006/85001
8 years ago (2012-12-19 20:58:26 UTC) #48
commit-bot: I haz the power
Step "update" is always a major failure. Look at the try server FAQ for more ...
8 years ago (2012-12-19 21:01:11 UTC) #49
commit-bot: I haz the power
8 years ago (2012-12-19 21:08:15 UTC) #50

Powered by Google App Engine
This is Rietveld 408576698