diff options
author | Nicolas Trangez <ikke@nicolast.be> | 2022-10-30 22:21:08 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-02 12:06:48 -0400 |
commit | 9ab999de7ab22dcb4e32825582203d99ce536f55 (patch) | |
tree | bd46321e91cb05badc93461621ec8a6440312301 /rts/RtsUtils.h | |
parent | 3a9a8bdee0103b33e314bfaebbddf8dc732e8643 (diff) | |
download | haskell-9ab999de7ab22dcb4e32825582203d99ce536f55.tar.gz |
rts: specify deallocator of allocating functions
This patch adds a new `STG_MALLOC1` macro (and its counterpart
`STG_MALLOC2` for completeness) which allows to specify the deallocation
function to be used with allocations of allocating functions, and
applies it to `stg*allocBytes`.
It also fixes a case where `free` was used to free up an
`stgMallocBytes` allocation, found by the above change.
See: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute
See: https://gitlab.haskell.org/ghc/ghc/-/issues/22381
Diffstat (limited to 'rts/RtsUtils.h')
-rw-r--r-- | rts/RtsUtils.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/rts/RtsUtils.h b/rts/RtsUtils.h index d3618d6435..5282be2035 100644 --- a/rts/RtsUtils.h +++ b/rts/RtsUtils.h @@ -17,18 +17,25 @@ void initAllocator(void); void shutdownAllocator(void); +void stgFree(void* p); + void *stgMallocBytes(size_t n, char *msg) - STG_MALLOC; + STG_MALLOC STG_MALLOC1(stgFree); -void *stgReallocBytes(void *p, size_t n, char *msg); +void *stgReallocBytes(void *p, size_t n, char *msg) + STG_MALLOC1(stgFree); +/* Note: `stgRallocBytes` can *not* be tagged as `STG_MALLOC` + * since its return value *can* alias an existing pointer (i.e., + * the given pointer `p`). + * See the documentation of the `malloc` attribute in the GCC manual + * for more information. + */ void *stgCallocBytes(size_t count, size_t size, char *msg) - STG_MALLOC; + STG_MALLOC STG_MALLOC1(stgFree); char *stgStrndup(const char *s, size_t n); -void stgFree(void* p); - /* ----------------------------------------------------------------------------- * Misc other utilities * -------------------------------------------------------------------------- */ |