Merge branch '1465-bye-bye-g-gnuc-malloc' into 'master'

glib: Drop G_GNUC_MALLOC usage from various allocation functions

Closes #1465

See merge request GNOME/glib!260
This commit is contained in:
Emmanuele Bassi 2018-08-22 11:17:52 +00:00
commit d77516df81
8 changed files with 37 additions and 23 deletions

View File

@ -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
*/

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);