Skip to content

Commit 67a67c2

Browse files
committed
Hide non-API library symbols
1 parent 281f811 commit 67a67c2

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ AC_LANG([C++])
1414

1515
AC_PATH_PROG(CCACHE,ccache)
1616

17+
saved_CXXFLAGS="$CXXFLAGS"
18+
CXXFLAGS="-fvisibility=hidden $CXXFLAGS"
19+
AC_MSG_CHECKING([if ${CXX} supports -fvisibility=hidden])
20+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
21+
[ AC_MSG_RESULT([yes]) ],
22+
[ AC_MSG_RESULT([no])
23+
CXXFLAGS="$saved_CXXFLAGS"
24+
])
25+
1726
AC_ARG_ENABLE([ccache],
1827
[AS_HELP_STRING([--disable-ccache],
1928
[do not use ccache for building (default is to use if found)])],
@@ -88,6 +97,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
8897
]
8998
)
9099

100+
AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]],[LDFLAGS="-Wl,--exclude-libs,ALL $LDFLAGS"])
101+
91102
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
92103
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
93104
## unknown options if any other warning is produced. Test the -Wfoo case, and

include/minisketch.h

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
# include <unistd.h>
1111
#endif
1212

13+
#ifndef MINISKETCH_API
14+
# if defined(_WIN32)
15+
# ifdef MINISKETCH_BUILD
16+
# define MINISKETCH_API __declspec(dllexport)
17+
# else
18+
# define MINISKETCH_API
19+
# endif
20+
# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(MINISKETCH_BUILD)
21+
# define MINISKETCH_API __attribute__ ((visibility ("default")))
22+
# else
23+
# define MINISKETCH_API
24+
# endif
25+
#endif
26+
1327
#ifdef __cplusplus
1428
# if __cplusplus >= 201103L
1529
# include <memory>
@@ -26,7 +40,7 @@ extern "C" {
2640
typedef struct minisketch minisketch;
2741

2842
/** Determine whether support for elements of `bits` bits was compiled in. */
29-
int minisketch_bits_supported(uint32_t bits);
43+
MINISKETCH_API int minisketch_bits_supported(uint32_t bits);
3044

3145
/** Determine the maximum number of implementations available.
3246
*
@@ -37,13 +51,13 @@ int minisketch_bits_supported(uint32_t bits);
3751
* function call, inclusive. Note that not every combination of implementation
3852
* and element size may exist (see further).
3953
*/
40-
uint32_t minisketch_implementation_max(void);
54+
MINISKETCH_API uint32_t minisketch_implementation_max(void);
4155

4256
/** Determine if the a combination of bits and implementation number is available.
4357
*
4458
* Returns 1 if it is, 0 otherwise.
4559
*/
46-
int minisketch_implementation_supported(uint32_t bits, uint32_t implementation);
60+
MINISKETCH_API int minisketch_implementation_supported(uint32_t bits, uint32_t implementation);
4761

4862
/** Construct a sketch for a given element size, implementation and capacity.
4963
*
@@ -54,16 +68,16 @@ int minisketch_implementation_supported(uint32_t bits, uint32_t implementation);
5468
*
5569
* If the result is not NULL, it must be destroyed using minisketch_destroy.
5670
*/
57-
minisketch* minisketch_create(uint32_t bits, uint32_t implementation, size_t capacity);
71+
MINISKETCH_API minisketch* minisketch_create(uint32_t bits, uint32_t implementation, size_t capacity);
5872

5973
/** Get the element size of a sketch in bits. */
60-
uint32_t minisketch_bits(const minisketch* sketch);
74+
MINISKETCH_API uint32_t minisketch_bits(const minisketch* sketch);
6175

6276
/** Get the capacity of a sketch. */
63-
size_t minisketch_capacity(const minisketch* sketch);
77+
MINISKETCH_API size_t minisketch_capacity(const minisketch* sketch);
6478

6579
/** Get the implementation of a sketch. */
66-
uint32_t minisketch_implementation(const minisketch* sketch);
80+
MINISKETCH_API uint32_t minisketch_implementation(const minisketch* sketch);
6781

6882
/** Set the seed for randomizing algorithm choices to a fixed value.
6983
*
@@ -76,28 +90,28 @@ uint32_t minisketch_implementation(const minisketch* sketch);
7690
* When seed is -1, a fixed internal value with predictable behavior is
7791
* used. It is only intended for testing.
7892
*/
79-
void minisketch_set_seed(minisketch* sketch, uint64_t seed);
93+
MINISKETCH_API void minisketch_set_seed(minisketch* sketch, uint64_t seed);
8094

8195
/** Clone a sketch.
8296
*
8397
* The result must be destroyed using minisketch_destroy.
8498
*/
85-
minisketch* minisketch_clone(const minisketch* sketch);
99+
MINISKETCH_API minisketch* minisketch_clone(const minisketch* sketch);
86100

87101
/** Destroy a sketch.
88102
*
89103
* The pointer that was passed in may not be used anymore afterwards.
90104
*/
91-
void minisketch_destroy(minisketch* sketch);
105+
MINISKETCH_API void minisketch_destroy(minisketch* sketch);
92106

93107
/** Compute the size in bytes for serializing a given sketch. */
94-
size_t minisketch_serialized_size(const minisketch* sketch);
108+
MINISKETCH_API size_t minisketch_serialized_size(const minisketch* sketch);
95109

96110
/** Serialize a sketch to bytes. */
97-
void minisketch_serialize(const minisketch* sketch, unsigned char* output);
111+
MINISKETCH_API void minisketch_serialize(const minisketch* sketch, unsigned char* output);
98112

99113
/** Deserialize a sketch from bytes. */
100-
void minisketch_deserialize(minisketch* sketch, const unsigned char* input);
114+
MINISKETCH_API void minisketch_deserialize(minisketch* sketch, const unsigned char* input);
101115

102116
/** Add an element to a sketch.
103117
*
@@ -112,7 +126,7 @@ void minisketch_deserialize(minisketch* sketch, const unsigned char* input);
112126
*
113127
* Note that adding the same element a second time removes it again.
114128
*/
115-
void minisketch_add_uint64(minisketch* sketch, uint64_t element);
129+
MINISKETCH_API void minisketch_add_uint64(minisketch* sketch, uint64_t element);
116130

117131
/** Merge the elements of another sketch into this sketch.
118132
*
@@ -130,7 +144,7 @@ void minisketch_add_uint64(minisketch* sketch, uint64_t element);
130144
* of two sketches with the same element size and capacity by performing a bitwise XOR
131145
* of the serializations.
132146
*/
133-
size_t minisketch_merge(minisketch* sketch, const minisketch* other_sketch);
147+
MINISKETCH_API size_t minisketch_merge(minisketch* sketch, const minisketch* other_sketch);
134148

135149
/** Decode a sketch.
136150
*
@@ -139,7 +153,7 @@ size_t minisketch_merge(minisketch* sketch, const minisketch* other_sketch);
139153
*
140154
* The return value is the number of decoded elements, or -1 if decoding failed.
141155
*/
142-
ssize_t minisketch_decode(const minisketch* sketch, size_t max_elements, uint64_t* output);
156+
MINISKETCH_API ssize_t minisketch_decode(const minisketch* sketch, size_t max_elements, uint64_t* output);
143157

144158
/** Compute the capacity needed to achieve a certain rate of false positives.
145159
*
@@ -153,7 +167,7 @@ ssize_t minisketch_decode(const minisketch* sketch, size_t max_elements, uint64_
153167
* function computes the necessary capacity. It is only guaranteed to be
154168
* accurate up to fpbits=256.
155169
*/
156-
size_t minisketch_compute_capacity(uint32_t bits, size_t max_elements, uint32_t fpbits);
170+
MINISKETCH_API size_t minisketch_compute_capacity(uint32_t bits, size_t max_elements, uint32_t fpbits);
157171

158172
/** Compute what max_elements can be decoded for a certain rate of false positives.
159173
*
@@ -171,7 +185,7 @@ size_t minisketch_compute_capacity(uint32_t bits, size_t max_elements, uint32_t
171185
* chance of 1 in 2^18.5). Therefore, minisketch_compute_max_elements with
172186
* capacity=9 will return 9.
173187
*/
174-
size_t minisketch_compute_max_elements(uint32_t bits, size_t capacity, uint32_t fpbits);
188+
MINISKETCH_API size_t minisketch_compute_max_elements(uint32_t bits, size_t capacity, uint32_t fpbits);
175189

176190
#ifdef __cplusplus
177191
}

src/minisketch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7+
78
#include <new>
89

10+
#define MINISKETCH_BUILD
11+
#ifdef _MINISKETCH_H_
12+
# error "minisketch.h cannot be included before minisketch.cpp"
13+
#endif
914
#include "../include/minisketch.h"
1015

1116
#include "false_positives.h"

0 commit comments

Comments
 (0)