Remove hfinfo->bitshift member, add hfinfo_bitshift() to get it.
authordarkjames <darkjames@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 6 Aug 2013 20:10:59 +0000 (20:10 +0000)
committerdarkjames <darkjames@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 6 Aug 2013 20:10:59 +0000 (20:10 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@51174 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-tpncp.c
epan/dissectors/packet-xml.c
epan/proto.c
epan/proto.h
epan/wspython/wspy_proto.c
plugins/opcua/opcua_simpletypes.c
plugins/opcua/opcua_transport_layer.c
ui/gtk/packet_panes.c
ui/gtk/packet_win.c
ui/qt/byte_view_tab.cpp

index 92d2e17be52f0c634a89475652225c43752de609..e1ed09d0be073865cc57038a6e1efa1af2376a4a 100644 (file)
@@ -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;
 
index 495b9ab2e1992ccf949116842767eb7f5cdb7aff..9569167b387999281ddfe1bf26c83cc3d19a3ee9 100644 (file)
@@ -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;
 
index 280248cddf9483e4567921af52260de0762e90fa..03ee55fab602bd01bff0855c832041bd966f092f 100644 (file)
@@ -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 */
@@ -5562,6 +5533,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)
 {
@@ -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:
index 378dd38ea2525f3b87eb7b6a333e2b51cfa2c101..8dfd85a05bda64dcde41c62d5af64aed70f7b11c 100644 (file)
@@ -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"
 
index 10f7c070091f4069f97b4c26e1122a5432f5ccb9..e315a73e2a8a944a789043af5a494d741a613fd9 100644 (file)
@@ -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;
 }
index 14a446b532d444897245cce65fb7943e14688ea7..5ec23002e56f02183becd224dfc08e6ddd63037e 100644 (file)
@@ -252,7 +252,7 @@ void registerSimpleTypes(int proto)
 {
     static hf_register_info hf[] =
     {
-        /* full name  ,           abbreviation  ,       type     , display  , strings, bitmask, blurb, id, parent, ref_count, bitshift */
+        /* full name  ,           abbreviation  ,       type     , display  , strings, bitmask, blurb, id, parent, ref_count */
         { &hf_opcua_diag_mask_symbolicflag,
         {  "has symbolic id",           "opcua.has_symbolic_id", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG, NULL, HFILL }
         },
index 427a1f6c41306b49ce86cf7ff9cf94ecb94abedc..09b3735ebeaef6095eafc906eed5d62265fd0173 100644 (file)
@@ -60,7 +60,7 @@ void registerTransportLayerTypes(int proto)
     static hf_register_info hf[] =
     {
         { &hf_opcua_transport_type,
-        /* full name  ,           abbreviation  ,       type     , display  , strings, bitmask, blurb, id, parent, ref_count, bitshift */
+        /* full name  ,           abbreviation  ,       type     , display  , strings, bitmask, blurb, id, parent, ref_count */
         {  "Message Type",        "transport.type",     FT_STRING, BASE_NONE, NULL,    0x0,     NULL,    HFILL }
         },
         { &hf_opcua_transport_chunk,
index 242cc8bb3b5aa2515b283b1fd05a0b5670abe795..9ae9888abe784e24d86aeec6c3e05a1360f0657e 100644 (file)
@@ -933,7 +933,7 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd,
             bstart = finfo->start;
         }
 
-        /* bmask = finfo->hfinfo->bitmask << finfo->hfinfo->bitshift; */ /* (value & mask) >> shift */
+        /* bmask = finfo->hfinfo->bitmask << hfinfo_bitshift(finfo->hfinfo); */ /* (value & mask) >> shift */
         if (finfo->hfinfo) bmask = finfo->hfinfo->bitmask;
         astart = finfo->appendix_start;
         alen = finfo->appendix_length;
index 6e52c3438c45ccfab034f64f826667654d88d878..5c8ee53656c0b46400a8331fc2039c861bd8326b 100644 (file)
@@ -406,8 +406,8 @@ finfo_integer_changed(GtkSpinButton *spinbutton, gpointer user_data)
                return;
        }
 
-       if (hfinfo->bitmask && hfinfo->bitshift > 0)
-               u_val <<= hfinfo->bitshift;
+       if (hfinfo->bitmask)
+               u_val <<= hfinfo_bitshift(hfinfo);
 
        finfo_integer_common(DataPtr, u_val);
 }
@@ -578,8 +578,8 @@ new_finfo_window(GtkWidget *w, struct FieldinfoWinData *DataPtr)
                if (finfo->length * 8 < bitcount)
                        bitcount = finfo->length / 8;
 
-               if (hfinfo->bitmask && hfinfo->bitshift > 0)
-                       bitcount -= hfinfo->bitshift;
+               if (hfinfo->bitmask)
+                       bitcount -= hfinfo_bitshift(hfinfo);
 
                /* XXX, hfinfo->bitmask: Can we configure GTK_ADJUSTMENT to do custom step? (value-changed signal?) */
 
index d9fa9877dee5c690794b4cb5f7ebf626a3a0cb8e..225781681a384096ab7a2e85f7d5abec05ab5232 100644 (file)
@@ -114,7 +114,7 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) {
                     f_len = fi->length;
                 }
 
-                /* bmask = finfo->hfinfo->bitmask << finfo->hfinfo->bitshift; */ /* (value & mask) >> shift */
+                /* bmask = finfo->hfinfo->bitmask << hfinfo_bitshift(finfo->hfinfo); */ /* (value & mask) >> shift */
                 if (fi->hfinfo) bmask = fi->hfinfo->bitmask;
                 fa_start = fi->appendix_start;
                 fa_len = fi->appendix_length;