public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Add ability to hide non-standard itoa/utoa() in stdlib.h ?
@ 2024-01-22 15:47 Christian Franke
  2024-01-22 16:12 ` Corinna Vinschen
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Franke @ 2024-01-22 15:47 UTC (permalink / raw)
  To: cygwin

Busybox does not build OOTB on Cygwin due to the addition of itoa/utoa() 
to newlib in 2014:
https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=32c96dd

This is because Busybox use local functions with same name but different 
signature. This does not affect build on FreeBSD, Linux (glibc, musl 
libc), ... because these functions simply do not exits there. For the 
busybox Cygwin package, I use an ugly local hack to fix this.

itoa() is mentioned as a non-standard extension here:
https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa
https://cplusplus.com/reference/cstdlib/itoa/

MSVC provides itoa() as a "POSIX version" of _itoa():
https://learn.microsoft.com/cpp/c-runtime-library/reference/itoa-itow

But SUS-1997... POSIX-2018 do not mention these functions:
https://pubs.opengroup.org/onlinepubs/7908799/
https://pubs.opengroup.org/onlinepubs/9699919799/

Newlib guards the prototypes with __MISC_VISIBLE in stdlib.h and 
sys/features.h says:

  * __MISC_VISIBLE
  *      Extensions found in both BSD and SVr4 (shorthand for
  *      (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific
  *      extensions; enabled by default.

__MISC_VISIBLE is set if and only if _DEFAULT_SOURCE is set, so the 
comment below should also include "... or newlib-specific extensions":

  * _DEFAULT_SOURCE (or none of the above)
  *     POSIX-1.2008 with BSD and SVr4 extensions


The above is not suitable to disable only the non-standard functions for 
such use cases. Using -D_GNU_SOURCE should IMO not enable functions 
unavailable on Linux. This is not the case because _GNU_SOURCE implies 
_DEFAULT_SOURCE.

No patch provided for now, as I'm not yet sure how to handle this. Possibly:

- Use __MISC_VISIBLE only for (__BSD_VISIBLE || __SVID_VISIBLE) - under 
the assumption that this is applicable for most cases.
- Introduce __NONSTD_VISIBLE for non-standard functions like itoa().
- Introduce _NONSTD_SOURCE to set __NONSTD_VISIBLE independent from 
other _*_SOURCE defines.

-- 
Regards,
Christian


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Add ability to hide non-standard itoa/utoa() in stdlib.h ?
  2024-01-22 15:47 Add ability to hide non-standard itoa/utoa() in stdlib.h ? Christian Franke
@ 2024-01-22 16:12 ` Corinna Vinschen
  2024-01-22 18:48   ` Christian Franke
  0 siblings, 1 reply; 3+ messages in thread
From: Corinna Vinschen @ 2024-01-22 16:12 UTC (permalink / raw)
  To: cygwin

On Jan 22 16:47, Christian Franke via Cygwin wrote:
> Busybox does not build OOTB on Cygwin due to the addition of itoa/utoa() to
> newlib in 2014:
> https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=32c96dd
> 
> This is because Busybox use local functions with same name but different
> signature. This does not affect build on FreeBSD, Linux (glibc, musl libc),
> ... because these functions simply do not exits there. For the busybox
> Cygwin package, I use an ugly local hack to fix this.
> 
> itoa() is mentioned as a non-standard extension here:
> https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa
> https://cplusplus.com/reference/cstdlib/itoa/
> 
> MSVC provides itoa() as a "POSIX version" of _itoa():
> https://learn.microsoft.com/cpp/c-runtime-library/reference/itoa-itow
> 
> But SUS-1997... POSIX-2018 do not mention these functions:
> https://pubs.opengroup.org/onlinepubs/7908799/
> https://pubs.opengroup.org/onlinepubs/9699919799/
> 
> Newlib guards the prototypes with __MISC_VISIBLE in stdlib.h and
> sys/features.h says:
> 
>  * __MISC_VISIBLE
>  *      Extensions found in both BSD and SVr4 (shorthand for
>  *      (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific
>  *      extensions; enabled by default.
> 
> __MISC_VISIBLE is set if and only if _DEFAULT_SOURCE is set, so the comment
> below should also include "... or newlib-specific extensions":
> 
>  * _DEFAULT_SOURCE (or none of the above)
>  *     POSIX-1.2008 with BSD and SVr4 extensions
> 
> 
> The above is not suitable to disable only the non-standard functions for
> such use cases. Using -D_GNU_SOURCE should IMO not enable functions
> unavailable on Linux. This is not the case because _GNU_SOURCE implies
> _DEFAULT_SOURCE.
> 
> No patch provided for now, as I'm not yet sure how to handle this. Possibly:
> 
> - Use __MISC_VISIBLE only for (__BSD_VISIBLE || __SVID_VISIBLE) - under the
> assumption that this is applicable for most cases.
> - Introduce __NONSTD_VISIBLE for non-standard functions like itoa().
> - Introduce _NONSTD_SOURCE to set __NONSTD_VISIBLE independent from other
> _*_SOURCE defines.

Counter proposal:

First of all, Cygwin does NOT export itoa/utoa!  Only the prototypes
exist from the Cygwin POV.

As Cygwin is usually the only newlib project with backward compat
issues, we have two simple choices:

- Drop itoa/utoa entirely, or
- just guard them with

    #if __MISC_VISIBLE && !defined (__CYGWIN__)

You can make a proposal like that on the newlib list and then we can
discuss it there, ok?


Corinna

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Add ability to hide non-standard itoa/utoa() in stdlib.h ?
  2024-01-22 16:12 ` Corinna Vinschen
