pass_scoped_ptr [Was: [chromium-dev] scoped_ptr<>::reset]

23 views
Skip to first unread message

Darin Fisher

unread,
Nov 12, 2012, 6:27:20 PM11/12/12
to ael...@google.com, Chromium-dev
[Fixing subject to reflect forking of thread.]

Are you familiar with the .Pass() method?  How is that deficient?  It seems superior to PassOwnPtr since it is clearer when you are giving up the pointer and "nulling out" the container.

-Darin


On Mon, Nov 12, 2012 at 3:22 PM, Alexandre Elias <ael...@google.com> wrote:
While we're on the topic of scoped_ptr improvements, is there interest in introducing a pass_scoped_ptr type?  As it stands, it's dangerous to pass around scoped_ptrs as parameters due to the problem described in http://www.webkit.org/coding/RefPtr.html (section "PassRefPtr").  I ran into a subtle bug caused by this just last week.

--
Alex

--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Alexandre Elias

unread,
Nov 12, 2012, 6:34:37 PM11/12/12
to Darin Fisher, Chromium-dev
Here's the buggy code I wrote while using .Pass() for the first time:

bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSettings, scoped_ptr<Thread> implThread)
 {
    ...
    m_layerTreeHost = LayerTreeHost::create(this, settings, implThread.Pass());
    if (implThread)
      m_hasImplThread = true;
    ...
}

The initialization call chain was originally passing around raw Thread*.  It broke after I changed it to use scoped_ptr without looking carefully for other nearby uses.


--
Alex

Peter Kasting

unread,
Nov 12, 2012, 6:36:21 PM11/12/12
to ael...@google.com, Darin Fisher, Chromium-dev
On Mon, Nov 12, 2012 at 3:34 PM, Alexandre Elias <ael...@google.com> wrote:
Here's the buggy code I wrote while using .Pass() for the first time:

bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSettings, scoped_ptr<Thread> implThread)
 {
    ...
    m_layerTreeHost = LayerTreeHost::create(this, settings, implThread.Pass());
    if (implThread)
      m_hasImplThread = true;
    ...
}

And how would pass_scoped_ptr save you?

PK 

Alexandre Elias

unread,
Nov 12, 2012, 6:40:55 PM11/12/12
to Peter Kasting, Darin Fisher, Chromium-dev
You're right, PassOwnPtrs have the same problem.  I assumed they were doing some fancy trick to maintain the lifetime but it looks like there's no benefit in the OwnPtr case, after all.

--
Alex
Reply all
Reply to author
Forward
0 new messages