From ae168e53ca2496da7de90fcf19e9f081e76e5dd3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 15 Jun 2015 18:40:34 +0200 Subject: [PATCH] Revert "core: add NMRefString" After hiding the udi field, there are no more users of NMRefString. Remove the code by explitly reverting the patch so that in case of a future need, we can find and resurrect NMRefString. This reverts commit d0e2937006aaf04f5682053c5cb17e0e0a4b1384. (cherry picked from commit 3359dddd2e301536aee389867e01d22880a99510) --- src/NetworkManagerUtils.c | 124 --------------------------- src/NetworkManagerUtils.h | 6 -- src/tests/test-general-with-expect.c | 52 ----------- 3 files changed, 182 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index b245574c54..2b4e7924d5 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -2707,127 +2707,3 @@ nm_utils_setpgid (gpointer unused G_GNUC_UNUSED) pid = getpid (); setpgid (pid, pid); } - -/****************************************************************** - * NMRefString - ******************************************************************/ - -#ifdef NM_MORE_ASSERTS -#define NM_STRING_CANARY(s) (GPOINTER_TO_UINT (s) ^ ((guint) 30112031329)) -#endif - -typedef struct _NMString { -#ifdef NM_STRING_CANARY - guint _canary; -#endif - int ref_count; - char str[1]; -} _NMString; - -static inline _NMString * -_nm_ref_string_up_cast (NMRefString nmstr) -{ - _NMString *s; - - s = (_NMString *) (((char *) nmstr) - G_STRUCT_OFFSET (_NMString, str)); -#ifdef NM_STRING_CANARY - g_return_val_if_fail (s->_canary == NM_STRING_CANARY (s), NULL); -#endif - g_return_val_if_fail (s->ref_count > 0, NULL); - - nm_assert (s->str == nmstr); - - return s; -} - -NMRefString -nm_ref_string_new (const char *str) -{ - _NMString *s; - gsize len; - - if (!str) - return NULL; - - len = strlen (str) + 1; - - s = g_malloc (G_STRUCT_OFFSET (_NMString, str) + len); - s->ref_count = 1; -#ifdef NM_STRING_CANARY - s->_canary = NM_STRING_CANARY (s); -#endif - memcpy (s->str, str, len); - return s->str; -} - -NMRefString -nm_ref_string_ref (NMRefString nmstr) -{ - _NMString *s; - - if (!nmstr) - return NULL; - - s = _nm_ref_string_up_cast (nmstr); - g_return_val_if_fail (s, NULL); - - s->ref_count++; - return s->str; -} - -void -nm_ref_string_unref (NMRefString nmstr) -{ - _NMString *s; - - if (!nmstr) - return; - - s = _nm_ref_string_up_cast (nmstr); - g_return_if_fail (s); - - if (--s->ref_count <= 0) { -#ifdef NM_STRING_CANARY - s->_canary = 0; -#endif - g_free (s); - } -} - -NMRefString -nm_ref_string_replace (NMRefString nmstr, const char *str) -{ - _NMString *s, *s2; - gsize len; - - if (!nmstr) - return nm_ref_string_new (str); - if (!str) { - nm_ref_string_unref (nmstr); - return NULL; - } - - s = _nm_ref_string_up_cast (nmstr); - g_return_val_if_fail (s, NULL); - - if (strcmp (s->str, str) == 0) - return nmstr; - - if (s->ref_count == 1) { - len = strlen (str) + 1; - - s2 = g_realloc (s, G_STRUCT_OFFSET (_NMString, str) + len); - -#ifdef NM_STRING_CANARY - s2->_canary = NM_STRING_CANARY (s2); -#endif - memcpy (s2->str, str, len); - return s2->str; - } else { - s->ref_count--; - return nm_ref_string_new (str); - } -} - -/******************************************************************/ - diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 675d6af062..3b73fdc0fc 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -211,10 +211,4 @@ GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value); void nm_utils_setpgid (gpointer unused); -typedef const char *NMRefString; -NMRefString nm_ref_string_new (const char *str); -NMRefString nm_ref_string_ref (NMRefString nmstr); -void nm_ref_string_unref (NMRefString nmstr); -NMRefString nm_ref_string_replace (NMRefString nmstr, const char *str); - #endif /* __NETWORKMANAGER_UTILS_H__ */ diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index 6dab87691f..ac32f52872 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -35,57 +35,6 @@ /*******************************************/ -static void -test_nm_ref_string (void) -{ - const char *nm_str, *s1, *s2; - - nm_str = nm_ref_string_new ("hallo"); - - g_assert_cmpstr (nm_str, ==, "hallo"); - - nm_ref_string_ref (nm_str); - g_assert_cmpstr (nm_str, ==, "hallo"); - - nm_ref_string_unref (nm_str); - g_assert_cmpstr (nm_str, ==, "hallo"); - - nm_str = nm_ref_string_replace (nm_str, "hallo"); - g_assert_cmpstr (nm_str, ==, "hallo"); - - nm_str = nm_ref_string_replace (nm_str, "hallo2"); - g_assert_cmpstr (nm_str, ==, "hallo2"); - - nm_ref_string_unref (nm_str); - - /* replace() reallocs old memory if ref-count is 1. */ - s1 = nm_ref_string_new ("abcdef"); - g_assert_cmpstr (s1, ==, "abcdef"); - s2 = nm_ref_string_replace (s1, "ABC"); - g_assert_cmpstr (s2, ==, "ABC"); - nm_ref_string_unref (s2); - - /* replace() reallocs old memory if ref-count is 1. */ - s1 = nm_ref_string_new ("ABC"); - g_assert_cmpstr (s1, ==, "ABC"); - s2 = nm_ref_string_replace (s1, "abcdef"); - g_assert_cmpstr (s2, ==, "abcdef"); - nm_ref_string_unref (s2); - - /* replace allocates new memory if ref-count larger 1. */ - s1 = nm_ref_string_new ("ABC"); - g_assert_cmpstr (s1, ==, "ABC"); - nm_ref_string_ref (s1); - s2 = nm_ref_string_replace (s1, "abcdef"); - g_assert_cmpstr (s2, ==, "abcdef"); - g_assert_cmpstr (s1, ==, "ABC"); - g_assert (s1 != s2); - nm_ref_string_unref (s2); - nm_ref_string_unref (s1); -} - -/*******************************************/ - struct test_nm_utils_kill_child_async_data { GMainLoop *loop; @@ -775,7 +724,6 @@ main (int argc, char **argv) { nmtst_init_assert_logging (&argc, &argv, "DEBUG", "DEFAULT"); - g_test_add_func ("/general/nm_ref_string", test_nm_ref_string); g_test_add_func ("/general/nm_utils_kill_child", test_nm_utils_kill_child); g_test_add_func ("/general/nm_ethernet_address_is_valid", test_nm_ethernet_address_is_valid); g_test_add_func ("/general/nm_multi_index", test_nm_multi_index);