mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
modules/media/magick: Add memory hooks; set safe callbacks before lib init.
This commit is contained in:
parent
1a55c43b0a
commit
e2e3d0bc3f
1 changed files with 29 additions and 3 deletions
|
@ -17,6 +17,9 @@ namespace ircd::magick
|
|||
static void handle_error(const ::ExceptionType, const char *, const char *) noexcept;
|
||||
static void handle_warning(const ::ExceptionType, const char *, const char *) noexcept;
|
||||
static void handle_log(const ::ExceptionType, const char *) noexcept;
|
||||
static void *handle_realloc(void *, size_t) noexcept;
|
||||
static void *handle_malloc(size_t) noexcept;
|
||||
static void handle_free(void *) noexcept;
|
||||
static uint handle_progress(const char *, const int64_t, const uint64_t, ExceptionInfo *) noexcept;
|
||||
|
||||
template<class R, class F, class... A> static R call(F&&, A&&...);
|
||||
|
@ -88,11 +91,12 @@ ircd::magick::init()
|
|||
std::get<0>(version),
|
||||
};
|
||||
|
||||
::MagickAllocFunctions(handle_free, handle_malloc, handle_realloc);
|
||||
::SetFatalErrorHandler(handle_fatal);
|
||||
::SetErrorHandler(handle_error);
|
||||
::SetWarningHandler(handle_warning);
|
||||
::InitializeMagick(nullptr);
|
||||
::SetLogMethod(handle_log);
|
||||
::SetWarningHandler(handle_warning);
|
||||
::SetErrorHandler(handle_error);
|
||||
::SetFatalErrorHandler(handle_fatal);
|
||||
::SetMonitorHandler(handle_progress);
|
||||
::SetMagickResourceLimit(ThreadsResource, 1UL);
|
||||
|
||||
|
@ -304,6 +308,28 @@ noexcept
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::magick::handle_free(void *const ptr)
|
||||
noexcept
|
||||
{
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
ircd::magick::handle_malloc(size_t size)
|
||||
noexcept
|
||||
{
|
||||
return std::malloc(size);
|
||||
}
|
||||
|
||||
void *
|
||||
ircd::magick::handle_realloc(void *const ptr,
|
||||
size_t size)
|
||||
noexcept
|
||||
{
|
||||
return std::realloc(ptr, size);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::magick::handle_log(const ::ExceptionType type,
|
||||
const char *const message)
|
||||
|
|
Loading…
Reference in a new issue