Skip to content

Commit

Permalink
Move private defines from zconf.h and zconf-ng.h to zbuild.h
Browse files Browse the repository at this point in the history
* move definition of z_size_t to zbuild.h
  • Loading branch information
mtl1979 authored and Dead2 committed Mar 22, 2018
1 parent ec6adfb commit df1fd15
Show file tree
Hide file tree
Showing 34 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions adler32.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/* @(#) $Id$ */

#include "zbuild.h"
#include "zutil.h"
#include "functable.h"

Expand Down
1 change: 1 addition & 0 deletions arch/aarch64/fill_window_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/* @(#) $Id$ */

#include "zbuild.h"
#include "deflate.h"
#include "deflate_p.h"
#include "functable.h"
Expand Down
1 change: 1 addition & 0 deletions arch/aarch64/insert_string_acle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
*/

#include "zbuild.h"
#ifdef __ARM_FEATURE_CRC32
#include <arm_acle.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions arch/arm/fill_window_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/* @(#) $Id$ */

#include "zbuild.h"
#include "deflate.h"
#include "deflate_p.h"
#include "functable.h"
Expand Down
1 change: 1 addition & 0 deletions arch/arm/insert_string_acle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
*/

#include "zbuild.h"
#ifdef __ARM_FEATURE_CRC32
#include <arm_acle.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions arch/x86/crc_folding.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#ifdef X86_PCLMULQDQ_CRC

#include "zbuild.h"
#include <inttypes.h>
#include <immintrin.h>
#include <wmmintrin.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/crc_pclmulqdq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/

#include "zbuild.h"
#include "x86.h"
#include "crc_folding.h"
#include "deflate.h"
Expand Down
1 change: 1 addition & 0 deletions arch/x86/deflate_quick.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include <immintrin.h>
#ifdef _MSC_VER
# include <nmmintrin.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/fill_window_sse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#ifdef X86_SSE2_FILL_WINDOW

#include "zbuild.h"
#include <immintrin.h>
#include "deflate.h"
#include "deflate_p.h"
Expand Down
1 change: 1 addition & 0 deletions arch/x86/insert_string_sse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
*/

#include "zbuild.h"
#include "deflate.h"

/* ===========================================================================
Expand Down
3 changes: 1 addition & 2 deletions compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
/* @(#) $Id$ */

#define ZLIB_INTERNAL
#include "zbuild.h"
#if defined(ZLIB_COMPAT)
# include "zlib.h"
# define z_size_t unsigned long
#else
# include "zlib-ng.h"
# define z_size_t size_t
#endif

/* ===========================================================================
Expand Down
1 change: 1 addition & 0 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/* @(#) $Id$ */

# include "zbuild.h"
# include "gzendian.h"

/*
Expand Down
1 change: 1 addition & 0 deletions deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

/* @(#) $Id$ */

#include "zbuild.h"
#include "deflate.h"
#include "deflate_p.h"
#include "match.h"
Expand Down
1 change: 1 addition & 0 deletions deflate_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "deflate.h"
#include "deflate_p.h"
#include "match.h"
Expand Down
1 change: 1 addition & 0 deletions deflate_medium.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifdef MEDIUM_STRATEGY
#include "zbuild.h"
#include "deflate.h"
#include "deflate_p.h"
#include "match.h"
Expand Down
1 change: 1 addition & 0 deletions deflate_slow.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "deflate.h"
#include "deflate_p.h"
#include "match.h"
Expand Down
1 change: 1 addition & 0 deletions functable.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "functable.h"
#include "deflate.h"
#include "deflate_p.h"
Expand Down
1 change: 1 addition & 0 deletions gzclose.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "gzguts.h"

/* gzclose() is in a separate file so that it is linked in only if it is used.
Expand Down
1 change: 1 addition & 0 deletions gzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "gzguts.h"

#if defined(WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
Expand Down
1 change: 1 addition & 0 deletions gzread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "gzguts.h"

/* Local functions */
Expand Down
1 change: 1 addition & 0 deletions gzwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include <stdarg.h>
#include "gzguts.h"

Expand Down
1 change: 1 addition & 0 deletions infback.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
inflate_fast() can be used with either inflate.c or infback.c.
*/

#include "zbuild.h"
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
Expand Down
1 change: 1 addition & 0 deletions inffast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
Expand Down
1 change: 1 addition & 0 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
*/

