Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIP pre-ANSI C #817

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

Conversation

alejandro-colomar
Copy link

@alejandro-colomar alejandro-colomar commented May 23, 2023

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
Copy link
Author

alejandro-colomar commented May 23, 2023

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. :)

CMakeLists.txt Show resolved Hide resolved
@alejandro-colomar
Copy link
Author

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
Copy link
Author

alejandro-colomar commented Jun 6, 2023

Changes:

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

@thesamesam
Copy link

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 e9d5486 (#633).

zconf.h Outdated
@@ -265,10 +265,6 @@

/* Type declarations */

#ifndef OF /* function prototypes */
# define OF(args) args

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please. This has caused endless conflicts in other packages.

Copy link
Contributor

@tbeu tbeu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to rebase and resolve conflicts.

@alejandro-colomar
Copy link
Author

alejandro-colomar commented Sep 22, 2023 via email

@AraHaan
Copy link
Contributor

AraHaan commented Sep 27, 2023

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

@alejandro-colomar
Copy link
Author

alejandro-colomar commented Sep 27, 2023 via email

@AraHaan
Copy link
Contributor

AraHaan commented Sep 28, 2023

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.

@alejandro-colomar
Copy link
Author

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
Copy link
Author

@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
Copy link
Author

@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.

@Neustradamus
Copy link

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

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.

-  As a consequence of this patch, vsprintf(3) is now always available,
   and vsnprintf(3) is available if snprintf(3) is.

Signed-off-by: Alejandro Colomar <alx@nginx.com>
I left the indentation in ./configure intact, to make the patch more clear,
so that it's visible that it doesn't touch anything that it shouldn't.

Fix the indentation now.

Signed-off-by: Alejandro Colomar <alx@nginx.com>
The definition of this macro was removed two commits ago.  Now, this
macro is never defined, so the condition !defined(NO_snprintf) would
always be true.

However, it might still be the case that snprintf(3) is not available,
since it was added in C99, but we're already covered by NO_vsnprintf,
since that function was added at the same time.

Signed-off-by: Alejandro Colomar <alx@nginx.org>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
This function wasn't present in C89.  It was added in C99, where it
returns the size.

SUSv2 (year 1997) already had vsnprintf(3), and it specified already
a return value.  BTW, there was a historic difference that was later
fixed in C99 and POSIX.1-2001, which is mentioned in the HISTORY section
in the manual page in the Linux man-pages, but this detail shouldn't
affect this patch.

snprintf(3):
HISTORY
	[...]

       snprintf()
       vsnprintf()
              SUSv2, C99, POSIX.1‐2001.

              Concerning the return value of snprintf(), SUSv2 and C99
              contradict  each  other:  when snprintf() is called with
              size=0 then SUSv2 stipulates an unspecified return value
              less than 1, while C99 allows str to  be  NULL  in  this
              case, and gives the return value (as always) as the num‐
              ber  of  characters that would have been written in case
              the output string has been large  enough.   POSIX.1‐2001
              and  later  align their specification of snprintf() with
              C99.

Signed-off-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar
Copy link
Author

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 <alx@kernel.org>
     
      ## Commit message ##
    -    Remove unused Z_ARG() macro
    +    Remove unused OF() macro
     
         Signed-off-by: Alejandro Colomar <alx@nginx.com>
     
    @@ 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

And ironically, the only file that was calling this function, was also
including <limits.h> unconditionally.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
gz_intmax() is just a wrapper around INT_MAX.  Use the real thing.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar
Copy link
Author

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
Copy link
Author

alejandro-colomar commented Jan 25, 2024

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

@madler
Copy link
Owner

madler commented Jan 25, 2024

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.

@alejandro-colomar
Copy link
Author

alejandro-colomar commented Jan 26, 2024 via email

@madler
Copy link
Owner

madler commented Jan 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants