zlib icon indicating copy to clipboard operation
zlib copied to clipboard

RIP pre-ANSI C

Open alejandro-colomar opened this issue 2 years ago • 18 comments

All compilers available today have at a minimum C89.  The dark times have come to
an end.

This patch does:

-  Assume ANSI C.  It is now a requirement to build zlib.  I wonder if anyone was still
   testing the old paths by compiling under obsolete compilers for the last decades.

-  Remove old code that was only triggered if !defined(STDC).

-  Remove definitions of STDC, since now we assume it's always true.

alejandro-colomar avatar May 23 '23 22:05 alejandro-colomar

Not sure if you're interested in supporting systems from the early 80's today. If so, please close the PR. Otherwise, I'm happy to simplify the code base a little bit. :)

alejandro-colomar avatar May 23 '23 23:05 alejandro-colomar

Changes:

  • Drop <stdint.h> changes. It is C99 stuff. [@tbeu]
$ git range-diff develop..gh/stdc develop..stdc 
 1:  3702222 =  1:  3702222 RIP pre-ANSI C
 2:  f2a4676 =  2:  f2a4676 Fix indentation after previous commit
 3:  2907307 =  3:  2907307 <stddef.h> is guaranteed by C89
 4:  de72975 <  -:  ------- <stdint.h> is guaranteed by C89
 5:  78b5dc9 =  4:  ed203a2 <stdarg.h> is guaranteed by C89
 6:  db569e5 =  5:  366b679 C89 guarantees the return of vsprintf(3)
 7:  25f2018 =  6:  01bed35 C99 guarantees the return of vsnprintf(3)
 8:  4f57065 =  7:  3ab80c3 Remove unused OF() macro
 9:  d8ea0f4 =  8:  d5ae4e8 Remove unused Z_ARG() macro

alejandro-colomar avatar Jun 01 '23 22:06 alejandro-colomar

Changes:

  • Remove spurious configure message for test that I had removed.
  • Update comment.
  • Remove always-true conditional, since we removed the corresponding macro definition.

alejandro-colomar avatar Jun 06 '23 01:06 alejandro-colomar

Not sure if you're interested in supporting systems from the early 80's today. If so, please close the PR. Otherwise, I'm happy to simplify the code base a little bit. :)

See also https://github.com/madler/zlib/commit/e9d5486e6635141f589e110fd789648aa08e9544 (https://github.com/madler/zlib/issues/633).

thesamesam avatar Jun 07 '23 10:06 thesamesam

On 2023-09-21 21:13, tbeu wrote:

@tbeu commented on this pull request.

Might be good to rebase and resolve conflicts.

Yup. Rebased. Also removed NO_ERRNO_H.

$ git range-diff develop..gh/stdc zlib/develop..stdc 1: fff91cf ! 1: 2eb262a RIP pre-ANSI C @@ contrib/minizip/unzip.c

 -#ifdef STDC
 -#  include <stddef.h>
--#  include <string.h>
--#  include <stdlib.h>
 -#endif
 +#include <stddef.h>
-+#include <string.h>
-+#include <stdlib.h>
  #ifdef NO_ERRNO_H
      extern int errno;
  #else
@@ contrib/minizip/zip.c
  
 -#ifdef STDC
 -#  include <stddef.h>
--#  include <string.h>
--#  include <stdlib.h>
 -#endif
 +#include <stddef.h>
-+#include <string.h>
-+#include <stdlib.h>
  #ifdef NO_ERRNO_H
      extern int errno;
  #else

2: af7fb73 = 2: 582315d Fix indentation after previous commit 3: a67481d ! 3: e5bb0f1 NO_snprintf is never defined @@ gzlib.c: void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) #else

  ## test/minigzip.c ##