#include "zbuild.h"
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
Expand Down
1 change: 1 addition & 0 deletions inftrees.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#include "zbuild.h"
#include "zutil.h"
#include "inftrees.h"

Expand Down
1 change: 1 addition & 0 deletions match.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* OUT assertion: the match length is not greater than s->lookahead
*/

#include "zbuild.h"
#include "deflate.h"

#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
Expand Down
3 changes: 1 addition & 2 deletions test/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

/* @(#) $Id$ */

#include "zbuild.h"
#ifdef ZLIB_COMPAT
# include "zlib.h"
# define z_size_t unsigned long
#else
# include "zlib-ng.h"
# define z_size_t size_t
#endif

#include <stdio.h>
Expand Down
1 change: 1 addition & 0 deletions test/minigzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* @(#) $Id$ */

#include "zbuild.h"
#ifdef ZLIB_COMPAT
# include "zlib.h"
#else
Expand Down
1 change: 1 addition & 0 deletions trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

/* #define GEN_TREES_H */

#include "zbuild.h"
#include "deflate.h"

#ifdef ZLIB_DEBUG
Expand Down
3 changes: 1 addition & 2 deletions uncompr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
/* @(#) $Id$ */

#define ZLIB_INTERNAL
#include "zbuild.h"
#ifdef ZLIB_COMPAT
# include "zlib.h"
# define z_size_t unsigned long
#else
# include "zlib-ng.h"
# define z_size_t size_t
#endif

/* ===========================================================================
Expand Down
24 changes: 24 additions & 0 deletions zbuild.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _ZBUILD_H
#define _ZBUILD_H

/* This has to be first include that defines any types */
#if defined(_MSC_VER)

This comment has been minimized.

Copy link
@pps83

pps83 Mar 16, 2020

Contributor

This shouldn't be compiler, but platform specific. E.g. should have been _WIN32 instead of _MSC_VER

# include <windows.h>

This comment has been minimized.

Copy link
@pps83

pps83 Mar 16, 2020

Contributor

This is extreme. It should not include windows.h

This comment has been minimized.

Copy link
@mtl1979

mtl1979 Mar 16, 2020

Author Collaborator

It's a compiler specific workaround. We have them for other compilers too. Including windows.h is safe in C code, but not in C++ code due to conflicting definitions of MIN and MAX macros.

This comment has been minimized.

Copy link
@pps83

pps83 Mar 16, 2020

Contributor

it's not about safety. WIndows.h is a heavy include. At least, WIN32_LEAN_AND_MEAN should be defined to avoid including all hairy stuff. It seems that the only reason it's included here is because of SSIZE_T. I'd remove the include and put actual type that windows.h defines for SSIZE_T or replace with ptrdiff_t.
Also, windows.h is obviously not compiler specific. Perhaps, most of compilers (clang?) that also compile for windows will also define _MSC_VER

This comment has been minimized.

Copy link
@mtl1979

mtl1979 Mar 16, 2020

Author Collaborator

windows.h is heavy include, because it makes sure all headers are included in correct order... including individual headers makes the code error prone as different versions of Visual Studio define certain types in different files.

Type 'ssize_t' does not exist in all versions and is defined incorrectly in some version, and so we use SSIZE_T as workaround as it is defined correctly in all versions... It is defined in basetsd.h which is not part of normal Visual Studio, but is part of Windows SDK.

This comment has been minimized.

Copy link
@pps83

pps83 Mar 20, 2020

Contributor

but... SSIZE_T cannot be ssize_t because, as you said yourself, ssize_t does not exist in ms world.
this piece wold work just as good and wouldn't need windows.h

#if INTPTR_MAX == INT64_MAX
typedef long long ssize_t;
#elif INTPTR_MAX == INT32_MAX
typedef int ssize_t;
#endif

This comment has been minimized.

Copy link
@mtl1979

mtl1979 Mar 20, 2020

Author Collaborator

"long long" is non-standard and doesn't exist in Visual C++.

This comment has been minimized.

Copy link
@pps83

pps83 Mar 23, 2020

Contributor

I don't know what to say. long long is obviously standard, and it does exist in visual c++. I used it in vs 2013, 2015, 2017, 2019 versions. I don't recall, but I'm fairly sure that it was also available in earlier versions, perhaps as early as vs2005/2008. Are you confusing long long with stdint/inttypes that didn't exist in VS up until 2015 (or whatever version when they finally added it)

This comment has been minimized.

Copy link
@mtl1979

mtl1979 Mar 23, 2020

Author Collaborator

"long long" is not ANSI C standard... ssize_t and size_t are not guaranteed to be 64 bits wide on 64-bit processors, so defining them as such is not correct. ssize_t and size_t have to be same width and differ in only signedness.

This comment has been minimized.

Copy link
@pps83

pps83 Mar 23, 2020

Contributor

I just realized that it's zip-ng which is c (not c++). I do c++, but I'd flip on my chair if long long wasn't ansi c. Are you sure?! :)
In any case, discussion stirs in wrong direction imo. We are talking windows here. Point is: including windows.h just to get definition of SSIZE_T is kind of not OK: pretty sure that windows.h (with all sub-includes is going to be larger than entire codebase of zlib-ng). For windows it would be ok to have int/long long for x86/x64. Alternatively, you might as well simply pull whatever windows.h itself defines for SSIZE_T and just typedef it right there. This is what windows.h defines SSIZE_T to:

#if INTPTR_MAX == INT64_MAX
typedef __int64 ssize_t;
#elif INTPTR_MAX == INT32_MAX
typedef long ssize_t;
#endif

__int64 is microsoft specific, and it's identical to long long. long is always the same size as int on windows, so, better simply use int imo, which brings it all to my original suggestion.

This comment has been minimized.

Copy link
@pps83

pps83 Mar 23, 2020

Contributor

https://en.wikibooks.org/wiki/C_Programming/Language_Reference says that long long was added in C99.
If this project is meant for the next generation systems as it states, it's fairly safe to assume that long long is available, especially that we are talking about windows here.

This comment has been minimized.

Copy link
@mtl1979

mtl1979 Mar 23, 2020

Author Collaborator

We still support Visual C++ 2013 that didn't implement most of the newer ANSI features... Basically we're limited to C89 features, which is quite old. Even Visual C++ 2015 had quite limited support for newer ANSI C versions.

This comment has been minimized.

Copy link
@mtl1979

mtl1979 Mar 23, 2020

Author Collaborator

The problem with using macros in preprocessor instructions is that most of the macros are defined in headers included from windows.h and not by the preprocessor itself.

This comment has been minimized.

Copy link
@nmoinvaz

nmoinvaz Mar 23, 2020

Member

I recommend submitting a PR with your suggested changes. Windows.h does seem a bit over kill (at least WIN32_MEAN_AND_LEAN can be used). A PR will move discussion there and give a better idea of suggested changes.

This comment has been minimized.

Copy link
@pps83
typedef SSIZE_T ssize_t;
#endif

#if defined(ZLIB_COMPAT)
# define PREFIX(x) x
# define PREFIX2(x) ZLIB_ ## x
# define PREFIX3(x) z_ ## x
# define zVersion zlibVersion
# define z_size_t unsigned long
#else
# define PREFIX(x) zng_ ## x
# define PREFIX2(x) ZLIBNG_ ## x
# define PREFIX3(x) zng_ ## x
# define zVersion zlibng_version
# define z_size_t size_t
#endif

#endif
5 changes: 0 additions & 5 deletions zconf-ng.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#ifndef ZCONFNG_H
#define ZCONFNG_H

#define PREFIX(x) zng_ ## x
#define PREFIX2(x) ZLIBNG_ ## x
#define PREFIX3(x) zng_ ## x
#define zVersion zlibng_version

#if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#endif
Expand Down
9 changes: 0 additions & 9 deletions zconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#ifndef ZCONF_H
#define ZCONF_H

#define PREFIX(x) x
#define PREFIX2(x) ZLIB_ ## x
#define PREFIX3(x) z_ ## x
#define zVersion zlibVersion

#if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#endif
Expand Down Expand Up @@ -84,10 +79,6 @@
# define ZEXPORT WINAPI
# define ZEXPORTVA WINAPIV
# endif
# if defined(_MSC_VER)
# include <windows.h>
typedef SSIZE_T ssize_t;
# endif
#endif

#ifndef ZEXTERN
Expand Down
1 change: 1 addition & 0 deletions zutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/* @(#) $Id$ */

#include "zbuild.h"
#include "zutil.h"
#ifdef WITH_GZFILEOP
# include "gzguts.h"
Expand Down

0 comments on commit df1fd15

Please sign in to comment.