Wireshark-dev: Re: [Wireshark-dev] The RSVD dissector and 32-bit builds ...
From: Martin Mathieson <[email protected]>
Date: Mon, 16 Feb 2015 15:25:13 +0000
The idiom I use for keys that are > 32 bits is to have a function to return a key, with a 'persist' flag

e.g. in packet-pdcp-lte.c :

/* Convenience function to get a pointer for the hash_func to work with */
static gpointer get_report_hash_key(guint16 SN, guint32 frameNumber,
                                    pdcp_lte_info *p_pdcp_lte_info,
                                    gboolean do_persist)
{
    static pdcp_result_hash_key  key;
    pdcp_result_hash_key        *p_key;

    /* Only allocate a struct when will be adding entry */
    if (do_persist) {
        p_key = wmem_new(wmem_file_scope(), pdcp_result_hash_key);
    }
    else {
        memset(&key, 0, sizeof(pdcp_result_hash_key));
        p_key = &key;
    }

    /* Fill in details, and return pointer */
    p_key->frameNumber = frameNumber;
    p_key->SN = SN;
    p_key->plane = (guint8)p_pdcp_lte_info->plane;
    p_key->channelId = p_pdcp_lte_info->channelId;
    p_key->direction = p_pdcp_lte_info->direction;
    p_key->notUsed = 0;

    return p_key;
}

then call with do_persist=TRUE for storing, and FALSE for lookup

Martin

On Mon, Feb 16, 2015 at 3:11 PM, Evan Huus <[email protected]xxxxxxxx> wrote:
On Mon, Feb 16, 2015 at 10:08 AM, Richard Sharpe
<[email protected]> wrote:
> On Mon, Feb 16, 2015 at 6:55 AM, Evan Huus <[email protected]> wrote:
>> Create the wmem_map using g_int64_equal instead of g_direct_equal and
>> wmem_int64_hash instead of g_direct_hash. Create a wmem_file_scope()
>> copy of the key, and pass the resulting pointer to the insert
>> function.
>
> Hmmm, why do we need a wmem_file_scope() copy of the key? We get the
> key in each request and response and I don't store the key anywhere.

The map itself has to store the key in order to use it for future
lookups. When the key is only 32 bits you can make the pointer itself
store the key, and since the pointer gets copied you don't need an
explicit copy of the key. But when the pointer is just a pointer, you
need a file-scope copy of the key.
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <[email protected]>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:[email protected]?subject=unsubscribe