-@@ test/minigzip.c: void file_compress(char *file, char *mode) {
+@@ test/minigzip.c: static void file_compress(char *file, char *mode) {
          exit(1);
      }
  
@@ test/minigzip.c: void file_compress(char *file, char *mode) {
      snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX);
  #else
      strcpy(outfile, file);
-@@ test/minigzip.c: void file_uncompress(char *file) {
+@@ test/minigzip.c: static void file_uncompress(char *file) {
          exit(1);
      }
  
@@ test/minigzip.c: void file_uncompress(char *file) {
      snprintf(buf, sizeof(buf), "%s", file);
  #else
      strcpy(buf, file);
-@@ test/minigzip.c: void file_uncompress(char *file) {
+@@ test/minigzip.c: static void file_uncompress(char *file) {
      } else {
          outfile = file;
          infile = buf;

4: 8e6dd13 = 4: d277547 <stddef.h> is guaranteed by C89 5: db0eaba = 5: a685e2b <stdarg.h> is guaranteed by C89 6: 37f135f = 6: 22f6fba C89 guarantees the return of vsprintf(3) 7: 1714c94 = 7: c883a00 C99 guarantees the return of vsnprintf(3) 8: 249ae7f = 8: b4e099a Remove unused OF() macro 9: 62f5ddb = 9: 3e2d5bf Remove unused Z_ARG() macro -: ------- > 10: 154c282 <errno.h> is guaranteed by ISO C

-- http://www.alejandro-colomar.es/ GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

alejandro-colomar avatar Sep 22 '23 14:09 alejandro-colomar

Would this affect those who compile zlib for the following toolsets though?

  • Visual Studio 2010
  • Visual Studio 2012
  • Visual Studio 2013
  • Visual Studio 2015
  • Visual Studio 2017
  • Visual Studio 2019
  • Visual Studio 2022

AraHaan avatar Sep 27 '23 21:09 AraHaan

On Wed, Sep 27, 2023 at 02:01:53PM -0700, AraHaan wrote:

Would this affect those who compile zlib for the following toolsets though?

  • Visual Studio 2010
  • Visual Studio 2012
  • Visual Studio 2013
  • Visual Studio 2015
  • Visual Studio 2017
  • Visual Studio 2019
  • Visual Studio 2022

I don't know. Do those toolsets support standard C (or at least the subset we need)?

alejandro-colomar avatar Sep 27 '23 21:09 alejandro-colomar

On Wed, Sep 27, 2023 at 02:01:53PM -0700, AraHaan wrote: Would this affect those who compile zlib for the following toolsets though? - Visual Studio 2010 - Visual Studio 2012 - Visual Studio 2013 - Visual Studio 2015 - Visual Studio 2017 - Visual Studio 2019 - Visual Studio 2022 I don't know. Do those toolsets support standard C (or at least the subset we need)?

Probably C89 with some Microsoft extensions.

AraHaan avatar Sep 28 '23 07:09 AraHaan

On Wed, Sep 27, 2023 at 02:01:53PM -0700, AraHaan wrote: Would this affect those who compile zlib for the following toolsets though? - Visual Studio 2010 - Visual Studio 2012 - Visual Studio 2013 - Visual Studio 2015 - Visual Studio 2017 - Visual Studio 2019 - Visual Studio 2022 I don't know. Do those toolsets support standard C (or at least the subset we need)?

Probably C89 with some Microsoft extensions.

Then most of the commits can be applied. I assume those extensions will include stdint. Not so sure about vsnprintf(3).

alejandro-colomar avatar Sep 28 '23 10:09 alejandro-colomar

@AraHaan

So, I suggest skipping the commit "C99 guarantees the return of vsnprintf(3)".

https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010

VS2010 doesn't provide snprintf(3).

Other than that, all should be good. AFAIR, VS has been only C89-complying (and probably not even that, but mostly). C99 support was only added recently. This PR is mostly C89-complying, except for the vsnprintf(3) commit, which specifically says C99. Skip that one, and we should be good. Should I rebase? Or will you skip it while applying?

alejandro-colomar avatar Oct 11 '23 11:10 alejandro-colomar

@AraHaan

So, I suggest skipping the commit "C99 guarantees the return of vsnprintf(3)".

https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010

VS2010 doesn't provide snprintf(3).

Other than that, all should be good. AFAIR, VS has been only C89-complying (and probably not even that, but mostly). C99 support was only added recently. This PR is mostly C89-complying, except for the vsnprintf(3) commit, which specifically says C99. Skip that one, and we should be good. Should I rebase? Or will you skip it while applying?

Oh, I didn't remember. This commit didn't assume that snprintf(3) was present. Only that if it was present it was standards complying. That's still valid with VS2010, which doesn't provide it. We can apply all commits.

alejandro-colomar avatar Oct 11 '23 11:10 alejandro-colomar

@alejandro-colomar, @tbeu, @AraHaan: Z_ARG has been removed:

  • https://github.com/madler/zlib/commit/3f635df97edbb85f55f8e991e5f00d94f4132a14

Neustradamus avatar Jan 19 '24 07:01 Neustradamus

Thanks!

v5 changes:

  • Rebase to madler/develop
$ git range-diff develop..alx/stdc madler/develop..stdc 
 1:  2eb262a !  1:  5bb6819 RIP pre-ANSI C
    @@ zconf.h
     +#  define OF(args)  args
      #endif
      
    - #ifndef Z_ARG /* function prototypes for stdarg */
    --#  if defined(STDC) || defined(Z_HAVE_STDARG_H)
    --#    define Z_ARG(args)  args
    --#  else
    --#    define Z_ARG(args)  ()
    --#  endif
    -+#  define Z_ARG(args)  args
    - #endif
    - 
      /* The following definitions for FAR are needed only for MSDOS mixed
     @@ zconf.h: typedef int   FAR intf;
      typedef uInt  FAR uIntf;
    @@ zconf.h.cmakein
     +#  define OF(args)  args
      #endif
      
    - #ifndef Z_ARG /* function prototypes for stdarg */
    --#  if defined(STDC) || defined(Z_HAVE_STDARG_H)
    --#    define Z_ARG(args)  args
    --#  else
    --#    define Z_ARG(args)  ()
    --#  endif
    -+#  define Z_ARG(args)  args
    - #endif
    - 
      /* The following definitions for FAR are needed only for MSDOS mixed
     @@ zconf.h.cmakein: typedef int   FAR intf;
      typedef uInt  FAR uIntf;
    @@ zconf.h.in
     +#  define OF(args)  args
      #endif
      
    - #ifndef Z_ARG /* function prototypes for stdarg */
    --#  if defined(STDC) || defined(Z_HAVE_STDARG_H)
    --#    define Z_ARG(args)  args
    --#  else
    --#    define Z_ARG(args)  ()
    --#  endif
    -+#  define Z_ARG(args)  args
    - #endif
    - 
      /* The following definitions for FAR are needed only for MSDOS mixed
     @@ zconf.h.in: typedef int   FAR intf;
      typedef uInt  FAR uIntf;
 2:  582315d =  2:  ab7a569 Fix indentation after previous commit
 3:  e5bb0f1 =  3:  44eda1a NO_snprintf is never defined
 4:  d277547 =  4:  fa45ad7 <stddef.h> is guaranteed by C89
 5:  a685e2b =  5:  9990f65 <stdarg.h> is guaranteed by C89
 6:  22f6fba =  6:  86fd62f C89 guarantees the return of vsprintf(3)
 7:  c883a00 =  7:  a9310aa C99 guarantees the return of vsnprintf(3)
 8:  b4e099a <  -:  ------- Remove unused OF() macro
 9:  3e2d5bf !  8:  18a5141 Remove unused Z_ARG() macro
    @@ Metadata
     Author: Alejandro Colomar <[email protected]>
     
      ## Commit message ##
    -    Remove unused Z_ARG() macro
    +    Remove unused OF() macro
     
         Signed-off-by: Alejandro Colomar <[email protected]>
     
    @@ zconf.h
      
                              /* Type declarations */
      
    --#ifndef Z_ARG /* function prototypes for stdarg */
    --#  define Z_ARG(args)  args
    +-#ifndef OF /* function prototypes */
    +-#  define OF(args)  args
     -#endif
     -
      /* The following definitions for FAR are needed only for MSDOS mixed
    @@ zconf.h.cmakein
      
                              /* Type declarations */
      
    --#ifndef Z_ARG /* function prototypes for stdarg */
    --#  define Z_ARG(args)  args
    +-#ifndef OF /* function prototypes */
    +-#  define OF(args)  args
     -#endif
     -
      /* The following definitions for FAR are needed only for MSDOS mixed
    @@ zconf.h.in
      
                              /* Type declarations */
      
    --#ifndef Z_ARG /* function prototypes for stdarg */
    --#  define Z_ARG(args)  args
    +-#ifndef OF /* function prototypes */
    +-#  define OF(args)  args
     -#endif
     -
      /* The following definitions for FAR are needed only for MSDOS mixed
10:  154c282 =  9:  a981f75 <errno.h> is guaranteed by ISO C

alejandro-colomar avatar Jan 19 '24 10:01 alejandro-colomar

v6 changes:

  • Use INT_MAX directly
$ git range-diff madler/develop alx/stdc stdc 
 1:  5bb6819 =  1:  5bb6819 RIP pre-ANSI C
 2:  ab7a569 =  2:  ab7a569 Fix indentation after previous commit
 3:  44eda1a =  3:  44eda1a NO_snprintf is never defined
 4:  fa45ad7 =  4:  fa45ad7 <stddef.h> is guaranteed by C89
 5:  9990f65 =  5:  9990f65 <stdarg.h> is guaranteed by C89
 6:  86fd62f =  6:  86fd62f C89 guarantees the return of vsprintf(3)
 7:  a9310aa =  7:  a9310aa C99 guarantees the return of vsnprintf(3)
 8:  18a5141 =  8:  18a5141 Remove unused OF() macro
 9:  a981f75 =  9:  a981f75 <errno.h> is guaranteed by ISO C
 -:  ------- > 10:  90b5f2d <limits.h> and INT_MAX are guaranteed by C89
 -:  ------- > 11:  3d86bb3 Use INT_MAX directly

alejandro-colomar avatar Jan 19 '24 10:01 alejandro-colomar

@madler Do you have any thoughts about this patch set?

alejandro-colomar avatar Jan 25 '24 14:01 alejandro-colomar

I am focusing on more critical items. None of this is required for zlib to build correctly. I have made the changes required to avoid warnings due to early adoption of C23.

madler avatar Jan 25 '24 17:01 madler

Hi Mark,

On Thu, Jan 25, 2024 at 09:06:36AM -0800, Mark Adler wrote:

I am focusing on more critical items. None of this is required for zlib to build correctly. I have made the changes required to avoid warnings due to early adoption of C23.

Sure, no problem. What I was wondering is if you'd accept the patches some day, when there are no critical items taking your time, or if you don't want them at all.

Have a lovely day, Alex

-- https://www.alejandro-colomar.es/ Looking for a remote C programming job at the moment.

alejandro-colomar avatar Jan 26 '24 12:01 alejandro-colomar

I may eventually apply them, once I look at them more closely.

madler avatar Jan 26 '24 17:01 madler