aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debian/libwireshark0.symbols1
-rw-r--r--debian/libwsutil0.symbols3
-rw-r--r--epan/strutil.c9
-rw-r--r--epan/strutil.h18
-rw-r--r--wsutil/str_util.c45
-rw-r--r--wsutil/str_util.h6
-rw-r--r--wsutil/wmem/wmem_strbuf.c9
-rw-r--r--wsutil/wmem/wmem_strbuf.h4
8 files changed, 43 insertions, 52 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols
index 54d7448713..bb44b75d22 100644
--- a/debian/libwireshark0.symbols
+++ b/debian/libwireshark0.symbols
@@ -660,7 +660,6 @@ libwireshark.so.0 libwireshark0 #MINVER#
follow_iterate_followers@Base 2.1.0
follow_reset_stream@Base 2.1.0
follow_tvb_tap_listener@Base 2.1.0
- format_size_wmem@Base 3.3.0
format_text@Base 1.9.1
format_text_chr@Base 1.12.0~rc1
format_text_string@Base 3.3.0
diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols
index 9746c18ec0..1966895485 100644
--- a/debian/libwsutil0.symbols
+++ b/debian/libwsutil0.symbols
@@ -69,7 +69,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
filetime_to_nstime@Base 2.0.0
find_codec@Base 3.1.0
find_last_pathname_separator@Base 1.12.0~rc1
- format_size@Base 1.10.0
+ format_size_wmem@Base 3.5.0
free_progdirs@Base 2.3.0
g_memdup2@Base 3.5.0
get_basename@Base 1.12.0~rc1
@@ -273,6 +273,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
wmem_strbuf_append_printf@Base 3.5.0
wmem_strbuf_append_unichar@Base 3.5.0
wmem_strbuf_append_vprintf@Base 3.5.0
+ wmem_strbuf_destroy@Base 3.5.0
wmem_strbuf_finalize@Base 3.5.0
wmem_strbuf_get_len@Base 3.5.0
wmem_strbuf_get_str@Base 3.5.0
diff --git a/epan/strutil.c b/epan/strutil.c
index 2f1d14fd22..bc3b19e537 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -1689,15 +1689,6 @@ string_replace(const gchar* str, const gchar *old_val, const gchar *new_val)
return new_str;
}
-gchar*
-format_size_wmem(wmem_allocator_t *allocator, gint64 size, format_size_flags_e flags)
-{
- gchar *str = format_size(size, flags);
- gchar *ptr = wmem_strdup(allocator, str);
- g_free(str);
- return ptr;
-}
-
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/epan/strutil.h b/epan/strutil.h
index 4f4e94faa0..037c65594d 100644
--- a/epan/strutil.h
+++ b/epan/strutil.h
@@ -358,24 +358,6 @@ gchar* ws_strdup_unescape_char (const gchar *str, const gchar chr);
WS_DLL_PUBLIC
gchar *string_replace(const gchar* str, const gchar *old_val, const gchar *new_val);
-/**
-* format_size_wmem:
-* Based on format_size (wsutil/str_util.h)
-*
-* Given a size, return its value in a human-readable format
-*
-* Prefixes up to "T/Ti" (tera, tebi) are currently supported.
-*
-* @param allocator An enumeration of the different types of available allocators.
-* @param size The size value
-* @param flags Flags to control the output (unit of measurement,
-* SI vs IEC, etc). Unit, prefix and suffix flags may be ORed together.
-* @return A newly-allocated string representing the value.
-*/
-WS_DLL_PUBLIC
-gchar*
-format_size_wmem(wmem_allocator_t *allocator, gint64 size, format_size_flags_e flags);
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/wsutil/str_util.c b/wsutil/str_util.c
index f802aeb214..51366265e3 100644
--- a/wsutil/str_util.c
+++ b/wsutil/str_util.c
@@ -125,24 +125,25 @@ static const char *thousands_grouping_fmt = NULL;
DIAG_OFF(format)
static void test_printf_thousands_grouping(void) {
- /* test whether g_printf works with "'" flag character */
- gchar *str = g_strdup_printf("%'d", 22);
- if (g_strcmp0(str, "22") == 0) {
+ /* test whether wmem_strbuf works with "'" flag character */
+ wmem_strbuf_t *buf = wmem_strbuf_new(NULL, NULL);
+ wmem_strbuf_append_printf(buf, "%'d", 22);
+ if (g_strcmp0(wmem_strbuf_get_str(buf), "22") == 0) {
thousands_grouping_fmt = "%'"G_GINT64_MODIFIER"d";
} else {
/* Don't use */
thousands_grouping_fmt = "%"G_GINT64_MODIFIER"d";
}
- g_free(str);
+ wmem_strbuf_destroy(buf);
}
DIAG_ON(format)
/* Given a size, return its value in a human-readable format */
/* This doesn't handle fractional values. We might want to make size a double. */
gchar *
-format_size(gint64 size, format_size_flags_e flags)
+format_size_wmem(wmem_allocator_t *allocator, gint64 size, format_size_flags_e flags)
{
- GString *human_str = g_string_new("");
+ wmem_strbuf_t *human_str = wmem_strbuf_new(allocator, NULL);
int power = 1000;
int pfx_off = 0;
gboolean is_small = FALSE;
@@ -158,19 +159,19 @@ format_size(gint64 size, format_size_flags_e flags)
}
if (size / power / power / power / power >= 10) {
- g_string_printf(human_str, thousands_grouping_fmt, size / power / power / power / power);
- g_string_append(human_str, prefix[pfx_off]);
+ wmem_strbuf_append_printf(human_str, thousands_grouping_fmt, size / power / power / power / power);
+ wmem_strbuf_append(human_str, prefix[pfx_off]);
} else if (size / power / power / power >= 10) {
- g_string_printf(human_str, thousands_grouping_fmt, size / power / power / power);
- g_string_append(human_str, prefix[pfx_off+1]);
+ wmem_strbuf_append_printf(human_str, thousands_grouping_fmt, size / power / power / power);
+ wmem_strbuf_append(human_str, prefix[pfx_off+1]);
} else if (size / power / power >= 10) {
- g_string_printf(human_str, thousands_grouping_fmt, size / power / power);
- g_string_append(human_str, prefix[pfx_off+2]);
+ wmem_strbuf_append_printf(human_str, thousands_grouping_fmt, size / power / power);
+ wmem_strbuf_append(human_str, prefix[pfx_off+2]);
} else if (size / power >= 10) {
- g_string_printf(human_str, thousands_grouping_fmt, size / power);
- g_string_append(human_str, prefix[pfx_off+3]);
+ wmem_strbuf_append_printf(human_str, thousands_grouping_fmt, size / power);
+ wmem_strbuf_append(human_str, prefix[pfx_off+3]);
} else {
- g_string_printf(human_str, thousands_grouping_fmt, size);
+ wmem_strbuf_append_printf(human_str, thousands_grouping_fmt, size);
is_small = TRUE;
}
@@ -178,28 +179,28 @@ format_size(gint64 size, format_size_flags_e flags)
case format_size_unit_none:
break;
case format_size_unit_bytes:
- g_string_append(human_str, is_small ? " bytes" : "B");
+ wmem_strbuf_append(human_str, is_small ? " bytes" : "B");
break;
case format_size_unit_bits:
- g_string_append(human_str, is_small ? " bits" : "b");
+ wmem_strbuf_append(human_str, is_small ? " bits" : "b");
break;
case format_size_unit_bits_s:
- g_string_append(human_str, is_small ? " bits/s" : "bps");
+ wmem_strbuf_append(human_str, is_small ? " bits/s" : "bps");
break;
case format_size_unit_bytes_s:
- g_string_append(human_str, is_small ? " bytes/s" : "Bps");
+ wmem_strbuf_append(human_str, is_small ? " bytes/s" : "Bps");
break;
case format_size_unit_packets:
- g_string_append(human_str, is_small ? " packets" : "packets");
+ wmem_strbuf_append(human_str, is_small ? " packets" : "packets");
break;
case format_size_unit_packets_s:
- g_string_append(human_str, is_small ? " packets/s" : "packets/s");
+ wmem_strbuf_append(human_str, is_small ? " packets/s" : "packets/s");
break;
default:
ws_assert_not_reached();
}
- ret_val = g_string_free(human_str, FALSE);
+ ret_val = wmem_strbuf_finalize(human_str);
return g_strchomp(ret_val);
}
diff --git a/wsutil/str_util.h b/wsutil/str_util.h
index 9bdc82bdcd..46e75f6d74 100644
--- a/wsutil/str_util.h
+++ b/wsutil/str_util.h
@@ -14,6 +14,8 @@
#include <glib.h>
#include "ws_symbol_export.h"
+#include <wsutil/wmem/wmem.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -105,7 +107,9 @@ typedef enum {
* @return A newly-allocated string representing the value.
*/
WS_DLL_PUBLIC
-gchar *format_size(gint64 size, format_size_flags_e flags);
+gchar *format_size_wmem(wmem_allocator_t *allocator, gint64 size, format_size_flags_e flags);
+
+#define format_size(size, flags) format_size_wmem(NULL, size, flags)
WS_DLL_PUBLIC
gchar printable_char_or_period(gchar c);
diff --git a/wsutil/wmem/wmem_strbuf.c b/wsutil/wmem/wmem_strbuf.c
index 0959105644..ac399c7964 100644
--- a/wsutil/wmem/wmem_strbuf.c
+++ b/wsutil/wmem/wmem_strbuf.c
@@ -294,6 +294,15 @@ wmem_strbuf_finalize(wmem_strbuf_t *strbuf)
return ret;
}
+void
+wmem_strbuf_destroy(wmem_strbuf_t *strbuf)
+{
+ wmem_allocator_t *allocator = strbuf->allocator;
+
+ wmem_free(allocator, strbuf->str);
+ wmem_free(allocator, strbuf);
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
diff --git a/wsutil/wmem/wmem_strbuf.h b/wsutil/wmem/wmem_strbuf.h
index d2f4b3bb2e..95559499f9 100644
--- a/wsutil/wmem/wmem_strbuf.h
+++ b/wsutil/wmem/wmem_strbuf.h
@@ -97,6 +97,10 @@ WS_DLL_PUBLIC
char *
wmem_strbuf_finalize(wmem_strbuf_t *strbuf);
+WS_DLL_PUBLIC
+void
+wmem_strbuf_destroy(wmem_strbuf_t *strbuf);
+
/** @}
* @} */