--- libelwix/inc/elwix/avar.h 2013/07/09 00:18:19 1.3 +++ libelwix/inc/elwix/avar.h 2015/06/25 17:53:49 1.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: avar.h,v 1.3 2013/07/09 00:18:19 misho Exp $ +* $Id: avar.h,v 1.9 2015/06/25 17:53:49 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2015 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -64,7 +64,11 @@ typedef struct { uint8_t val_in:1; uint8_t val_be:1; uint8_t val_le:1; - uint8_t val_pad:5; + uint8_t val_const:1; + uint8_t val_f0:1; + uint8_t val_f1:1; + uint8_t val_f2:1; + uint8_t val_f3:1; }; uint8_t val_opt; }; @@ -99,6 +103,11 @@ typedef struct { #define AIT_IN(_vl) (_vl)->val_in #define AIT_BE(_vl) (_vl)->val_be #define AIT_LE(_vl) (_vl)->val_le +#define AIT_CONST(_vl) (_vl)->val_const +#define AIT_FLAG0(_vl) (_vl)->val_f0 +#define AIT_FLAG1(_vl) (_vl)->val_f1 +#define AIT_FLAG2(_vl) (_vl)->val_f2 +#define AIT_FLAG3(_vl) (_vl)->val_f3 #define AIT_BLOB_CHUNKS(_vl, _n) (AIT_LEN((_vl)) / _n + (AIT_LEN((_vl)) % _n) ? 1 : 0) #define AIT_ISEMPTY(_vl) (AIT_TYPE((_vl)) == empty) @@ -123,7 +132,9 @@ typedef struct { #define AIT_GET_F32(_vl) (assert(AIT_TYPE((_vl)) == f32), (_vl)->val.f32) #define AIT_GET_F64(_vl) (assert(AIT_TYPE((_vl)) == f64), (_vl)->val.f64) -#define AIT_SET_DATA(_vl, _p, _len) do { ait_val_t *__val = e_realloc((_vl), (sizeof(ait_val_t) + _len)); \ +#define AIT_SET_DATA(_vl, _p, _len) do { assert(!(_vl) || ((_vl) && !AIT_CONST((_vl)))); \ + ait_val_t *__val = e_realloc((_vl), \ + (sizeof(ait_val_t) + _len)); \ if (__val) { \ void *__p = (_p); \ if (__p) \ @@ -133,22 +144,26 @@ typedef struct { (_vl) = __val; \ } \ } while (0); -#define AIT_SET_PTR(_vl, _p, _len) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_PTR(_vl, _p, _len) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = ptr; __val->val.ptr = _p; \ AIT_LEN(__val) = _len; } while (0) -#define AIT_RE_BUF(_vl, _len) do { ait_val_t *__val = (_vl); assert(__val && !__val->val_in); \ +#define AIT_RE_BUF(_vl, _len) do { ait_val_t *__val = (_vl); \ + assert(__val && !__val->val_in && !AIT_CONST(__val)); \ void *__ptr = e_realloc(AIT_GET_BUF(__val), _len); \ if (__ptr) { \ __val->val.buffer = __ptr; AIT_LEN(__val) = _len; \ } } while (0) -#define AIT_SET_BUFSIZ(_vl, _c, _len) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_BUFSIZ(_vl, _c, _len) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val.buffer = e_malloc(_len); \ if (__val->val.buffer) { \ __val->val_in ^= __val->val_in; \ __val->val_type = buffer; AIT_LEN(__val) = _len; \ memset(__val->val.buffer, _c, _len); \ } } while (0) -#define AIT_SET_BUF(_vl, _v, _len) do { ait_val_t *__val = (_vl); void *__p = (_v); assert(__val); \ +#define AIT_SET_BUF(_vl, _v, _len) do { ait_val_t *__val = (_vl); void *__p = (_v); \ + assert(__val && !AIT_CONST(__val)); \ __val->val.buffer = e_malloc(_len); \ if (__val->val.buffer) { \ __val->val_in ^= __val->val_in; \ @@ -158,7 +173,8 @@ typedef struct { else \ memset(__val->val.buffer, 0, _len); \ } } while (0) -#define AIT_SET_STR(_vl, _v) do { ait_val_t *__val = (_vl); const char *__s = (_v); assert(__val); \ +#define AIT_SET_STR(_vl, _v) do { ait_val_t *__val = (_vl); const char *__s = (_v); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = string; \ __val->val_in ^= __val->val_in; \ if (__s) { \ @@ -170,7 +186,8 @@ typedef struct { AIT_LEN(__val) = 0; \ } \ } while (0) -#define AIT_SET_STRSIZ(_vl, _len) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_STRSIZ(_vl, _len) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val.string = (int8_t*) e_malloc(_len + 1); \ if (__val->val.string) { \ __val->val_in ^= __val->val_in; \ @@ -179,7 +196,7 @@ typedef struct { } \ } while (0) #define AIT_SET_STRCAT(_vl, _v) do { ait_val_t *__val = (_vl); const char *__s = (_v); int __l; \ - assert(__val && !__val->val_in); \ + assert(__val && !__val->val_in && !AIT_CONST(__val)); \ assert(AIT_TYPE(__val) == string); \ if (!__s || !*__s) \ break; \ @@ -198,7 +215,7 @@ typedef struct { } \ } while (0) #define AIT_SET_STRCPY(_vl, _v) do { ait_val_t *__val = (_vl); const char *__s = (_v); int __l; \ - assert(__val && !__val->val_in); \ + assert(__val && !__val->val_in && !AIT_CONST(__val)); \ assert(AIT_TYPE(__val) == string); \ if (!__s || !*__s) \ break; \ @@ -212,7 +229,7 @@ typedef struct { AIT_LEN(__val)); \ } } while (0) #define AIT_SET_STRLCPY(_vl, _v, _len) do { ait_val_t *__val = (_vl); const char *__s = (_v); \ - assert(__val && !__val->val_in); \ + assert(__val && !__val->val_in && !AIT_CONST(__val)); \ assert(AIT_TYPE(__val) == string); \ if (!__s || !*__s) \ break; \ @@ -223,47 +240,59 @@ typedef struct { strlcpy((char*) __val->val.string, __s, \ AIT_LEN(__val)); \ } } while (0) -#define AIT_SET_BLOB(_vl, _n, _len) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_BLOB(_vl, _n, _len) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = blob; __val->val.blob = _n; \ AIT_LEN(__val) = _len; } while (0) -#define AIT_SET_BLOB2(_vl, _bv) do { ait_val_t *__val = (_vl); assert(__val); assert((_bv)); \ +#define AIT_SET_BLOB2(_vl, _bv) do { ait_val_t *__val = (_vl); assert((_bv)); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = blob; AIT_LEN(__val) = \ (_bv)->blob_len; \ __val->val.blob = (_bv)->blob_var; } while (0) #define AIT_NEW_BLOB(_vl, _len) AIT_SET_BLOB((_vl), 0, _len) -#define AIT_SET_U8(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_U8(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = u8; __val->val.u8 = _n; \ AIT_LEN(__val) = sizeof(uint8_t); } while (0) -#define AIT_SET_U16(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_U16(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = u16; __val->val.u16 = _n; \ AIT_LEN(__val) = sizeof(uint16_t); } while (0) -#define AIT_SET_U32(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_U32(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = u32; __val->val.u32 = _n; \ AIT_LEN(__val) = sizeof(uint32_t); } while (0) -#define AIT_SET_U64(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_U64(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = u64; __val->val.u64 = _n; \ AIT_LEN(__val) = sizeof(uint64_t); } while (0) -#define AIT_SET_I8(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_I8(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = i8; __val->val.i8 = _n; \ AIT_LEN(__val) = sizeof(int8_t); } while (0) -#define AIT_SET_I16(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_I16(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = i16; __val->val.i16 = _n; \ AIT_LEN(__val) = sizeof(int16_t); } while (0) -#define AIT_SET_I32(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_I32(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = i32; __val->val.i32 = _n; \ AIT_LEN(__val) = sizeof(int32_t); } while (0) -#define AIT_SET_I64(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_I64(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = i64; __val->val.i64 = _n; \ AIT_LEN(__val) = sizeof(int64_t); } while (0) -#define AIT_SET_F32(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_F32(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = f32; __val->val.f32 = _n; \ AIT_LEN(__val) = sizeof(float); } while (0) -#define AIT_SET_F64(_vl, _n) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_SET_F64(_vl, _n) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ __val->val_type = f64; __val->val.f64 = _n; \ AIT_LEN(__val) = sizeof(double); } while (0) -#define AIT_COPY_VAL(_vl, _v) do { assert((_vl)); assert((_v)); \ +#define AIT_COPY_VAL(_vl, _v) do { assert((_vl) && (_v) && !AIT_CONST((_vl))); \ memcpy((_vl), (_v), sizeof(ait_val_t)); \ switch (AIT_TYPE((_vl))) { \ case buffer: \ @@ -285,10 +314,11 @@ typedef struct { AIT_LEN((_v))); \ } while (0) -#define AIT_VAL_INITIALIZER(_vl) { .val_type = empty, .val_opt = 0, \ +#define AIT_VAL_INITIALIZER(_vl) { .val_type = empty, { .val_opt = 0 }, \ .val_key = 0, .val_len = 0, \ .val.net = 0LL \ } +#define AIT_VAL_INIT AIT_VAL_INITIALIZER() #define AIT_INIT_VAL(_vl) (memset((_vl), 0, sizeof(ait_val_t))) #define AIT_INIT_VAL2(_vl, _t) do { \ AIT_INIT_VAL((_vl)); \ @@ -317,7 +347,8 @@ typedef struct { AIT_LEN(__val) = 0; \ AIT_KEY(__val) = 0; \ } while (0) -#define AIT_ZERO_VAL(_vl) do { ait_val_t *__val = (_vl); assert(__val); \ +#define AIT_ZERO_VAL(_vl) do { ait_val_t *__val = (_vl); \ + assert(__val && !AIT_CONST(__val)); \ switch (AIT_TYPE(__val)) { \ case buffer: \ case string: \ @@ -474,6 +505,13 @@ void ait_freeVars(array_t ** __restrict vars); * return: NULL error or !=NULL ait_val_t element */ ait_val_t *ait_getVars(array_t ** __restrict vars, int n); +/* + * ait_resideVars() - Calculate footprint of resided variables into array + * + * @vars = Variable array + * return: bytes for whole array + */ +size_t ait_resideVars(array_t * __restrict vars); /* * ait_sortVarsByKey() - Sorting array with variables by key *