diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-05-28 15:47:37 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-05-28 15:47:37 -0400 |
commit | df8f98982552112039f66b5f1639599e423c6800 (patch) | |
tree | d93c3d723aa8785edc74e01b7161f93adf873e38 /src | |
parent | 968ba1132d4c9f861ca2690dcdd9119c7b149bf1 (diff) | |
download | libgd-df8f98982552112039f66b5f1639599e423c6800.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/gd.h | 2 | ||||
-rw-r--r-- | src/gdhelpers.h | 4 |
2 files changed, 4 insertions, 2 deletions
@@ -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 diff --git a/src/gdhelpers.h b/src/gdhelpers.h index 687e156..9b187af 100644 --- a/src/gdhelpers.h +++ b/src/gdhelpers.h @@ -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 */ |