1 /* grcbox.h: Reference counted data
3 * Copyright 2018 Emmanuele Bassi
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.1 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, see <http://www.gnu.org/licenses/>.
21 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
22 #error "Only <glib.h> can be included directly."
25 #include <glib/gmem.h>
29 GLIB_AVAILABLE_IN_2_58
30 gpointer
g_rc_box_alloc (gsize block_size
) G_GNUC_MALLOC
G_GNUC_ALLOC_SIZE(1);
31 GLIB_AVAILABLE_IN_2_58
32 gpointer
g_rc_box_alloc0 (gsize block_size
) G_GNUC_MALLOC
G_GNUC_ALLOC_SIZE(1);
33 GLIB_AVAILABLE_IN_2_58
34 gpointer
g_rc_box_dup (gpointer mem_block
) G_GNUC_MALLOC
G_GNUC_ALLOC_SIZE(1);
35 GLIB_AVAILABLE_IN_2_58
36 gpointer
g_rc_box_acquire (gpointer mem_block
);
37 GLIB_AVAILABLE_IN_2_58
38 void g_rc_box_release (gpointer mem_block
);
39 GLIB_AVAILABLE_IN_2_58
40 void g_rc_box_release_full (gpointer mem_block
,
41 GDestroyNotify clear_func
);
43 #define g_rc_box_new(type) \
44 ((type *) g_rc_box_alloc (sizeof (type)))
45 #define g_rc_box_new0(type) \
46 ((type *) g_rc_box_alloc0 (sizeof (type)))
48 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(_cplusplus)
49 /* Type check to avoid assigning references to different types */
50 # define g_rc_box_acquire(mem_block) ((__typeof__(mem_block)) (g_rc_box_acquire) (mem_block))
51 /* Type check to avoid duplicating data to different types */
52 # define g_rc_box_dup(mem_block) ((__typeof__(mem_block)) (g_rc_box_dup) (mem_block))