use malloc compiler attribute if available

This informs the compiler that these functions return allocated
memory.  That allows it to make some optimization decisions which
can produce better code.
master
Mike Frysinger 2021-05-28 15:47:37 -04:00
parent 968ba1132d
commit df8f989825
2 changed files with 4 additions and 2 deletions

View File

@ -65,6 +65,7 @@ extern "C" {
# endif
# define BGD_STDCALL __stdcall
# define BGD_EXPORT_DATA_IMPL
# define BGD_MALLOC
#else
# if defined(__GNUC__) || defined(__clang__)
# define BGD_EXPORT_DATA_PROT __attribute__ ((__visibility__ ("default")))
@ -74,6 +75,7 @@ extern "C" {
# define BGD_EXPORT_DATA_IMPL
# endif
# define BGD_STDCALL
# define BGD_MALLOC __attribute__ ((__malloc__))
#endif
#define BGD_DECLARE(rt) BGD_EXPORT_DATA_PROT rt BGD_STDCALL

View File

@ -20,8 +20,8 @@ extern "C" {
in gd.h, where callers can utilize it to correctly
free memory allocated by these functions with the
right version of free(). */
void *gdCalloc (size_t nmemb, size_t size);
void *gdMalloc (size_t size);
void *gdCalloc(size_t nmemb, size_t size) BGD_MALLOC;
void *gdMalloc(size_t size) BGD_MALLOC;
void *gdRealloc (void *ptr, size_t size);
/* The extended version of gdReallocEx will free *ptr if the
* realloc fails */