[patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

View: New views
7 Messages — Rating Filter:   Alert me  

[patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Dave Korn-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    Hello Jeff and list,

Refs: http://www.cygwin.com/ml/cygwin/2009-04/threads.html#00435
      http://cygwin.com/ml/cygwin/2009-10/threads.html#00324
      http://cygwin.com/ml/cygwin/2009-10/msg00406.html

  We had a couple of complaints over on the Cygwin list about function
prototypes not present when using --std=c99; this is of course to be expected
since newlib's definition of _STRICT_ANSI_ is based as we all know on c90, and
none of those functions were defined in the earlier ANSI standards.

  On Cygwin, we'd like to be as Linux, POSIX and c99 compatible as we can,
which is why this patch only changes the semantics of _STRICT_ANSI_ when
__CYGWIN__.  If the c99 standard is in effect, then it includes all the
functions that people have complained about missing: the {sn,v*}{print,scan}f
family and f{seek,tell}o.

  I've made this conditional on __CYGWIN__ so as not to produce any unexpected
side-effects for any other users, but you might decide it makes as much sense
to make this an unconditional change.

  However, even in that case, a Cygwin-specific bit may be needed:

  The new formatted i/o functions are part of c99, but the fseeko and ftello
functions are not; they are only part of POSIX.  Since Linux/Glibc includes
their declarations in _STRICT_ANSI_ (taking, if I've read the wording right,
advantage of the leeway provided by the definition of the CX extension type
annotation in the SUS to allow them to be regarded as extensions to the c99
spec in this context, as described in the third reference above), and since
Cygwin's goal is Linux emulation, it certainly makes sense to include them in
_STRICT_ANSI_ for Cygwin.

  Other platforms might only want the formatted i/o functions from the core
c99 spec to be added to _STRICT_ANSI_, depending on their own stance toward
POSIX compliance.  So even if it was desirable to make this change not
conditional on __CYGWIN__, I think it might still make sense to keep this part
of the change Cygwin-only.  Then again, there are also Linux newlib platforms;
they'd probably like to have the definitions visible in c99 mode.

  So, here's the patch, and I figured I'd leave it to you to decide what's the
best form for the conditional to take.  Tested by building a winsup checkout
before and after the change in separate objdirs, installing both into separate
DESTDIRs, manually verifying the difference was in the second installed header
and not the first, and that the warnings from the testcases posted to the
threads referenced above were manifested when compiling with a -I option into
the before DESTDIR/usr/include and not generated when compiling with a -I
option pointing into the after DESTDIR/usr/include.

newlib/ChangeLog:

        * libc/include/stdio.h: Include additional C99 formatted I/O
        functions and POSIX fseeko/ftello in _STRICT_ANSI_ for Cygwin
        when __STDC_VERSION__ indicates C99 or later standard in use.

  What do you think?

    cheers,
      DaveK



Index: newlib/libc/include/stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.58
diff -p -u -r1.58 stdio.h
--- newlib/libc/include/stdio.h 3 Jul 2009 11:58:04 -0000 1.58
+++ newlib/libc/include/stdio.h 14 Oct 2009 06:33:14 -0000
@@ -232,7 +232,7 @@ int _EXFUN(sprintf, (char *, const char
 int _EXFUN(remove, (const char *));
 int _EXFUN(rename, (const char *, const char *));
 #endif
-#ifndef __STRICT_ANSI__
+#if !defined (__STRICT_ANSI__) || (defined (__CYGWIN__) &&  __STDC_VERSION__ >= 199901L)
 #ifdef _COMPILING_NEWLIB
 int _EXFUN(fseeko, (FILE *, _off_t, int));
 _off_t _EXFUN(ftello, ( FILE *));


Re: [patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Jeff Johnston :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think the better solution is to emulate glibc which uses the flag
__USE_XOPEN2K to determine if fseeko and ftello are to be used.

So I made the following patch which sets the __USE_XOPEN2K flag for
Cygwin and uses to check for fseeko, ftello when __STRICT_ANSI__ is set.

The remainder of the I/O functions in that chunk are included if C99.

A patch is attached.  Let me know if you have any concerns, otherwise
I'll check it in.

-- Jeff J.

On 15/10/09 12:11 AM, Dave Korn wrote:

>
>      Hello Jeff and list,
>
> Refs: http://www.cygwin.com/ml/cygwin/2009-04/threads.html#00435
>        http://cygwin.com/ml/cygwin/2009-10/threads.html#00324
>        http://cygwin.com/ml/cygwin/2009-10/msg00406.html
>
>    We had a couple of complaints over on the Cygwin list about function
> prototypes not present when using --std=c99; this is of course to be expected
> since newlib's definition of _STRICT_ANSI_ is based as we all know on c90, and
> none of those functions were defined in the earlier ANSI standards.
>
>    On Cygwin, we'd like to be as Linux, POSIX and c99 compatible as we can,
> which is why this patch only changes the semantics of _STRICT_ANSI_ when
> __CYGWIN__.  If the c99 standard is in effect, then it includes all the
> functions that people have complained about missing: the {sn,v*}{print,scan}f
> family and f{seek,tell}o.
>
>    I've made this conditional on __CYGWIN__ so as not to produce any unexpected
> side-effects for any other users, but you might decide it makes as much sense
> to make this an unconditional change.
>
>    However, even in that case, a Cygwin-specific bit may be needed:
>
>    The new formatted i/o functions are part of c99, but the fseeko and ftello
> functions are not; they are only part of POSIX.  Since Linux/Glibc includes
> their declarations in _STRICT_ANSI_ (taking, if I've read the wording right,
> advantage of the leeway provided by the definition of the CX extension type
> annotation in the SUS to allow them to be regarded as extensions to the c99
> spec in this context, as described in the third reference above), and since
> Cygwin's goal is Linux emulation, it certainly makes sense to include them in
> _STRICT_ANSI_ for Cygwin.
>
>    Other platforms might only want the formatted i/o functions from the core
> c99 spec to be added to _STRICT_ANSI_, depending on their own stance toward
> POSIX compliance.  So even if it was desirable to make this change not
> conditional on __CYGWIN__, I think it might still make sense to keep this part
> of the change Cygwin-only.  Then again, there are also Linux newlib platforms;
> they'd probably like to have the definitions visible in c99 mode.
>
>    So, here's the patch, and I figured I'd leave it to you to decide what's the
> best form for the conditional to take.  Tested by building a winsup checkout
> before and after the change in separate objdirs, installing both into separate
> DESTDIRs, manually verifying the difference was in the second installed header
> and not the first, and that the warnings from the testcases posted to the
> threads referenced above were manifested when compiling with a -I option into
> the before DESTDIR/usr/include and not generated when compiling with a -I
> option pointing into the after DESTDIR/usr/include.
>
> newlib/ChangeLog:
>
> * libc/include/stdio.h: Include additional C99 formatted I/O
> functions and POSIX fseeko/ftello in _STRICT_ANSI_ for Cygwin
> when __STDC_VERSION__ indicates C99 or later standard in use.
>
>    What do you think?
>
>      cheers,
>        DaveK
>
>

[cygwin.patch]

Index: configure.host
===================================================================
RCS file: /cvs/src/src/newlib/configure.host,v
retrieving revision 1.110
diff -u -p -r1.110 configure.host
--- configure.host 8 Oct 2009 16:44:09 -0000 1.110
+++ configure.host 16 Oct 2009 16:50:08 -0000
@@ -536,7 +536,7 @@ case "${host}" in
  default_newlib_io_long_double="yes"
  default_newlib_io_pos_args="yes"
  CC="${CC} -I${cygwin_srcdir}/include"
- newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -D_COMPILING_NEWLIB -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED"
+ newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -D_COMPILING_NEWLIB -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED -D__USE_XOPEN2K"
  syscall_dir=syscalls
  ;;
 # RTEMS supplies its own versions of some routines:
Index: libc/include/stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.58
diff -u -p -r1.58 stdio.h
--- libc/include/stdio.h 3 Jul 2009 11:58:04 -0000 1.58
+++ libc/include/stdio.h 16 Oct 2009 16:50:08 -0000
@@ -232,7 +232,7 @@ int _EXFUN(sprintf, (char *, const char
 int _EXFUN(remove, (const char *));
 int _EXFUN(rename, (const char *, const char *));
 #endif
-#ifndef __STRICT_ANSI__
+#if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
 #ifdef _COMPILING_NEWLIB
 int _EXFUN(fseeko, (FILE *, _off_t, int));
 _off_t _EXFUN(ftello, ( FILE *));
@@ -240,6 +240,7 @@ _off_t _EXFUN(ftello, ( FILE *));
 int _EXFUN(fseeko, (FILE *, off_t, int));
 off_t _EXFUN(ftello, ( FILE *));
 #endif
+#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
 #ifndef _REENT_ONLY
 int _EXFUN(asiprintf, (char **, const char *, ...)
                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));


Re: [patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Corinna Vinschen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Oct 16 12:55, Jeff Johnston wrote:

> I think the better solution is to emulate glibc which uses the flag
> __USE_XOPEN2K to determine if fseeko and ftello are to be used.
>
> So I made the following patch which sets the __USE_XOPEN2K flag for Cygwin
> and uses to check for fseeko, ftello when __STRICT_ANSI__ is set.
>
> The remainder of the I/O functions in that chunk are included if C99.
>
> A patch is attached.  Let me know if you have any concerns, otherwise I'll
> check it in.

I don't think this patch is correct.  It sets the __USE_XOPEN2K
flag only when building newlib.  However, this is a header file
and we need the right definition at compile time of any subsequent
application, not only when building newlib.

So, I assume what we need is a definition in config.h, similar to
what Dave suggested:

  #if __STDC_VERSION__ >= 199901L
  #define __USE_XOPEN2K 1
  #endif


Corinna


> Index: configure.host
> ===================================================================
> RCS file: /cvs/src/src/newlib/configure.host,v
> retrieving revision 1.110
> diff -u -p -r1.110 configure.host
> --- configure.host 8 Oct 2009 16:44:09 -0000 1.110
> +++ configure.host 16 Oct 2009 16:50:08 -0000
> @@ -536,7 +536,7 @@ case "${host}" in
>   default_newlib_io_long_double="yes"
>   default_newlib_io_pos_args="yes"
>   CC="${CC} -I${cygwin_srcdir}/include"
> - newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -D_COMPILING_NEWLIB -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED"
> + newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -D_COMPILING_NEWLIB -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED -D__USE_XOPEN2K"
>   syscall_dir=syscalls
>   ;;
>  # RTEMS supplies its own versions of some routines:
> Index: libc/include/stdio.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
> retrieving revision 1.58
> diff -u -p -r1.58 stdio.h
> --- libc/include/stdio.h 3 Jul 2009 11:58:04 -0000 1.58
> +++ libc/include/stdio.h 16 Oct 2009 16:50:08 -0000
> @@ -232,7 +232,7 @@ int _EXFUN(sprintf, (char *, const char
>  int _EXFUN(remove, (const char *));
>  int _EXFUN(rename, (const char *, const char *));
>  #endif
> -#ifndef __STRICT_ANSI__
> +#if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
>  #ifdef _COMPILING_NEWLIB
>  int _EXFUN(fseeko, (FILE *, _off_t, int));
>  _off_t _EXFUN(ftello, ( FILE *));
> @@ -240,6 +240,7 @@ _off_t _EXFUN(ftello, ( FILE *));
>  int _EXFUN(fseeko, (FILE *, off_t, int));
>  off_t _EXFUN(ftello, ( FILE *));
>  #endif
> +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
>  #ifndef _REENT_ONLY
>  int _EXFUN(asiprintf, (char **, const char *, ...)
>                 _ATTRIBUTE ((__format__ (__printf__, 2, 3))));


--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

Re: [patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Jeff Johnston :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, I should of thought of that.  I'll add the setting of the flag
under Cygwin's portion of sys/config.h.

Does the __STDC_VERSION__ level need to be checked as you've implied
below or as I would expect, should it just be set all the time for Cygwin?

-- Jeff J.

On 16/10/09 01:16 PM, Corinna Vinschen wrote:

> On Oct 16 12:55, Jeff Johnston wrote:
>> I think the better solution is to emulate glibc which uses the flag
>> __USE_XOPEN2K to determine if fseeko and ftello are to be used.
>>
>> So I made the following patch which sets the __USE_XOPEN2K flag for Cygwin
>> and uses to check for fseeko, ftello when __STRICT_ANSI__ is set.
>>
>> The remainder of the I/O functions in that chunk are included if C99.
>>
>> A patch is attached.  Let me know if you have any concerns, otherwise I'll
>> check it in.
>
> I don't think this patch is correct.  It sets the __USE_XOPEN2K
> flag only when building newlib.  However, this is a header file
> and we need the right definition at compile time of any subsequent
> application, not only when building newlib.
>
> So, I assume what we need is a definition in config.h, similar to
> what Dave suggested:
>
>    #if __STDC_VERSION__>= 199901L
>    #define __USE_XOPEN2K 1
>    #endif
>
>
> Corinna
>
>
>> Index: configure.host
>> ===================================================================
>> RCS file: /cvs/src/src/newlib/configure.host,v
>> retrieving revision 1.110
>> diff -u -p -r1.110 configure.host
>> --- configure.host 8 Oct 2009 16:44:09 -0000 1.110
>> +++ configure.host 16 Oct 2009 16:50:08 -0000
>> @@ -536,7 +536,7 @@ case "${host}" in
>>   default_newlib_io_long_double="yes"
>>   default_newlib_io_pos_args="yes"
>>   CC="${CC} -I${cygwin_srcdir}/include"
>> - newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -D_COMPILING_NEWLIB -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED"
>> + newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -D_COMPILING_NEWLIB -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED -D__USE_XOPEN2K"
>>   syscall_dir=syscalls
>>   ;;
>>   # RTEMS supplies its own versions of some routines:
>> Index: libc/include/stdio.h
>> ===================================================================
>> RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
>> retrieving revision 1.58
>> diff -u -p -r1.58 stdio.h
>> --- libc/include/stdio.h 3 Jul 2009 11:58:04 -0000 1.58
>> +++ libc/include/stdio.h 16 Oct 2009 16:50:08 -0000
>> @@ -232,7 +232,7 @@ int _EXFUN(sprintf, (char *, const char
>>   int _EXFUN(remove, (const char *));
>>   int _EXFUN(rename, (const char *, const char *));
>>   #endif
>> -#ifndef __STRICT_ANSI__
>> +#if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
>>   #ifdef _COMPILING_NEWLIB
>>   int _EXFUN(fseeko, (FILE *, _off_t, int));
>>   _off_t _EXFUN(ftello, ( FILE *));
>> @@ -240,6 +240,7 @@ _off_t _EXFUN(ftello, ( FILE *));
>>   int _EXFUN(fseeko, (FILE *, off_t, int));
>>   off_t _EXFUN(ftello, ( FILE *));
>>   #endif
>> +#if !defined(__STRICT_ANSI__) || __STDC_VERSION__>= 199901L)
>>   #ifndef _REENT_ONLY
>>   int _EXFUN(asiprintf, (char **, const char *, ...)
>>                  _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
>
>


Re: [patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Dave Korn-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jeff Johnston wrote:

> Does the __STDC_VERSION__ level need to be checked as you've implied
> below or as I would expect, should it just be set all the time for Cygwin?

  I think the check would make sense as:


  #if !defined (__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
  #define __USE_XOPEN2K 1
  #endif



    cheers,
      DaveK


Re: [patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Jeff Johnston :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 16/10/09 02:35 PM, Dave Korn wrote:
> #if !defined (__STRICT_ANSI__) || (__STDC_VERSION__>= 199901L)
>    #define __USE_XOPEN2K 1
>    #endif

Ok, done.

-- Jeff J.

Re: [patch] Include some c99 functions in __STRICT_ANSI__ for cygwin c99.

by Dave Korn-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jeff Johnston wrote:
> On 16/10/09 02:35 PM, Dave Korn wrote:
>> #if !defined (__STRICT_ANSI__) || (__STDC_VERSION__>= 199901L)
>>    #define __USE_XOPEN2K 1
>>    #endif
>
> Ok, done.

  Thanks Jeff :)

    cheers,
      DaveK