Changeset 25813 in webkit


Ignore:
Timestamp:
Sep 30, 2007 6:54:09 PM (17 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • tone down the assertion I asked Harrison to include in his fix for <rdar://problem/5511128>; it's OK to re-ref and deref the document as long as you do so after the children are done being destroyed

No effect on release builds. Assertion change only.

Besides the changes listed below, renamed m_hasDeleted flag to
m_deletionHasBegun.

  • dom/ContainerNode.cpp: (WebCore::ContainerNode::removeAllChildren): Added code to set the m_deletionHasBegun flag and some assertions that test its state.
  • dom/Document.h: Removed m_hasDeleted -- we now use m_deletionHasBegun in the base class TreeShared.
  • dom/Document.cpp: (WebCore::Document::Document): Removed initialization of m_hasDeleted. (WebCore::Document::removedLastRef): Added code to clear m_inRemovedLastRefFunction if we end up deciding not to delete this.
  • platform/Shared.h: (WebCore::TreeShared::TreeShared): Added m_deletionHasBegun in addition to m_inRemovedLastRefFunction (formerly named m_hasRemovedLastRef). (WebCore::TreeShared::~TreeShared): Assert that m_deletionHasBegun is true. (WebCore::TreeShared::ref): Assert neither flag is true. (WebCore::TreeShared::deref): Ditto. (WebCore::TreeShared::hasOneRef): Ditto. (WebCore::TreeShared::removedLastRef): Made private. Added code to set m_hasDeleted to true. Also removed cast; since this class template has a virtual destructor, we don't need to cast before calling delete.
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r25808 r25813  
     12007-09-30  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Maciej.
     4
     5        - tone down the assertion I asked Harrison to include in his fix for
     6          <rdar://problem/5511128>; it's OK to re-ref and deref the document
     7          as long as you do so after the children are done being destroyed
     8
     9        No effect on release builds. Assertion change only.
     10
     11        Besides the changes listed below, renamed m_hasDeleted flag to
     12        m_deletionHasBegun.
     13
     14        * dom/ContainerNode.cpp: (WebCore::ContainerNode::removeAllChildren):
     15        Added code to set the m_deletionHasBegun flag and some assertions
     16        that test its state.
     17
     18        * dom/Document.h: Removed m_hasDeleted -- we now use m_deletionHasBegun
     19        in the base class TreeShared.
     20        * dom/Document.cpp:
     21        (WebCore::Document::Document): Removed initialization of m_hasDeleted.
     22        (WebCore::Document::removedLastRef): Added code to clear
     23        m_inRemovedLastRefFunction if we end up deciding not to delete this.
     24
     25        * platform/Shared.h:
     26        (WebCore::TreeShared::TreeShared): Added m_deletionHasBegun in addition to
     27        m_inRemovedLastRefFunction (formerly named m_hasRemovedLastRef).
     28        (WebCore::TreeShared::~TreeShared): Assert that m_deletionHasBegun is true.
     29        (WebCore::TreeShared::ref): Assert neither flag is true.
     30        (WebCore::TreeShared::deref): Ditto.
     31        (WebCore::TreeShared::hasOneRef): Ditto.
     32        (WebCore::TreeShared::removedLastRef): Made private. Added code to
     33        set m_hasDeleted to true. Also removed cast; since this class template
     34        has a virtual destructor, we don't need to cast before calling delete.
     35
    1362007-09-29  Holger Hans Peter Freyther  <zecke@selfish.org>
    237
     
    96131
    97132        - <rdar://5261371> Nothing downloaded when exporting bookmarks from iGoogle web history
    98         - Implemented IWebHTTPURLResponse::allHeaderFields so that if the content disposition is "attachment" we will download the file instead of display it. Also implemented some missing functionality.
     133
     134        Function for use by WebKit. Currently used only on Windows.
    99135
    100136        * platform/network/ResourceResponse.cpp:
  • trunk/WebCore/dom/ContainerNode.cpp

    r25797 r25813  
    6363    if (topLevel)
    6464        alreadyInsideDestructor = true;
    65    
     65
    6666    // List of nodes to be deleted.
    67     static Node *head;
    68     static Node *tail;
    69    
     67    static Node* head;
     68    static Node* tail;
     69
    7070    // We have to tell all children that their parent has died.
    71     Node *n;
    72     Node *next;
    73 
    74     for (n = m_firstChild; n != 0; n = next ) {
     71    Node* n;
     72    Node* next;
     73    for (n = m_firstChild; n != 0; n = next) {
     74        ASSERT(!n->m_deletionHasBegun);
     75
    7576        next = n->nextSibling();
    7677        n->setPreviousSibling(0);
     
    7879        n->setParent(0);
    7980       
    80         if ( !n->refCount() ) {
     81        if (!n->refCount()) {
     82#ifndef NDEBUG
     83            n->m_deletionHasBegun = true;
     84#endif
    8185            // Add the node to the list of nodes to be deleted.
    8286            // Reuse the nextSibling pointer for this purpose.
     
    8993            n->removedFromDocument();
    9094    }
    91    
     95
    9296    // Only for the top level call, do the actual deleting.
    9397    if (topLevel) {
    9498        while ((n = head) != 0) {
     99            ASSERT(n->m_deletionHasBegun);
     100
    95101            next = n->nextSibling();
    96102            n->setNextSibling(0);
     
    99105            if (next == 0)
    100106                tail = 0;
    101            
     107
    102108            delete n;
    103109        }
    104        
     110
    105111        alreadyInsideDestructor = false;
    106112        m_firstChild = 0;
  • trunk/WebCore/dom/Document.cpp

    r25797 r25813  
    268268    , m_designMode(inherit)
    269269    , m_selfOnlyRefCount(0)
    270 #ifndef NDEBUG
    271     , m_hasDeleted(false)
    272 #endif
    273270#if ENABLE(SVG)
    274271    , m_svgExtensions(0)
     
    345342void Document::removedLastRef()
    346343{
    347     ASSERT(!m_hasDeleted);
     344    ASSERT(!m_deletionHasBegun);
    348345    if (m_selfOnlyRefCount) {
    349         // if removing a child removes the last self-only ref, we don't
     346        // If removing a child removes the last self-only ref, we don't
    350347        // want the document to be destructed until after
    351348        // removeAllChildren returns, so we guard ourselves with an
    352         // extra self-only ref
     349        // extra self-only ref.
    353350
    354351        DocPtr<Document> guard(this);
    355352
    356         // we must make sure not to be retaining any of our children through
    357         // these extra pointers or we will create a reference cycle
     353        // We must make sure not to be retaining any of our children through
     354        // these extra pointers or we will create a reference cycle.
    358355        m_docType = 0;
    359356        m_focusedNode = 0;
     
    370367        delete m_tokenizer;
    371368        m_tokenizer = 0;
     369
     370#ifndef NDEBUG
     371        m_inRemovedLastRefFunction = false;
     372#endif
    372373    } else {
    373374#ifndef NDEBUG
    374         m_hasDeleted = true;
     375        m_deletionHasBegun = true;
    375376#endif
    376377        delete this;
  • trunk/WebCore/dom/Document.h

    r25797 r25813  
    150150    void selfOnlyRef()
    151151    {
    152         ASSERT(!m_hasDeleted);
     152        ASSERT(!m_deletionHasBegun);
    153153        ++m_selfOnlyRefCount;
    154154    }
    155155    void selfOnlyDeref()
    156156    {
    157         ASSERT(!m_hasDeleted);
     157        ASSERT(!m_deletionHasBegun);
    158158        --m_selfOnlyRefCount;
    159159        if (!m_selfOnlyRefCount && !refCount()) {
    160160#ifndef NDEBUG
    161             m_hasDeleted = true;
     161            m_deletionHasBegun = true;
    162162#endif
    163163            delete this;
     
    883883   
    884884    int m_selfOnlyRefCount;
    885 #ifndef NDEBUG
    886     bool m_hasDeleted;
    887 #endif
    888885
    889886    HTMLFormElement::CheckedRadioButtons m_checkedRadioButtons;
  • trunk/WebCore/platform/Shared.h

    r25797 r25813  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    3232        : m_refCount(0)
    3333#ifndef NDEBUG
    34         , m_hasDeleted(false)
     34        , m_deletionHasBegun(false)
    3535#endif
    3636    {
     
    3939    void ref()
    4040    {
    41         ASSERT(!m_hasDeleted);
     41        ASSERT(!m_deletionHasBegun);
    4242        ++m_refCount;
    4343    }
     
    4545    void deref()
    4646    {
    47         ASSERT(!m_hasDeleted);
     47        ASSERT(!m_deletionHasBegun);
    4848        if (--m_refCount <= 0) {
    4949#ifndef NDEBUG
    50             m_hasDeleted = true;
     50            m_deletionHasBegun = true;
    5151#endif
    5252            delete static_cast<T*>(this);
     
    5656    bool hasOneRef()
    5757    {
    58         ASSERT(!m_hasDeleted);
     58        ASSERT(!m_deletionHasBegun);
    5959        return m_refCount == 1;
    6060    }
     
    6868    int m_refCount;
    6969#ifndef NDEBUG
    70     bool m_hasDeleted;
     70    bool m_deletionHasBegun;
    7171#endif
    7272};
     
    7777        : m_refCount(0)
    7878        , m_parent(0)
     79    {
    7980#ifndef NDEBUG
    80         , m_hasRemovedLastRef(false)
     81        m_deletionHasBegun = false;
     82        m_inRemovedLastRefFunction = false;
    8183#endif
    82     {
    8384    }
    8485    TreeShared(T* parent)
    8586        : m_refCount(0)
    86         , m_parent(parent)
     87        , m_parent(0)
     88    {
    8789#ifndef NDEBUG
    88         , m_hasRemovedLastRef(false)
     90        m_deletionHasBegun = false;
     91        m_inRemovedLastRefFunction = false;
    8992#endif
     93    }
     94    virtual ~TreeShared()
    9095    {
     96        ASSERT(m_deletionHasBegun);
    9197    }
    92     virtual ~TreeShared() { }
    93 
    94     virtual void removedLastRef() { delete static_cast<T*>(this); }
    9598
    9699    void ref()
    97100    {
    98         ASSERT(!m_hasRemovedLastRef);
     101        ASSERT(!m_deletionHasBegun);
     102        ASSERT(!m_inRemovedLastRefFunction);
    99103        ++m_refCount;
    100104    }
     
    102106    void deref()
    103107    {
    104         ASSERT(!m_hasRemovedLastRef);
     108        ASSERT(!m_deletionHasBegun);
     109        ASSERT(!m_inRemovedLastRefFunction);
    105110        if (--m_refCount <= 0 && !m_parent) {
    106111#ifndef NDEBUG
    107             m_hasRemovedLastRef = true;
     112            m_inRemovedLastRefFunction = true;
    108113#endif
    109114            removedLastRef();
     
    113118    bool hasOneRef() const
    114119    {
    115         ASSERT(!m_hasRemovedLastRef);
     120        ASSERT(!m_deletionHasBegun);
     121        ASSERT(!m_inRemovedLastRefFunction);
    116122        return m_refCount == 1;
    117123    }
     
    125131    T* parent() const { return m_parent; }
    126132
     133#ifndef NDEBUG
     134    bool m_deletionHasBegun;
     135    bool m_inRemovedLastRefFunction;
     136#endif
     137
    127138private:
     139    virtual void removedLastRef()
     140    {
     141#ifndef NDEBUG
     142        m_deletionHasBegun = true;
     143#endif
     144        delete this;
     145    }
     146
    128147    int m_refCount;
    129148    T* m_parent;
    130 #ifndef NDEBUG
    131     bool m_hasRemovedLastRef;
    132 #endif
    133149};
    134150
Note: See TracChangeset for help on using the changeset viewer.