@ 2024-01-22 18:48   ` Christian Franke
  0 siblings, 0 replies; 3+ messages in thread
From: Christian Franke @ 2024-01-22 18:48 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen via Cygwin wrote:
> On Jan 22 16:47, Christian Franke via Cygwin wrote:
>> Busybox does not build OOTB on Cygwin due to the addition of itoa/utoa() to
>> newlib in 2014:
>> https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=32c96dd
>>
>> This is because Busybox use local functions with same name but different
>> signature. This does not affect build on FreeBSD, Linux (glibc, musl libc),
>> ... because these functions simply do not exits there. For the busybox
>> Cygwin package, I use an ugly local hack to fix this.
>>
>> itoa() is mentioned as a non-standard extension here:
>> https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa
>> https://cplusplus.com/reference/cstdlib/itoa/
>>
>> MSVC provides itoa() as a "POSIX version" of _itoa():
>> https://learn.microsoft.com/cpp/c-runtime-library/reference/itoa-itow
>>
>> But SUS-1997... POSIX-2018 do not mention these functions:
>> https://pubs.opengroup.org/onlinepubs/7908799/
>> https://pubs.opengroup.org/onlinepubs/9699919799/
>>
>> Newlib guards the prototypes with __MISC_VISIBLE in stdlib.h and
>> sys/features.h says:
>>
>>   * __MISC_VISIBLE
>>   *      Extensions found in both BSD and SVr4 (shorthand for
>>   *      (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific
>>   *      extensions; enabled by default.
>>
>> __MISC_VISIBLE is set if and only if _DEFAULT_SOURCE is set, so the comment
>> below should also include "... or newlib-specific extensions":
>>
>>   * _DEFAULT_SOURCE (or none of the above)
>>   *     POSIX-1.2008 with BSD and SVr4 extensions
>>
>>
>> The above is not suitable to disable only the non-standard functions for
>> such use cases. Using -D_GNU_SOURCE should IMO not enable functions
>> unavailable on Linux. This is not the case because _GNU_SOURCE implies
>> _DEFAULT_SOURCE.
>>
>> No patch provided for now, as I'm not yet sure how to handle this. Possibly:
>>
>> - Use __MISC_VISIBLE only for (__BSD_VISIBLE || __SVID_VISIBLE) - under the
>> assumption that this is applicable for most cases.
>> - Introduce __NONSTD_VISIBLE for non-standard functions like itoa().
>> - Introduce _NONSTD_SOURCE to set __NONSTD_VISIBLE independent from other
>> _*_SOURCE defines.
> Counter proposal:
>
> First of all, Cygwin does NOT export itoa/utoa!  Only the prototypes
> exist from the Cygwin POV.

Thanks, I missed that.


> As Cygwin is usually the only newlib project with backward compat
> issues, we have two simple choices:
>
> - Drop itoa/utoa entirely, or
> - just guard them with
>
>      #if __MISC_VISIBLE && !defined (__CYGWIN__)
>
> You can make a proposal like that on the newlib list and then we can
> discuss it there, ok?

Done.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-22 18:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-22 15:47 Add ability to hide non-standard itoa/utoa() in stdlib.h ? Christian Franke
2024-01-22 16:12 ` Corinna Vinschen
2024-01-22 18:48   ` Christian Franke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).