Commit e729ed16 authored by paroga@webkit.org's avatar paroga@webkit.org

2011-05-12 Maciej Stachowiak <mjs@apple.com>

        Reviewed by Darin Adler.

        XMLDocumentParserLibxml2 should play nice with strict OwnPtrs
        https://bugs.webkit.org/show_bug.cgi?id=59394

        This portion of the change introduces a PassTraits template, which
        is used to enable takeFirst() to work for a Deque holding OwnPtrs,
        and optimize it for a Deque holding RefPtrs. In the future it can
        be deployed elsewhere to make our data structures work better with
        our smart pointers.

        * GNUmakefile.list.am:
        * JavaScriptCore.gypi:
        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
        * JavaScriptCore.xcodeproj/project.pbxproj:
        * wtf/CMakeLists.txt:
        * wtf/Deque.h:
        (WTF::::takeFirst):
        * wtf/PassTraits.h: Added.
        (WTF::PassTraits::transfer):
2011-05-12  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Darin Adler.

        XMLDocumentParserLibxml2 should play nice with strict OwnPtrs
        https://bugs.webkit.org/show_bug.cgi?id=59394

        Properly fix this (formerly rolled out for breaking the build). I think the original
        failure had nothing to do with Deque<OwnPtr>, which in fact appears to work fine.

        * dom/XMLDocumentParserLibxml2.cpp:
        (WebCore::PendingCallbacks::~PendingCallbacks):
        (WebCore::PendingCallbacks::create):
        (WebCore::PendingCallbacks::appendStartElementNSCallback):
        (WebCore::PendingCallbacks::appendEndElementNSCallback):
        (WebCore::PendingCallbacks::appendCharactersCallback):
        (WebCore::PendingCallbacks::appendProcessingInstructionCallback):
        (WebCore::PendingCallbacks::appendCDATABlockCallback):
        (WebCore::PendingCallbacks::appendCommentCallback):
        (WebCore::PendingCallbacks::appendInternalSubsetCallback):
        (WebCore::PendingCallbacks::appendErrorCallback):
        (WebCore::PendingCallbacks::PendingCallbacks):
        (WebCore::XMLDocumentParser::XMLDocumentParser):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86383 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ab797127
