diff options
author | Robert Griebl <rgriebl@trolltech.com> | 2009-06-10 11:46:23 (GMT) |
---|---|---|
committer | Robert Griebl <rgriebl@trolltech.com> | 2009-06-10 11:46:23 (GMT) |
commit | 7604f8087f88171ef933d8ae08f501467e647338 (patch) | |
tree | 51d071f462ed48d0b25884d9f62b8ba11c5dff13 /src/xml | |
parent | 8c265860b41214daade7c8a28237c1e07ea71a3c (diff) | |
download | Qt-7604f8087f88171ef933d8ae08f501467e647338.zip Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.gz Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.bz2 |
Make Qt exception safer.
Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions,
which also contains the full history.
Rev-By: Harald Fernengel
Rev-By: Ralf Engels
Diffstat (limited to 'src/xml')
-rw-r--r-- | src/xml/dom/qdom.cpp | 88 | ||||
-rw-r--r-- | src/xml/sax/qxml.cpp | 81 | ||||
-rw-r--r-- | src/xml/sax/qxml.h | 5 |
3 files changed, 86 insertions, 88 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 550abc9..5e2c74b 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -512,8 +512,8 @@ public: bool setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn); // Attributes - QDomDocumentTypePrivate* doctype() { return type; }; - QDomImplementationPrivate* implementation() { return impl; }; + QDomDocumentTypePrivate* doctype() { return type.data(); }; + QDomImplementationPrivate* implementation() { return impl.data(); }; QDomElementPrivate* documentElement(); // Factories @@ -537,8 +537,8 @@ public: void clear(); // Variables - QDomImplementationPrivate* impl; - QDomDocumentTypePrivate* type; + QScopedSharedPointer<QDomImplementationPrivate> impl; + QScopedSharedPointer<QDomDocumentTypePrivate> type; void saveDocument(QTextStream& stream, const int indent, QDomNode::EncodingPolicy encUsed) const; @@ -3060,7 +3060,7 @@ QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate() QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) { - QDomNamedNodeMapPrivate* m = new QDomNamedNodeMapPrivate(p); + QScopedPointer<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p)); m->readonly = readonly; m->appendToParent = appendToParent; @@ -3073,7 +3073,7 @@ QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) // we are no longer interested in ownership m->ref.deref(); - return m; + return m.take(); } void QDomNamedNodeMapPrivate::clearMap() @@ -3499,13 +3499,18 @@ QDomDocumentTypePrivate::~QDomDocumentTypePrivate() void QDomDocumentTypePrivate::init() { entities = new QDomNamedNodeMapPrivate(this); - notations = new QDomNamedNodeMapPrivate(this); - publicId.clear(); - systemId.clear(); - internalSubset.clear(); - - entities->setAppendToParent(true); - notations->setAppendToParent(true); + QT_TRY { + notations = new QDomNamedNodeMapPrivate(this); + publicId.clear(); + systemId.clear(); + internalSubset.clear(); + + entities->setAppendToParent(true); + notations->setAppendToParent(true); + } QT_CATCH(...) { + delete entities; + QT_RETHROW; + } } QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(bool deep) @@ -6148,8 +6153,8 @@ QDomDocumentPrivate::QDomDocumentPrivate() : QDomNodePrivate(0), nodeListTime(1) { - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); + impl.reset(new QDomImplementationPrivate); + type.reset(new QDomDocumentTypePrivate(this, this)); name = QLatin1String("#document"); } @@ -6158,8 +6163,8 @@ QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname) : QDomNodePrivate(0), nodeListTime(1) { - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); + impl.reset(new QDomImplementationPrivate); + type.reset(new QDomDocumentTypePrivate(this, this)); type->name = aname; name = QLatin1String("#document"); @@ -6169,12 +6174,11 @@ QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt) : QDomNodePrivate(0), nodeListTime(1) { - impl = new QDomImplementationPrivate; + impl.reset(new QDomImplementationPrivate); if (dt != 0) { - type = dt; - type->ref.ref(); + type.assign(dt); } else { - type = new QDomDocumentTypePrivate(this, this); + type.reset(new QDomDocumentTypePrivate(this, this)); } name = QLatin1String("#document"); @@ -6184,31 +6188,19 @@ QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep) : QDomNodePrivate(n, deep), nodeListTime(1) { - impl = n->impl->clone(); - // Reference count is down to 0, so we set it to 1 here. - impl->ref.ref(); - type = (QDomDocumentTypePrivate*)n->type->cloneNode(); + impl.assign(n->impl->clone()); + type.assign((QDomDocumentTypePrivate*)n->type->cloneNode()); type->setParent(this); - // Reference count is down to 0, so we set it to 1 here. - type->ref.ref(); } QDomDocumentPrivate::~QDomDocumentPrivate() { - if (!impl->ref.deref()) - delete impl; - if (!type->ref.deref()) - delete type; } void QDomDocumentPrivate::clear() { - if (!impl->ref.deref()) - delete impl; - if (!type->ref.deref()) - delete type; - impl = 0; - type = 0; + impl.assign(0); + type.assign(0); QDomNodePrivate::clear(); } @@ -6229,8 +6221,8 @@ bool QDomDocumentPrivate::setContent(QXmlInputSource *source, bool namespaceProc bool QDomDocumentPrivate::setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn) { clear(); - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); + impl.reset(new QDomImplementationPrivate); + type.reset(new QDomDocumentTypePrivate(this, this)); bool namespaceProcessing = reader->feature(QLatin1String("http://xml.org/sax/features/namespaces")) && !reader->feature(QLatin1String("http://xml.org/sax/features/namespace-prefixes")); @@ -7448,20 +7440,22 @@ bool QDomHandler::characters(const QString& ch) if (node == doc) return false; - QDomNodePrivate *n; + QScopedPointer<QDomNodePrivate> n; if (cdata) { - n = doc->createCDATASection(ch); + n.reset(doc->createCDATASection(ch)); } else if (!entityName.isEmpty()) { - QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, entityName, - QString(), QString(), QString()); + QScopedPointer<QDomEntityPrivate> e(new QDomEntityPrivate(doc, 0, entityName, + QString(), QString(), QString())); e->value = ch; - doc->doctype()->appendChild(e); - n = doc->createEntityReference(entityName); + doc->doctype()->appendChild(e.data()); + e.take(); + n.reset(doc->createEntityReference(entityName)); } else { - n = doc->createTextNode(ch); + n.reset(doc->createTextNode(ch)); } n->setLocation(locator->lineNumber(), locator->columnNumber()); - node->appendChild(n); + node->appendChild(n.data()); + n.take(); return true; } diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index ba68636..1655642 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -262,10 +262,11 @@ class QXmlDefaultHandlerPrivate class QXmlSimpleReaderPrivate { +public: + ~QXmlSimpleReaderPrivate(); private: // functions - QXmlSimpleReaderPrivate(); - ~QXmlSimpleReaderPrivate(); + QXmlSimpleReaderPrivate(QXmlSimpleReader *reader); void initIncrementalParsing(); // used to determine if elements are correctly nested @@ -350,7 +351,7 @@ private: bool contentCharDataRead; // helper classes - QXmlLocator *locator; + QScopedPointer<QXmlLocator> locator; QXmlNamespaceSupport namespaceSupport; // error string @@ -545,8 +546,8 @@ private: QXmlParseException::QXmlParseException(const QString& name, int c, int l, const QString& p, const QString& s) + : d(new QXmlParseExceptionPrivate) { - d = new QXmlParseExceptionPrivate; d->msg = name; d->column = c; d->line = l; @@ -559,7 +560,6 @@ QXmlParseException::QXmlParseException(const QString& name, int c, int l, */ QXmlParseException::~QXmlParseException() { - delete d; } /*! @@ -928,8 +928,9 @@ void QXmlNamespaceSupport::popContext() */ void QXmlNamespaceSupport::reset() { + QXmlNamespaceSupportPrivate *newD = new QXmlNamespaceSupportPrivate; delete d; - d = new QXmlNamespaceSupportPrivate; + d = newD; } @@ -1260,18 +1261,23 @@ void QXmlInputSource::init() { d = new QXmlInputSourcePrivate; - d->inputDevice = 0; - d->inputStream = 0; + QT_TRY { + d->inputDevice = 0; + d->inputStream = 0; - setData(QString()); + setData(QString()); #ifndef QT_NO_TEXTCODEC - d->encMapper = 0; + d->encMapper = 0; #endif - d->nextReturnedEndOfData = true; // first call to next() will call fetchData() + d->nextReturnedEndOfData = true; // first call to next() will call fetchData() - d->encodingDeclBytes.clear(); - d->encodingDeclChars.clear(); - d->lookingForEncodingDecl = true; + d->encodingDeclBytes.clear(); + d->encodingDeclChars.clear(); + d->lookingForEncodingDecl = true; + } QT_CATCH(...) { + delete(d); + QT_RETHROW; + } } /*! @@ -2715,9 +2721,24 @@ inline void QXmlSimpleReaderPrivate::refClear() refValueLen = 0; refArrayPos = 0; } -QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate() +QXmlSimpleReaderPrivate::QXmlSimpleReaderPrivate(QXmlSimpleReader *reader) { + q_ptr = reader; parseStack = 0; + + locator.reset(new QXmlSimpleReaderLocator(reader)); + entityRes = 0; + dtdHnd = 0; + contentHnd = 0; + errorHnd = 0; + lexicalHnd = 0; + declHnd = 0; + + // default feature settings + useNamespaces = true; + useNamespacePrefixes = false; + reportWhitespaceCharData = true; + reportEntities = false; } QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() @@ -2727,8 +2748,10 @@ QXmlSimpleReaderPrivate::~QXmlSimpleReaderPrivate() void QXmlSimpleReaderPrivate::initIncrementalParsing() { - delete parseStack; - parseStack = new QStack<ParseState>; + if( parseStack ) + parseStack->clear(); + else + parseStack = new QStack<ParseState>; } /********************************************* @@ -3101,25 +3124,8 @@ static NameChar determineNameChar(QChar ch) */ QXmlSimpleReader::QXmlSimpleReader() + : d_ptr(new QXmlSimpleReaderPrivate(this)) { - d_ptr = new QXmlSimpleReaderPrivate(); - Q_D(QXmlSimpleReader); - d->q_ptr = this; - - d->locator = new QXmlSimpleReaderLocator(this); - - d->entityRes = 0; - d->dtdHnd = 0; - d->contentHnd = 0; - d->errorHnd = 0; - d->lexicalHnd = 0; - d->declHnd = 0; - - // default feature settings - d->useNamespaces = true; - d->useNamespacePrefixes = false; - d->reportWhitespaceCharData = true; - d->reportEntities = false; } /*! @@ -3127,9 +3133,6 @@ QXmlSimpleReader::QXmlSimpleReader() */ QXmlSimpleReader::~QXmlSimpleReader() { - Q_D(QXmlSimpleReader); - delete d->locator; - delete d; } /*! @@ -3412,7 +3415,7 @@ bool QXmlSimpleReader::parse(const QXmlInputSource *input, bool incremental) // call the handler if (d->contentHnd) { - d->contentHnd->setDocumentLocator(d->locator); + d->contentHnd->setDocumentLocator(d->locator.data()); if (!d->contentHnd->startDocument()) { d->reportParseError(d->contentHnd->errorString()); d->tags.clear(); diff --git a/src/xml/sax/qxml.h b/src/xml/sax/qxml.h index e0165d3..8e3eb25 100644 --- a/src/xml/sax/qxml.h +++ b/src/xml/sax/qxml.h @@ -47,6 +47,7 @@ #include <QtCore/qstring.h> #include <QtCore/qstringlist.h> #include <QtCore/qlist.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_HEADER @@ -202,7 +203,7 @@ public: QString message() const; private: - QXmlParseExceptionPrivate *d; + QScopedPointer<QXmlParseExceptionPrivate> d; }; @@ -271,7 +272,7 @@ public: private: Q_DISABLE_COPY(QXmlSimpleReader) Q_DECLARE_PRIVATE(QXmlSimpleReader) - QXmlSimpleReaderPrivate* d_ptr; + QScopedPointer<QXmlSimpleReaderPrivate> d_ptr; friend class QXmlSimpleReaderLocator; }; |