Changeset 11684 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Dec 20, 2005, 12:12:50 PM (19 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Darin.

  • fixed a leak in the assignment operator from PassRefPtr to RefPtr
  • kxmlcore/RefPtr.h: (KXMLCore::RefPtr::operator=):
  • fix problem with PassRefPtr that darin spotted - it lacked a copy constructor and therefore was using the default one, which can lead to excess derefs

I fixed this by adding a copy constructor from non-const
reference, and by adding a template pass() function that you have
to use when raw pointer or RefPtr are passed where PassRefPtr is
expected.

  • kjs/identifier.cpp: (KJS::Identifier::add): Changed to have PassRefPtr return type and pass() the results.
  • kjs/identifier.h:
  • kjs/property_map.cpp: (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): Use pass() where required.
  • kjs/ustring.cpp: (KJS::UString::UString): Use pass() as needed. (KJS::UString::append): ditto (KJS::UString::substr): ditto
  • kjs/ustring.h: (KJS::UString::UString): Use initializer instead of assignment
  • kxmlcore/PassRefPtr.h: (KXMLCore::PassRefPtr::PassRefPtr): Added copy constructor (KXMLCore::pass): new template function to make it convenient to pass a PassRefPtr

WebCore:

Reviewed by Darin.

  • change an assignment to a contructor declaration to build with PassRefPtr leak fix changes
  • ksvg2/svg/SVGTransformableImpl.cpp: (SVGTransformableImpl::parseTransformAttribute):
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r11682 r11684  
     12005-12-19  Maciej Stachowiak  <[email protected]>
     2
     3        Reviewed by Darin.
     4
     5        - fixed a leak in the assignment operator from PassRefPtr to RefPtr
     6
     7        * kxmlcore/RefPtr.h:
     8        (KXMLCore::RefPtr::operator=):
     9
     10        - fix problem with PassRefPtr that darin spotted - it lacked a copy constructor
     11        and therefore was using the default one, which can lead to excess derefs
     12
     13        I fixed this by adding a copy constructor from non-const
     14        reference, and by adding a template pass() function that you have
     15        to use when raw pointer or RefPtr are passed where PassRefPtr is
     16        expected.
     17
     18        * kjs/identifier.cpp:
     19        (KJS::Identifier::add): Changed to have PassRefPtr return type and
     20        pass() the results.     
     21        * kjs/identifier.h:
     22        * kjs/property_map.cpp:
     23        (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): Use pass()
     24        where required.
     25        * kjs/ustring.cpp:
     26        (KJS::UString::UString): Use pass() as needed.
     27        (KJS::UString::append): ditto
     28        (KJS::UString::substr): ditto
     29        * kjs/ustring.h:
     30        (KJS::UString::UString): Use initializer instead of assignment
     31        * kxmlcore/PassRefPtr.h:
     32        (KXMLCore::PassRefPtr::PassRefPtr): Added copy constructor
     33        (KXMLCore::pass): new template function to make it convenient to pass
     34        a PassRefPtr
     35
    1362005-12-19  Geoffrey Garen  <[email protected]>
    237 
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r11661 r11684  
    124124}
    125125
    126 UString::Rep *Identifier::add(const char *c)
     126PassRefPtr<UString::Rep> Identifier::add(const char *c)
    127127{
    128128    if (!c)
    129         return &UString::Rep::null;
     129        return pass(&UString::Rep::null);
    130130    int length = strlen(c);
    131131    if (length == 0)
    132         return &UString::Rep::empty;
     132        return pass(&UString::Rep::empty);
    133133   
    134     return *identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first;
     134    return pass(*identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first);
    135135}
    136136
     
    164164}
    165165
    166 UString::Rep *Identifier::add(const UChar *s, int length)
     166PassRefPtr<UString::Rep> Identifier::add(const UChar *s, int length)
    167167{
    168168    if (length == 0)
    169         return &UString::Rep::empty;
     169        return pass(&UString::Rep::empty);
    170170   
    171171    UCharBuffer buf = {s, length};
    172     return *identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first;
    173 }
    174 
    175 UString::Rep *Identifier::add(UString::Rep *r)
     172    return pass(*identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first);
     173}
     174
     175PassRefPtr<UString::Rep> Identifier::add(UString::Rep *r)
    176176{
    177177    if (r->isIdentifier)
    178         return r;
     178        return pass(r);
    179179
    180180    if (r->len == 0)
    181         return &UString::Rep::empty;
     181        return pass(&UString::Rep::empty);
    182182
    183183    UString::Rep *result = *identifierTable().insert(r).first;
    184184    if (result == r)
    185185        r->isIdentifier = true;
    186     return result;
     186    return pass(result);
    187187}
    188188
  • trunk/JavaScriptCore/kjs/identifier.h

    r11661 r11684  
    7878            { return equal(a._ustring.rep(), b); }
    7979       
    80         static UString::Rep *add(const char *);
    81         static UString::Rep *add(const UChar *, int length);
    82         static UString::Rep *add(UString::Rep *);
     80        static PassRefPtr<UString::Rep> add(const char *);
     81        static PassRefPtr<UString::Rep> add(const UChar *, int length);
     82        static PassRefPtr<UString::Rep> add(UString::Rep *);
    8383    };
    8484   
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r11527 r11684  
    615615        UString::Rep *key = _singleEntry.key;
    616616        if (key) {
    617             UString k(key);
     617            UString k(pass(key));
    618618            bool fitsInUInt32;
    619619            k.toUInt32(&fitsInUInt32);
    620620            if (fitsInUInt32)
    621                 list.append(Reference(base, Identifier(key)));
     621                list.append(Reference(base, Identifier(pass(key))));
    622622        }
    623623#endif
     
    630630        UString::Rep *key = entries[i].key;
    631631        if (key && key != &UString::Rep::null) {
    632             UString k(key);
     632            UString k(pass(key));
    633633            bool fitsInUInt32;
    634634            k.toUInt32(&fitsInUInt32);
    635635            if (fitsInUInt32)
    636                 list.append(Reference(base, Identifier(key)));
     636                list.append(Reference(base, Identifier(pass(key))));
    637637        }
    638638    }
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r11638 r11684  
    200200  r->usedPreCapacity = 0;
    201201  r->preCapacity = 0;
     202
    202203  // steal the single reference this Rep was created with
    203204  return PassRefPtr<Rep>::adopt(r);
     
    229230  r->usedPreCapacity = 0;
    230231  r->preCapacity = 0;
     232
    231233  // steal the single reference this Rep was created with
    232234  return PassRefPtr<Rep>::adopt(r);
     
    458460    x.expandCapacity(aOffset + length);
    459461    memcpy(const_cast<UChar *>(a.data() + aSize), b.data(), bSize * sizeof(UChar));
    460     m_rep = Rep::create(a.m_rep, 0, length);
     462    m_rep = Rep::create(pass(a.m_rep), 0, length);
    461463  } else if (-bOffset == b.usedPreCapacity() && 4 * bSize >= aSize) {
    462464    // - b reaches the beginning of its buffer so it qualifies for shared prepend
     
    466468    y.expandPreCapacity(-bOffset + aSize);
    467469    memcpy(const_cast<UChar *>(b.data() - aSize), a.data(), aSize * sizeof(UChar));
    468     m_rep = Rep::create(b.m_rep, -aSize, length);
     470    m_rep = Rep::create(pass(b.m_rep), -aSize, length);
    469471  } else {
    470472    // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string
     
    684686    expandCapacity(thisOffset + length);
    685687    memcpy(const_cast<UChar *>(data() + thisSize), t.data(), tSize * sizeof(UChar));
    686     m_rep = Rep::create(m_rep, 0, length);
     688    m_rep = Rep::create(pass(m_rep), 0, length);
    687689  } else {
    688690    // this is shared with someone using more capacity, gotta make a whole new string
     
    725727    for (int i = 0; i < tSize; ++i)
    726728      d[thisSize+i] = t[i];
    727     m_rep = Rep::create(m_rep, 0, length);
     729    m_rep = Rep::create(pass(m_rep), 0, length);
    728730  } else {
    729731    // this is shared with someone using more capacity, gotta make a whole new string
     
    765767    UChar *d = const_cast<UChar *>(data());
    766768    d[length] = c;
    767     m_rep = Rep::create(m_rep, 0, length + 1);
     769    m_rep = Rep::create(pass(m_rep), 0, length + 1);
    768770  } else {
    769771    // this is shared with someone using more capacity, gotta make a whole new string
     
    11211123    return *this;
    11221124
    1123   return UString(Rep::create(m_rep, pos, len));
     1125  return UString(Rep::create(pass(m_rep), pos, len));
    11241126}
    11251127
  • trunk/JavaScriptCore/kxmlcore/PassRefPtr.h

    r11670 r11684  
    4545        PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
    4646        PassRefPtr(const RefPtr<T>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
     47        PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {}
    4748
    4849        ~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); }
     
    8485            return *this;
    8586        }
    86      
     87
    8788        template<typename U>
    8889        operator PassRefPtr_Ref<U>()
     
    191192    }
    192193
     194    template <typename T> inline PassRefPtr<T> pass(T *ptr)
     195    {
     196        return PassRefPtr<T>(ptr);
     197    }
     198
     199    template <typename T> inline PassRefPtr<T> pass(const RefPtr<T>& ptr)
     200    {
     201        return PassRefPtr<T>(ptr);
     202    }
     203
    193204} // namespace KXMLCore
    194205
     
    196207using KXMLCore::static_pointer_cast;
    197208using KXMLCore::const_pointer_cast;
     209using KXMLCore::pass;
    198210
    199211#endif // KXMLCORE_PASS_REF_PTR_H
  • trunk/JavaScriptCore/kxmlcore/RefPtr.h

    r11670 r11684  
    9191    template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)
    9292    {
    93         T *optr = o.release();
    94         if (optr)
    95             optr->ref();
    9693        if (T *ptr = m_ptr)
    9794            ptr->deref();
    98         m_ptr = optr;
     95        m_ptr = o.release();
    9996        return *this;
    10097    }
Note: See TracChangeset for help on using the changeset viewer.