diff options
-rw-r--r-- | colm/Makefile.in | 4 | ||||
-rw-r--r-- | colm/bytecode.cpp | 2 | ||||
-rw-r--r-- | colm/codevect.c (renamed from colm/codevect.cpp) | 37 | ||||
-rw-r--r-- | colm/rtvector.h | 40 |
4 files changed, 41 insertions, 42 deletions
diff --git a/colm/Makefile.in b/colm/Makefile.in index 1eae521f..145f181f 100644 --- a/colm/Makefile.in +++ b/colm/Makefile.in @@ -62,9 +62,9 @@ COLM_SRC = \ ctinput.cpp \ RUNTIME_SRC = fsmrun.cpp pdarun.cpp bytecode.cpp \ - map.cpp string.cpp tree.cpp pool.cpp codevect.cpp + map.cpp string.cpp tree.cpp pool.cpp -RUNTIME_SRC_C = map2.c fsmrun2.c list.c input.c debug.c +RUNTIME_SRC_C = map2.c fsmrun2.c list.c input.c debug.c codevect.c ALL_SRC = $(COLM_SRC) $(RUNTIME_SRC) diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index 69d102b8..5d3f2b7b 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -1013,7 +1013,7 @@ bool makeReverseCode( RtCodeVect *all, RtCodeVect &reverseCode ) p--; long len = *p; p = p - len; - append( all, p, len ); + append2( all, p, len ); } /* Stop, then place a total length in the global stack. */ diff --git a/colm/codevect.cpp b/colm/codevect.c index 021401d4..9fd57fc2 100644 --- a/colm/codevect.cpp +++ b/colm/codevect.c @@ -21,7 +21,6 @@ #include "rtvector.h" -#include <new> #include <string.h> #include <stdlib.h> #include <assert.h> @@ -57,14 +56,14 @@ static void upResize( RtCodeVect *vect, long len ) if ( vect->data != 0 ) { /* Table exists already, resize it up. */ vect->data = (Code*) realloc( vect->data, sizeof(Code) * newLen ); - if ( vect->data == 0 ) - throw std::bad_alloc(); + //if ( vect->data == 0 ) + // throw std::bad_alloc(); } else { /* Create the data. */ vect->data = (Code*) malloc( sizeof(Code) * newLen ); - if ( vect->data == 0 ) - throw std::bad_alloc(); + //if ( vect->data == 0 ) + // throw std::bad_alloc(); } } } @@ -87,8 +86,8 @@ static void downResize( RtCodeVect *vect, long len) else { /* Not shrinking to size zero, realloc it to the smaller size. */ vect->data = (Code*) realloc( vect->data, sizeof(Code) * newLen ); - if ( vect->data == 0 ) - throw std::bad_alloc(); + //if ( vect->data == 0 ) + // throw std::bad_alloc(); } } } @@ -98,9 +97,9 @@ void rtCodeVectEmpty( RtCodeVect *vect ) { if ( vect->data != 0 ) { /* Call All destructors. */ - Code *pos = vect->data; - for ( long i = 0; i < vect->tabLen; pos++, i++ ) - pos->~Code(); + //Code *pos = vect->data; + //for ( long i = 0; i < vect->tabLen; pos++, i++ ) + // pos->~Code(); /* Free the data space. */ free( vect->data ); @@ -129,8 +128,8 @@ void rtCodeVectReplace( RtCodeVect *vect, long pos, const Code *val, long len ) /* Delete any objects we need to delete. */ item = vect->data + pos; - for ( i = pos; i < vect->tabLen; i++, item++ ) - item->~Code(); + //for ( i = pos; i < vect->tabLen; i++, item++ ) + // item->~Code(); /* We are extending the vector, set the new data length. */ vect->tabLen = endPos; @@ -138,21 +137,21 @@ void rtCodeVectReplace( RtCodeVect *vect, long pos, const Code *val, long len ) else { /* Delete any objects we need to delete. */ item = vect->data + pos; - for ( i = pos; i < endPos; i++, item++ ) - item->~Code(); + //for ( i = pos; i < endPos; i++, item++ ) + // item->~Code(); } /* Copy data in using copy constructor. */ Code *dst = vect->data + pos; const Code *src = val; for ( i = 0; i < len; i++, dst++, src++ ) - new(dst) Code(*src); + *dst = *src; } void rtCodeVectRemove( RtCodeVect *vect, long pos, long len ) { long newLen, lenToSlideOver, endPos; - Code *dst, *item; + Code *dst;//, *item; /* If we are given a negative position to remove at then * treat it as a position relative to the length. */ @@ -169,9 +168,9 @@ void rtCodeVectRemove( RtCodeVect *vect, long pos, long len ) dst = vect->data + pos; /* Call Destructors. */ - item = dst; - for ( long i = 0; i < len; i += 1, item += 1 ) - item->~Code(); +// item = dst; +// for ( long i = 0; i < len; i += 1, item += 1 ) +// item->~Code(); /* Shift data over if necessary. */ lenToSlideOver = vect->tabLen - endPos; diff --git a/colm/rtvector.h b/colm/rtvector.h index e8eb0c75..3f60e7cc 100644 --- a/colm/rtvector.h +++ b/colm/rtvector.h @@ -22,11 +22,22 @@ #ifndef _RT_VECTOR_H #define _RT_VECTOR_H +#ifdef __cplusplus +extern "C" { +#endif + typedef unsigned char Code; typedef unsigned long Word; typedef unsigned long Half; -struct RtCodeVect; +typedef struct _RtCodeVect +{ + Code *data; + long tabLen; + long allocLen; + + /* FIXME: leak when freed. */ +} RtCodeVect; void rtCodeVectReplace( RtCodeVect *vect, long pos, const Code *val, long len ); void rtCodeVectEmpty( RtCodeVect *vect ); @@ -34,32 +45,18 @@ void rtCodeVectRemove( RtCodeVect *vect, long pos, long len ); void initRtCodeVect( RtCodeVect *codeVect ); -inline static void remove( RtCodeVect *vect, long pos ); -inline static void append( RtCodeVect *vect, const Code *val, long len ); -inline static void append( RtCodeVect *vect, const Code &val ); +//inline static void remove( RtCodeVect *vect, long pos ); +inline static void append( RtCodeVect *vect, const Code val ); +inline static void append2( RtCodeVect *vect, const Code *val, long len ); inline static void appendHalf( RtCodeVect *vect, Half half ); inline static void appendWord( RtCodeVect *vect, Word word ); -struct RtCodeVect -{ - Code *data; - long tabLen; - long allocLen; - - /* FIXME: leak when freed. */ -}; - -inline static void remove( RtCodeVect *vect, long pos ) -{ - rtCodeVectRemove( vect, pos, 1 ); -} - -inline static void append( RtCodeVect *vect, const Code *val, long len ) +inline static void append2( RtCodeVect *vect, const Code *val, long len ) { rtCodeVectReplace( vect, vect->tabLen, val, len ); } -inline static void append( RtCodeVect *vect, const Code &val ) +inline static void append( RtCodeVect *vect, const Code val ) { rtCodeVectReplace( vect, vect->tabLen, &val, 1 ); } @@ -86,6 +83,9 @@ inline static void appendWord( RtCodeVect *vect, Word word ) #endif } +#ifdef __cplusplus +} +#endif #endif |