0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 22:41:12 +01: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; int errc;
void *ret; void *ret;
if(unlikely((errc = ::posix_memalign(&ret, alignment, size)) != 0)) switch((errc = ::posix_memalign(&ret, alignment, size)))
throw std::system_error {
{ case 0:
errc, std::system_category() 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)> return std::unique_ptr<char, decltype(&std::free)>
{ {
reinterpret_cast<char *>(ret), std::free reinterpret_cast<char *>(ret), std::free