1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
3
* Copyright (C) 2012,2013 Colin Walters <walters@verbum.org>.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
21
#ifndef __LIBGSYSTEM_GLIB_COMPAT__
22
#define __LIBGSYSTEM_GLIB_COMPAT__
26
#if !GLIB_CHECK_VERSION(2,34,0)
28
g_type_ensure (GType type)
30
if (G_UNLIKELY (type == (GType)-1))
31
g_error ("can't happen");
34
#define g_clear_pointer(pp, destroy) \
36
G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \
37
/* Only one access, please */ \
38
gpointer *_pp = (gpointer *) (pp); \
40
/* This assignment is needed to avoid a gcc warning */ \
41
GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
43
(void) (0 ? (gpointer) *(pp) : 0); \
45
_p = g_atomic_pointer_get (_pp); \
46
while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \