hook gvariant vectors up to kdbus
[platform/upstream/glib.git] / glib / gmem.h
index cb250dc..5dcc3f8 100644 (file)
@@ -12,9 +12,7 @@
  * 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.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  * GLib at ftp://ftp.gtk.org/pub/gtk/.
  */
 
+#ifndef __G_MEM_H__
+#define __G_MEM_H__
+
 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
 #error "Only <glib.h> can be included directly."
 #endif
 
-#ifndef __G_MEM_H__
-#define __G_MEM_H__
-
 #include <glib/gtypes.h>
 
 G_BEGIN_DECLS
@@ -67,49 +65,64 @@ typedef struct _GMemVTable GMemVTable;
 /* Memory allocation functions
  */
 
+GLIB_AVAILABLE_IN_ALL
 void    g_free           (gpointer      mem);
 
 GLIB_AVAILABLE_IN_2_34
 void     g_clear_pointer  (gpointer      *pp,
                            GDestroyNotify destroy);
 
+GLIB_AVAILABLE_IN_ALL
 gpointer g_malloc         (gsize        n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_malloc0        (gsize        n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_realloc        (gpointer     mem,
                           gsize         n_bytes) G_GNUC_WARN_UNUSED_RESULT;
+GLIB_AVAILABLE_IN_ALL
 gpointer g_try_malloc     (gsize        n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_try_malloc0    (gsize        n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_try_realloc    (gpointer     mem,
                           gsize         n_bytes) G_GNUC_WARN_UNUSED_RESULT;
 
+GLIB_AVAILABLE_IN_ALL
 gpointer g_malloc_n       (gsize        n_blocks,
                           gsize         n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_malloc0_n      (gsize        n_blocks,
                           gsize         n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_realloc_n      (gpointer     mem,
                           gsize         n_blocks,
                           gsize         n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
+GLIB_AVAILABLE_IN_ALL
 gpointer g_try_malloc_n   (gsize        n_blocks,
                           gsize         n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_try_malloc0_n  (gsize        n_blocks,
                           gsize         n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
 gpointer g_try_realloc_n  (gpointer     mem,
                           gsize         n_blocks,
                           gsize         n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
 
 #define g_clear_pointer(pp, destroy) \
   G_STMT_START {                                                               \
-    G_STATIC_ASSERT (sizeof (*(pp)) == sizeof (gpointer));                     \
+    G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer));                       \
     /* Only one access, please */                                              \
-    gpointer *_pp = (gpointer *) pp;                                           \
+    gpointer *_pp = (gpointer *) (pp);                                         \
     gpointer _p;                                                               \
+    /* This assignment is needed to avoid a gcc warning */                     \
+    GDestroyNotify _destroy = (GDestroyNotify) (destroy);                      \
                                                                                \
-    do                                                                         \
-      _p = g_atomic_pointer_get (_pp);                                         \
-    while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \
-                                                                               \
-    if (_p)                                                                    \
-      ((GDestroyNotify) (destroy)) (_p);                                       \
+    _p = *_pp;                                                                 \
+    if (_p)                                                                   \
+      {                                                                       \
+        *_pp = NULL;                                                          \
+        _destroy (_p);                                                         \
+      }                                                                        \
   } G_STMT_END
 
 /* Optimise: avoid the call to the (slower) _n function if we can
@@ -267,7 +280,9 @@ struct _GMemVTable {
   gpointer (*try_realloc) (gpointer mem,
                           gsize    n_bytes);
 };
+GLIB_AVAILABLE_IN_ALL
 void    g_mem_set_vtable (GMemVTable   *vtable);
+GLIB_AVAILABLE_IN_ALL
 gboolean g_mem_is_system_malloc (void);
 
 GLIB_VAR gboolean g_mem_gc_friendly;
@@ -275,6 +290,7 @@ GLIB_VAR gboolean g_mem_gc_friendly;
 /* Memory profiler and checker, has to be enabled via g_mem_set_vtable()
  */
 GLIB_VAR GMemVTable    *glib_mem_profiler_table;
+GLIB_AVAILABLE_IN_ALL
 void   g_mem_profile   (void);
 
 G_END_DECLS