[PATCH] Reimplement aligned_alloc
Szabolcs Nagy
szabolcs.nagy@arm.com
Fri May 22 15:22:35 GMT 2020
The 05/20/2020 08:32, Brian Inglis wrote:
> >> On 19/05/2020 11:52, Szabolcs Nagy wrote:
> >>> - Failed to set errno on error.
>
> > The 05/19/2020 19:41, Sebastian Huber wrote:
> >> why should aligned_alloc() set errno on error?
>
> On 2020-05-20 02:54, Szabolcs Nagy wrote:
> > iso c allows standard api calls to set errno
> > (except not to 0) but usually does not specify
> > error conditions, however posix does and
> > requires allocation functions to set errno
> > to ENOMEM on failure.
> >
> > posix is not yet aligned with c11 so there is
> > no errno specification for aligned_alloc but
> > that does not mean newlib should make it
> > deliberately inconsistent with other allocation
> > functions, users will try to use perror or
> > strerror when calls fail that may internally
> > use aligned_alloc and expect reasonable error
> > message.
>
> IEC 9899-2011[2012] specifies no errno values for any of the 7.22.3 Memory
> management functions, and under Annex J.1 Unspecified behaviour and J.2
> Undefined behaviour, omits aligned_alloc from issues of related functions, but
> under J.2 specifies as a portability issue only:
>
> -- The alignment requested of the aligned_alloc function is not valid or not
> supported by the implementation, or the size requested is not an integral
> multiple of the alignment (7.22.3.1).
>
> POSIX posix_memalign specifies errno = EINVAL for this case and errno = ENOMEM
> for the OoM case.
>
> It seems more useful to set errno to POSIX compatible values when returning a
> NULL pointer than attempt nasal demon emission.
note that posix_memalign does not set errno,
but returns an error value.
in principle aligned_alloc could check its
alignement argument too and set errno to
EINVAL, but to me that case seems less
important in practice: it's not a dynamic
runtime failure like running out of memory,
but wrong argument bug in user code that
should be fixed statically instead of
checking errno.
if posix is updated to cover aligned_alloc
and requires EINVAL for this case, then
newlib can be updated.
More information about the Newlib
mailing list