diff options
author | Adrian Thurston <thurston@complang.org> | 2012-01-08 20:31:44 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-01-08 20:31:44 +0000 |
commit | db6fa5a5ef92d20e0629d7c67e0384b36a77a221 (patch) | |
tree | 0d8cabcdbefa22dbd5d6af05cab17dde1c7057e5 | |
parent | 99d6b340c6092e614a20757cac64cb21576ac99e (diff) | |
download | colm-db6fa5a5ef92d20e0629d7c67e0384b36a77a221.tar.gz |
A few refcounting fixes.
-rw-r--r-- | colm/bytecode.c | 25 | ||||
-rw-r--r-- | colm/pdarun.c | 17 |
2 files changed, 24 insertions, 18 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index 62bd63b5..c6e073dc 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -874,10 +874,9 @@ again: } case IN_LOAD_TREE: { debug( REALM_BYTECODE, "IN_LOAD_TREE\n" ); - Word w; - read_word( w ); - treeUpref( (Tree*)w ); - vm_push( (SW)w ); + Tree *tree; + read_tree( tree ); + vm_push( tree ); break; } case IN_LOAD_WORD: { @@ -2584,9 +2583,9 @@ again: case IN_INPUT_PUSH_WV: { debug( REALM_BYTECODE, "IN_INPUT_PUSH_WV\n" ); - Input *accumStream = (Input*)vm_pop(); + Input *input = (Input*)vm_pop(); Tree *tree = vm_pop(); - long len = streamPush( prg, sp, 0, accumStream->in, tree, false ); + long len = streamPush( prg, sp, 0, input->in, tree, false ); vm_push( 0 ); /* Single unit. */ @@ -2595,16 +2594,16 @@ again: exec->rcodeUnitLen += SIZEOF_CODE + SIZEOF_WORD; append( &exec->pdaRun->rcodeCollect, exec->rcodeUnitLen ); - treeDownref( prg, sp, (Tree*)accumStream ); + treeDownref( prg, sp, (Tree*)input ); treeDownref( prg, sp, tree ); break; } case IN_INPUT_PUSH_IGNORE_WV: { debug( REALM_BYTECODE, "IN_INPUT_PUSH_IGNORE_WV\n" ); - Input *accumStream = (Input*)vm_pop(); + Input *input = (Input*)vm_pop(); Tree *tree = vm_pop(); - long len = streamPush( prg, sp, 0, accumStream->in, tree, true ); + long len = streamPush( prg, sp, 0, input->in, tree, true ); vm_push( 0 ); /* Single unit. */ @@ -2613,7 +2612,7 @@ again: exec->rcodeUnitLen += SIZEOF_CODE + SIZEOF_WORD; append( &exec->pdaRun->rcodeCollect, exec->rcodeUnitLen ); - treeDownref( prg, sp, (Tree*)accumStream ); + treeDownref( prg, sp, (Tree*)input ); treeDownref( prg, sp, tree ); break; } @@ -2621,12 +2620,12 @@ again: Word len; read_word( len ); - Input *accumStream = (Input*)vm_pop(); + Input *input = (Input*)vm_pop(); debug( REALM_BYTECODE, "IN_INPUT_PUSH_BKT\n" ); - undoStreamPush( prg, sp, 0, accumStream->in, len ); - treeDownref( prg, sp, (Tree*)accumStream ); + undoStreamPush( prg, sp, 0, input->in, len ); + treeDownref( prg, sp, (Tree*)input ); break; } case IN_CONSTRUCT: { diff --git a/colm/pdarun.c b/colm/pdarun.c index 486fbd60..bf797a2b 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -176,10 +176,13 @@ void streamPushTree( FsmRun *fsmRun, InputStream *inputStream, Tree *tree, int i void undoStreamPush( Program *prg, Tree **sp, FsmRun *fsmRun, InputStream *inputStream, long length ) { - if ( length < 0 ) - undoPrependTree( inputStream ); - else + if ( length < 0 ) { + Tree *tree = undoPrependTree( inputStream ); + treeDownref( prg, sp, tree ); + } + else { undoPrependData( inputStream, length ); + } } void undoStreamAppend( Program *prg, Tree **sp, FsmRun *fsmRun, InputStream *inputStream, Tree *input, long length ) @@ -206,6 +209,11 @@ static void sendBackText( FsmRun *fsmRun, InputStream *inputStream, const char * undoPosition( inputStream, data, length ); } +void sendBackTree( InputStream *inputStream, Tree *tree ) +{ + undoConsumeTree( inputStream, tree, false ); +} + /* * Stops on: * PcrRevIgnore @@ -421,7 +429,7 @@ static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, treeUpref( input->tree ); - streamPushTree( fsmRun, inputStream, input->tree, false ); + sendBackTree( inputStream, input->tree ); } else { /* Check for reverse code. */ @@ -435,7 +443,6 @@ static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, sendBackText( fsmRun, inputStream, stringData( input->tree->tokdata ), stringLength( input->tree->tokdata ) ); - /* If eof was just sent back remember that it needs to be sent again. */ if ( input->tree->id == prg->rtd->eofLelIds[pdaRun->parserId] ) inputStream->eofSent = false; |