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:
parent
aee34ec734
commit
2ab314e687
1 changed files with 14 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue