diff options
author | Evan Huus <eapache@gmail.com> | 2015-01-12 10:08:29 -0500 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2015-01-12 17:11:34 +0000 |
commit | 0b271aa867cfaeed4b955c914a19f44777424142 (patch) | |
tree | c513b284c5edf658fb243067f0757ece7bd82295 | |
parent | f699f617782e832e87e102ff5324d29e05755f75 (diff) |
Remove ep_strbuf code
Thanks to Michael's work, it is now totally unused.
Change-Id: I67b5f7c69535a08f96f449c36c429e2548f4ea11
Reviewed-on: https://code.wireshark.org/review/6505
Petri-Dish: Evan Huus <eapache@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Evan Huus <eapache@gmail.com>
-rw-r--r-- | debian/libwireshark0.symbols | 3 | ||||
-rw-r--r-- | epan/emem.c | 138 | ||||
-rw-r--r-- | epan/emem.h | 48 | ||||
-rwxr-xr-x | tools/checkAPIs.pl | 10 |
4 files changed, 0 insertions, 199 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 43ab55de6d..84644034b6 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -441,9 +441,6 @@ libwireshark.so.0 libwireshark0 #MINVER# ep_alloc0@Base 1.9.1 ep_alloc@Base 1.9.1 ep_memdup@Base 1.9.1 - ep_strbuf_append_printf@Base 1.9.1 - ep_strbuf_new@Base 1.9.1 - ep_strbuf_printf@Base 1.9.1 ep_strconcat@Base 1.9.1 ep_strdup@Base 1.9.1 ep_strdup_printf@Base 1.9.1 diff --git a/epan/emem.c b/epan/emem.c index 782618c757..69294ac27d 100644 --- a/epan/emem.c +++ b/epan/emem.c @@ -1137,144 +1137,6 @@ se_free_all(void) emem_free_all(&se_packet_mem); } - -/* - * String buffers - */ - -/* - * Presumably we're using these routines for building strings for the tree. - * Use ITEM_LABEL_LENGTH as the basis for our default lengths. - */ - -#define DEFAULT_STRBUF_LEN (ITEM_LABEL_LENGTH / 10) -#define MAX_STRBUF_LEN 65536 - -static gsize -next_size(gsize cur_alloc_len, gsize wanted_alloc_len, gsize max_alloc_len) -{ - if (max_alloc_len < 1 || max_alloc_len > MAX_STRBUF_LEN) { - max_alloc_len = MAX_STRBUF_LEN; - } - - if (cur_alloc_len < 1) { - cur_alloc_len = DEFAULT_STRBUF_LEN; - } - - while (cur_alloc_len < wanted_alloc_len) { - cur_alloc_len *= 2; - } - - return cur_alloc_len < max_alloc_len ? cur_alloc_len : max_alloc_len; -} - -static void -ep_strbuf_grow(emem_strbuf_t *strbuf, gsize wanted_alloc_len) -{ - gsize new_alloc_len; - gchar *new_str; - - if (!strbuf || (wanted_alloc_len <= strbuf->alloc_len) || (strbuf->alloc_len >= strbuf->max_alloc_len)) { - return; - } - - new_alloc_len = next_size(strbuf->alloc_len, wanted_alloc_len, strbuf->max_alloc_len); - new_str = (gchar *)ep_alloc(new_alloc_len); - g_strlcpy(new_str, strbuf->str, new_alloc_len); - - strbuf->alloc_len = new_alloc_len; - strbuf->str = new_str; -} - -static emem_strbuf_t * -ep_strbuf_sized_new(gsize alloc_len, gsize max_alloc_len) -{ - emem_strbuf_t *strbuf; - - strbuf = ep_new(emem_strbuf_t); - - if ((max_alloc_len == 0) || (max_alloc_len > MAX_STRBUF_LEN)) - max_alloc_len = MAX_STRBUF_LEN; - if (alloc_len == 0) - alloc_len = 1; - else if (alloc_len > max_alloc_len) - alloc_len = max_alloc_len; - - strbuf->str = (char *)ep_alloc(alloc_len); - strbuf->str[0] = '\0'; - - strbuf->len = 0; - strbuf->alloc_len = alloc_len; - strbuf->max_alloc_len = max_alloc_len; - - return strbuf; -} - -emem_strbuf_t * -ep_strbuf_new(const gchar *init) -{ - emem_strbuf_t *strbuf; - - strbuf = ep_strbuf_sized_new(next_size(0, init?strlen(init)+1:0, 0), 0); /* +1 for NULL terminator */ - if (init) { - gsize full_len; - full_len = g_strlcpy(strbuf->str, init, strbuf->alloc_len); - strbuf->len = MIN(full_len, strbuf->alloc_len-1); - } - - return strbuf; -} - -static void -ep_strbuf_append_vprintf(emem_strbuf_t *strbuf, const gchar *format, va_list ap) -{ - va_list ap2; - gsize add_len, full_len; - - G_VA_COPY(ap2, ap); - - /* Be optimistic; try the g_vsnprintf first & see if enough room. */ - /* Note: full_len doesn't count the trailing '\0'; add_len does allow for same. */ - add_len = strbuf->alloc_len - strbuf->len; - full_len = g_vsnprintf(&strbuf->str[strbuf->len], (gulong) add_len, format, ap); - if (full_len < add_len) { - strbuf->len += full_len; - } else { - strbuf->str[strbuf->len] = '\0'; /* end string at original length again */ - ep_strbuf_grow(strbuf, strbuf->len + full_len + 1); - add_len = strbuf->alloc_len - strbuf->len; - full_len = g_vsnprintf(&strbuf->str[strbuf->len], (gulong) add_len, format, ap2); - strbuf->len += MIN(add_len-1, full_len); - } - - va_end(ap2); -} - -void -ep_strbuf_append_printf(emem_strbuf_t *strbuf, const gchar *format, ...) -{ - va_list ap; - - va_start(ap, format); - ep_strbuf_append_vprintf(strbuf, format, ap); - va_end(ap); -} - -void -ep_strbuf_printf(emem_strbuf_t *strbuf, const gchar *format, ...) -{ - va_list ap; - if (!strbuf) { - return; - } - - strbuf->len = 0; - - va_start(ap, format); - ep_strbuf_append_vprintf(strbuf, format, ap); - va_end(ap); -} - /* * Editor modelines * diff --git a/epan/emem.h b/epan/emem.h index f690f73e82..421698c539 100644 --- a/epan/emem.h +++ b/epan/emem.h @@ -127,54 +127,6 @@ void se_free_all(void); #define WS_MEM_ALIGN G_MEM_ALIGN #endif -/* ****************************************************************** - * String buffers - Growable strings similar to GStrings - * ****************************************************************** */ - -typedef struct _emem_strbuf_t { - gchar *str; /**< Points to the character data. It may move as text is */ - /* added. The str field is null-terminated and so can */ - /* be used as an ordinary C string. */ - gsize len; /**< strlen: ie: length of str not including trailing '\0' */ - gsize alloc_len; /**< num bytes curently allocated for str: 1 .. MAX_STRBUF_LEN */ - gsize max_alloc_len; /**< max num bytes to allocate for str: 1 .. MAX_STRBUF_LEN */ -} emem_strbuf_t; - -/* - * The maximum length is limited to 64K. If you need something bigger, you - * should probably use an actual GString or GByteArray. - */ - -/** - * Allocate an ephemeral string buffer with "unlimited" size. - * - * @param init The initial string for the buffer, or NULL to allocate an initial zero-length string. - * - * @return A newly-allocated string buffer. - */ -WS_DLL_PUBLIC -emem_strbuf_t *ep_strbuf_new(const gchar *init) G_GNUC_MALLOC; - -/** - * Apply printf-style formatted text to a string buffer. - * - * @param strbuf The ep_strbuf-allocated string buffer to set to. - * @param format A printf-style string format. - */ -WS_DLL_PUBLIC -void ep_strbuf_printf(emem_strbuf_t *strbuf, const gchar *format, ...) - G_GNUC_PRINTF(2, 3); - -/** - * Append printf-style formatted text to a string buffer. - * - * @param strbuf The ep_strbuf-allocated string buffer to append to. - * @param format A printf-style string format. - */ -WS_DLL_PUBLIC -void ep_strbuf_append_printf(emem_strbuf_t *strbuf, const gchar *format, ...) - G_GNUC_PRINTF(2, 3); - /* #define DEBUG_INTENSE_CANARY_CHECKS */ /** Helper to troubleshoot ep memory corruption. diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index 1e13680ecb..8b097a43f2 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -194,16 +194,6 @@ my %APIs = ( 'emem_tree_insert_string', 'emem_tree_lookup_string', 'emem_tree_foreach', - 'ep_strbuf_new', - 'ep_strbuf_new_label', - 'ep_strbuf_sized_new', - 'ep_strbuf_append_vprintf', - 'ep_strbuf_printf', - 'ep_strbuf_append_printf', - 'ep_strbuf_append', - 'ep_strbuf_append_c', - 'ep_strbuf_append_unichar', - 'ep_strbuf_truncate', 'emem_print_tree', # Locale-unsafe APIs # These may have unexpected behaviors in some locales (e.g., |