diff options
author | Colin Walters <walters@verbum.org> | 2013-05-21 06:56:20 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-05-21 11:06:48 -0400 |
commit | 759384420c1578bf399473440ab34af18fa46b8d (patch) | |
tree | ddab58cc47b80c3742f117b93d54a0e7e0a5f8e2 | |
parent | 52f38c8d9bf9f4ba1ac3dea4fd1a5c89a7362191 (diff) | |
download | libgsystem-759384420c1578bf399473440ab34af18fa46b8d.tar.gz |
Add gsystem-glib-compat.h to support compilation with GLib 2.32
For NetworkManager.
-rw-r--r-- | gsystem-file-utils.c | 1 | ||||
-rw-r--r-- | gsystem-glib-compat.h | 53 |
2 files changed, 54 insertions, 0 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index a074a5d..9422f86 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -29,6 +29,7 @@ #define _GSYSTEM_NO_LOCAL_ALLOC #include "libgsystem.h" +#include "gsystem-glib-compat.h" #include <glib/gstdio.h> #include <gio/gunixinputstream.h> #include <glib-unix.h> diff --git a/gsystem-glib-compat.h b/gsystem-glib-compat.h new file mode 100644 index 0000000..edbdaab --- /dev/null +++ b/gsystem-glib-compat.h @@ -0,0 +1,53 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2012,2013 Colin Walters <walters@verbum.org>. + * + * 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 __LIBGSYSTEM_GLIB_COMPAT__ +#define __LIBGSYSTEM_GLIB_COMPAT__ + +#include <gio/gio.h> + +#if !GLIB_CHECK_VERSION(2,34,0) +static inline void +g_type_ensure (GType type) +{ + if (G_UNLIKELY (type == (GType)-1)) + g_error ("can't happen"); +} + +#define g_clear_pointer(pp, destroy) \ + G_STMT_START { \ + G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \ + /* Only one access, please */ \ + gpointer *_pp = (gpointer *) (pp); \ + gpointer _p; \ + /* This assignment is needed to avoid a gcc warning */ \ + GDestroyNotify _destroy = (GDestroyNotify) (destroy); \ + \ + (void) (0 ? (gpointer) *(pp) : 0); \ + do \ + _p = g_atomic_pointer_get (_pp); \ + while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \ + \ + if (_p) \ + _destroy (_p); \ + } G_STMT_END + +#endif + |