diff --git a/glib/docs.c b/glib/docs.c index 5a786311c..23ef41916 100644 --- a/glib/docs.c +++ b/glib/docs.c @@ -2096,15 +2096,29 @@ /** * G_GNUC_MALLOC: * - * Expands to the GNU C malloc function attribute if the compiler is gcc. - * Declaring a function as malloc enables better optimization of the function. - * A function can have the malloc attribute if it returns a pointer which is - * guaranteed to not alias with any other pointer when the function returns - * (in practice, this means newly allocated memory). + * Expands to the + * [GNU C `malloc` function attribute](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc) + * if the compiler is gcc. + * Declaring a function as `malloc` enables better optimization of the function, + * but must only be done if the allocation behaviour of the function is fully + * understood, otherwise miscompilation can result. + * + * A function can have the `malloc` attribute if it returns a pointer which is + * guaranteed to not alias with any other pointer valid when the function + * returns, and moreover no pointers to valid objects occur in any storage + * addressed by the returned pointer. + * + * In practice, this means that `G_GNUC_MALLOC` can be used with any function + * which returns unallocated or zeroed-out memory, but not with functions which + * return initialised structures containing other pointers, or with functions + * that reallocate memory. This definition changed in GLib 2.58 to match the + * stricter definition introduced around GCC 5. * * Place the attribute after the declaration, just before the semicolon. * - * See the GNU C documentation for more details. + * See the + * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc) + * for more details. * * Since: 2.6 */ diff --git a/glib/gbookmarkfile.h b/glib/gbookmarkfile.h index b87d27e08..8dd93a1dc 100644 --- a/glib/gbookmarkfile.h +++ b/glib/gbookmarkfile.h @@ -146,7 +146,7 @@ GLIB_AVAILABLE_IN_ALL gchar ** g_bookmark_file_get_groups (GBookmarkFile *bookmark, const gchar *uri, gsize *length, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL void g_bookmark_file_add_application (GBookmarkFile *bookmark, const gchar *uri, @@ -161,7 +161,7 @@ GLIB_AVAILABLE_IN_ALL gchar ** g_bookmark_file_get_applications (GBookmarkFile *bookmark, const gchar *uri, gsize *length, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark, const gchar *uri, @@ -228,7 +228,7 @@ GLIB_AVAILABLE_IN_ALL gint g_bookmark_file_get_size (GBookmarkFile *bookmark); GLIB_AVAILABLE_IN_ALL gchar ** g_bookmark_file_get_uris (GBookmarkFile *bookmark, - gsize *length) G_GNUC_MALLOC; + gsize *length); GLIB_AVAILABLE_IN_ALL gboolean g_bookmark_file_remove_group (GBookmarkFile *bookmark, const gchar *uri, diff --git a/glib/gconvert.h b/glib/gconvert.h index c2e69a5a0..be58ecfbe 100644 --- a/glib/gconvert.h +++ b/glib/gconvert.h @@ -170,7 +170,7 @@ GLIB_AVAILABLE_IN_ALL gchar *g_filename_display_basename (const gchar *filename) G_GNUC_MALLOC; GLIB_AVAILABLE_IN_ALL -gchar **g_uri_list_extract_uris (const gchar *uri_list) G_GNUC_MALLOC; +gchar **g_uri_list_extract_uris (const gchar *uri_list); G_END_DECLS diff --git a/glib/gkeyfile.h b/glib/gkeyfile.h index 78495518d..7a1004841 100644 --- a/glib/gkeyfile.h +++ b/glib/gkeyfile.h @@ -106,12 +106,12 @@ GLIB_AVAILABLE_IN_ALL gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC; GLIB_AVAILABLE_IN_ALL gchar **g_key_file_get_groups (GKeyFile *key_file, - gsize *length) G_GNUC_MALLOC; + gsize *length); GLIB_AVAILABLE_IN_ALL gchar **g_key_file_get_keys (GKeyFile *key_file, const gchar *group_name, gsize *length, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL gboolean g_key_file_has_group (GKeyFile *key_file, const gchar *group_name); @@ -212,7 +212,7 @@ gchar **g_key_file_get_string_list (GKeyFile *key_file, const gchar *group_name, const gchar *key, gsize *length, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL void g_key_file_set_string_list (GKeyFile *key_file, const gchar *group_name, @@ -225,7 +225,7 @@ gchar **g_key_file_get_locale_string_list (GKeyFile *key_file, const gchar *key, const gchar *locale, gsize *length, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL void g_key_file_set_locale_string_list (GKeyFile *key_file, const gchar *group_name, diff --git a/glib/gmappedfile.h b/glib/gmappedfile.h index 1a06f7c56..8256811e6 100644 --- a/glib/gmappedfile.h +++ b/glib/gmappedfile.h @@ -34,11 +34,11 @@ typedef struct _GMappedFile GMappedFile; GLIB_AVAILABLE_IN_ALL GMappedFile *g_mapped_file_new (const gchar *filename, gboolean writable, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL GMappedFile *g_mapped_file_new_from_fd (gint fd, gboolean writable, - GError **error) G_GNUC_MALLOC; + GError **error); GLIB_AVAILABLE_IN_ALL gsize g_mapped_file_get_length (GMappedFile *file); GLIB_AVAILABLE_IN_ALL diff --git a/glib/grcbox.h b/glib/grcbox.h index e66f1ff6d..c92791260 100644 --- a/glib/grcbox.h +++ b/glib/grcbox.h @@ -32,7 +32,7 @@ GLIB_AVAILABLE_IN_2_58 gpointer g_rc_box_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); GLIB_AVAILABLE_IN_2_58 gpointer g_rc_box_dup (gsize block_size, - gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); + gconstpointer mem_block) G_GNUC_ALLOC_SIZE(1); GLIB_AVAILABLE_IN_2_58 gpointer g_rc_box_acquire (gpointer mem_block); GLIB_AVAILABLE_IN_2_58 @@ -50,7 +50,7 @@ GLIB_AVAILABLE_IN_2_58 gpointer g_atomic_rc_box_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); GLIB_AVAILABLE_IN_2_58 gpointer g_atomic_rc_box_dup (gsize block_size, - gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); + gconstpointer mem_block) G_GNUC_ALLOC_SIZE(1); GLIB_AVAILABLE_IN_2_58 gpointer g_atomic_rc_box_acquire (gpointer mem_block); GLIB_AVAILABLE_IN_2_58 diff --git a/glib/gslice.h b/glib/gslice.h index 80762761f..ff8b02a65 100644 --- a/glib/gslice.h +++ b/glib/gslice.h @@ -34,7 +34,7 @@ GLIB_AVAILABLE_IN_ALL gpointer g_slice_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); GLIB_AVAILABLE_IN_ALL gpointer g_slice_copy (gsize block_size, - gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1); + gconstpointer mem_block) G_GNUC_ALLOC_SIZE(1); GLIB_AVAILABLE_IN_ALL void g_slice_free1 (gsize block_size, gpointer mem_block); diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h index d09de568c..6b6ce52f9 100644 --- a/glib/gstrfuncs.h +++ b/glib/gstrfuncs.h @@ -255,7 +255,7 @@ gchar* g_strescape (const gchar *source, GLIB_AVAILABLE_IN_ALL gpointer g_memdup (gconstpointer mem, - guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2); + guint byte_size) G_GNUC_ALLOC_SIZE(2); /* NULL terminated string arrays. * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens @@ -270,18 +270,18 @@ typedef gchar** GStrv; GLIB_AVAILABLE_IN_ALL gchar** g_strsplit (const gchar *string, const gchar *delimiter, - gint max_tokens) G_GNUC_MALLOC; + gint max_tokens); GLIB_AVAILABLE_IN_ALL gchar ** g_strsplit_set (const gchar *string, const gchar *delimiters, - gint max_tokens) G_GNUC_MALLOC; + gint max_tokens); GLIB_AVAILABLE_IN_ALL gchar* g_strjoinv (const gchar *separator, gchar **str_array) G_GNUC_MALLOC; GLIB_AVAILABLE_IN_ALL void g_strfreev (gchar **str_array); GLIB_AVAILABLE_IN_ALL -gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC; +gchar** g_strdupv (gchar **str_array); GLIB_AVAILABLE_IN_ALL guint g_strv_length (gchar **str_array);