Ignore:
Timestamp:
Jul 6, 2007, 5:09:08 AM (18 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Antti.

  • <rdar://problem/5311093> JavaScriptCore fails to build with strict-aliasing warnings


  • Configurations/Base.xcconfig: Re-enable -Wstrict-aliasing
  • bindings/jni/jni_utility.cpp: (KJS::Bindings::getJNIEnv): Type-pun via a union instead of a pointer cast.
  • wtf/HashMap.h: (WTF::): Instead of doing type-punned assignments via pointer cast, do one of three things: (1) assign directly w/o cast if storage type matches real type; (2) assign using cast via union if type does not need reffing; (3) copy with memcpy and ref/deref manually if type needs reffing. This is ok peref-wise because memcpy of a constant length gets optomized. HashTraits are now expected to make ref()/deref() take the storage type, not the true type.
  • wtf/HashSet.h: (WTF::): Same basic idea.
  • wtf/HashTable.h: (WTF::): Added Assigner template for use by HashMap/HashSet. Change RefCounter to call ref() and deref() via storage type, avoiding the need to type-pun. (WTF::RefCounter::ref): ditto (WTF::RefCounter::deref): ditto
  • wtf/HashTraits.h: (WTF::): Change ref() and deref() for RefPtr HashTraits to take the storage type; cast via union to pointer type.
  • wtf/FastMalloc.cpp: (WTF::TCMalloc_PageHeap::init): Changed from constructor to init function so this can go in a union. (WTF::): redefine pageheap macro in terms of getPageHeap(). (WTF::getPageHeap): new inline function, helper for pageheap macro. This hides the cast in a union. (WTF::TCMalloc_ThreadCache::InitModule): Call init() instead of using placement new to initialize page heap.
  • wtf/TCPageMap.h: (TCMalloc_PageMap1::init): Changed from constructor to init function. (TCMalloc_PageMap2::init): ditto (TCMalloc_PageMap3::init): ditto

WebCore:

Reviewed by Antti.

  • <rdar://problem/5311093> JavaScriptCore fails to build with strict-aliasing warnings
  • platform/StringHash.h: (WTF::): Adapt to newer way to do storage types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/HashTraits.h

    r19947 r24059  
    104104    template<typename P> struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > {
    105105        typedef HashTraits<typename IntTypes<sizeof(P*)>::SignedType> StorageTraits;
     106        typedef typename StorageTraits::TraitType StorageType;
    106107        static const bool emptyValueIsZero = true;
    107108        static const bool needsRef = true;
    108         static void ref(const RefPtr<P>& p) { if (p) p->ref(); }
    109         static void deref(const RefPtr<P>& p) { if (p) p->deref(); }
     109
     110        typedef union {
     111            P* m_p;
     112            StorageType m_s;
     113        } UnionType;
     114
     115        static void ref(const StorageType& s)
     116        {
     117            if (const P* p = reinterpret_cast<const UnionType*>(&s)->m_p)
     118                const_cast<P*>(p)->ref();
     119        }
     120        static void deref(const StorageType& s)
     121        {
     122            if (const P* p = reinterpret_cast<const UnionType*>(&s)->m_p)
     123                const_cast<P*>(p)->deref();
     124        }
    110125    };
    111126
Note: See TracChangeset for help on using the changeset viewer.