summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-05-28 15:47:37 -0400
committerMike Frysinger <vapier@gentoo.org>2021-05-28 15:47:37 -0400
commitdf8f98982552112039f66b5f1639599e423c6800 (patch)
treed93c3d723aa8785edc74e01b7161f93adf873e38 /src
parent968ba1132d4c9f861ca2690dcdd9119c7b149bf1 (diff)
downloadlibgd-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.h2
-rw-r--r--src/gdhelpers.h4
2 files changed, 4 insertions, 2 deletions
diff --git a/src/gd.h b/src/gd.h
index 89bca20..a1e1393 100644
--- a/src/gd.h
+++ b/src/gd.h
@@ -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 */