peiyongz 2004/01/13 12:05:00 Modified: c/src/xercesc/util/regx RegularExpression.cpp RegularExpression.hpp Log: revert code back to previous version Revision Changes Path 1.22 +83 -70 xml-xerces/c/src/xercesc/util/regx/RegularExpression.cpp Index: RegularExpression.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/regx/RegularExpression.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- RegularExpression.cpp 13 Jan 2004 16:34:22 -0000 1.21 +++ RegularExpression.cpp 13 Jan 2004 20:05:00 -0000 1.22 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001-2004 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -56,11 +56,8 @@ /* * $Log$ - * Revision 1.21 2004/01/13 16:34:22 cargilld - * Misc memory management changes. - * - * Revision 1.20 2004/01/06 18:12:31 peiyongz - * using ctor/setPattern to avoid exception thrown from ctor + * Revision 1.22 2004/01/13 20:05:00 peiyongz + * revert code back to previous version * * Revision 1.19 2003/12/24 15:24:15 cargilld * More updates to memory management so that the static memory manager. @@ -305,9 +302,21 @@ fTokenFactory(0), fMemoryManager(manager) { - XMLCh* tmpBuf = XMLString::transcode(pattern, fMemoryManager); - ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); - setPattern(tmpBuf); + try { + + XMLCh* tmpBuf = XMLString::transcode(pattern, fMemoryManager); + ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); + setPattern(tmpBuf); + } + catch(const OutOfMemoryException&) + { + throw; + } + catch (...) { + + cleanUp(); + throw; + } } RegularExpression::RegularExpression(const char* const pattern, @@ -329,11 +338,23 @@ fTokenFactory(0), fMemoryManager(manager) { - XMLCh* tmpBuf = XMLString::transcode(pattern, fMemoryManager); - ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); - XMLCh* tmpOptions = XMLString::transcode(options, fMemoryManager); - ArrayJanitor<XMLCh> janOps(tmpOptions, fMemoryManager); - setPattern(tmpBuf, tmpOptions); + try { + + XMLCh* tmpBuf = XMLString::transcode(pattern, fMemoryManager); + ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); + XMLCh* tmpOptions = XMLString::transcode(options, fMemoryManager); + ArrayJanitor<XMLCh> janOps(tmpOptions, fMemoryManager); + setPattern(tmpBuf, tmpOptions); + } + catch(const OutOfMemoryException&) + { + throw; + } + catch (...) { + + cleanUp(); + throw; + } } @@ -355,7 +376,19 @@ fTokenFactory(0), fMemoryManager(manager) { - setPattern(pattern); + try { + + setPattern(pattern); + } + catch(const OutOfMemoryException&) + { + throw; + } + catch (...) { + + cleanUp(); + throw; + } } RegularExpression::RegularExpression(const XMLCh* const pattern, @@ -377,7 +410,19 @@ fTokenFactory(0), fMemoryManager(manager) { - setPattern(pattern, options); + try { + + setPattern(pattern, options); + } + catch(const OutOfMemoryException&) + { + throw; + } + catch (...) { + + cleanUp(); + throw; + } } RegularExpression::~RegularExpression() { @@ -385,70 +430,38 @@ cleanUp(); } -RegularExpression::RegularExpression(MemoryManager* const manager) - :fHasBackReferences(false), - fFixedStringOnly(false), - fNoGroups(0), - fMinLength(0), - fNoClosures(0), - fOptions(0), - fBMPattern(0), - fPattern(0), - fFixedString(0), - fOperations(0), - fTokenTree(0), - fFirstChar(0), - fOpFactory(manager), - fTokenFactory(0), - fMemoryManager(manager) -{ -} - // --------------------------------------------------------------------------- // RegularExpression: Setter methods // --------------------------------------------------------------------------- void RegularExpression::setPattern(const XMLCh* const pattern, const XMLCh* const options) { - try { - - fTokenFactory = new (fMemoryManager) TokenFactory(fMemoryManager); - fOptions = parseOptions(options); - fPattern = XMLString::replicate(pattern, fMemoryManager); - - // the following construct causes an error in an Intel 7.1 32 bit compiler for - // red hat linux 7.2 - // (when an exception is thrown the wrong object is deleted) - //RegxParser* regxParser = isSet(fOptions, XMLSCHEMA_MODE) - // ? new (fMemoryManager) ParserForXMLSchema(fMemoryManager) - // : new (fMemoryManager) RegxParser(fMemoryManager); - - RegxParser* regxParser; - if (isSet(fOptions, XMLSCHEMA_MODE)) { - regxParser = new (fMemoryManager) ParserForXMLSchema(fMemoryManager); - } - else { - regxParser = new (fMemoryManager) RegxParser(fMemoryManager); - } - - if (regxParser) { - regxParser->setTokenFactory(fTokenFactory); - } + fTokenFactory = new (fMemoryManager) TokenFactory(fMemoryManager); + fOptions = parseOptions(options); + fPattern = XMLString::replicate(pattern, fMemoryManager); + + // the following construct causes an error in an Intel 7.1 32 bit compiler for + // red hat linux 7.2 + // (when an exception is thrown the wrong object is deleted) + //RegxParser* regxParser = isSet(fOptions, XMLSCHEMA_MODE) + // ? new (fMemoryManager) ParserForXMLSchema(fMemoryManager) + // : new (fMemoryManager) RegxParser(fMemoryManager); + RegxParser* regxParser; + if (isSet(fOptions, XMLSCHEMA_MODE)) { + regxParser = new (fMemoryManager) ParserForXMLSchema(fMemoryManager); + } + else { + regxParser = new (fMemoryManager) RegxParser(fMemoryManager); + } - Janitor<RegxParser> janRegxParser(regxParser); - fTokenTree = regxParser->parse(fPattern, fOptions); - fNoGroups = regxParser->getNoParen(); - fHasBackReferences = regxParser->hasBackReferences(); - } - catch(const OutOfMemoryException&) - { - throw; + if (regxParser) { + regxParser->setTokenFactory(fTokenFactory); } - catch (...) { - cleanUp(); - throw; - } + Janitor<RegxParser> janRegxParser(regxParser); + fTokenTree = regxParser->parse(fPattern, fOptions); + fNoGroups = regxParser->getNoParen(); + fHasBackReferences = regxParser->hasBackReferences(); } // --------------------------------------------------------------------------- @@ -1444,7 +1457,7 @@ case Token::T_BACKREFERENCE: case Token::T_EMPTY: ret = compileSingle(token, next, tokenType); - break; + break; case Token::T_CONCAT: ret = compileConcat(token, next, reverse); break; 1.17 +9 -33 xml-xerces/c/src/xercesc/util/regx/RegularExpression.hpp Index: RegularExpression.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/regx/RegularExpression.hpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- RegularExpression.hpp 6 Jan 2004 18:12:31 -0000 1.16 +++ RegularExpression.hpp 13 Jan 2004 20:05:00 -0000 1.17 @@ -113,16 +113,6 @@ ); ~RegularExpression(); - RegularExpression - ( - MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - - // ----------------------------------------------------------------------- - // Setter methods - // ----------------------------------------------------------------------- - void setPattern(const XMLCh* const pattern, const XMLCh* const options=0); - // ----------------------------------------------------------------------- // Public Constants // ----------------------------------------------------------------------- @@ -230,6 +220,11 @@ void cleanUp(); // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setPattern(const XMLCh* const pattern, const XMLCh* const options=0); + + // ----------------------------------------------------------------------- // Private Helper methods // ----------------------------------------------------------------------- void prepare(); @@ -346,29 +341,10 @@ // --------------------------------------------------------------------------- inline void RegularExpression::cleanUp() { - if (fPattern) - { - fMemoryManager->deallocate(fPattern);//delete [] fPattern; - fPattern = 0; - } - - if (fFixedString) - { - fMemoryManager->deallocate(fFixedString);//delete [] fFixedString; - fFixedString = 0; - } - - if (fBMPattern) - { - delete fBMPattern; - fBMPattern = 0; - } - - if (fTokenFactory) - { - delete fTokenFactory; - fTokenFactory = 0; - } + fMemoryManager->deallocate(fPattern);//delete [] fPattern; + fMemoryManager->deallocate(fFixedString);//delete [] fFixedString; + delete fBMPattern; + delete fTokenFactory; } // ---------------------------------------------------------------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]