aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-10-30 18:44:35 -0400
committerDavid Robillard <d@drobilla.net>2022-10-30 18:46:24 -0400
commitb30d8f984cd2744d06044c28b6a76399e3634e00 (patch)
treed9c93c4338aa78adf8e259e79b7b96b66a2759cb
parentdecde99974f4d879329837d2f8ceb6a556895127 (diff)
downloadpugl-b30d8f984cd2744d06044c28b6a76399e3634e00.tar.gz
pugl-b30d8f984cd2744d06044c28b6a76399e3634e00.tar.bz2
pugl-b30d8f984cd2744d06044c28b6a76399e3634e00.zip
Add malloc attributes to allocating functions
These inform the compiler that the returned value doesn't alias with anything. Also somewhat handy as pseudo-documentation.
-rw-r--r--include/pugl/pugl.h10
-rw-r--r--meson/suppressions/meson.build1
-rw-r--r--src/platform.h2
3 files changed, 10 insertions, 3 deletions
diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h
index 431efab..b928c9e 100644
--- a/include/pugl/pugl.h
+++ b/include/pugl/pugl.h
@@ -35,14 +35,20 @@
#if defined(__GNUC__)
# define PUGL_CONST_FUNC __attribute__((const))
+# define PUGL_MALLOC_FUNC __attribute__((malloc))
#else
# define PUGL_CONST_FUNC
+# define PUGL_MALLOC_FUNC
#endif
#define PUGL_CONST_API \
PUGL_API \
PUGL_CONST_FUNC
+#define PUGL_MALLOC_API \
+ PUGL_API \
+ PUGL_MALLOC_FUNC
+
#ifdef __cplusplus
# define PUGL_BEGIN_DECLS extern "C" {
# define PUGL_END_DECLS }
@@ -703,7 +709,7 @@ typedef uint32_t PuglWorldFlags;
@param flags Flags to control world features.
@return A new world, which must be later freed with puglFreeWorld().
*/
-PUGL_API
+PUGL_MALLOC_API
PuglWorld*
puglNewWorld(PuglWorldType type, PuglWorldFlags flags);
@@ -927,7 +933,7 @@ typedef PuglStatus (*PuglEventFunc)(PuglView* view, const PuglEvent* event);
It must first be configured, then the system view can be created with
puglRealize().
*/
-PUGL_API
+PUGL_MALLOC_API
PuglView*
puglNewView(PuglWorld* world);
diff --git a/meson/suppressions/meson.build b/meson/suppressions/meson.build
index ffc6595..1cbdb99 100644
--- a/meson/suppressions/meson.build
+++ b/meson/suppressions/meson.build
@@ -40,7 +40,6 @@ elif cc.get_id() == 'gcc'
'-Wno-padded',
'-Wno-pedantic',
'-Wno-suggest-attribute=const',
- '-Wno-suggest-attribute=malloc',
'-Wno-suggest-attribute=pure',
'-Wno-switch-default',
'-Wno-switch-enum',
diff --git a/src/platform.h b/src/platform.h
index ec16197..cfdb1b7 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -13,6 +13,7 @@
PUGL_BEGIN_DECLS
/// Allocate and initialise world internals (implemented once per platform)
+PUGL_MALLOC_FUNC
PuglWorldInternals*
puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags);
@@ -21,6 +22,7 @@ void
puglFreeWorldInternals(PuglWorld* world);
/// Allocate and initialise view internals (implemented once per platform)
+PUGL_MALLOC_FUNC
PuglInternals*
puglInitViewInternals(PuglWorld* world);