diff --git a/.gitignore b/.gitignore index a1a417ecd7..5162fe7748 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ cscope.*out valgrind-*.log *-glue.h +/libgsystem/ + /ABOUT-NLS /COPYING /INSTALL diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e93bbea6db..0000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "libgsystem"] - path = libgsystem - url = git://git.gnome.org/libgsystem diff --git a/Makefile.am b/Makefile.am index 86102abbae..97f094d791 100644 --- a/Makefile.am +++ b/Makefile.am @@ -66,10 +66,4 @@ CLEANFILES = cscope.in.out cscope.out cscope.po.out cscope: cscope -b -q -R -Iinclude -ssrc -slibnm-glib -slibnm-util -scli/src; -libgsystem_srcpath := libgsystem -libgsystem_cflags := $(filter-out -DGLIB_VERSION%,$(GLIB_CFLAGS)) -I$(srcdir)/libgsystem -libgsystem_libs = $(GLIB_LIBS) -include libgsystem/Makefile-libgsystem.am -noinst_LTLIBRARIES = libgsystem.la - .PHONY: cscope diff --git a/autogen.sh b/autogen.sh index 1b56207af9..141bcf120e 100755 --- a/autogen.sh +++ b/autogen.sh @@ -22,13 +22,6 @@ PKG_NAME=NetworkManager cd $srcdir -# Fetch submodules if needed -if test -d $srcdir/.git; then - echo "+ Setting up submodules" - git submodule init - git submodule update -fi - gtkdocize autopoint --force AUTOPOINT='intltoolize --automake --copy' autoreconf --force --install --verbose diff --git a/include/Makefile.am b/include/Makefile.am index efc070354d..b465d8b5aa 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,5 @@ EXTRA_DIST = \ + gsystem-local-alloc.h \ nm-dbus-glib-types.h \ nm-glib-compat.h \ nm-gvaluearray-compat.h \ diff --git a/include/gsystem-local-alloc.h b/include/gsystem-local-alloc.h new file mode 100644 index 0000000000..68b1227425 --- /dev/null +++ b/include/gsystem-local-alloc.h @@ -0,0 +1,183 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2012 Colin Walters . + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GSYSTEM_LOCAL_ALLOC_H__ +#define __GSYSTEM_LOCAL_ALLOC_H__ + +#include + +G_BEGIN_DECLS + +#define GS_DEFINE_CLEANUP_FUNCTION(Type, name, func) \ + static inline void name (void *v) \ + { \ + func (*(Type*)v); \ + } + +#define GS_DEFINE_CLEANUP_FUNCTION0(Type, name, func) \ + static inline void name (void *v) \ + { \ + if (*(Type*)v) \ + func (*(Type*)v); \ + } + +/* These functions shouldn't be invoked directly; + * they are stubs that: + * 1) Take a pointer to the location (typically itself a pointer). + * 2) Provide %NULL-safety where it doesn't exist already (e.g. g_object_unref) + */ +GS_DEFINE_CLEANUP_FUNCTION0(GArray*, gs_local_array_unref, g_array_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GBytes*, gs_local_bytes_unref, g_bytes_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GChecksum*, gs_local_checksum_free, g_checksum_free) +GS_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, gs_local_keyfile_unref, g_key_file_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GError*, gs_local_free_error, g_error_free) +GS_DEFINE_CLEANUP_FUNCTION0(GHashTable*, gs_local_hashtable_unref, g_hash_table_unref) +GS_DEFINE_CLEANUP_FUNCTION(GList*, gs_local_free_list, g_list_free) +GS_DEFINE_CLEANUP_FUNCTION(GSList*, gs_local_free_slist, g_slist_free) +GS_DEFINE_CLEANUP_FUNCTION0(GObject*, gs_local_obj_unref, g_object_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GPtrArray*, gs_local_ptrarray_unref, g_ptr_array_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GVariant*, gs_local_variant_unref, g_variant_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GVariantBuilder*, gs_local_variant_builder_unref, g_variant_builder_unref) +GS_DEFINE_CLEANUP_FUNCTION0(GVariantIter*, gs_local_variant_iter_free, g_variant_iter_free) + +GS_DEFINE_CLEANUP_FUNCTION(char**, gs_local_strfreev, g_strfreev) +GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free) + +/** + * gs_free: + * + * Call g_free() on a variable location when it goes out of scope. + */ +#define gs_free __attribute__ ((cleanup(gs_local_free))) + +/** + * gs_unref_object: + * + * Call g_object_unref() on a variable location when it goes out of + * scope. Note that unlike g_object_unref(), the variable may be + * %NULL. + */ +#define gs_unref_object __attribute__ ((cleanup(gs_local_obj_unref))) + +/** + * gs_unref_variant: + * + * Call g_variant_unref() on a variable location when it goes out of + * scope. Note that unlike g_variant_unref(), the variable may be + * %NULL. + */ +#define gs_unref_variant __attribute__ ((cleanup(gs_local_variant_unref))) + +/** + * gs_free_variant_iter: + * + * Call g_variant_iter_free() on a variable location when it goes out of + * scope. + */ +#define gs_free_variant_iter __attribute__ ((cleanup(gs_local_variant_iter_free))) + +/** + * gs_free_variant_builder: + * + * Call g_variant_builder_unref() on a variable location when it goes out of + * scope. + */ +#define gs_unref_variant_builder __attribute__ ((cleanup(gs_local_variant_builder_unref))) + +/** + * gs_unref_array: + * + * Call g_array_unref() on a variable location when it goes out of + * scope. Note that unlike g_array_unref(), the variable may be + * %NULL. + + */ +#define gs_unref_array __attribute__ ((cleanup(gs_local_array_unref))) + +/** + * gs_unref_ptrarray: + * + * Call g_ptr_array_unref() on a variable location when it goes out of + * scope. Note that unlike g_ptr_array_unref(), the variable may be + * %NULL. + + */ +#define gs_unref_ptrarray __attribute__ ((cleanup(gs_local_ptrarray_unref))) + +/** + * gs_unref_hashtable: + * + * Call g_hash_table_unref() on a variable location when it goes out + * of scope. Note that unlike g_hash_table_unref(), the variable may + * be %NULL. + */ +#define gs_unref_hashtable __attribute__ ((cleanup(gs_local_hashtable_unref))) + +/** + * gs_free_list: + * + * Call g_list_free() on a variable location when it goes out + * of scope. + */ +#define gs_free_list __attribute__ ((cleanup(gs_local_free_list))) + +/** + * gs_free_slist: + * + * Call g_slist_free() on a variable location when it goes out + * of scope. + */ +#define gs_free_slist __attribute__ ((cleanup(gs_local_free_slist))) + +/** + * gs_free_checksum: + * + * Call g_checksum_free() on a variable location when it goes out + * of scope. Note that unlike g_checksum_free(), the variable may + * be %NULL. + */ +#define gs_free_checksum __attribute__ ((cleanup(gs_local_checksum_free))) + +/** + * gs_unref_bytes: + * + * Call g_bytes_unref() on a variable location when it goes out + * of scope. Note that unlike g_bytes_unref(), the variable may + * be %NULL. + */ +#define gs_unref_bytes __attribute__ ((cleanup(gs_local_bytes_unref))) + +/** + * gs_strfreev: + * + * Call g_strfreev() on a variable location when it goes out of scope. + */ +#define gs_strfreev __attribute__ ((cleanup(gs_local_strfreev))) + +/** + * gs_free_error: + * + * Call g_error_free() on a variable location when it goes out of scope. + */ +#define gs_free_error __attribute__ ((cleanup(gs_local_free_error))) + +G_END_DECLS + +#endif diff --git a/libgsystem b/libgsystem deleted file mode 160000 index 856b8f9431..0000000000 --- a/libgsystem +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 856b8f9431a63c7807fb3859ed6de2a0f3abfb3b diff --git a/src/Makefile.am b/src/Makefile.am index 0a0b52dc0b..ebbee17935 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,7 +38,6 @@ endif AM_CPPFLAGS = \ -I$(top_srcdir)/include \ - -I${top_srcdir}/libgsystem \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/callouts \ @@ -58,7 +57,7 @@ sbin_PROGRAMS = NetworkManager NetworkManager_SOURCES = \ main.c -NetworkManager_LDADD = libNetworkManager.la $(top_builddir)/libgsystem.la $(LIBNDP_LIBS) +NetworkManager_LDADD = libNetworkManager.la $(LIBNDP_LIBS) noinst_LTLIBRARIES = libNetworkManager.la @@ -356,7 +355,6 @@ libNetworkManager_la_SOURCES = \ $(glue_sources) libNetworkManager_la_LIBADD = \ - $(top_builddir)/libgsystem.la \ $(top_builddir)/libnm-util/libnm-util.la \ $(DBUS_LIBS) \ $(GLIB_LIBS) \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index bc21035b5c..6f659e53a1 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -38,7 +38,7 @@ #include #include -#include "libgsystem.h" +#include "gsystem-local-alloc.h" #include "nm-glib-compat.h" #include "nm-device.h" #include "nm-device-private.h" diff --git a/src/main.c b/src/main.c index 0ba65b0b8a..57e0b873f3 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,7 @@ #include #include -#include "libgsystem.h" +#include "gsystem-local-alloc.h" #include "NetworkManager.h" #include "NetworkManagerUtils.h" #include "nm-manager.h" diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index 9f9ee0f940..97db7eb867 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -27,7 +27,7 @@ #include #include -#include "libgsystem.h" +#include "gsystem-local-alloc.h" #include "nm-activation-request.h" #include "nm-logging.h" diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index aea5119940..e8925ae45b 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -23,7 +23,6 @@ #include "nm-ip4-config.h" -#include "libgsystem.h" #include "nm-platform.h" #include "nm-utils.h" #include "nm-dbus-manager.h" diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 203ed8128b..365f48667a 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -24,7 +24,6 @@ #include "nm-ip6-config.h" #include "nm-glib-compat.h" -#include "libgsystem.h" #include "nm-platform.h" #include "nm-utils.h" #include "nm-dbus-manager.h" diff --git a/src/nm-manager.c b/src/nm-manager.c index 5d7149ab70..520654fb4f 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1537,17 +1537,6 @@ done: g_clear_error (&error); } -/* This should really be moved to gsystem. */ -#define free_slist __attribute__ ((cleanup(local_slist_free))) -static void -local_slist_free (void *loc) -{ - GSList **location = loc; - - if (location) - g_slist_free (*location); -} - static gboolean match_connection_filter (NMConnection *connection, gpointer user_data) { @@ -1566,7 +1555,7 @@ static NMConnection * get_existing_connection (NMManager *manager, NMDevice *device) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - free_slist GSList *connections = nm_manager_get_activatable_connections (manager); + gs_free_slist GSList *connections = nm_manager_get_activatable_connections (manager); NMConnection *connection = NULL, *matched; NMSettingsConnection *added = NULL; GError *error = NULL; diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 46272217d0..4cbfd7854c 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -543,7 +543,7 @@ link_get_master (NMPlatform *platform, int slave) static gboolean master_set_option (NMPlatform *platform, int master, const char *option, const char *value) { - auto_g_free char *path = g_strdup_printf ("master:%d:%s", master, option); + gs_free char *path = g_strdup_printf ("master:%d:%s", master, option); return sysctl_set (platform, path, value); } @@ -551,7 +551,7 @@ master_set_option (NMPlatform *platform, int master, const char *option, const c static char * master_get_option (NMPlatform *platform, int master, const char *option) { - auto_g_free char *path = g_strdup_printf ("master:%d:%s", master, option); + gs_free char *path = g_strdup_printf ("master:%d:%s", master, option); return sysctl_get (platform, path); } @@ -559,7 +559,7 @@ master_get_option (NMPlatform *platform, int master, const char *option) static gboolean slave_set_option (NMPlatform *platform, int slave, const char *option, const char *value) { - auto_g_free char *path = g_strdup_printf ("slave:%d:%s", slave, option); + gs_free char *path = g_strdup_printf ("slave:%d:%s", slave, option); return sysctl_set (platform, path, value); } @@ -567,7 +567,7 @@ slave_set_option (NMPlatform *platform, int slave, const char *option, const cha static char * slave_get_option (NMPlatform *platform, int slave, const char *option) { - auto_g_free char *path = g_strdup_printf ("slave:%d:%s", slave, option); + gs_free char *path = g_strdup_printf ("slave:%d:%s", slave, option); return sysctl_get (platform, path); } diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 0b10afd2ae..ec0bd7521a 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -598,8 +598,8 @@ ethtool_get (const char *name, gpointer edata) static int ethtool_get_stringset_index (const char *ifname, int stringset_id, const char *string) { - auto_g_free struct ethtool_sset_info *info = NULL; - auto_g_free struct ethtool_gstrings *strings = NULL; + gs_free struct ethtool_sset_info *info = NULL; + gs_free struct ethtool_gstrings *strings = NULL; guint32 len, i; info = g_malloc0 (sizeof (*info) + sizeof (guint32)); @@ -2472,7 +2472,7 @@ link_supports_vlans (NMPlatform *platform, int ifindex) { auto_nl_object struct rtnl_link *rtnllink = link_get (platform, ifindex); const char *name = nm_platform_link_get_name (ifindex); - auto_g_free struct ethtool_gfeatures *features = NULL; + gs_free struct ethtool_gfeatures *features = NULL; int idx, block, bit, size; /* Only ARPHRD_ETHER links can possibly support VLANs. */ @@ -2684,7 +2684,7 @@ link_option_path (int master, const char *category, const char *option) static gboolean link_set_option (int master, const char *category, const char *option, const char *value) { - auto_g_free char *path = link_option_path (master, category, option); + gs_free char *path = link_option_path (master, category, option); return path && nm_platform_sysctl_set (path, value); } @@ -2692,7 +2692,7 @@ link_set_option (int master, const char *category, const char *option, const cha static char * link_get_option (int master, const char *category, const char *option) { - auto_g_free char *path = link_option_path (master, category, option); + gs_free char *path = link_option_path (master, category, option); return path ? nm_platform_sysctl_get (path) : NULL; } @@ -2771,7 +2771,7 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key) g_free (path); if (success) { - auto_g_free char *ifname = g_strdup_printf ("%s.%04x", parent_name, p_key); + gs_free char *ifname = g_strdup_printf ("%s.%04x", parent_name, p_key); auto_nl_object struct rtnl_link *rtnllink = _nm_rtnl_link_alloc (0, ifname); success = refresh_object (platform, (struct nl_object *) rtnllink, FALSE, NM_PLATFORM_REASON_INTERNAL); @@ -2784,7 +2784,7 @@ static gboolean veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties *props) { const char *ifname; - auto_g_free struct ethtool_stats *stats = NULL; + gs_free struct ethtool_stats *stats = NULL; int peer_ifindex_stat; ifname = nm_platform_link_get_name (ifindex); diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 96b6cfabbd..9bdc6a9cb1 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -29,6 +29,7 @@ #include #include +#include "gsystem-local-alloc.h" #define NM_TYPE_PLATFORM (nm_platform_get_type ()) #define NM_PLATFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PLATFORM, NMPlatform)) @@ -624,11 +625,4 @@ void nm_platform_addr_flags2str (int flags, char *buf, size_t size); int nm_platform_ip_address_cmp_expiry (const NMPlatformIPAddress *a, const NMPlatformIPAddress *b); -#define auto_g_free __attribute__((cleanup(put_g_free))) -static void __attribute__((unused)) -put_g_free (void *ptr) -{ - g_clear_pointer ((gpointer *) ptr, g_free); -} - #endif /* NM_PLATFORM_H */ diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index ea8bd0e3b3..8a680c521b 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -47,7 +47,7 @@ do_sysctl_set (char **argv) static gboolean do_sysctl_get (char **argv) { - auto_g_free char *value = nm_platform_sysctl_get (argv[0]); + gs_free char *value = nm_platform_sysctl_get (argv[0]); printf ("%s\n", value); @@ -281,7 +281,7 @@ do_master_get_option (char **argv) { int ifindex = parse_ifindex (*argv++); const char *option = *argv++; - auto_g_free char *value = nm_platform_master_get_option (ifindex, option); + gs_free char *value = nm_platform_master_get_option (ifindex, option); printf ("%s\n", value); @@ -303,7 +303,7 @@ do_slave_get_option (char **argv) { int ifindex = parse_ifindex (*argv++); const char *option = *argv++; - auto_g_free char *value = nm_platform_slave_get_option (ifindex, option); + gs_free char *value = nm_platform_slave_get_option (ifindex, option); printf ("%s\n", value);