Re: [PATCH] Reimplement aligned_alloc
Brian Inglis <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Organization | Systematic Software |
| Message-ID | <[email protected]> |
>> 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. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. [Data in IEC units and prefixes, physical quantities in SI.]