Skip to content

Commit

Permalink
Determine whether platform supports dll declspec
Browse files Browse the repository at this point in the history
Clang contains __has_declspec_attribute for MSVC compatibility. This can be
used to determine whether __declspec is available. Use this to determine if
dllimport/dllexport should be used when exporting the zlib API.
  • Loading branch information
donny-dont authored and Dead2 committed Jun 24, 2020
1 parent ba72bc9 commit c5dd84b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 42 deletions.
48 changes: 27 additions & 21 deletions zconf-ng.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
# endif
#endif

/* Clang macro for detecting declspec support
* https://clang.llvm.org/docs/LanguageExtensions.html#has-declspec-attribute
*/
#ifndef __has_declspec_attribute
# define __has_declspec_attribute(x) 0
#endif

/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# define MAX_MEM_LEVEL 9
Expand Down Expand Up @@ -48,30 +55,29 @@
/* Type declarations */


#if defined(_WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
# if defined(ZLIB_DLL)
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# define ZEXPORTVA WINAPIV
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
#if defined(ZLIB_DLL) && (defined(_WIN32) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport)))
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif

/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
#if defined(ZLIB_WINAPI) && defined(_WIN32)
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# define ZEXPORTVA WINAPIV
#endif

#ifndef ZEXTERN
# define ZEXTERN extern
#endif
Expand Down
48 changes: 27 additions & 21 deletions zconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
# endif
#endif

/* Clang macro for detecting declspec support
* https://clang.llvm.org/docs/LanguageExtensions.html#has-declspec-attribute
*/
#ifndef __has_declspec_attribute
# define __has_declspec_attribute(x) 0
#endif

/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# define MAX_MEM_LEVEL 9
Expand Down Expand Up @@ -52,30 +59,29 @@
# define OF(args) args
#endif

#if defined(_WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
# if defined(ZLIB_DLL)
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# define ZEXPORTVA WINAPIV
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
#if defined(ZLIB_DLL) && (defined(_WIN32) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport)))
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif

/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
#if defined(ZLIB_WINAPI) && defined(_WIN32)
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# define ZEXPORTVA WINAPIV
#endif

#ifndef ZEXTERN
# define ZEXTERN extern
#endif
Expand Down

0 comments on commit c5dd84b

Please sign in to comment.