0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 19:28:52 +02:00

ircd::buffer: Improve exceptions thrown from aligned_alloc().

This commit is contained in:
Jason Volk 2018-11-12 16:49:06 -08:00
parent aee34ec734
commit 2ab314e687

View file

@ -119,14 +119,21 @@ ircd::buffer::aligned_alloc(const size_t &align,
int errc;
void *ret;
if(unlikely((errc = ::posix_memalign(&ret, alignment, size)) != 0))
throw std::system_error
{
errc, std::system_category()
};
switch((errc = ::posix_memalign(&ret, alignment, size)))
{
case 0:
break;
case int(std::errc::not_enough_memory):
throw std::bad_alloc{};
default:
throw std::system_error
{
errc, std::system_category()
};
}
assert(errc == 0);
assert(ret != nullptr);
return std::unique_ptr<char, decltype(&std::free)>
{
reinterpret_cast<char *>(ret), std::free