--- libaitio/inc/aitio.h 2012/04/05 12:21:14 1.16.2.9 +++ libaitio/inc/aitio.h 2012/04/24 08:24:01 1.16.2.13 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.h,v 1.16.2.9 2012/04/05 12:21:14 misho Exp $ +* $Id: aitio.h,v 1.16.2.13 2012/04/24 08:24:01 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -74,6 +74,7 @@ typedef struct _tagSplitArray { } sarr_t; typedef struct _tagArray { + int arr_last; int arr_num; void **arr_data; } array_t; @@ -118,11 +119,11 @@ typedef struct { #define AIT_LEN(_vl) (_vl)->val_len #define AIT_KEY(_vl) (_vl)->val_key #define AIT_RAW(_vl) (_vl)->val.net -#define AIT_VOID(_vl) (_vl)->val.ptr +#define AIT_ADDR(_vl) (_vl)->val.ptr #define AIT_BLOB_CHUNKS(_vl, _n) (AIT_LEN((_vl)) / _n + (AIT_LEN((_vl)) % _n) ? 1 : 0) #define AIT_ISEMPTY(_vl) (AIT_TYPE((_vl)) == empty) -#define AIT_GET_LIKE(_vl, _type) ((_type) (_vl)->val.ptr) +#define AIT_GET_LIKE(_vl, _type) ((_type) AIT_ADDR(_vl)) #define AIT_GET_PTR(_vl) (assert(AIT_TYPE((_vl)) == ptr), (_vl)->val.ptr) #define AIT_GET_DATA(_vl) (assert(AIT_TYPE((_vl)) == data), (_vl)->val_data) @@ -558,7 +559,7 @@ inline char **io_arrayTo(array_t * __restrict arr); * io_arrayLen() - Get last used element in dynamic array (array Length) * * @arr = Array - * return: -1 error, 0 empty or >0 position of last used element + * return: -1 empty or >-1 position of last used element */ inline int io_arrayLen(array_t * __restrict arr); /* @@ -596,6 +597,7 @@ int io_arrayGrow(array_t * __restrict arr, int newNumI int io_arrayVacuum(array_t * __restrict arr, int fromWhere); #define io_arraySize(_arr) ((_arr) ? (_arr)->arr_num : 0) +#define io_arrayLast(_arr) (io_arraySize((_arr)) ? (_arr)->arr_last : -1) #define io_arrayZero(_arr) (assert((_arr)), memset((_arr)->arr_data, 0, \ io_arraySize((_arr)) * sizeof(void*))) @@ -604,6 +606,8 @@ int io_arrayVacuum(array_t * __restrict arr, int fromW ((_type) *((_arr)->arr_data + _d))) #define io_arraySet(_arr, _d, _ptr) do { \ assert((_arr) && (_arr)->arr_num > _d); \ + if ((_arr)->arr_last < _d) \ + (_arr)->arr_last = _d; \ *((_arr)->arr_data + _d) = (void*) (_ptr); \ } while (0) #define io_arrayDel(_arr, _d, _fri) do { \ @@ -612,6 +616,10 @@ int io_arrayVacuum(array_t * __restrict arr, int fromW free(*((_arr)->arr_data + _d)); \ *((_arr)->arr_data + _d) = NULL; \ } while (0) +#define io_arraySyncLast(_arr) do { \ + assert((_arr)); \ + (_arr)->arr_last = io_arrayLen((_arr)); \ + } while (0) /* * io_arrayElem() - Always GET/PUT element into dynamic array, if not enough elements grow array @@ -627,9 +635,10 @@ inline void *io_arrayElem(array_t * __restrict arr, in * * @arr = Array * @data = Element, if set NULL return only first empty position + * @mayGrow = Array may to grow, if not enough room for new element * return: -1 not found empty position, array is full!, >-1 return position of stored element into array */ -inline int io_arrayPush(array_t * __restrict arr, void **data); +inline int io_arrayPush(array_t * __restrict arr, void **data, int mayGrow); /* * io_arrayPop() - Pop element from dynamic array like stack manner, last used position *