fix some leaks in parser, add debug code to node manager to find more
authorMorgan Deters <mdeters@gmail.com>
Tue, 12 Oct 2010 21:49:07 +0000 (21:49 +0000)
committerMorgan Deters <mdeters@gmail.com>
Tue, 12 Oct 2010 21:49:07 +0000 (21:49 +0000)
src/expr/node_manager.cpp
src/parser/antlr_input.cpp
src/parser/antlr_input.h

index 4e872ad5c396fde1d8416eb0d422a371a386794a..8ff83bb945edd58d78943986612eba6e55d9413a 100644 (file)
@@ -118,6 +118,20 @@ NodeManager::~NodeManager() {
   }
 
   poolRemove( &expr::NodeValue::s_null );
+
+  if(Debug.isOn("gc:leaks")) {
+    Debug("gc:leaks") << "still in pool:" << std::endl;
+    for(NodeValuePool::const_iterator i = d_nodeValuePool.begin(),
+          iend = d_nodeValuePool.end();
+        i != iend;
+        ++i) {
+      Debug("gc:leaks") << "  " << *i
+                        << " id=" << (*i)->d_id
+                        << " rc=" << (*i)->d_rc
+                        << " " << **i << std::endl;
+    }
+    Debug("gc:leaks") << ":end:" << std::endl;
+  }
 }
 
 void NodeManager::reclaimZombies() {
index 39c8e11b3645bc38ebe2a00f3d72e02eed91ae00..74157acd7f2ecfd920766f0fe86ebfcc95a40181 100644 (file)
@@ -171,7 +171,7 @@ AntlrInput::AntlrInput(AntlrInputStream& inputStream, unsigned int lookahead) :
     d_lexer(NULL),
     d_parser(NULL),
     d_antlr3InputStream( inputStream.getAntlr3InputStream() ),
-    d_tokenStream(NULL) {
+    d_tokenBuffer(NULL) {
 }
 
 /*
@@ -204,11 +204,11 @@ AntlrInput::Input(ExprManager* exprManager, const std::string& input, const std:
 */
 
 AntlrInput::~AntlrInput() {
-  d_tokenStream->free(d_tokenStream);
+  BoundedTokenBufferFree(d_tokenBuffer);
 }
 
 pANTLR3_COMMON_TOKEN_STREAM AntlrInput::getTokenStream() {
-  return d_tokenStream;
+  return d_tokenBuffer->commonTstream;
 }
 
 void AntlrInput::lexerError(pANTLR3_BASE_RECOGNIZER recognizer) {
@@ -260,7 +260,7 @@ void AntlrInput::setAntlr3Lexer(pANTLR3_LEXER pLexer) {
     throw ParserException("Couldn't create token buffer.");
   }
 
-  d_tokenStream = buffer->commonTstream;
+  d_tokenBuffer = buffer;
 
   // Override default lexer error reporting
   d_lexer->rec->reportError = &lexerError;
index 82b15d19967a21c8778ff719bb2d9a8a95df0d65..e55e07efd2a6587104d299964c0d6039bf8dc4c5 100644 (file)
 #include <string>
 #include <vector>
 
-#include "input.h"
-#include "parser_options.h"
-#include "parser_exception.h"
+#include "parser/input.h"
+#include "parser/parser_options.h"
+#include "parser/parser_exception.h"
+#include "parser/bounded_token_buffer.h"
 #include "expr/expr.h"
 #include "expr/expr_manager.h"
 #include "util/Assert.h"
@@ -117,10 +118,11 @@ class AntlrInput : public Input {
   /** The ANTLR3 input stream associated with this input. */
   pANTLR3_INPUT_STREAM d_antlr3InputStream;
 
-  /** The ANTLR3 token stream associated with this input. We only need this so we can free it on exit.
+  /** The ANTLR3 bounded token buffer associated with this input.
+   *  We only need this so we can free it on exit.
    *  This is set by <code>setLexer</code>.
    *  NOTE: We assume that we <em>can</em> free it on exit. No sharing! */
-  pANTLR3_COMMON_TOKEN_STREAM d_tokenStream;
+  pBOUNDED_TOKEN_BUFFER d_tokenBuffer;
 
   /** Turns an ANTLR3 exception into a message for the user and calls <code>parseError</code>. */
   static void reportError(pANTLR3_BASE_RECOGNIZER recognizer);