X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgmem.h;h=5dcc3f8915ce973a03d49fc70c98b7cbc87eff89;hb=4454b815367831a71b1ae00b0182b5b389a78df2;hp=01d953e6c515180d6fda0f05de7cf58961a7b6ac;hpb=631d0c3534661e549f7df18fbb9832bdf19c5eaf;p=platform%2Fupstream%2Fglib.git
diff --git a/glib/gmem.h b/glib/gmem.h
index 01d953e..5dcc3f8 100644
--- a/glib/gmem.h
+++ b/glib/gmem.h
@@ -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 .
*/
/*
@@ -24,14 +22,13 @@
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
-#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
-#error "Only can be included directly."
-#endif
-
#ifndef __G_MEM_H__
#define __G_MEM_H__
-#include
+#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
+#error "Only can be included directly."
+#endif
+
#include
G_BEGIN_DECLS
@@ -55,7 +52,7 @@ typedef struct _GMemVTable GMemVTable;
#if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
/**
* G_MEM_ALIGN:
- *
+ *
* Indicates the number of bytes to which memory will be aligned on the
* current platform.
*/
@@ -68,39 +65,72 @@ 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)); \
+ /* Only one access, please */ \
+ gpointer *_pp = (gpointer *) (pp); \
+ gpointer _p; \
+ /* This assignment is needed to avoid a gcc warning */ \
+ GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
+ \
+ _p = *_pp; \
+ if (_p) \
+ { \
+ *_pp = NULL; \
+ _destroy (_p); \
+ } \
+ } G_STMT_END
/* Optimise: avoid the call to the (slower) _n function if we can
* determine at compile-time that no overflow happens.
*/
#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
# define _G_NEW(struct_type, n_structs, func) \
- (struct_type *) (__extension__ ({ \
+ (struct_type *) (G_GNUC_EXTENSION ({ \
gsize __n = (gsize) (n_structs); \
gsize __s = sizeof (struct_type); \
gpointer __p; \
@@ -114,7 +144,7 @@ gpointer g_try_realloc_n (gpointer mem,
__p; \
}))
# define _G_RENEW(struct_type, mem, n_structs, func) \
- (struct_type *) (__extension__ ({ \
+ (struct_type *) (G_GNUC_EXTENSION ({ \
gsize __n = (gsize) (n_structs); \
gsize __s = sizeof (struct_type); \
gpointer __p = (gpointer) (mem); \
@@ -250,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;
@@ -258,52 +290,9 @@ 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);
-
-/* deprecated memchunks and allocators */
-#if !defined (G_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) || defined (GDK_COMPILATION)
-typedef struct _GAllocator GAllocator;
-typedef struct _GMemChunk GMemChunk;
-#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
- g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
- sizeof (type), \
- sizeof (type) * (pre_alloc), \
- (alloc_type)) \
-)
-#define g_chunk_new(type, chunk) ( \
- (type *) g_mem_chunk_alloc (chunk) \
-)
-#define g_chunk_new0(type, chunk) ( \
- (type *) g_mem_chunk_alloc0 (chunk) \
-)
-#define g_chunk_free(mem, mem_chunk) G_STMT_START { \
- g_mem_chunk_free ((mem_chunk), (mem)); \
-} G_STMT_END
-#define G_ALLOC_ONLY 1
-#define G_ALLOC_AND_FREE 2
-GMemChunk* g_mem_chunk_new (const gchar *name,
- gint atom_size,
- gsize area_size,
- gint type);
-void g_mem_chunk_destroy (GMemChunk *mem_chunk);
-gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
-gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
-void g_mem_chunk_free (GMemChunk *mem_chunk,
- gpointer mem);
-void g_mem_chunk_clean (GMemChunk *mem_chunk);
-void g_mem_chunk_reset (GMemChunk *mem_chunk);
-void g_mem_chunk_print (GMemChunk *mem_chunk);
-void g_mem_chunk_info (void);
-void g_blow_chunks (void);
-GAllocator*g_allocator_new (const gchar *name,
- guint n_preallocs);
-void g_allocator_free (GAllocator *allocator);
-#define G_ALLOCATOR_LIST (1)
-#define G_ALLOCATOR_SLIST (2)
-#define G_ALLOCATOR_NODE (3)
-#endif /* G_DISABLE_DEPRECATED */
-
G_END_DECLS
#endif /* __G_MEM_H__ */