You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2004/01/06 19:12:31 UTC

cvs commit: xml-xerces/c/src/xercesc/util/regx RegularExpression.hpp RegularExpression.cpp

peiyongz    2004/01/06 10:12:31

  Modified:    c/src/xercesc/util/regx RegularExpression.hpp
                        RegularExpression.cpp
  Log:
  using ctor/setPattern to avoid exception thrown from ctor
  
  Revision  Changes    Path
  1.16      +34 -10    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- RegularExpression.hpp	24 Dec 2003 15:24:15 -0000	1.15
  +++ RegularExpression.hpp	6 Jan 2004 18:12:31 -0000	1.16
  @@ -113,6 +113,16 @@
       );
       ~RegularExpression();
   
  +    RegularExpression
  +    (
  +        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
  +    );
  +
  +    // -----------------------------------------------------------------------
  +    //  Setter methods
  +    // -----------------------------------------------------------------------
  +    void setPattern(const XMLCh* const pattern, const XMLCh* const options=0);
  +
       // -----------------------------------------------------------------------
       //  Public Constants
       // -----------------------------------------------------------------------
  @@ -220,11 +230,6 @@
       void cleanUp();
   
       // -----------------------------------------------------------------------
  -    //  Setter methods
  -    // -----------------------------------------------------------------------
  -    void setPattern(const XMLCh* const pattern, const XMLCh* const options=0);
  -
  -    // -----------------------------------------------------------------------
       //  Private Helper methods
       // -----------------------------------------------------------------------
       void prepare();
  @@ -341,10 +346,29 @@
     // ---------------------------------------------------------------------------
     inline void RegularExpression::cleanUp() {
   
  -      fMemoryManager->deallocate(fPattern);//delete [] fPattern;
  -      fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;      
  -      delete fBMPattern;
  -      delete fTokenFactory;
  +      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;
  +      }
     }
   
     // ---------------------------------------------------------------------------
  
  
  
  1.20      +68 -81    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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- RegularExpression.cpp	24 Dec 2003 15:24:15 -0000	1.19
  +++ RegularExpression.cpp	6 Jan 2004 18:12:31 -0000	1.20
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.20  2004/01/06 18:12:31  peiyongz
  + * using ctor/setPattern to avoid exception thrown from ctor
  + *
    * Revision 1.19  2003/12/24 15:24:15  cargilld
    * More updates to memory management so that the static memory manager.
    *
  @@ -299,21 +302,9 @@
        fTokenFactory(0),
        fMemoryManager(manager)
   {
  -	try {
  -
  -		XMLCh* tmpBuf = XMLString::transcode(pattern, fMemoryManager);
  -        ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager);
  -		setPattern(tmpBuf);
  -	}
  -    catch(const OutOfMemoryException&)
  -    {
  -        throw;
  -    }
  -    catch (...) {
  -
  -		cleanUp();
  -		throw;
  -	}
  +    XMLCh* tmpBuf = XMLString::transcode(pattern, fMemoryManager);
  +    ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager);
  +    setPattern(tmpBuf);
   }
   
   RegularExpression::RegularExpression(const char* const pattern,
  @@ -335,23 +326,11 @@
        fTokenFactory(0),
        fMemoryManager(manager)
   {
  -	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;
  -	}
  +    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);
   }
   
   
  @@ -373,19 +352,7 @@
        fTokenFactory(0),
        fMemoryManager(manager)
   {
  -	try {
  -
  -		setPattern(pattern);
  -	}
  -    catch(const OutOfMemoryException&)
  -    {
  -        throw;
  -    }
  -    catch (...) {
  -
  -		cleanUp();
  -		throw;
  -	}
  +    setPattern(pattern);
   }
   
   RegularExpression::RegularExpression(const XMLCh* const pattern,
  @@ -407,19 +374,7 @@
        fTokenFactory(0),
        fMemoryManager(manager)
   {
  -	try {
  -
  -		setPattern(pattern, options);
  -	}
  -    catch(const OutOfMemoryException&)
  -    {
  -        throw;
  -    }
  -    catch (...) {
  -
  -		cleanUp();
  -		throw;
  -	}
  +    setPattern(pattern, options);
   }
   
   RegularExpression::~RegularExpression() {
  @@ -427,38 +382,70 @@
   	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) {
   
  -    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);
  -    }
  +	try {
   
  -    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);
  +        }
  +
  +        if (regxParser) {
  +            regxParser->setTokenFactory(fTokenFactory);
  +        }
  +
  +        Janitor<RegxParser> janRegxParser(regxParser);
  +        fTokenTree = regxParser->parse(fPattern, fOptions);
  +        fNoGroups = regxParser->getNoParen();
  +        fHasBackReferences = regxParser->hasBackReferences();
  +	}
  +    catch(const OutOfMemoryException&)
  +    {
  +        throw;
       }
  +    catch (...) {
   
  -	Janitor<RegxParser> janRegxParser(regxParser);
  -	fTokenTree = regxParser->parse(fPattern, fOptions);
  -	fNoGroups = regxParser->getNoParen();
  -	fHasBackReferences = regxParser->hasBackReferences();
  +		cleanUp();
  +		throw;
  +	}
   }
   
   // ---------------------------------------------------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org