diff options
author | Leon Clarke <leonclarke@google.com> | 2010-07-15 12:03:35 +0100 |
---|---|---|
committer | Leon Clarke <leonclarke@google.com> | 2010-07-20 16:57:23 +0100 |
commit | e458d70a0d18538346f41b503114c9ebe6b2ce12 (patch) | |
tree | 86f1637deca2c524432a822e5fcedd4bef221091 /JavaScriptCore/wtf | |
parent | f43eabc081f7ce6af24b9df4953498a3cd6ca24d (diff) | |
download | external_webkit-e458d70a0d18538346f41b503114c9ebe6b2ce12.zip external_webkit-e458d70a0d18538346f41b503114c9ebe6b2ce12.tar.gz external_webkit-e458d70a0d18538346f41b503114c9ebe6b2ce12.tar.bz2 |
Merge WebKit at r63173 : Initial merge by git.
Change-Id: Ife5af0c7c6261fbbc8ae6bc08c390efa9ef10b44
Diffstat (limited to 'JavaScriptCore/wtf')
-rw-r--r-- | JavaScriptCore/wtf/CrossThreadRefCounted.h | 11 | ||||
-rw-r--r-- | JavaScriptCore/wtf/MessageQueue.h | 6 | ||||
-rw-r--r-- | JavaScriptCore/wtf/OwnArrayPtr.h | 25 | ||||
-rw-r--r-- | JavaScriptCore/wtf/OwnPtr.h | 99 | ||||
-rw-r--r-- | JavaScriptCore/wtf/PassOwnPtr.h | 107 | ||||
-rw-r--r-- | JavaScriptCore/wtf/PassRefPtr.h | 27 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Platform.h | 26 | ||||
-rw-r--r-- | JavaScriptCore/wtf/RefCounted.h | 22 | ||||
-rw-r--r-- | JavaScriptCore/wtf/RefPtr.h | 11 | ||||
-rw-r--r-- | JavaScriptCore/wtf/RetainPtr.h | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/SizeLimits.cpp | 3 | ||||
-rw-r--r-- | JavaScriptCore/wtf/StringExtras.h | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/TCSystemAlloc.cpp | 1 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Vector.h | 13 | ||||
-rw-r--r-- | JavaScriptCore/wtf/gobject/GOwnPtr.h | 3 | ||||
-rw-r--r-- | JavaScriptCore/wtf/gobject/GRefPtr.h | 5 | ||||
-rw-r--r-- | JavaScriptCore/wtf/text/WTFString.cpp | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/unicode/icu/CollatorICU.cpp | 11 |
18 files changed, 265 insertions, 113 deletions
diff --git a/JavaScriptCore/wtf/CrossThreadRefCounted.h b/JavaScriptCore/wtf/CrossThreadRefCounted.h index f682f0d..0c0e997 100644 --- a/JavaScriptCore/wtf/CrossThreadRefCounted.h +++ b/JavaScriptCore/wtf/CrossThreadRefCounted.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -31,10 +32,9 @@ #ifndef CrossThreadRefCounted_h #define CrossThreadRefCounted_h -#include <wtf/Noncopyable.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> -#include <wtf/Threading.h> +#include "PassRefPtr.h" +#include "RefCounted.h" +#include "Threading.h" namespace WTF { @@ -78,6 +78,9 @@ namespace WTF { , m_threadId(0) #endif { + // We use RefCountedBase in an unusual way here, so get rid of the requirement + // that adoptRef be called on it. + m_refCounter.relaxAdoptionRequirement(); } ~CrossThreadRefCounted() diff --git a/JavaScriptCore/wtf/MessageQueue.h b/JavaScriptCore/wtf/MessageQueue.h index 13ce1e8..14100c9 100644 --- a/JavaScriptCore/wtf/MessageQueue.h +++ b/JavaScriptCore/wtf/MessageQueue.h @@ -92,7 +92,7 @@ namespace WTF { inline void MessageQueue<DataType>::append(PassOwnPtr<DataType> message) { MutexLocker lock(m_mutex); - m_queue.append(message.release()); + m_queue.append(message.leakPtr()); m_condition.signal(); } @@ -102,7 +102,7 @@ namespace WTF { { MutexLocker lock(m_mutex); bool wasEmpty = m_queue.isEmpty(); - m_queue.append(message.release()); + m_queue.append(message.leakPtr()); m_condition.signal(); return wasEmpty; } @@ -111,7 +111,7 @@ namespace WTF { inline void MessageQueue<DataType>::prepend(PassOwnPtr<DataType> message) { MutexLocker lock(m_mutex); - m_queue.prepend(message.release()); + m_queue.prepend(message.leakPtr()); m_condition.signal(); } diff --git a/JavaScriptCore/wtf/OwnArrayPtr.h b/JavaScriptCore/wtf/OwnArrayPtr.h index b06e640..d40ea17 100644 --- a/JavaScriptCore/wtf/OwnArrayPtr.h +++ b/JavaScriptCore/wtf/OwnArrayPtr.h @@ -30,20 +30,21 @@ namespace WTF { template <typename T> class OwnArrayPtr : public Noncopyable { public: explicit OwnArrayPtr(T* ptr = 0) : m_ptr(ptr) { } - ~OwnArrayPtr() { safeDelete(); } + ~OwnArrayPtr() { safeDelete(m_ptr); } T* get() const { return m_ptr; } T* release() { T* ptr = m_ptr; m_ptr = 0; return ptr; } - // FIXME: This should be renamed to adopt. + // FIXME: This should be removed and replaced with PassOwnArrayPtr. void set(T* ptr) { ASSERT(!ptr || m_ptr != ptr); - safeDelete(); + T* oldPtr = m_ptr; m_ptr = ptr; + safeDelete(oldPtr); } - void clear() { safeDelete(); m_ptr = 0; } + void clear(); T& operator*() const { ASSERT(m_ptr); return *m_ptr; } T* operator->() const { ASSERT(m_ptr); return m_ptr; } @@ -63,11 +64,25 @@ namespace WTF { void swap(OwnArrayPtr& o) { std::swap(m_ptr, o.m_ptr); } private: - void safeDelete() { typedef char known[sizeof(T) ? 1 : -1]; if (sizeof(known)) delete [] m_ptr; } + static void safeDelete(T*); T* m_ptr; }; + template<typename T> inline void OwnArrayPtr<T>::clear() + { + T* ptr = m_ptr; + m_ptr = 0; + safeDelete(ptr); + } + + template<typename T> inline void OwnArrayPtr<T>::safeDelete(T* ptr) + { + typedef char known[sizeof(T) ? 1 : -1]; + if (sizeof(known)) + delete [] ptr; + } + template <typename T> inline void swap(OwnArrayPtr<T>& a, OwnArrayPtr<T>& b) { a.swap(b); } template <typename T> inline T* getPtr(const OwnArrayPtr<T>& p) diff --git a/JavaScriptCore/wtf/OwnPtr.h b/JavaScriptCore/wtf/OwnPtr.h index af1684b..cadfad2 100644 --- a/JavaScriptCore/wtf/OwnPtr.h +++ b/JavaScriptCore/wtf/OwnPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,36 +28,39 @@ #include <algorithm> #include <memory> +// Remove this once we make all WebKit code compatible with stricter rules about OwnPtr. +#define LOOSE_OWN_PTR + namespace WTF { // Unlike most of our smart pointers, OwnPtr can take either the pointer type or the pointed-to type. - template <typename T> class PassOwnPtr; + template<typename T> class PassOwnPtr; + template<typename T> PassOwnPtr<T> adoptPtr(T*); - template <typename T> class OwnPtr : public Noncopyable { + template<typename T> class OwnPtr : public Noncopyable { public: typedef typename RemovePointer<T>::Type ValueType; typedef ValueType* PtrType; - explicit OwnPtr(PtrType ptr = 0) : m_ptr(ptr) { } + OwnPtr() : m_ptr(0) { } + // See comment in PassOwnPtr.h for why this takes a const reference. - template <typename U> OwnPtr(const PassOwnPtr<U>& o); + template<typename U> OwnPtr(const PassOwnPtr<U>& o); // This copy constructor is used implicitly by gcc when it generates // transients for assigning a PassOwnPtr<T> object to a stack-allocated - // OwnPtr<T> object. It should never be called explicitly and gcc + // OwnPtr<T> object. It should never be called explicitly and gcc // should optimize away the constructor when generating code. - OwnPtr(const OwnPtr<ValueType>& o); + OwnPtr(const OwnPtr<ValueType>&); ~OwnPtr() { deleteOwnedPtr(m_ptr); } PtrType get() const { return m_ptr; } - PtrType release() { PtrType ptr = m_ptr; m_ptr = 0; return ptr; } - - // FIXME: This should be renamed to adopt. - void set(PtrType ptr) { ASSERT(!ptr || m_ptr != ptr); deleteOwnedPtr(m_ptr); m_ptr = ptr; } - void clear() { deleteOwnedPtr(m_ptr); m_ptr = 0; } + void clear(); + PassOwnPtr<T> release(); + PtrType leakPtr() WARN_UNUSED_RETURN; ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; } PtrType operator->() const { ASSERT(m_ptr); return m_ptr; } @@ -69,65 +72,99 @@ namespace WTF { operator UnspecifiedBoolType() const { return m_ptr ? &OwnPtr::m_ptr : 0; } OwnPtr& operator=(const PassOwnPtr<T>&); - template <typename U> OwnPtr& operator=(const PassOwnPtr<U>&); + template<typename U> OwnPtr& operator=(const PassOwnPtr<U>&); void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); } +#ifdef LOOSE_OWN_PTR + explicit OwnPtr(PtrType ptr) : m_ptr(ptr) { } + void set(PtrType); +#endif + private: PtrType m_ptr; }; - template <typename T> template <typename U> inline OwnPtr<T>::OwnPtr(const PassOwnPtr<U>& o) - : m_ptr(o.release()) + template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const PassOwnPtr<U>& o) + : m_ptr(o.leakPtr()) { } - template <typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr<T>& o) + template<typename T> inline void OwnPtr<T>::clear() + { + PtrType ptr = m_ptr; + m_ptr = 0; + deleteOwnedPtr(ptr); + } + + template<typename T> inline PassOwnPtr<T> OwnPtr<T>::release() + { + PtrType ptr = m_ptr; + m_ptr = 0; + return adoptPtr(ptr); + } + + template<typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() + { + PtrType ptr = m_ptr; + m_ptr = 0; + return ptr; + } + +#ifdef LOOSE_OWN_PTR + template<typename T> inline void OwnPtr<T>::set(PtrType ptr) + { + ASSERT(!ptr || m_ptr != ptr); + PtrType oldPtr = m_ptr; + m_ptr = ptr; + deleteOwnedPtr(oldPtr); + } +#endif + + template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr<T>& o) { - T* ptr = m_ptr; - m_ptr = o.release(); + PtrType ptr = m_ptr; + m_ptr = o.leakPtr(); ASSERT(!ptr || m_ptr != ptr); - if (ptr) - deleteOwnedPtr(ptr); + deleteOwnedPtr(ptr); return *this; } - template <typename T> template <typename U> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr<U>& o) + template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr<U>& o) { - T* ptr = m_ptr; - m_ptr = o.release(); + PtrType ptr = m_ptr; + m_ptr = o.leakPtr(); ASSERT(!ptr || m_ptr != ptr); - if (ptr) - deleteOwnedPtr(ptr); + deleteOwnedPtr(ptr); return *this; } - template <typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) + template<typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) { a.swap(b); } - template <typename T, typename U> inline bool operator==(const OwnPtr<T>& a, U* b) + template<typename T, typename U> inline bool operator==(const OwnPtr<T>& a, U* b) { return a.get() == b; } - template <typename T, typename U> inline bool operator==(T* a, const OwnPtr<U>& b) + template<typename T, typename U> inline bool operator==(T* a, const OwnPtr<U>& b) { return a == b.get(); } - template <typename T, typename U> inline bool operator!=(const OwnPtr<T>& a, U* b) + template<typename T, typename U> inline bool operator!=(const OwnPtr<T>& a, U* b) { return a.get() != b; } - template <typename T, typename U> inline bool operator!=(T* a, const OwnPtr<U>& b) + template<typename T, typename U> inline bool operator!=(T* a, const OwnPtr<U>& b) { return a != b.get(); } - template <typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<T>& p) + template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<T>& p) { return p.get(); } diff --git a/JavaScriptCore/wtf/PassOwnPtr.h b/JavaScriptCore/wtf/PassOwnPtr.h index ae70457..a223fa9 100644 --- a/JavaScriptCore/wtf/PassOwnPtr.h +++ b/JavaScriptCore/wtf/PassOwnPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,31 +30,36 @@ #include "OwnPtrCommon.h" #include "TypeTraits.h" +// Remove this once we make all WebKit code compatible with stricter rules about PassOwnPtr. +#define LOOSE_PASS_OWN_PTR + namespace WTF { // Unlike most of our smart pointers, PassOwnPtr can take either the pointer type or the pointed-to type. - template <typename T> class OwnPtr; + template<typename T> class OwnPtr; + template<typename T> class PassOwnPtr; + template<typename T> PassOwnPtr<T> adoptPtr(T*); - template <typename T> class PassOwnPtr { + template<typename T> class PassOwnPtr { public: typedef typename RemovePointer<T>::Type ValueType; typedef ValueType* PtrType; - PassOwnPtr(PtrType ptr = 0) : m_ptr(ptr) { } + PassOwnPtr() : m_ptr(0) { } + // It somewhat breaks the type system to allow transfer of ownership out of // a const PassOwnPtr. However, it makes it much easier to work with PassOwnPtr - // temporaries, and we don't really have a need to use real const PassOwnPtrs - // anyway. - PassOwnPtr(const PassOwnPtr& o) : m_ptr(o.release()) { } - template <typename U> PassOwnPtr(const PassOwnPtr<U>& o) : m_ptr(o.release()) { } + // temporaries, and we don't have a need to use real const PassOwnPtrs anyway. + PassOwnPtr(const PassOwnPtr& o) : m_ptr(o.leakPtr()) { } + template<typename U> PassOwnPtr(const PassOwnPtr<U>& o) : m_ptr(o.leakPtr()) { } ~PassOwnPtr() { deleteOwnedPtr(m_ptr); } PtrType get() const { return m_ptr; } - void clear() { m_ptr = 0; } - PtrType release() const { PtrType ptr = m_ptr; m_ptr = 0; return ptr; } + void clear(); + PtrType leakPtr() const WARN_UNUSED_RETURN; ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; } PtrType operator->() const { ASSERT(m_ptr); return m_ptr; } @@ -65,105 +70,136 @@ namespace WTF { typedef PtrType PassOwnPtr::*UnspecifiedBoolType; operator UnspecifiedBoolType() const { return m_ptr ? &PassOwnPtr::m_ptr : 0; } - PassOwnPtr& operator=(T*); PassOwnPtr& operator=(const PassOwnPtr<T>&); - template <typename U> PassOwnPtr& operator=(const PassOwnPtr<U>&); + template<typename U> PassOwnPtr& operator=(const PassOwnPtr<U>&); + + template<typename U> friend PassOwnPtr<U> adoptPtr(U*); + +#ifdef LOOSE_PASS_OWN_PTR + PassOwnPtr(PtrType ptr) : m_ptr(ptr) { } + PassOwnPtr& operator=(PtrType); +#endif private: +#ifndef LOOSE_PASS_OWN_PTR + explicit PassOwnPtr(PtrType ptr) : m_ptr(ptr) { } +#endif + mutable PtrType m_ptr; }; - template <typename T> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(T* optr) + template<typename T> inline void PassOwnPtr<T>::clear() + { + PtrType ptr = m_ptr; + m_ptr = 0; + deleteOwnedPtr(ptr); + } + + template<typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::leakPtr() const + { + PtrType ptr = m_ptr; + m_ptr = 0; + return ptr; + } + +#ifdef LOOSE_PASS_OWN_PTR + template<typename T> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(PtrType optr) { - T* ptr = m_ptr; + PtrType ptr = m_ptr; m_ptr = optr; ASSERT(!ptr || m_ptr != ptr); if (ptr) deleteOwnedPtr(ptr); return *this; } +#endif - template <typename T> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(const PassOwnPtr<T>& optr) + template<typename T> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(const PassOwnPtr<T>& optr) { - T* ptr = m_ptr; - m_ptr = optr.release(); + PtrType ptr = m_ptr; + m_ptr = optr.leakPtr(); ASSERT(!ptr || m_ptr != ptr); if (ptr) deleteOwnedPtr(ptr); return *this; } - template <typename T> template <typename U> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(const PassOwnPtr<U>& optr) + template<typename T> template<typename U> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(const PassOwnPtr<U>& optr) { - T* ptr = m_ptr; - m_ptr = optr.release(); + PtrType ptr = m_ptr; + m_ptr = optr.leakPtr(); ASSERT(!ptr || m_ptr != ptr); if (ptr) deleteOwnedPtr(ptr); return *this; } - template <typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, const PassOwnPtr<U>& b) + template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, const PassOwnPtr<U>& b) { return a.get() == b.get(); } - template <typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, const OwnPtr<U>& b) + template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, const OwnPtr<U>& b) { return a.get() == b.get(); } - template <typename T, typename U> inline bool operator==(const OwnPtr<T>& a, const PassOwnPtr<U>& b) + template<typename T, typename U> inline bool operator==(const OwnPtr<T>& a, const PassOwnPtr<U>& b) { return a.get() == b.get(); } - template <typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, U* b) + template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, U* b) { return a.get() == b; } - template <typename T, typename U> inline bool operator==(T* a, const PassOwnPtr<U>& b) + template<typename T, typename U> inline bool operator==(T* a, const PassOwnPtr<U>& b) { return a == b.get(); } - template <typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, const PassOwnPtr<U>& b) + template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, const PassOwnPtr<U>& b) { return a.get() != b.get(); } - template <typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, const OwnPtr<U>& b) + template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, const OwnPtr<U>& b) { return a.get() != b.get(); } - template <typename T, typename U> inline bool operator!=(const OwnPtr<T>& a, const PassOwnPtr<U>& b) + template<typename T, typename U> inline bool operator!=(const OwnPtr<T>& a, const PassOwnPtr<U>& b) { return a.get() != b.get(); } - template <typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, U* b) + template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, U* b) { return a.get() != b; } - template <typename T, typename U> inline bool operator!=(T* a, const PassOwnPtr<U>& b) + template<typename T, typename U> inline bool operator!=(T* a, const PassOwnPtr<U>& b) { return a != b.get(); } - template <typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(const PassOwnPtr<U>& p) + template<typename T> inline PassOwnPtr<T> adoptPtr(T* ptr) + { + return PassOwnPtr<T>(ptr); + } + + template<typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(const PassOwnPtr<U>& p) { - return PassOwnPtr<T>(static_cast<T*>(p.release())); + return adoptPtr(static_cast<T*>(p.leakPtr())); } - template <typename T, typename U> inline PassOwnPtr<T> const_pointer_cast(const PassOwnPtr<U>& p) + template<typename T, typename U> inline PassOwnPtr<T> const_pointer_cast(const PassOwnPtr<U>& p) { - return PassOwnPtr<T>(const_cast<T*>(p.release())); + return adoptPtr(const_cast<T*>(p.leakPtr())); } - template <typename T> inline T* getPtr(const PassOwnPtr<T>& p) + template<typename T> inline T* getPtr(const PassOwnPtr<T>& p) { return p.get(); } @@ -171,6 +207,7 @@ namespace WTF { } // namespace WTF using WTF::PassOwnPtr; +using WTF::adoptPtr; using WTF::const_pointer_cast; using WTF::static_pointer_cast; diff --git a/JavaScriptCore/wtf/PassRefPtr.h b/JavaScriptCore/wtf/PassRefPtr.h index 7c5d868..230637a 100644 --- a/JavaScriptCore/wtf/PassRefPtr.h +++ b/JavaScriptCore/wtf/PassRefPtr.h @@ -76,8 +76,8 @@ namespace WTF { T* get() const { return m_ptr; } - void clear() { T* ptr = m_ptr; derefIfNotNull(ptr); m_ptr = 0; } - T* leakRef() const; + void clear(); + T* leakRef() const WARN_UNUSED_RETURN; T& operator*() const { return *m_ptr; } T* operator->() const { return m_ptr; } @@ -96,7 +96,7 @@ namespace WTF { friend PassRefPtr adoptRef<T>(T*); // FIXME: Remove releaseRef once we change all callers to call leakRef instead. - T* releaseRef() const { return leakRef(); } + T* releaseRef() const { return leakRef(); } WARN_UNUSED_RETURN; private: // adopting constructor @@ -151,12 +151,15 @@ namespace WTF { T* get() const { return m_ptr; } - void clear() { derefIfNotNull(m_ptr); m_ptr = 0; } - T* releaseRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; } + void clear(); + T* leakRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; } WARN_UNUSED_RETURN; T& operator*() const { return *m_ptr; } T* operator->() const { return m_ptr; } + // FIXME: Remove releaseRef once we change all callers to call leakRef instead. + T* releaseRef() const { return leakRef(); } WARN_UNUSED_RETURN; + private: mutable T* m_ptr; }; @@ -168,6 +171,13 @@ namespace WTF { refIfNotNull(ptr); } + template<typename T> inline void PassRefPtr<T>::clear() + { + T* ptr = m_ptr; + m_ptr = 0; + derefIfNotNull(ptr); + } + template<typename T> inline T* PassRefPtr<T>::leakRef() const { T* ptr = m_ptr; @@ -281,6 +291,13 @@ namespace WTF { return p.get(); } + template<typename T> inline void NonNullPassRefPtr<T>::clear() + { + T* ptr = m_ptr; + m_ptr = 0; + derefIfNotNull(ptr); + } + } // namespace WTF using WTF::PassRefPtr; diff --git a/JavaScriptCore/wtf/Platform.h b/JavaScriptCore/wtf/Platform.h index feb3a4d..2500c56 100644 --- a/JavaScriptCore/wtf/Platform.h +++ b/JavaScriptCore/wtf/Platform.h @@ -921,7 +921,7 @@ || CPU(ALPHA) \ || CPU(SPARC64) #define WTF_USE_JSVALUE64 1 -#elif CPU(ARM) || CPU(PPC64) || CPU(MIPS) +#elif CPU(ARM_TRADITIONAL) || CPU(PPC64) || CPU(MIPS) #define WTF_USE_JSVALUE32 1 #elif OS(WINDOWS) && COMPILER(MINGW) /* Using JSVALUE32_64 causes padding/alignement issues for JITStubArg @@ -984,6 +984,14 @@ on MinGW. See https://bugs.webkit.org/show_bug.cgi?id=29268 */ #endif /* !defined(ENABLE_JIT) */ +#if !ENABLE(JIT) +#define ENABLE_INTERPRETER 1 +#endif + +#if !(ENABLE(JIT) || ENABLE(INTERPRETER)) +#error You have to have at least one execution model enabled to build JSC +#endif + /* CPU architecture specific optimizations */ #if CPU(ARM_TRADITIONAL) #if ENABLE(JIT) && !defined(ENABLE_JIT_OPTIMIZE_MOD) && WTF_ARM_ARCH_AT_LEAST(5) @@ -1024,10 +1032,14 @@ on MinGW. See https://bugs.webkit.org/show_bug.cgi?id=29268 */ #define JSC_HOST_CALL #endif -#if COMPILER(GCC) && !ENABLE(JIT) +#if COMPILER(GCC) #define HAVE_COMPUTED_GOTO 1 #endif +#if HAVE(COMPUTED_GOTO) && ENABLE(INTERPRETER) +#define ENABLE_COMPUTED_GOTO_INTERPRETER 1 +#endif + /* Yet Another Regex Runtime. */ #if !defined(ENABLE_YARR_JIT) @@ -1055,6 +1067,16 @@ on MinGW. See https://bugs.webkit.org/show_bug.cgi?id=29268 */ #define ENABLE_ASSEMBLER_WX_EXCLUSIVE 0 #endif +/* Pick which allocator to use; we only need an executable allocator if the assembler is compiled in. + On x86-64 we use a single fixed mmap, on other platforms we mmap on demand. */ +#if ENABLE(ASSEMBLER) +#if CPU(X86_64) +#define ENABLE_EXECUTABLE_ALLOCATOR_FIXED 1 +#else +#define ENABLE_EXECUTABLE_ALLOCATOR_DEMAND 1 +#endif +#endif + #if !defined(ENABLE_PAN_SCROLLING) && OS(WINDOWS) #define ENABLE_PAN_SCROLLING 1 #endif diff --git a/JavaScriptCore/wtf/RefCounted.h b/JavaScriptCore/wtf/RefCounted.h index 5aedac3..d85c47e 100644 --- a/JavaScriptCore/wtf/RefCounted.h +++ b/JavaScriptCore/wtf/RefCounted.h @@ -21,11 +21,8 @@ #ifndef RefCounted_h #define RefCounted_h -#include <wtf/Assertions.h> -#include <wtf/Noncopyable.h> - -// Remove this once we make all WebKit code compatible with stricter rules about RefCounted. -#define LOOSE_REF_COUNTED +#include "Assertions.h" +#include "Noncopyable.h" namespace WTF { @@ -37,9 +34,7 @@ public: void ref() { ASSERT(!m_deletionHasBegun); -#ifndef LOOSE_REF_COUNTED ASSERT(!m_adoptionIsRequired); -#endif ++m_refCount; } @@ -54,6 +49,15 @@ public: return m_refCount; } + void relaxAdoptionRequirement() + { +#ifndef NDEBUG + ASSERT(!m_deletionHasBegun); + ASSERT(m_adoptionIsRequired); + m_adoptionIsRequired = false; +#endif + } + protected: RefCountedBase() : m_refCount(1) @@ -66,19 +70,15 @@ protected: ~RefCountedBase() { -#ifndef LOOSE_REF_COUNTED ASSERT(m_deletionHasBegun); ASSERT(!m_adoptionIsRequired); -#endif } // Returns whether the pointer should be freed or not. bool derefBase() { ASSERT(!m_deletionHasBegun); -#ifndef LOOSE_REF_COUNTED ASSERT(!m_adoptionIsRequired); -#endif ASSERT(m_refCount > 0); if (m_refCount == 1) { diff --git a/JavaScriptCore/wtf/RefPtr.h b/JavaScriptCore/wtf/RefPtr.h index 86e4323..f0c3091 100644 --- a/JavaScriptCore/wtf/RefPtr.h +++ b/JavaScriptCore/wtf/RefPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -59,7 +59,7 @@ namespace WTF { T* get() const { return m_ptr; } - void clear() { derefIfNotNull(m_ptr); m_ptr = 0; } + void clear(); PassRefPtr<T> release() { PassRefPtr<T> tmp = adoptRef(m_ptr); m_ptr = 0; return tmp; } T& operator*() const { return *m_ptr; } @@ -97,6 +97,13 @@ namespace WTF { { } + template <typename T> inline void RefPtr<T>::clear() + { + T* ptr = m_ptr; + m_ptr = 0; + derefIfNotNull(ptr); + } + template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o) { T* optr = o.get(); diff --git a/JavaScriptCore/wtf/RetainPtr.h b/JavaScriptCore/wtf/RetainPtr.h index f5a027e..2768be7 100644 --- a/JavaScriptCore/wtf/RetainPtr.h +++ b/JavaScriptCore/wtf/RetainPtr.h @@ -71,7 +71,7 @@ namespace WTF { PtrType get() const { return m_ptr; } - PtrType releaseRef() { PtrType tmp = m_ptr; m_ptr = 0; return tmp; } + PtrType releaseRef() { PtrType tmp = m_ptr; m_ptr = 0; return tmp; } WARN_UNUSED_RETURN; PtrType operator->() const { return m_ptr; } diff --git a/JavaScriptCore/wtf/SizeLimits.cpp b/JavaScriptCore/wtf/SizeLimits.cpp index 090c1ed..4e481bb 100644 --- a/JavaScriptCore/wtf/SizeLimits.cpp +++ b/JavaScriptCore/wtf/SizeLimits.cpp @@ -41,7 +41,8 @@ namespace WTF { #ifndef NDEBUG -static const size_t refCountedExtraDebugSize = sizeof(int); +struct StructWithIntAndTwoBools { int a; bool b; bool c; }; +static const size_t refCountedExtraDebugSize = sizeof(StructWithIntAndTwoBools) - sizeof(int); #else static const size_t refCountedExtraDebugSize = 0; #endif diff --git a/JavaScriptCore/wtf/StringExtras.h b/JavaScriptCore/wtf/StringExtras.h index 342261b..473bb22 100644 --- a/JavaScriptCore/wtf/StringExtras.h +++ b/JavaScriptCore/wtf/StringExtras.h @@ -65,8 +65,8 @@ inline double wtf_vsnprintf(char* buffer, size_t count, const char* format, va_l return result; } -// Work around a bug in Microsoft's implementation of vsnprintf, where -// vsnprintf does not null terminate the buffer +// Work around a difference in Microsoft's implementation of vsnprintf, where +// vsnprintf does not null terminate the buffer. WebKit can rely on the null termination. #define vsnprintf(buffer, count, format, args) wtf_vsnprintf(buffer, count, format, args) #if OS(WINCE) diff --git a/JavaScriptCore/wtf/TCSystemAlloc.cpp b/JavaScriptCore/wtf/TCSystemAlloc.cpp index c46ff31..0b7ecc9 100644 --- a/JavaScriptCore/wtf/TCSystemAlloc.cpp +++ b/JavaScriptCore/wtf/TCSystemAlloc.cpp @@ -34,7 +34,6 @@ #include "TCSystemAlloc.h" #include <algorithm> -#include <fcntl.h> #include "Assertions.h" #include "TCSpinLock.h" #include "UnusedParam.h" diff --git a/JavaScriptCore/wtf/Vector.h b/JavaScriptCore/wtf/Vector.h index c833eeb..c60de15 100644 --- a/JavaScriptCore/wtf/Vector.h +++ b/JavaScriptCore/wtf/Vector.h @@ -557,6 +557,7 @@ namespace WTF { const T& last() const { return at(size() - 1); } template<typename U> size_t find(const U&) const; + template<typename U> size_t reverseFind(const U&) const; void shrink(size_t size); void grow(size_t size); @@ -744,6 +745,18 @@ namespace WTF { } template<typename T, size_t inlineCapacity> + template<typename U> + size_t Vector<T, inlineCapacity>::reverseFind(const U& value) const + { + for (size_t i = 1; i <= size(); ++i) { + const size_t index = size() - i; + if (at(index) == value) + return index; + } + return notFound; + } + + template<typename T, size_t inlineCapacity> void Vector<T, inlineCapacity>::fill(const T& val, size_t newSize) { if (size() > newSize) diff --git a/JavaScriptCore/wtf/gobject/GOwnPtr.h b/JavaScriptCore/wtf/gobject/GOwnPtr.h index 1fc594c..40c0bf4 100644 --- a/JavaScriptCore/wtf/gobject/GOwnPtr.h +++ b/JavaScriptCore/wtf/gobject/GOwnPtr.h @@ -78,8 +78,9 @@ public: void clear() { - freeOwnedGPtr(m_ptr); + T* ptr = m_ptr; m_ptr = 0; + freeOwnedGPtr(ptr); } T& operator*() const diff --git a/JavaScriptCore/wtf/gobject/GRefPtr.h b/JavaScriptCore/wtf/gobject/GRefPtr.h index 3a33605..c4d4107 100644 --- a/JavaScriptCore/wtf/gobject/GRefPtr.h +++ b/JavaScriptCore/wtf/gobject/GRefPtr.h @@ -52,9 +52,10 @@ public: void clear() { - if (T* ptr = m_ptr) - derefGPtr(ptr); + T* ptr = m_ptr; m_ptr = 0; + if (ptr) + derefGPtr(ptr); } T* get() const { return m_ptr; } diff --git a/JavaScriptCore/wtf/text/WTFString.cpp b/JavaScriptCore/wtf/text/WTFString.cpp index d744b15..2d4417f 100644 --- a/JavaScriptCore/wtf/text/WTFString.cpp +++ b/JavaScriptCore/wtf/text/WTFString.cpp @@ -663,7 +663,7 @@ CString String::utf8() const // simply encode it to UTF-8. if (result == sourceExhausted) { // This should be one unpaired high surrogate. - ASSERT((characters + 1) == (characters + length)); + ASSERT((characters + 1) == (this->characters() + length)); ASSERT((*characters >= 0xD800) && (*characters <= 0xDBFF)); // There should be room left, since one UChar hasn't been converted. ASSERT((buffer + 3) <= (buffer + bufferVector.size())); diff --git a/JavaScriptCore/wtf/unicode/icu/CollatorICU.cpp b/JavaScriptCore/wtf/unicode/icu/CollatorICU.cpp index ecab5bd..5112de5 100644 --- a/JavaScriptCore/wtf/unicode/icu/CollatorICU.cpp +++ b/JavaScriptCore/wtf/unicode/icu/CollatorICU.cpp @@ -69,13 +69,12 @@ PassOwnPtr<Collator> Collator::userDefault() CFStringRef collationOrder = collationOrderRetainer.get(); #endif char buf[256]; - if (collationOrder) { - CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII); - return new Collator(buf); - } else - return new Collator(""); + if (!collationOrder) + return adoptPtr(new Collator("")); + CFStringGetCString(collationOrder, buf, sizeof(buf), kCFStringEncodingASCII); + return adoptPtr(new Collator(buf)); #else - return new Collator(0); + return adoptPtr(new Collator(0)); #endif } |