Use GSlice API instead of GMemChunk API for some memory allocation.
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 16 Jan 2012 19:05:32 +0000 (19:05 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 16 Jan 2012 19:05:32 +0000 (19:05 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@40547 f5534014-38df-0310-8fa8-9805f1628bb7

plugins/mate/mate.h
plugins/mate/mate_runtime.c
plugins/mate/mate_util.c
plugins/mate/mate_util.h

index a326123b2a99e5060bbfb38e0d6b737eae78ee6c..d14e88cbe492c8ccee0ce995b3ed5c4d3ba54c96 100644 (file)
 # include "config.h"
 #endif
 
-/* The mate dissector is using deprecated GMemChunk. Do not error out
- * when encountering it.
- */
-#undef G_DISABLE_DEPRECATED
-
 #ifndef ENABLE_STATIC
 #include "moduleinfo.h"
 #include <gmodule.h>
@@ -274,7 +269,6 @@ typedef struct _mate_config_frame {
 
 typedef struct _mate_runtime_data {
        guint current_items; /* a count of items */
-       GMemChunk* mate_items;
        float now;
        guint highest_analyzed_frame;
 
index 62024e332863451400581ab812ccb308faccdeb3..39489005ecf2807180aac5f672fb478be636f702 100644 (file)
@@ -61,7 +61,7 @@ static FILE* dbg_facility = NULL;
 static gboolean destroy_mate_pdus(gpointer k _U_, gpointer v, gpointer p _U_) {
        mate_pdu* pdu = (mate_pdu*) v;
        if (pdu->avpl) delete_avpl(pdu->avpl,TRUE);
-       g_mem_chunk_free(rd->mate_items,pdu);
+       g_slice_free(mate_max_size, (mate_max_size *)pdu);
        return TRUE;
 }
 
@@ -78,7 +78,7 @@ static gboolean destroy_mate_gops(gpointer k _U_, gpointer v, gpointer p _U_) {
                g_free(gop->gop_key);
        }
 
-       g_mem_chunk_free(rd->mate_items,gop);
+       g_slice_free(mate_max_size,(mate_max_size*)gop);
 
        return TRUE;
 }
@@ -96,7 +96,7 @@ static gboolean destroy_mate_gogs(gpointer k _U_, gpointer v, gpointer p _U_) {
                g_ptr_array_free(gog->gog_keys,FALSE);
        }
 
-       g_mem_chunk_free(rd->mate_items,gog);
+       g_slice_free(mate_max_size,(mate_max_size*)gog);
 
        return TRUE;
 }
@@ -140,7 +140,6 @@ extern void initialize_mate_runtime(void) {
        if (( mc = mate_cfg() )) {
                if (rd == NULL ) {
                        rd = g_malloc(sizeof(mate_runtime_data));
-                       rd->mate_items = g_mem_chunk_new("mate_items",sizeof(mate_max_size),1024,G_ALLOC_AND_FREE);
                } else {
                        g_hash_table_foreach(mc->pducfgs,destroy_pdus_in_cfg,NULL);
                        g_hash_table_foreach(mc->gopcfgs,destroy_gops_in_cfg,NULL);
@@ -173,7 +172,7 @@ extern void initialize_mate_runtime(void) {
 
 
 static mate_gop* new_gop(mate_cfg_gop* cfg, mate_pdu* pdu, gchar* key) {
-       mate_gop* gop = g_mem_chunk_alloc(rd->mate_items);
+       mate_gop* gop = (mate_gop*)g_slice_new(mate_max_size);
 
        gop->id = ++(cfg->last_id);
        gop->cfg = cfg;
@@ -237,8 +236,7 @@ static void adopt_gop(mate_gog* gog, mate_gop* gop) {
 }
 
 static mate_gog* new_gog(mate_cfg_gog* cfg, mate_gop* gop) {
-       mate_gog* gog = g_mem_chunk_alloc(rd->mate_items);
-
+       mate_gog* gog = (mate_gog*)g_slice_new(mate_max_size);
        gog->id = ++(cfg->last_id);
        gog->cfg = cfg;
 
@@ -709,7 +707,7 @@ static void get_pdu_fields(gpointer k, gpointer v, gpointer p) {
 }
 
 static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto, proto_tree* tree) {
-       mate_pdu* pdu = g_mem_chunk_alloc(rd->mate_items);
+       mate_pdu* pdu = (mate_pdu*)g_slice_new(mate_max_size);
        field_info* cfi;
        GPtrArray* ptrs;
        mate_range* range;
@@ -880,7 +878,7 @@ extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree) {
                                                         || ( ! criterium_match && cfg->criterium_accept_mode == ACCEPT_MODE )) {
 
                                                        delete_avpl(pdu->avpl,TRUE);
-                                                       g_mem_chunk_free(rd->mate_items,pdu);
+                                                       g_slice_free(mate_max_size,(mate_max_size*)pdu);
                                                        pdu = NULL;
 
                                                        continue;
@@ -891,7 +889,7 @@ extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree) {
 
                                        if ( ! pdu->gop && cfg->drop_unassigned) {
                                                delete_avpl(pdu->avpl,TRUE);
-                                               g_mem_chunk_free(rd->mate_items,pdu);
+                                               g_slice_free(mate_max_size,(mate_max_size*)pdu);
                                                pdu = NULL;
                                                continue;
                                        }
index 151fc62d1770230a997a6f79388592f2960b1f4f..4b6755ef090fb453c382685762e26a5ee1682495 100644 (file)
@@ -82,50 +82,30 @@ void dbg_print(const gint* which, gint how, FILE* where, const gchar* fmt, ... )
 
 /**
  * scs_init:
- * @collection: the scs hash
  *
  *  Initializes the scs hash.
  **/
 
-/* Don't call variables "small" or "huge". They are keywords for the MSVC compiler. Rename them to "mate_small" and "mate_huge"*/
 struct _scs_collection {
        GHashTable* hash;       /* key: a string value: guint number of subscribers */
-       GMemChunk* ctrs;
-       GMemChunk* mate_small;
-       GMemChunk* mate_medium;
-       GMemChunk* mate_large;
-       GMemChunk* mate_huge;
 };
 
-extern void destroy_scs_collection(SCS_collection* c) {
-       if ( c->ctrs ) g_mem_chunk_destroy(c->ctrs);
-       if ( c->mate_small ) g_mem_chunk_destroy(c->mate_small);
-       if ( c->mate_medium ) g_mem_chunk_destroy(c->mate_medium);
-       if ( c->mate_large ) g_mem_chunk_destroy(c->mate_large);
-       if ( c->mate_huge ) g_mem_chunk_destroy(c->mate_huge);
-
-       if (c->hash) g_hash_table_destroy(c->hash);
+/* ToDo? free any string,ctr entries pointed to by the hash table ??
+ *       XXX: AFAIKT destroy_scs_collection() might be called only when reading a
+ *         mate config file. Since reading a new config file can apparently currently
+ *         only be done once after starting Wireshark, in theory this fcn
+ *         currently should never be called since there will never be an existing
+ *         scs_collection to be destroyed.
+ */
+static void destroy_scs_collection(SCS_collection* c) {
+    if (c->hash) g_hash_table_destroy(c->hash);
 }
 
-extern SCS_collection* scs_init(void) {
+static SCS_collection* scs_init(void) {
        SCS_collection* c = g_malloc(sizeof(SCS_collection));
 
        c->hash =  g_hash_table_new(g_str_hash,g_str_equal);
 
-       c->ctrs = g_mem_chunk_new("ints_scs_chunk", sizeof(guint),
-                                                          sizeof(guint) * SCS_SMALL_CHUNK_SIZE, G_ALLOC_AND_FREE);
-
-       c->mate_small = g_mem_chunk_new("small_scs_chunk", SCS_SMALL_SIZE,
-                                                          SCS_SMALL_SIZE * SCS_SMALL_CHUNK_SIZE, G_ALLOC_AND_FREE);
-
-       c->mate_medium = g_mem_chunk_new("medium_scs_chunk", SCS_MEDIUM_SIZE,
-                                                          SCS_MEDIUM_SIZE * SCS_MEDIUM_CHUNK_SIZE, G_ALLOC_AND_FREE);
-
-       c->mate_large = g_mem_chunk_new("large_scs_chunk", SCS_LARGE_SIZE,
-                                                          SCS_LARGE_SIZE * SCS_LARGE_CHUNK_SIZE, G_ALLOC_AND_FREE);
-
-       c->mate_huge = g_mem_chunk_new("huge_scs_chunk", SCS_HUGE_SIZE,
-                                                          SCS_HUGE_SIZE * SCS_HUGE_CHUNK_SIZE, G_ALLOC_AND_FREE);
        return c;
 }
 
@@ -146,37 +126,31 @@ gchar* scs_subscribe(SCS_collection* c, const gchar* s) {
        gchar* orig = NULL;
        guint* ip = NULL;
        size_t len = 0;
-       GMemChunk* chunk = NULL;
 
        g_hash_table_lookup_extended(c->hash,(gconstpointer)s,(gpointer)&orig,(gpointer)&ip);
 
        if (ip) {
                (*ip)++;
        } else {
-               ip = g_mem_chunk_alloc(c->ctrs);
+               ip = g_slice_new(guint);
                *ip = 0;
 
                len = strlen(s) + 1;
 
                if (len <= SCS_SMALL_SIZE) {
-                       chunk = c->mate_small;
                        len = SCS_SMALL_SIZE;
                } else if (len <= SCS_MEDIUM_SIZE) {
-                       chunk = c->mate_medium;
                        len = SCS_MEDIUM_SIZE;
                } else if (len <= SCS_LARGE_SIZE) {
-                       chunk = c->mate_large;
                        len = SCS_LARGE_SIZE;
                } else if (len < SCS_HUGE_SIZE) {
-                       chunk = c->mate_huge;
                        len = SCS_HUGE_SIZE;
                } else {
-                       chunk = c->mate_huge;
                        len = SCS_HUGE_SIZE;
                        g_warning("mate SCS: string truncated due to huge size");
                }
 
-               orig = g_mem_chunk_alloc(chunk);
+                orig = g_slice_alloc(len);
                g_strlcpy(orig,s,len);
 
                g_hash_table_insert(c->hash,orig,ip);
@@ -197,7 +171,6 @@ void scs_unsubscribe(SCS_collection* c, gchar* s) {
        gchar* orig = NULL;
        guint* ip = NULL;
        size_t len = 0xffff;
-       GMemChunk* chunk = NULL;
 
        g_hash_table_lookup_extended(c->hash,(gconstpointer)s,(gpointer)&orig,(gpointer)&ip);
 
@@ -208,17 +181,17 @@ void scs_unsubscribe(SCS_collection* c, gchar* s) {
                        len = strlen(orig);
 
                        if (len < SCS_SMALL_SIZE) {
-                               chunk = c->mate_small;
+                               len = SCS_SMALL_SIZE;
                        } else if (len < SCS_MEDIUM_SIZE) {
-                               chunk = c->mate_medium;
+                               len = SCS_MEDIUM_SIZE;
                        } else if (len < SCS_LARGE_SIZE) {
-                               chunk = c->mate_large;
+                               len = SCS_LARGE_SIZE;
                        } else {
-                               chunk = c->mate_huge;
+                               len = SCS_HUGE_SIZE;
                        }
 
-                       g_mem_chunk_free(chunk,orig);
-                       g_mem_chunk_free(c->ctrs,ip);
+                       g_slice_free1(len, orig);
+                       g_slice_free(guint,ip);
                }
                else {
                        (*ip)--;
@@ -252,7 +225,7 @@ gchar* scs_subscribe_printf(SCS_collection* c, gchar* fmt, ...) {
 *  AVPs & Co.
 ***************************************************************************
 * The Thing operates mainly on avps, avpls and loals
-* - attribute value pairs (two strings: the name and the value and an opeartor)
+* - attribute value pairs (two strings: the name and the value and an operator)
 * - avp lists a somehow sorted list of avps
 * - loal (list of avp lists) an arbitrarily sorted list of avpls
 *
@@ -269,7 +242,6 @@ typedef union _any_avp_type {
 } any_avp_type;
 
 
-static GMemChunk* avp_chunk = NULL;
 static SCS_collection* avp_strings = NULL;
 
 #ifdef _AVP_DEBUGGING
@@ -299,7 +271,7 @@ static int* dbg_avpl_op = &dbg_avpl_op_level;
  * @avpl: a pointer to the level of debugging of facility "avpl"
  * @avpl_op: a pointer to the level of debugging of facility "avpl_op"
  *
- * If enabled set's up the debug facilities for the avp library.
+ * If enabled sets up the debug facilities for the avp library.
  *
  **/
 extern void setup_avp_debug(FILE* fp, int* general, int* avp, int* avp_op, int* avpl, int* avpl_op) {
@@ -315,7 +287,6 @@ extern void setup_avp_debug(FILE* fp, int* general, int* avp, int* avp_op, int*
 
 /**
  * avp_init:
- * @chunk_size: the initial chunk's size.
  *
  * (Re)Initializes the avp library.
  *
@@ -325,13 +296,8 @@ extern void avp_init(void) {
        if (avp_strings) destroy_scs_collection(avp_strings);
        avp_strings = scs_init();
 
-       if ( avp_chunk ) g_mem_chunk_destroy(avp_chunk);
-       avp_chunk = g_mem_chunk_new("avp_chunk", sizeof(any_avp_type),
-                                                               AVP_CHUNK_SIZE, G_ALLOC_AND_FREE);
-
 }
 
-
 /**
  * new_avp_from_finfo:
  * @name: the name the avp will have.
@@ -343,7 +309,7 @@ extern void avp_init(void) {
  *
  **/
 extern AVP* new_avp_from_finfo(const gchar* name, field_info* finfo) {
-       AVP* new = g_mem_chunk_alloc(avp_chunk);
+       AVP*   new = (AVP*)g_slice_new(any_avp_type);
        gchar* value;
 
        new->n = scs_subscribe(avp_strings, name);
@@ -384,7 +350,7 @@ extern AVP* new_avp_from_finfo(const gchar* name, field_info* finfo) {
  *
  **/
 extern AVP* new_avp(const gchar* name, const gchar* value, gchar o) {
-       AVP* new = g_mem_chunk_alloc(avp_chunk);
+       AVP* new = (AVP*)g_slice_new(any_avp_type);
 
        new->n = scs_subscribe(avp_strings, name);
        new->v = scs_subscribe(avp_strings, value);
@@ -411,7 +377,7 @@ extern void delete_avp(AVP* avp) {
 
        scs_unsubscribe(avp_strings, avp->n);
        scs_unsubscribe(avp_strings, avp->v);
-       g_mem_chunk_free(avp_chunk,avp);
+       g_slice_free(any_avp_type,(any_avp_type*)avp);
 }
 
 
@@ -419,13 +385,13 @@ extern void delete_avp(AVP* avp) {
 * avp_copy:
  * @from: the avp to be copied.
  *
- * Creates an avp whose name op and value are copyes of the given one.
+ * Creates an avp whose name op and value are copies of the given one.
  *
  * Return value: a pointer to the newly created avp.
  *
  **/
 extern AVP* avp_copy(AVP* from) {
-       AVP* new = g_mem_chunk_alloc(avp_chunk);
+       AVP* new = (AVP*)g_slice_new(any_avp_type);
 
        new->n = scs_subscribe(avp_strings, from->n);
        new->v = scs_subscribe(avp_strings, from->v);
@@ -448,7 +414,7 @@ extern AVP* avp_copy(AVP* from) {
  *
  **/
 extern AVPL* new_avpl(const gchar* name) {
-       AVPL* new_avpl_p = g_mem_chunk_alloc(avp_chunk);
+       AVPL* new_avpl_p = (AVPL*)g_slice_new(any_avp_type);
 
 #ifdef _AVP_DEBUGGING
        dbg_print(dbg_avpl_op,7,dbg_fp,"new_avpl_p: %X name=%s",new_avpl_p,name);
@@ -482,7 +448,7 @@ extern void rename_avpl(AVPL* avpl, gchar* name) {
  *         it is not inserted.
  **/
 extern gboolean insert_avp(AVPL* avpl, AVP* avp) {
-       AVPN* new = g_mem_chunk_alloc(avp_chunk);
+       AVPN* new = (AVPN*)g_slice_new(any_avp_type);
        AVPN* c;
 
        new->avp = avp;
@@ -506,7 +472,7 @@ extern gboolean insert_avp(AVPL* avpl, AVP* avp) {
 #ifdef _AVP_DEBUGGING
                                        dbg_print(dbg_avpl_op,7,dbg_fp,"delete_avpn: %X",new);
 #endif
-                                       g_mem_chunk_free(avp_chunk,new);
+                                       g_slice_free(any_avp_type,(any_avp_type*)new);
                                        return FALSE;
                                }
                        }
@@ -611,7 +577,7 @@ extern AVP* extract_avp_by_name(AVPL* avpl, gchar* name) {
 
        avp = curr->avp;
 
-       g_mem_chunk_free(avp_chunk,curr);
+       g_slice_free(any_avp_type,(any_avp_type*)curr);
 
        (avpl->len)--;
 
@@ -652,7 +618,7 @@ extern AVP* extract_first_avp(AVPL* avpl) {
        avp = node->avp;
 
        if (avp) {
-               g_mem_chunk_free(avp_chunk,node);
+               g_slice_free(any_avp_type,(any_avp_type*)node);
                (avpl->len)--;
 #ifdef _AVP_DEBUGGING
                dbg_print(dbg_avpl,4,dbg_fp,"avpl: %X new len: %i",avpl,avpl->len);
@@ -689,7 +655,7 @@ extern AVP* extract_last_avp(AVPL* avpl) {
        avp = node->avp;
 
        if (avp) {
-               g_mem_chunk_free(avp_chunk,node);
+               g_slice_free(any_avp_type,(any_avp_type*)node);
                (avpl->len)--;
 #ifdef _AVP_DEBUGGING
                dbg_print(dbg_avpl,4,dbg_fp,"avpl: %X new len: %i",avpl,avpl->len);
@@ -727,7 +693,7 @@ extern void delete_avpl(AVPL* avpl, gboolean avps_too) {
        }
 
        scs_unsubscribe(avp_strings,avpl->name);
-       g_mem_chunk_free(avp_chunk,avpl);
+       g_slice_free(any_avp_type,(any_avp_type*)avpl);
 }
 
 
@@ -1357,7 +1323,7 @@ extern void avpl_transform(AVPL* src, AVPL_Transf* op) {
 
                                                        cs->prev->next = cs->next;
                                                        cs->next->prev = cs->prev;
-                                                       g_mem_chunk_free(avp_chunk,cs);
+                                                       g_slice_free(any_avp_type,(any_avp_type*)cs);
 
                                                        cs = n;
                                                        cm = cm->next;
@@ -1384,7 +1350,7 @@ extern void avpl_transform(AVPL* src, AVPL_Transf* op) {
  * Return value: a pointer to the newly created loal.
  **/
 extern LoAL* new_loal(const gchar* name) {
-       LoAL* new_loal_p = g_mem_chunk_alloc(avp_chunk);
+       LoAL* new_loal_p = (LoAL*)g_slice_new(any_avp_type);
 
        if (! name) {
                name = "anonymous";
@@ -1411,7 +1377,7 @@ extern LoAL* new_loal(const gchar* name) {
  *
  **/
 extern void loal_append(LoAL* loal, AVPL* avpl) {
-       LoALnode* node = g_mem_chunk_alloc(avp_chunk);
+       LoALnode* node = (LoALnode*)g_slice_new(any_avp_type);
 
 #ifdef _AVP_DEBUGGING
        dbg_print(dbg_avpl_op,3,dbg_fp,"new_loal_node: %X",node);
@@ -1454,7 +1420,7 @@ extern AVPL* extract_first_avpl(LoAL* loal) {
        avpl = node->avpl;
 
        if ( avpl ) {
-               g_mem_chunk_free(avp_chunk,node);
+               g_slice_free(any_avp_type,(any_avp_type*)node);
 
 #ifdef _AVP_DEBUGGING
                dbg_print(dbg_avpl_op,3,dbg_fp,"extract_first_avpl: got %s",avpl->name);
@@ -1488,7 +1454,7 @@ extern AVPL* extract_last_avpl(LoAL* loal){
        avpl = node->avpl;
 
        if ( avpl ) {
-               g_mem_chunk_free(avp_chunk,node);
+               g_slice_free(any_avp_type,(any_avp_type*)node);
 #ifdef _AVP_DEBUGGING
                dbg_print(dbg_avpl_op,3,dbg_fp,"delete_loal_node: %X",node);
 #endif
@@ -1549,7 +1515,7 @@ extern void delete_loal(LoAL* loal, gboolean avpls_too, gboolean avps_too) {
        }
 
        scs_unsubscribe(avp_strings,loal->name);
-       g_mem_chunk_free(avp_chunk,loal);
+       g_slice_free(any_avp_type,(any_avp_type*)loal);
 }
 
 
index d5a82260ee842b69812d006b3e08f4e7593057e4..d3759ecc5d8195dbdb91c38fcccaee78fa9f85d1 100644 (file)
@@ -49,25 +49,17 @@ typedef struct _scs_collection SCS_collection;
 #define SCS_LARGE_SIZE 4096
 #define SCS_HUGE_SIZE 65536
 
-#define SCS_SMALL_CHUNK_SIZE 4096
-#define SCS_MEDIUM_CHUNK_SIZE 1024
-#define SCS_LARGE_CHUNK_SIZE 256
-#define SCS_HUGE_CHUNK_SIZE 128
-
-extern void destroy_scs_collection(SCS_collection* c);
-extern SCS_collection* scs_init(void);
 extern gchar* scs_subscribe(SCS_collection* collection, const gchar* s);
 extern void scs_unsubscribe(SCS_collection* collection, gchar* s);
 extern gchar* scs_subscribe_printf(SCS_collection* collection, gchar* fmt, ...);
 
 /******* AVPs & Co. *********/
-#define AVP_CHUNK_SIZE 4096
 
 /* these are the defined oreators of avps */
 #define AVP_OP_EQUAL           '='
 #define AVP_OP_NOTEQUAL                '!'
 #define AVP_OP_STARTS          '^'
-#define AVP_OP_ENDS                    '$'
+#define AVP_OP_ENDS            '$'
 #define AVP_OP_CONTAINS                '~'
 #define AVP_OP_LOWER           '<'
 #define AVP_OP_HIGHER          '>'