aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2013-08-06 20:10:59 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2013-08-06 20:10:59 +0000
commit72ea2f9c9c63c7e5c6270383888ad32683d96edf (patch)
treec58a12fbefc4c245ec132d2c7db06486a6981945 /epan
parent93f56d8a770e9a29bfeb27f0698ae25ae89206a9 (diff)
Remove hfinfo->bitshift member, add hfinfo_bitshift() to get it.
svn path=/trunk/; revision=51174
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-tpncp.c1
-rw-r--r--epan/dissectors/packet-xml.c1
-rw-r--r--epan/proto.c63
-rw-r--r--epan/proto.h8
-rw-r--r--epan/wspython/wspy_proto.c1
5 files changed, 31 insertions, 43 deletions
diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c
index 92d2e17be5..e1ed09d0be 100644
--- a/epan/dissectors/packet-tpncp.c
+++ b/epan/dissectors/packet-tpncp.c
@@ -583,7 +583,6 @@ static gint init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info,
hf_entr.hfinfo.id = 0;
hf_entr.hfinfo.parent = 0;
hf_entr.hfinfo.ref_type = HF_REF_TYPE_NONE;
- hf_entr.hfinfo.bitshift = 0;
hf_entr.hfinfo.same_name_next = NULL;
hf_entr.hfinfo.same_name_prev = NULL;
diff --git a/epan/dissectors/packet-xml.c b/epan/dissectors/packet-xml.c
index 495b9ab2e1..9569167b38 100644
--- a/epan/dissectors/packet-xml.c
+++ b/epan/dissectors/packet-xml.c
@@ -816,7 +816,6 @@ static void add_xml_field(wmem_array_t *hfs, int *p_id, const gchar *name, const
hfri.hfinfo.id = 0;
hfri.hfinfo.parent = 0;
hfri.hfinfo.ref_type = HF_REF_TYPE_NONE;
- hfri.hfinfo.bitshift = 0;
hfri.hfinfo.same_name_next = NULL;
hfri.hfinfo.same_name_prev = NULL;
diff --git a/epan/proto.c b/epan/proto.c
index 280248cddf..03ee55fab6 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -71,22 +71,6 @@ struct ptvcursor {
gint offset;
};
-static int
-wrs_count_bitshift(const guint32 bitmask)
-{
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
- return __builtin_ctz(bitmask);
-#else
- /* From http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
- static const int table[32] = {
- 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
- 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
- };
-
- return table[((guint32)((bitmask & -(gint32)bitmask) * 0x077CB531U)) >> 27];
-#endif
-}
-
#define cVALS(x) (const value_string*)(x)
/** See inlined comments.
@@ -3023,9 +3007,7 @@ proto_tree_set_uint(field_info *fi, guint32 value)
integer &= hfinfo->bitmask;
/* Shift bits */
- if (hfinfo->bitshift > 0) {
- integer >>= hfinfo->bitshift;
- }
+ integer >>= hfinfo_bitshift(hfinfo);
}
fvalue_set_uinteger(&fi->value, integer);
@@ -3169,9 +3151,7 @@ proto_tree_set_int(field_info *fi, gint32 value)
integer &= hfinfo->bitmask;
/* Shift bits */
- if (hfinfo->bitshift > 0) {
- integer >>= hfinfo->bitshift;
- }
+ integer >>= hfinfo_bitshift(hfinfo);
}
fvalue_set_sinteger(&fi->value, integer);
@@ -3572,8 +3552,7 @@ proto_tree_set_representation_value(proto_item *pi, const char *format, va_list
char *p;
val = fvalue_get_uinteger(&fi->value);
- if (hf->bitshift > 0)
- val <<= hf->bitshift;
+ val <<= hfinfo_bitshift(hf);
p = decode_bitfield_value(fi->rep->representation, val, hf->bitmask, hfinfo_bitwidth(hf));
ret = (int) (p - fi->rep->representation);
@@ -4390,7 +4369,6 @@ proto_register_protocol(const char *name, const char *short_name,
hfinfo->display = BASE_NONE;
hfinfo->strings = protocol;
hfinfo->bitmask = 0;
- hfinfo->bitshift = 0;
hfinfo->ref_type = HF_REF_TYPE_NONE;
hfinfo->blurb = NULL;
hfinfo->parent = -1; /* this field differentiates protos and fields */
@@ -4979,11 +4957,6 @@ proto_register_field_init(header_field_info *hfinfo, const int parent)
tmp_fld_check_assert(hfinfo);
- /* if this is a bitfield, compute bitshift */
- if (hfinfo->bitmask) {
- hfinfo->bitshift = wrs_count_bitshift(hfinfo->bitmask);
- }
-
hfinfo->parent = parent;
hfinfo->same_name_next = NULL;
hfinfo->same_name_prev = NULL;
@@ -5373,9 +5346,7 @@ fill_label_boolean(field_info *fi, gchar *label_str)
/* Un-shift bits */
unshifted_value = value;
- if (hfinfo->bitshift > 0) {
- unshifted_value <<= hfinfo->bitshift;
- }
+ unshifted_value <<= hfinfo_bitshift(hfinfo);
/* Create the bitfield first */
p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
@@ -5453,8 +5424,8 @@ fill_label_bitfield(field_info *fi, gchar *label_str)
/* Un-shift bits */
unshifted_value = fvalue_get_uinteger(&fi->value);
value = unshifted_value;
- if (hfinfo->bitshift > 0) {
- unshifted_value <<= hfinfo->bitshift;
+ if (hfinfo->bitmask) {
+ unshifted_value <<= hfinfo_bitshift(hfinfo);
}
/* Create the bitfield first */
@@ -5563,6 +5534,26 @@ fill_label_number64(field_info *fi, gchar *label_str, gboolean is_signed)
}
int
+hfinfo_bitshift(const header_field_info *hfinfo)
+{
+ const guint32 bitmask = hfinfo->bitmask;
+
+ g_assert(bitmask != 0);
+
+#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+ return __builtin_ctz(bitmask);
+#else
+ /* From http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
+ static const int table[32] = {
+ 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+ 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
+ };
+
+ return table[((guint32)((bitmask & -(gint32)bitmask) * 0x077CB531U)) >> 27];
+#endif
+}
+
+int
hfinfo_bitwidth(const header_field_info *hfinfo)
{
int bitwidth = 0;
@@ -6738,7 +6729,7 @@ proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset,
fields++;
continue;
}
- tmpval = (value & hf->bitmask) >> hf->bitshift;
+ tmpval = (value & hf->bitmask) >> hfinfo_bitshift(hf);
switch (hf->type) {
case FT_INT8:
diff --git a/epan/proto.h b/epan/proto.h
index 378dd38ea2..8dfd85a05b 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -373,7 +373,7 @@ struct _header_field_info {
int id; /**< Field ID */
int parent; /**< parent protocol tree */
hf_ref_type ref_type; /**< is this field referenced by a filter */
- int bitshift; /**< bits to shift */
+ /* 4B padding */
header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev */
header_field_info *same_name_prev; /**< Link to previous hfinfo with same abbrev */
};
@@ -383,7 +383,7 @@ struct _header_field_info {
* _header_field_info. If new fields are added or removed, it should
* be changed as necessary.
*/
-#define HFILL 0, 0, HF_REF_TYPE_NONE, 0, NULL, NULL
+#define HFILL 0, 0, HF_REF_TYPE_NONE, NULL, NULL
/** Used when registering many fields at once, using proto_register_field_array() */
typedef struct hf_register_info {
@@ -1863,8 +1863,8 @@ WS_DLL_PUBLIC void tree_expanded_set(int tree_type, gboolean value);
extern int
hfinfo_bitwidth(const header_field_info *hfinfo);
-
-
+WS_DLL_PUBLIC int
+hfinfo_bitshift(const header_field_info *hfinfo);
#include "epan.h"
diff --git a/epan/wspython/wspy_proto.c b/epan/wspython/wspy_proto.c
index 10f7c07009..e315a73e2a 100644
--- a/epan/wspython/wspy_proto.c
+++ b/epan/wspython/wspy_proto.c
@@ -69,7 +69,6 @@ void hf_register_info_add(hf_register_info *hf, guint8 index,
hf[index].hfinfo.id = 0;
hf[index].hfinfo.parent = 0;
hf[index].hfinfo.ref_type = HF_REF_TYPE_NONE;
- hf[index].hfinfo.bitshift = 0;
hf[index].hfinfo.same_name_next = NULL;
hf[index].hfinfo.same_name_prev = NULL;
}