From 76cc1ea613e038ced4bc6ae26233cb0681b63be5 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Fri, 28 Sep 2018 13:03:38 +0530 Subject: libglusterfs/dict: Add sizeof()-1 variants of dict functions One needs to be very careful about giving same key for the key and SLEN(key) arguments in dict_xxxn() functions. Writing macros that would take care of passing the SLEN(key) would help reduce this burden on the developer and reviewer. updates: bz#1193929 Change-Id: I312c479b919826570b47ae2c219c53e2f9b2ddef Signed-off-by: Pranith Kumar K --- libglusterfs/src/dict.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libglusterfs/src/dict.h') diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 45cdb33ec9e..6cbf0ce5a54 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -22,6 +22,35 @@ typedef struct _data data_t; typedef struct _dict dict_t; typedef struct _data_pair data_pair_t; +#define dict_set_sizen(this, key, value) dict_setn(this, key, SLEN(key), value) + +#define dict_add_sizen(this, key, value) dict_addn(this, key, SLEN(key), value) + +#define dict_get_with_ref_sizen(this, key, value) \ + dict_get_with_refn(this, key, SLEN(key), value) + +#define dict_get_sizen(this, key) dict_getn(this, key, SLEN(key)) + +#define dict_del_sizen(this, key) dict_deln(this, key, SLEN(key)) + +#define dict_set_str_sizen(this, key, str) \ + dict_set_strn(this, key, SLEN(key), str) + +#define dict_set_sizen_str_sizen(this, key, str) \ + dict_set_nstrn(this, key, SLEN(key), str, SLEN(str)) + +#define dict_set_dynstr_sizen(this, key, str) \ + dict_set_dynstrn(this, key, SLEN(key), str) + +#define dict_get_str_sizen(this, key, str) \ + dict_get_strn(this, key, SLEN(key), str) + +#define dict_get_int32_sizen(this, key, val) \ + dict_get_int32n(this, key, SLEN(key), val) + +#define dict_set_int32_sizen(this, key, val) \ + dict_set_int32n(this, key, SLEN(key), val) + #define GF_PROTOCOL_DICT_SERIALIZE(this, from_dict, to, len, ope, labl) \ do { \ int _ret = 0; \ -- cgit