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:
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;
|
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
|
||||||
|
|
Loading…
Reference in a new issue