gmem.h   gmem.h 
skipping to change at line 39 skipping to change at line 39
#endif #endif
#ifndef __G_MEM_H__ #ifndef __G_MEM_H__
#define __G_MEM_H__ #define __G_MEM_H__
#include <glib/gslice.h> #include <glib/gslice.h>
#include <glib/gtypes.h> #include <glib/gtypes.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* GMemVTable:
* @malloc: function to use for allocating memory.
* @realloc: function to use for reallocating memory.
* @free: function to use to free memory.
* @calloc: function to use for allocating zero-filled memory.
* @try_malloc: function to use for allocating memory without a default err
or handler.
* @try_realloc: function to use for reallocating memory without a default
error handler.
*
* A set of functions used to perform memory allocation. The same #GMemVTab
le must
* be used for all allocations in the same program; a call to g_mem_set_vta
ble(),
* if it exists, should be prior to any use of GLib.
*/
typedef struct _GMemVTable GMemVTable; typedef struct _GMemVTable GMemVTable;
#if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG #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.
*/
# define G_MEM_ALIGN GLIB_SIZEOF_VOID_P # define G_MEM_ALIGN GLIB_SIZEOF_VOID_P
#else /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */ #else /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
# define G_MEM_ALIGN GLIB_SIZEOF_LONG # define G_MEM_ALIGN GLIB_SIZEOF_LONG
#endif /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */ #endif /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
/* Memory allocation functions /* Memory allocation functions
*/ */
void g_free (gpointer mem); void g_free (gpointer mem);
skipping to change at line 85 skipping to change at line 104
/* Optimise: avoid the call to the (slower) _n function if we can /* Optimise: avoid the call to the (slower) _n function if we can
* determine at compile-time that no overflow happens. * determine at compile-time that no overflow happens.
*/ */
#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__) #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
# define _G_NEW(struct_type, n_structs, func) \ # define _G_NEW(struct_type, n_structs, func) \
(struct_type *) (__extension__ ({ \ (struct_type *) (__extension__ ({ \
gsize __n = (gsize) (n_structs); \ gsize __n = (gsize) (n_structs); \
gsize __s = sizeof (struct_type); \ gsize __s = sizeof (struct_type); \
gpointer __p; \ gpointer __p; \
if (__s == 1) \ if (__s == 1) \
__p = g_##func (__n); \ __p = g_##func (__n); \
else if (__builtin_constant_p (__n) && \ else if (__builtin_constant_p (__n) && \
(__s == 0 || __n <= G_MAXSIZE / __s)) \ (__s == 0 || __n <= G_MAXSIZE / __s)) \
__p = g_##func (__n * __s); \ __p = g_##func (__n * __s); \
else \ else \
__p = g_##func##_n (__n, __s); \ __p = g_##func##_n (__n, __s); \
__p; \ __p; \
})) }))
# define _G_RENEW(struct_type, mem, n_structs, func) \ # define _G_RENEW(struct_type, mem, n_structs, func) \
(struct_type *) (__extension__ ({ \ (struct_type *) (__extension__ ({ \
skipping to change at line 120 skipping to change at line 139
/* Unoptimised version: always call the _n() function. */ /* Unoptimised version: always call the _n() function. */
#define _G_NEW(struct_type, n_structs, func) \ #define _G_NEW(struct_type, n_structs, func) \
((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type))) ((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type)))
#define _G_RENEW(struct_type, mem, n_structs, func) \ #define _G_RENEW(struct_type, mem, n_structs, func) \
((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_typ e))) ((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_typ e)))
#endif #endif
/**
* g_new:
* @struct_type: the type of the elements to allocate
* @n_structs: the number of elements to allocate
*
* Allocates @n_structs elements of type @struct_type.
* The returned pointer is cast to a pointer to the given type.
* If @n_structs is 0 it returns %NULL.
* Care is taken to avoid overflow when calculating the size of the allocat
ed block.
*
* Since the returned pointer is already casted to the right type,
* it is normally unnecessary to cast it explicitly, and doing
* so might hide memory allocation errors.
*
* Returns: a pointer to the allocated memory, cast to a pointer to @struct
_type
*/
#define g_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc) #define g_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc)
/**
* g_new0:
* @struct_type: the type of the elements to allocate.
* @n_structs: the number of elements to allocate.
*
* Allocates @n_structs elements of type @struct_type, initialized to 0's.
* The returned pointer is cast to a pointer to the given type.
* If @n_structs is 0 it returns %NULL.
* Care is taken to avoid overflow when calculating the size of the allocat
ed block.
*
* Since the returned pointer is already casted to the right type,
* it is normally unnecessary to cast it explicitly, and doing
* so might hide memory allocation errors.
*
* Returns: a pointer to the allocated memory, cast to a pointer to @struct
_type.
*/
#define g_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc0) #define g_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc0)
/**
* g_renew:
* @struct_type: the type of the elements to allocate
* @mem: the currently allocated memory
* @n_structs: the number of elements to allocate
*
* Reallocates the memory pointed to by @mem, so that it now has space for
* @n_structs elements of type @struct_type. It returns the new address of
* the memory, which may have been moved.
* Care is taken to avoid overflow when calculating the size of the allocat
ed block.
*
* Returns: a pointer to the new allocated memory, cast to a pointer to @st
ruct_type
*/
#define g_renew(struct_type, mem, n_structs) _G_RENEW (struct_typ e, mem, n_structs, realloc) #define g_renew(struct_type, mem, n_structs) _G_RENEW (struct_typ e, mem, n_structs, realloc)
/**
* g_try_new:
* @struct_type: the type of the elements to allocate
* @n_structs: the number of elements to allocate
*
* Attempts to allocate @n_structs elements of type @struct_type, and retur
ns
* %NULL on failure. Contrast with g_new(), which aborts the program on fai
lure.
* The returned pointer is cast to a pointer to the given type.
* The function returns %NULL when @n_structs is 0 of if an overflow occurs
.
*
* Since: 2.8
* Returns: a pointer to the allocated memory, cast to a pointer to @struct
_type
*/
#define g_try_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc) #define g_try_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc)
/**
* g_try_new0:
* @struct_type: the type of the elements to allocate
* @n_structs: the number of elements to allocate
*
* Attempts to allocate @n_structs elements of type @struct_type, initializ
ed
* to 0's, and returns %NULL on failure. Contrast with g_new0(), which abor
ts
* the program on failure.
* The returned pointer is cast to a pointer to the given type.
* The function returns %NULL when @n_structs is 0 of if an overflow occurs
.
*
* Since: 2.8
* Returns: a pointer to the allocated memory, cast to a pointer to @struct
_type
*/
#define g_try_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc0) #define g_try_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc0)
/**
* g_try_renew:
* @struct_type: the type of the elements to allocate
* @mem: the currently allocated memory
* @n_structs: the number of elements to allocate
*
* Attempts to reallocate the memory pointed to by @mem, so that it now has
* space for @n_structs elements of type @struct_type, and returns %NULL on
* failure. Contrast with g_renew(), which aborts the program on failure.
* It returns the new address of the memory, which may have been moved.
* The function returns %NULL if an overflow occurs.
*
* Since: 2.8
* Returns: a pointer to the new allocated memory, cast to a pointer to @st
ruct_type
*/
#define g_try_renew(struct_type, mem, n_structs) _G_RENEW (struct_typ e, mem, n_structs, try_realloc) #define g_try_renew(struct_type, mem, n_structs) _G_RENEW (struct_typ e, mem, n_structs, try_realloc)
/* Memory allocation virtualization for debugging purposes /* Memory allocation virtualization for debugging purposes
* g_mem_set_vtable() has to be the very first GLib function called * g_mem_set_vtable() has to be the very first GLib function called
* if being used * if being used
*/ */
struct _GMemVTable { struct _GMemVTable {
gpointer (*malloc) (gsize n_bytes); gpointer (*malloc) (gsize n_bytes);
gpointer (*realloc) (gpointer mem, gpointer (*realloc) (gpointer mem,
gsize n_bytes); gsize n_bytes);
 End of changes. 9 change blocks. 
1 lines changed or deleted 126 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/