--- libelwix/inc/elwix/avar.h 2013/08/20 22:26:54 1.5 +++ libelwix/inc/elwix/avar.h 2019/08/16 15:29:51 1.10.42.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: avar.h,v 1.5 2013/08/20 22:26:54 misho Exp $ +* $Id: avar.h,v 1.10.42.2 2019/08/16 15:29:51 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 - 2019 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -57,7 +57,7 @@ typedef enum { i8, i16, i32, i64, /* integers ... */ } ait_type_t; -typedef struct { +typedef struct __packed { uint8_t val_type; union { struct { @@ -93,7 +93,7 @@ typedef struct { int64_t i64; } val; uint8_t val_data[0]; -} __packed ait_val_t; /* sizeof 16 bytes */ +} /*__packed*/ ait_val_t; /* sizeof 16 bytes */ #define AIT_TYPE(_vl) ((ait_type_t) (_vl)->val_type) #define AIT_LEN(_vl) (_vl)->val_len @@ -304,20 +304,21 @@ typedef struct { AIT_SET_STR((_vl), \ AIT_GET_STR((_v))); \ break; \ + case data: \ + AIT_SET_DATA((_vl), \ + AIT_GET_DATA((_v)), \ + AIT_LEN((_v))); \ + break; \ default: \ break; \ } \ } while (0) -#define AIT_COPY_DATA(_vl, _v) do { AIT_COPY_VAL((_vl), (_v)); \ - if (AIT_TYPE((_vl)) == data) \ - AIT_SET_DATA((_vl), AIT_GET_DATA((_v)), \ - AIT_LEN((_v))); \ - } while (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)); \ @@ -330,19 +331,23 @@ typedef struct { if (!__val->val_in && \ __val->val.buffer) \ e_free(__val->val.buffer); \ - __val->val.buffer = NULL; \ break; \ case string: \ if (!__val->val_in && \ __val->val.string) \ e_free(__val->val.string); \ - __val->val.string = NULL; \ break; \ + case data: \ + if (!__val->val_in) \ + memset(__val->val_data, 0, \ + AIT_LEN(__val)); \ + break; \ default: \ break; \ } \ __val->val_type = empty; \ __val->val_opt ^= __val->val_opt; \ + __val->val.net ^= __val->val.net; \ AIT_LEN(__val) = 0; \ AIT_KEY(__val) = 0; \ } while (0) @@ -504,6 +509,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 *