Skip to content

Commit 13b778d

Browse files
committed
[api][visibility] Make the visibility macros more consistent
1. Follow the scheme introduced in PR facebook#2501 for both `zdict.h` and `zstd_errors.h`. 2. If the `*_VISIBLE` macro isn't set, but the `*_VISIBILITY` macro is, use that. Also make this change for `zstd.h`, since we probably shouldn't have changed that macro name without backward compatibility in the first place. 3. Change all references to `*_VISIBILITY` to `*_VISIBLE`. Fixes facebook#3359.
1 parent a78c91a commit 13b778d

File tree

5 files changed

+61
-21
lines changed

5 files changed

+61
-21
lines changed

contrib/linux-kernel/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ libzstd:
4949
-UZSTD_MULTITHREAD \
5050
-U_MSC_VER \
5151
-U_WIN32 \
52-
-RZSTDLIB_VISIBILITY= \
53-
-RZSTDERRORLIB_VISIBILITY= \
52+
-RZSTDLIB_VISIBLE= \
53+
-RZSTDERRORLIB_VISIBLE= \
5454
-RZSTD_FALLTHROUGH=fallthrough \
5555
-DZSTD_HAVE_WEAK_SYMBOLS=0 \
5656
-DZSTD_TRACE=0 \

lib/module.modulemap

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
module libzstd [extern_c] {
22
header "zstd.h"
33
export *
4-
config_macros [exhaustive] /* zstd.h */ \
4+
config_macros [exhaustive] \
5+
/* zstd.h */ \
56
ZSTD_STATIC_LINKING_ONLY, \
7+
ZSTDLIB_VISIBILITY, \
68
ZSTDLIB_VISIBLE, \
79
ZSTD_DLL_EXPORT, \
810
ZSTDLIB_STATIC_API, \
911
ZSTD_DISABLE_DEPRECATE_WARNINGS, \
1012
ZSTD_CLEVEL_DEFAULT, \
11-
/* zdict.h */ ZDICT_STATIC_LINKING_ONLY, \
13+
/* zdict.h */ \
14+
ZDICT_STATIC_LINKING_ONLY, \
15+
ZDICTLIB_VISIBLE, \
1216
ZDICTLIB_VISIBILITY, \
1317
ZDICT_DISABLE_DEPRECATE_WARNINGS, \
14-
/* zstd_errors.h */ ZSTDERRORLIB_VISIBILITY
18+
/* zstd_errors.h */ \
19+
ZSTDERRORLIB_VISIBLE, \
20+
ZSTDERRORLIB_VISIBILITY
1521

1622
module dictbuilder [extern_c] {
1723
header "zdict.h"

lib/zdict.h

+19-7
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,31 @@ extern "C" {
2121

2222

2323
/* ===== ZDICTLIB_API : control library symbols visibility ===== */
24-
#ifndef ZDICTLIB_VISIBILITY
25-
# if defined(__GNUC__) && (__GNUC__ >= 4)
26-
# define ZDICTLIB_VISIBILITY __attribute__ ((visibility ("default")))
24+
#ifndef ZDICTLIB_VISIBLE
25+
/* Backwards compatibility with old macro name */
26+
# ifdef ZDICTLIB_VISIBILITY
27+
# define ZDICTLIB_VISIBLE ZDICTLIB_VISIBILITY
28+
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
29+
# define ZDICTLIB_VISIBLE __attribute__ ((visibility ("default")))
2730
# else
28-
# define ZDICTLIB_VISIBILITY
31+
# define ZDICTLIB_VISIBLE
2932
# endif
3033
#endif
34+
35+
#ifndef ZDICTLIB_HIDDEN
36+
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
37+
# define ZDICTLIB_HIDDEN __attribute__ ((visibility ("hidden")))
38+
# else
39+
# define ZDICTLIB_HIDDEN
40+
# endif
41+
#endif
42+
3143
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
32-
# define ZDICTLIB_API __declspec(dllexport) ZDICTLIB_VISIBILITY
44+
# define ZDICTLIB_API __declspec(dllexport) ZDICTLIB_VISIBLE
3345
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
34-
# define ZDICTLIB_API __declspec(dllimport) ZDICTLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
46+
# define ZDICTLIB_API __declspec(dllimport) ZDICTLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
3547
#else
36-
# define ZDICTLIB_API ZDICTLIB_VISIBILITY
48+
# define ZDICTLIB_API ZDICTLIB_VISIBLE
3749
#endif
3850

3951
/*******************************************************************************

lib/zstd.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ extern "C" {
2121

2222
/* ===== ZSTDLIB_API : control library symbols visibility ===== */
2323
#ifndef ZSTDLIB_VISIBLE
24-
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
24+
/* Backwards compatibility with old macro name */
25+
# ifdef ZSTDLIB_VISIBILITY
26+
# define ZSTDLIB_VISIBLE ZSTDLIB_VISIBILITY
27+
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
2528
# define ZSTDLIB_VISIBLE __attribute__ ((visibility ("default")))
26-
# define ZSTDLIB_HIDDEN __attribute__ ((visibility ("hidden")))
2729
# else
2830
# define ZSTDLIB_VISIBLE
31+
# endif
32+
#endif
33+
34+
#ifndef ZSTDLIB_HIDDEN
35+
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
36+
# define ZSTDLIB_HIDDEN __attribute__ ((visibility ("hidden")))
37+
# else
2938
# define ZSTDLIB_HIDDEN
3039
# endif
3140
#endif
41+
3242
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
3343
# define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBLE
3444
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)

lib/zstd_errors.h

+19-7
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ extern "C" {
2020

2121

2222
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
23-
#ifndef ZSTDERRORLIB_VISIBILITY
24-
# if defined(__GNUC__) && (__GNUC__ >= 4)
25-
# define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default")))
23+
#ifndef ZSTDERRORLIB_VISIBLE
24+
/* Backwards compatibility with old macro name */
25+
# ifdef ZSTDERRORLIB_VISIBILITY
26+
# define ZSTDERRORLIB_VISIBLE ZSTDERRORLIB_VISIBILITY
27+
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
28+
# define ZSTDERRORLIB_VISIBLE __attribute__ ((visibility ("default")))
2629
# else
27-
# define ZSTDERRORLIB_VISIBILITY
30+
# define ZSTDERRORLIB_VISIBLE
2831
# endif
2932
#endif
33+
34+
#ifndef ZSTDERRORLIB_HIDDEN
35+
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
36+
# define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
37+
# else
38+
# define ZSTDERRORLIB_HIDDEN
39+
# endif
40+
#endif
41+
3042
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
31-
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY
43+
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBLE
3244
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
33-
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
45+
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
3446
#else
35-
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY
47+
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
3648
#endif
3749

3850
/*-*********************************************

0 commit comments

Comments
 (0)