diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-02-22 09:51:34 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-02-22 09:51:34 +0000 |
commit | d3da6ba716d94ec684186a89a52fb90636db89ee (patch) | |
tree | c653c0c7e560be2839c468f4f877f1cf47ac83c5 | |
parent | 8fdd3b45c0c2b2a5751efd79e2be4cc0241af53e (diff) | |
download | rsyslog-d3da6ba716d94ec684186a89a52fb90636db89ee.tar.gz rsyslog-d3da6ba716d94ec684186a89a52fb90636db89ee.tar.xz rsyslog-d3da6ba716d94ec684186a89a52fb90636db89ee.zip |
completed initial vmstk implementation
-rw-r--r-- | rsyslog.h | 2 | ||||
-rw-r--r-- | vmstk.c | 17 | ||||
-rw-r--r-- | vmstk.h | 5 |
3 files changed, 23 insertions, 1 deletions
@@ -128,6 +128,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_INVALID_OCTAL_DIGIT = -2052, /**< invalid octal digit during parsing */ RS_RET_INVALID_HEX_DIGIT = -2053, /**< invalid hex digit during parsing */ RS_RET_INTERFACE_NOT_SUPPORTED = -2054, /**< interface not supported */ + RS_RET_OUT_OF_STACKSPACE = -2055, /**< a stack data structure is exhausted and can not be grown */ + RS_RET_STACK_EMPTY = -2056, /**< a pop was requested on a stack, but the stack was already empty */ RS_RET_OK_DELETE_LISTENTRY = 1, /**< operation successful, but callee requested the deletion of an entry (special state) */ RS_RET_TERMINATE_NOW = 2, /**< operation successful, function is requested to terminate (mostly used with threads) */ RS_RET_NO_RUN = 3, /**< operation successful, but function does not like to be executed */ @@ -66,7 +66,9 @@ CODESTARTobjDebugPrint(vmstk) ENDobjDebugPrint(vmstk) -/* push a value on the stack +/* push a value on the stack. The provided pVar is now owned + * by the stack. If the user intends to continue use it, it + * must be duplicated. */ static rsRetVal push(vmstk_t *pThis, var_t *pVar) @@ -76,11 +78,18 @@ push(vmstk_t *pThis, var_t *pVar) ISOBJ_TYPE_assert(pThis, vmstk); ISOBJ_TYPE_assert(pVar, var); + if(pThis->iStkPtr >= VMSTK_SIZE) + ABORT_FINALIZE(RS_RET_OUT_OF_STACKSPACE); + + pThis->vStk[pThis->iStkPtr++] = pVar; + +finalize_it: RETiRet; } /* pop a value from the stack + * The user is responsible for destructing the ppVar returned. */ static rsRetVal pop(vmstk_t *pThis, var_t **ppVar) @@ -90,6 +99,12 @@ pop(vmstk_t *pThis, var_t **ppVar) ISOBJ_TYPE_assert(pThis, vmstk); assert(ppVar != NULL); + if(pThis->iStkPtr == 0) + ABORT_FINALIZE(RS_RET_STACK_EMPTY); + + *ppVar = pThis->vStk[pThis->iStkPtr--]; + +finalize_it: RETiRet; } @@ -22,9 +22,14 @@ #ifndef INCLUDED_VMSTK_H #define INCLUDED_VMSTK_H +/* The max size of the stack - TODO: make configurable */ +#define VMSTK_SIZE 256 + /* the vmstk object */ typedef struct vmstk_s { BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */ + var_t *vStk[VMSTK_SIZE];/* the actual stack */ + int iStkPtr; /* stack pointer, points to next free location, grows from 0 --> topend */ } vmstk_t; |