2011-05-12 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin Adler.
XMLDocumentParserLibxml2 should play nice with strict OwnPtrs
https://bugs.webkit.org/show_bug.cgi?id=59394
This portion of the change introduces a PassTraits template, which
is used to enable takeFirst() to work for a Deque holding OwnPtrs,
and optimize it for a Deque holding RefPtrs. In the future it can
be deployed elsewhere to make our data structures work better with
our smart pointers.
* GNUmakefile.list.am:
* JavaScriptCore.gypi:
* JavaScriptCore.vcproj/WTF/WTF.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/Deque.h:
(WTF::::takeFirst):
* wtf/PassTraits.h: Added.
(WTF::PassTraits::transfer):
2011-05-12 Nikolas Zimmermann <nzimmermann@rim.com>
Not reviewed.
......
......@@ -479,6 +479,7 @@ javascriptcore_sources += \
Source/JavaScriptCore/wtf/PassOwnArrayPtr.h \
Source/JavaScriptCore/wtf/PassOwnPtr.h \
Source/JavaScriptCore/wtf/PassRefPtr.h \
Source/JavaScriptCore/wtf/PassTraits.h \
Source/JavaScriptCore/wtf/ParallelJobs.h \
Source/JavaScriptCore/wtf/ParallelJobsGeneric.cpp \
Source/JavaScriptCore/wtf/ParallelJobsGeneric.h \
......
......@@ -187,6 +187,7 @@
'wtf/PassOwnArrayPtr.h',
'wtf/PassOwnPtr.h',
'wtf/PassRefPtr.h',
'wtf/PassTraits.h',
'wtf/Platform.h',
'wtf/PossiblyNull.h',
'wtf/RandomNumber.h',
......
......@@ -848,6 +848,10 @@
RelativePath="..\..\wtf\PassRefPtr.h"
>
</File>
<File
RelativePath="..\..\wtf\PassTraits.h"
>
</File>
<File
RelativePath="..\..\wtf\ParallelJobs.h"
>
......
......@@ -218,6 +218,7 @@
5DBB1525131D0BD70056AD36 /* minidom.js in Copy Support Script */ = {isa = PBXBuildFile; fileRef = 1412110D0A48788700480255 /* minidom.js */; };
5DE6E5B30E1728EC00180407 /* create_hash_table in Headers */ = {isa = PBXBuildFile; fileRef = F692A8540255597D01FF60F7 /* create_hash_table */; settings = {ATTRIBUTES = (); }; };
6507D29E0E871E5E00D7D896 /* JSTypeInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 6507D2970E871E4A00D7D896 /* JSTypeInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
651DCA04136A6FEF00F74194 /* PassTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 651DCA02136A6FAB00F74194 /* PassTraits.h */; settings = {ATTRIBUTES = (Private, ); }; };
655EB29B10CE2581001A990E /* NodesCodegen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 655EB29A10CE2581001A990E /* NodesCodegen.cpp */; };
65DFC93308EA173A00F7300B /* HashTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65DFC92D08EA173A00F7300B /* HashTable.cpp */; };
65E1A3DF122B894500B26097 /* NonCopyingSort.h in Headers */ = {isa = PBXBuildFile; fileRef = 65E1A2F4122B880D00B26097 /* NonCopyingSort.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -868,6 +869,7 @@
5DBD18AF0C5401A700C15EAE /* MallocZoneSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MallocZoneSupport.h; sourceTree = "<group>"; };
5DE3D0F40DD8DDFB00468714 /* WebKitAvailability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAvailability.h; sourceTree = "<group>"; };
6507D2970E871E4A00D7D896 /* JSTypeInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypeInfo.h; sourceTree = "<group>"; };
651DCA02136A6FAB00F74194 /* PassTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PassTraits.h; sourceTree = "<group>"; };
651F6412039D5B5F0078395C /* dtoa.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dtoa.cpp; sourceTree = "<group>"; tabWidth = 8; };
651F6413039D5B5F0078395C /* dtoa.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = dtoa.h; sourceTree = "<group>"; tabWidth = 8; };
652246A40C8D7A0E007BDAF7 /* HashIterators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HashIterators.h; sourceTree = "<group>"; };
......@@ -1724,6 +1726,7 @@
BCFBE695122560E800309E9D /* PassOwnArrayPtr.h */,
44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */,
6580F795094070560082C219 /* PassRefPtr.h */,
651DCA02136A6FAB00F74194 /* PassTraits.h */,
7934BB761361979300CB99A1 /* ParallelJobs.h */,
7934BB771361979300CB99A1 /* ParallelJobsGeneric.cpp */,
7934BB781361979300CB99A1 /* ParallelJobsGeneric.h */,
......@@ -2603,6 +2606,7 @@
7934BB7D1361979400CB99A1 /* ParallelJobsGeneric.h in Headers */,
7934BB7E1361979400CB99A1 /* ParallelJobsLibdispatch.h in Headers */,
7934BB7F1361979400CB99A1 /* ParallelJobsOpenMP.h in Headers */,
651DCA04136A6FEF00F74194 /* PassTraits.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -58,6 +58,7 @@ SET(WTF_HEADERS
PassOwnArrayPtr.h
PassOwnPtr.h
PassRefPtr.h
PassTraits.h
ParallelJobs.h
ParallelJobsGeneric.h
ParallelJobsLibdispatch.h
......
......@@ -33,6 +33,7 @@
// FIXME: Could move what Vector and Deque share into a separate file.
// Deque doesn't actually use Vector.
#include "PassTraits.h"
#include "Vector.h"
namespace WTF {
......@@ -51,6 +52,8 @@ namespace WTF {
typedef DequeConstIterator<T, inlineCapacity> const_iterator;
typedef DequeReverseIterator<T, inlineCapacity> reverse_iterator;
typedef DequeConstReverseIterator<T, inlineCapacity> const_reverse_iterator;
typedef PassTraits<T> Pass;
typedef typename PassTraits<T>::PassType PassType;
Deque();
Deque(const Deque<T, inlineCapacity>&);
......@@ -73,7 +76,7 @@ namespace WTF {
T& first() { ASSERT(m_start != m_end); return m_buffer.buffer()[m_start]; }
const T& first() const { ASSERT(m_start != m_end); return m_buffer.buffer()[m_start]; }
T takeFirst();
PassType takeFirst();
template<typename U> void append(const U&);
template<typename U> void prepend(const U&);
......@@ -436,11 +439,11 @@ namespace WTF {
}
template<typename T, size_t inlineCapacity>
inline T Deque<T, inlineCapacity>::takeFirst()
inline typename Deque<T, inlineCapacity>::PassType Deque<T, inlineCapacity>::takeFirst()
{
T oldFirst = first();
T oldFirst = Pass::transfer(first());
removeFirst();
return oldFirst;
return Pass::transfer(oldFirst);
}
template<typename T, size_t inlineCapacity> template<typename U>
......
/*
* Copyright (C) 2011 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 met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WTF_PassTraits_h
#define WTF_PassTraits_h
#include "OwnPtr.h"
#include "RefPtr.h"
// The PassTraits template exists to help optimize (or make possible) use
// of WTF data structures with WTF smart pointers that have a Pass
// variant for transfer of ownership
namespace WTF {
template<typename T> struct PassTraits {
typedef T Type;
typedef T PassType;
static PassType transfer(Type& value) { return value; }
};
template<typename T> struct PassTraits<OwnPtr<T> > {
typedef OwnPtr<T> Type;
typedef PassOwnPtr<T> PassType;
static PassType transfer(Type& value) { return value.release(); }
};
template<typename T> struct PassTraits<RefPtr<T> > {
typedef RefPtr<T> Type;
typedef PassRefPtr<T> PassType;
static PassType transfer(Type& value) { return value.release(); }
};
} // namespace WTF
using WTF::PassTraits;
#endif // WTF_PassTraits_h
2011-05-12 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin Adler.
XMLDocumentParserLibxml2 should play nice with strict OwnPtrs
https://bugs.webkit.org/show_bug.cgi?id=59394
Properly fix this (formerly rolled out for breaking the build). I think the original
failure had nothing to do with Deque<OwnPtr>, which in fact appears to work fine.
* dom/XMLDocumentParserLibxml2.cpp:
(WebCore::PendingCallbacks::~PendingCallbacks):
(WebCore::PendingCallbacks::create):
(WebCore::PendingCallbacks::appendStartElementNSCallback):
(WebCore::PendingCallbacks::appendEndElementNSCallback):
(WebCore::PendingCallbacks::appendCharactersCallback):
(WebCore::PendingCallbacks::appendProcessingInstructionCallback):
(WebCore::PendingCallbacks::appendCDATABlockCallback):
(WebCore::PendingCallbacks::appendCommentCallback):
(WebCore::PendingCallbacks::appendInternalSubsetCallback):
(WebCore::PendingCallbacks::appendErrorCallback):
(WebCore::PendingCallbacks::PendingCallbacks):
(WebCore::XMLDocumentParser::XMLDocumentParser):
2011-05-12 Daniel Bates <dbates@rim.com>
Reviewed by Kenneth Rohde Christiansen.
......@@ -25,10 +25,6 @@
*/
#include "config.h"
// FIXME: Remove this define!
#define LOOSE_OWN_PTR
#include "XMLDocumentParser.h"
#include "CDATASection.h"
......@@ -84,16 +80,16 @@ namespace WebCore {
class PendingCallbacks {
WTF_MAKE_NONCOPYABLE(PendingCallbacks);
public:
PendingCallbacks() { }
~PendingCallbacks()
~PendingCallbacks() { }
static PassOwnPtr<PendingCallbacks> create()
{
deleteAllValues(m_callbacks);
return adoptPtr(new PendingCallbacks);
}
void appendStartElementNSCallback(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, int nb_namespaces,
const xmlChar** namespaces, int nb_attributes, int nb_defaulted, const xmlChar** attributes)
{
PendingStartElementNSCallback* callback = new PendingStartElementNSCallback;
OwnPtr<PendingStartElementNSCallback> callback = adoptPtr(new PendingStartElementNSCallback);
callback->xmlLocalName = xmlStrdup(xmlLocalName);
callback->xmlPrefix = xmlStrdup(xmlPrefix);
......@@ -118,87 +114,87 @@ public:
callback->attributes[i * 5 + 4] = callback->attributes[i * 5 + 3] + len;
}
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void appendEndElementNSCallback()
{
PendingEndElementNSCallback* callback = new PendingEndElementNSCallback;
m_callbacks.append(callback);
m_callbacks.append(adoptPtr(new PendingEndElementNSCallback));
}
void appendCharactersCallback(const xmlChar* s, int len)
{
PendingCharactersCallback* callback = new PendingCharactersCallback;
OwnPtr<PendingCharactersCallback> callback = adoptPtr(new PendingCharactersCallback);
callback->s = xmlStrndup(s, len);
callback->len = len;
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void appendProcessingInstructionCallback(const xmlChar* target, const xmlChar* data)
{
PendingProcessingInstructionCallback* callback = new PendingProcessingInstructionCallback;
OwnPtr<PendingProcessingInstructionCallback> callback = adoptPtr(new PendingProcessingInstructionCallback);
callback->target = xmlStrdup(target);
callback->data = xmlStrdup(data);
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void appendCDATABlockCallback(const xmlChar* s, int len)
{
PendingCDATABlockCallback* callback = new PendingCDATABlockCallback;
OwnPtr<PendingCDATABlockCallback> callback = adoptPtr(new PendingCDATABlockCallback);
callback->s = xmlStrndup(s, len);
callback->len = len;
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void appendCommentCallback(const xmlChar* s)
{
PendingCommentCallback* callback = new PendingCommentCallback;
OwnPtr<PendingCommentCallback> callback = adoptPtr(new PendingCommentCallback);
callback->s = xmlStrdup(s);
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void appendInternalSubsetCallback(const xmlChar* name, const xmlChar* externalID, const xmlChar* systemID)
{
PendingInternalSubsetCallback* callback = new PendingInternalSubsetCallback;
OwnPtr<PendingInternalSubsetCallback> callback = adoptPtr(new PendingInternalSubsetCallback);
callback->name = xmlStrdup(name);
callback->externalID = xmlStrdup(externalID);
callback->systemID = xmlStrdup(systemID);
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void appendErrorCallback(XMLDocumentParser::ErrorType type, const xmlChar* message, int lineNumber, int columnNumber)
{
PendingErrorCallback* callback = new PendingErrorCallback;
OwnPtr<PendingErrorCallback> callback = adoptPtr(new PendingErrorCallback);
callback->message = xmlStrdup(message);
callback->type = type;
callback->lineNumber = lineNumber;
callback->columnNumber = columnNumber;
m_callbacks.append(callback);
m_callbacks.append(callback.release());
}
void callAndRemoveFirstCallback(XMLDocumentParser* parser)
{
OwnPtr<PendingCallback> callback(m_callbacks.takeFirst());
OwnPtr<PendingCallback> callback = m_callbacks.takeFirst();
callback->call(parser);
}
bool isEmpty() const { return m_callbacks.isEmpty(); }
private:
PendingCallbacks() { }
struct PendingCallback {
virtual ~PendingCallback() { }
virtual void call(XMLDocumentParser* parser) = 0;
......@@ -338,7 +334,7 @@ private:
int columnNumber;
};
Deque<PendingCallback*> m_callbacks;
Deque<OwnPtr<PendingCallback> > m_callbacks;
};
// --------------------------------
......@@ -551,7 +547,7 @@ XMLDocumentParser::XMLDocumentParser(Document* document, FrameView* frameView)
: ScriptableDocumentParser(document)
, m_view(frameView)
, m_context(0)
, m_pendingCallbacks(new PendingCallbacks)
, m_pendingCallbacks(PendingCallbacks::create())
, m_currentNode(document)
, m_sawError(false)
, m_sawCSS(false)
......@@ -578,7 +574,7 @@ XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
: ScriptableDocumentParser(fragment->document())
, m_view(0)
, m_context(0)
, m_pendingCallbacks(new PendingCallbacks)
, m_pendingCallbacks(PendingCallbacks::create())
, m_currentNode(fragment)
, m_sawError(false)
, m_sawCSS(false)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment