Add LEVELDB_EXPORT macro to export public symbols.

gcc defaults to exporting all symbols, but other linkers do not. Adding
the LEVELDB_EXPORT macro allows a project to set LEVELDB_SHARED_LIBRARY
when building/linking with leveldb as a shared library.

This is to allow leveldb to be created as a shared library on all
platforms support by Chrome and enables a fix for
https://bugs.chromium.org/p/chromium/issues/detail?id=764810.

This also has the benefit of reducing the shared library size from
418863 to 380367 bytes (64-bit Linux).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171037148
This commit is contained in:
cmumford 2017-10-04 11:26:45 -07:00 committed by Victor Costan
parent 542590d2a8
commit 4a7e7f50dc
17 changed files with 224 additions and 191 deletions

View File

@ -81,7 +81,7 @@ else
STATIC_OUTDIR=out-static STATIC_OUTDIR=out-static
SHARED_OUTDIR=out-shared SHARED_OUTDIR=out-shared
STATIC_PROGRAMS := $(addprefix $(STATIC_OUTDIR)/, $(PROGNAMES)) STATIC_PROGRAMS := $(addprefix $(STATIC_OUTDIR)/, $(PROGNAMES))
SHARED_PROGRAMS := $(addprefix $(SHARED_OUTDIR)/, db_bench) SHARED_PROGRAMS := $(addprefix $(SHARED_OUTDIR)/, db_bench c_test)
endif endif
STATIC_LIBOBJECTS := $(addprefix $(STATIC_OUTDIR)/, $(SOURCES:.cc=.o)) STATIC_LIBOBJECTS := $(addprefix $(STATIC_OUTDIR)/, $(SOURCES:.cc=.o))
@ -98,6 +98,7 @@ SHARED_MEMENVOBJECTS := $(addprefix $(SHARED_OUTDIR)/, $(MEMENV_SOURCES:.cc=.o))
TESTUTIL := $(STATIC_OUTDIR)/util/testutil.o TESTUTIL := $(STATIC_OUTDIR)/util/testutil.o
TESTHARNESS := $(STATIC_OUTDIR)/util/testharness.o $(TESTUTIL) TESTHARNESS := $(STATIC_OUTDIR)/util/testharness.o $(TESTUTIL)
TEST_STATIC_OBJS := $(STATIC_OUTDIR)/port/port_posix.o $(STATIC_OUTDIR)/port/port_posix_sse.o $(STATIC_OUTDIR)/util/crc32c.o $(STATIC_OUTDIR)/util/histogram.o
STATIC_TESTOBJS := $(addprefix $(STATIC_OUTDIR)/, $(addsuffix .o, $(TESTS))) STATIC_TESTOBJS := $(addprefix $(STATIC_OUTDIR)/, $(addsuffix .o, $(TESTS)))
STATIC_UTILOBJS := $(addprefix $(STATIC_OUTDIR)/, $(addsuffix .o, $(UTILS))) STATIC_UTILOBJS := $(addprefix $(STATIC_OUTDIR)/, $(addsuffix .o, $(UTILS)))
@ -112,6 +113,8 @@ ifneq ($(PLATFORM_SHARED_EXT),)
# Many leveldb test apps use non-exported API's. Only build a subset for testing. # Many leveldb test apps use non-exported API's. Only build a subset for testing.
SHARED_ALLOBJS := $(SHARED_LIBOBJECTS) $(SHARED_MEMENVOBJECTS) $(TESTHARNESS) SHARED_ALLOBJS := $(SHARED_LIBOBJECTS) $(SHARED_MEMENVOBJECTS) $(TESTHARNESS)
SHARED_CXXFLAGS += -DLEVELDB_SHARED_LIBRARY
SHARED_BUILD_CXXFLAGS += $(SHARED_CXXFLAGS) -DLEVELDB_COMPILE_LIBRARY
ifneq ($(PLATFORM_SHARED_VERSIONED),true) ifneq ($(PLATFORM_SHARED_VERSIONED),true)
SHARED_LIB1 = libleveldb.$(PLATFORM_SHARED_EXT) SHARED_LIB1 = libleveldb.$(PLATFORM_SHARED_EXT)
@ -386,13 +389,20 @@ $(STATIC_OUTDIR)/write_batch_test:db/write_batch_test.cc $(STATIC_LIBOBJECTS) $(
$(STATIC_OUTDIR)/memenv_test:$(STATIC_OUTDIR)/helpers/memenv/memenv_test.o $(STATIC_OUTDIR)/libmemenv.a $(STATIC_OUTDIR)/libleveldb.a $(TESTHARNESS) $(STATIC_OUTDIR)/memenv_test:$(STATIC_OUTDIR)/helpers/memenv/memenv_test.o $(STATIC_OUTDIR)/libmemenv.a $(STATIC_OUTDIR)/libleveldb.a $(TESTHARNESS)
$(XCRUN) $(CXX) $(LDFLAGS) $(STATIC_OUTDIR)/helpers/memenv/memenv_test.o $(STATIC_OUTDIR)/libmemenv.a $(STATIC_OUTDIR)/libleveldb.a $(TESTHARNESS) -o $@ $(LIBS) $(XCRUN) $(CXX) $(LDFLAGS) $(STATIC_OUTDIR)/helpers/memenv/memenv_test.o $(STATIC_OUTDIR)/libmemenv.a $(STATIC_OUTDIR)/libleveldb.a $(TESTHARNESS) -o $@ $(LIBS)
$(SHARED_OUTDIR)/db_bench:$(SHARED_OUTDIR)/db/db_bench.o $(SHARED_LIBS) $(TESTUTIL) $(SHARED_OUTDIR)/db_bench:$(SHARED_OUTDIR)/db/db_bench.o $(SHARED_LIBS) $(TESTUTIL) $(TEST_STATIC_OBJS)
$(XCRUN) $(CXX) $(LDFLAGS) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SHARED_OUTDIR)/db/db_bench.o $(TESTUTIL) $(SHARED_OUTDIR)/$(SHARED_LIB3) -o $@ $(LIBS) $(XCRUN) $(CXX) $(LDFLAGS) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SHARED_CXXFLAGS) $(SHARED_OUTDIR)/db/db_bench.o $(TESTUTIL) $(TEST_STATIC_OBJS) $(SHARED_OUTDIR)/$(SHARED_LIB3) -o $@ $(LIBS)
.PHONY: run-shared $(SHARED_OUTDIR)/c_test:$(SHARED_OUTDIR)/db/c_test.o $(SHARED_LIBS) $(TESTUTIL) $(TEST_STATIC_OBJS)
run-shared: $(SHARED_OUTDIR)/db_bench $(XCRUN) $(CXX) $(LDFLAGS) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SHARED_CXXFLAGS) $(SHARED_OUTDIR)/db/c_test.o $(TESTUTIL) $(TEST_STATIC_OBJS) $(SHARED_OUTDIR)/$(SHARED_LIB3) -o $@ $(LIBS)
.PHONY: run-shared-db_bench
run-shared-db_bench: $(SHARED_OUTDIR)/db_bench
LD_LIBRARY_PATH=$(SHARED_OUTDIR) $(SHARED_OUTDIR)/db_bench LD_LIBRARY_PATH=$(SHARED_OUTDIR) $(SHARED_OUTDIR)/db_bench
.PHONY: run-shared-c_test
run-shared-c_test: $(SHARED_OUTDIR)/c_test
LD_LIBRARY_PATH=$(SHARED_OUTDIR) $(SHARED_OUTDIR)/c_test
$(SIMULATOR_OUTDIR)/%.o: %.cc $(SIMULATOR_OUTDIR)/%.o: %.cc
xcrun -sdk iphonesimulator $(CXX) $(CXXFLAGS) $(SIMULATOR_CFLAGS) -c $< -o $@ xcrun -sdk iphonesimulator $(CXX) $(CXXFLAGS) $(SIMULATOR_CFLAGS) -c $< -o $@
@ -412,13 +422,13 @@ $(STATIC_OUTDIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
$(SHARED_OUTDIR)/%.o: %.cc $(SHARED_OUTDIR)/%.o: %.cc
$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@ $(CXX) $(CXXFLAGS) $(SHARED_BUILD_CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@
$(SHARED_OUTDIR)/%.o: %.c $(SHARED_OUTDIR)/%.o: %.c
$(CC) $(CFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) $(SHARED_BUILD_CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@
$(STATIC_OUTDIR)/port/port_posix_sse.o: port/port_posix_sse.cc $(STATIC_OUTDIR)/port/port_posix_sse.o: port/port_posix_sse.cc
$(CXX) $(CXXFLAGS) $(PLATFORM_SSEFLAGS) -c $< -o $@ $(CXX) $(CXXFLAGS) $(SHARED_BUILD_CXXFLAGS) $(PLATFORM_SSEFLAGS) -c $< -o $@
$(SHARED_OUTDIR)/port/port_posix_sse.o: port/port_posix_sse.cc $(SHARED_OUTDIR)/port/port_posix_sse.o: port/port_posix_sse.cc
$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(PLATFORM_SSEFLAGS) -c $< -o $@ $(CXX) $(CXXFLAGS) $(SHARED_BUILD_CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(PLATFORM_SSEFLAGS) -c $< -o $@

View File

@ -61,7 +61,7 @@ PLATFORM_LDFLAGS=
PLATFORM_LIBS= PLATFORM_LIBS=
PLATFORM_SHARED_EXT="so" PLATFORM_SHARED_EXT="so"
PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl," PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
PLATFORM_SHARED_CFLAGS="-fPIC" PLATFORM_SHARED_CFLAGS="-fPIC -fvisibility=hidden"
PLATFORM_SHARED_VERSIONED=true PLATFORM_SHARED_VERSIONED=true
PLATFORM_SSEFLAGS= PLATFORM_SSEFLAGS=

View File

@ -47,6 +47,7 @@ extern "C" {
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "leveldb/export.h"
/* Exported types */ /* Exported types */
@ -69,204 +70,178 @@ typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
/* DB operations */ /* DB operations */
extern leveldb_t* leveldb_open( LEVELDB_EXPORT leveldb_t* leveldb_open(const leveldb_options_t* options,
const leveldb_options_t* options, const char* name, char** errptr);
const char* name,
char** errptr);
extern void leveldb_close(leveldb_t* db); LEVELDB_EXPORT void leveldb_close(leveldb_t* db);
extern void leveldb_put( LEVELDB_EXPORT void leveldb_put(leveldb_t* db,
leveldb_t* db,
const leveldb_writeoptions_t* options, const leveldb_writeoptions_t* options,
const char* key, size_t keylen, const char* key, size_t keylen, const char* val,
const char* val, size_t vallen, size_t vallen, char** errptr);
char** errptr);
extern void leveldb_delete( LEVELDB_EXPORT void leveldb_delete(leveldb_t* db,
leveldb_t* db,
const leveldb_writeoptions_t* options, const leveldb_writeoptions_t* options,
const char* key, size_t keylen, const char* key, size_t keylen,
char** errptr); char** errptr);
extern void leveldb_write( LEVELDB_EXPORT void leveldb_write(leveldb_t* db,
leveldb_t* db,
const leveldb_writeoptions_t* options, const leveldb_writeoptions_t* options,
leveldb_writebatch_t* batch, leveldb_writebatch_t* batch, char** errptr);
char** errptr);
/* Returns NULL if not found. A malloc()ed array otherwise. /* Returns NULL if not found. A malloc()ed array otherwise.
Stores the length of the array in *vallen. */ Stores the length of the array in *vallen. */
extern char* leveldb_get( LEVELDB_EXPORT char* leveldb_get(leveldb_t* db,
leveldb_t* db,
const leveldb_readoptions_t* options, const leveldb_readoptions_t* options,
const char* key, size_t keylen, const char* key, size_t keylen, size_t* vallen,
size_t* vallen,
char** errptr); char** errptr);
extern leveldb_iterator_t* leveldb_create_iterator( LEVELDB_EXPORT leveldb_iterator_t* leveldb_create_iterator(
leveldb_t* db, leveldb_t* db, const leveldb_readoptions_t* options);
const leveldb_readoptions_t* options);
extern const leveldb_snapshot_t* leveldb_create_snapshot( LEVELDB_EXPORT const leveldb_snapshot_t* leveldb_create_snapshot(leveldb_t* db);
leveldb_t* db);
extern void leveldb_release_snapshot( LEVELDB_EXPORT void leveldb_release_snapshot(
leveldb_t* db, leveldb_t* db, const leveldb_snapshot_t* snapshot);
const leveldb_snapshot_t* snapshot);
/* Returns NULL if property name is unknown. /* Returns NULL if property name is unknown.
Else returns a pointer to a malloc()-ed null-terminated value. */ Else returns a pointer to a malloc()-ed null-terminated value. */
extern char* leveldb_property_value( LEVELDB_EXPORT char* leveldb_property_value(leveldb_t* db,
leveldb_t* db,
const char* propname); const char* propname);
extern void leveldb_approximate_sizes( LEVELDB_EXPORT void leveldb_approximate_sizes(
leveldb_t* db, leveldb_t* db, int num_ranges, const char* const* range_start_key,
int num_ranges, const size_t* range_start_key_len, const char* const* range_limit_key,
const char* const* range_start_key, const size_t* range_start_key_len, const size_t* range_limit_key_len, uint64_t* sizes);
const char* const* range_limit_key, const size_t* range_limit_key_len,
uint64_t* sizes);
extern void leveldb_compact_range( LEVELDB_EXPORT void leveldb_compact_range(leveldb_t* db, const char* start_key,
leveldb_t* db, size_t start_key_len,
const char* start_key, size_t start_key_len, const char* limit_key,
const char* limit_key, size_t limit_key_len); size_t limit_key_len);
/* Management operations */ /* Management operations */
extern void leveldb_destroy_db( LEVELDB_EXPORT void leveldb_destroy_db(const leveldb_options_t* options,
const leveldb_options_t* options, const char* name, char** errptr);
const char* name,
char** errptr);
extern void leveldb_repair_db( LEVELDB_EXPORT void leveldb_repair_db(const leveldb_options_t* options,
const leveldb_options_t* options, const char* name, char** errptr);
const char* name,
char** errptr);
/* Iterator */ /* Iterator */
extern void leveldb_iter_destroy(leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_destroy(leveldb_iterator_t*);
extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*); LEVELDB_EXPORT unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
extern void leveldb_iter_seek_to_first(leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_seek_to_first(leveldb_iterator_t*);
extern void leveldb_iter_seek_to_last(leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_seek_to_last(leveldb_iterator_t*);
extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen); LEVELDB_EXPORT void leveldb_iter_seek(leveldb_iterator_t*, const char* k,
extern void leveldb_iter_next(leveldb_iterator_t*); size_t klen);
extern void leveldb_iter_prev(leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_next(leveldb_iterator_t*);
extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen); LEVELDB_EXPORT void leveldb_iter_prev(leveldb_iterator_t*);
extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen); LEVELDB_EXPORT const char* leveldb_iter_key(const leveldb_iterator_t*,
extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr); size_t* klen);
LEVELDB_EXPORT const char* leveldb_iter_value(const leveldb_iterator_t*,
size_t* vlen);
LEVELDB_EXPORT void leveldb_iter_get_error(const leveldb_iterator_t*,
char** errptr);
/* Write batch */ /* Write batch */
extern leveldb_writebatch_t* leveldb_writebatch_create(); LEVELDB_EXPORT leveldb_writebatch_t* leveldb_writebatch_create();
extern void leveldb_writebatch_destroy(leveldb_writebatch_t*); LEVELDB_EXPORT void leveldb_writebatch_destroy(leveldb_writebatch_t*);
extern void leveldb_writebatch_clear(leveldb_writebatch_t*); LEVELDB_EXPORT void leveldb_writebatch_clear(leveldb_writebatch_t*);
extern void leveldb_writebatch_put( LEVELDB_EXPORT void leveldb_writebatch_put(leveldb_writebatch_t*,
leveldb_writebatch_t*,
const char* key, size_t klen, const char* key, size_t klen,
const char* val, size_t vlen); const char* val, size_t vlen);
extern void leveldb_writebatch_delete( LEVELDB_EXPORT void leveldb_writebatch_delete(leveldb_writebatch_t*,
leveldb_writebatch_t*,
const char* key, size_t klen); const char* key, size_t klen);
extern void leveldb_writebatch_iterate( LEVELDB_EXPORT void leveldb_writebatch_iterate(
leveldb_writebatch_t*, leveldb_writebatch_t*, void* state,
void* state,
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
void (*deleted)(void*, const char* k, size_t klen)); void (*deleted)(void*, const char* k, size_t klen));
/* Options */ /* Options */
extern leveldb_options_t* leveldb_options_create(); LEVELDB_EXPORT leveldb_options_t* leveldb_options_create();
extern void leveldb_options_destroy(leveldb_options_t*); LEVELDB_EXPORT void leveldb_options_destroy(leveldb_options_t*);
extern void leveldb_options_set_comparator( LEVELDB_EXPORT void leveldb_options_set_comparator(leveldb_options_t*,
leveldb_options_t*,
leveldb_comparator_t*); leveldb_comparator_t*);
extern void leveldb_options_set_filter_policy( LEVELDB_EXPORT void leveldb_options_set_filter_policy(leveldb_options_t*,
leveldb_options_t*,
leveldb_filterpolicy_t*); leveldb_filterpolicy_t*);
extern void leveldb_options_set_create_if_missing( LEVELDB_EXPORT void leveldb_options_set_create_if_missing(leveldb_options_t*,
leveldb_options_t*, unsigned char); unsigned char);
extern void leveldb_options_set_error_if_exists( LEVELDB_EXPORT void leveldb_options_set_error_if_exists(leveldb_options_t*,
leveldb_options_t*, unsigned char); unsigned char);
extern void leveldb_options_set_paranoid_checks( LEVELDB_EXPORT void leveldb_options_set_paranoid_checks(leveldb_options_t*,
leveldb_options_t*, unsigned char); unsigned char);
extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*); LEVELDB_EXPORT void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*); LEVELDB_EXPORT void leveldb_options_set_info_log(leveldb_options_t*,
extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t); leveldb_logger_t*);
extern void leveldb_options_set_max_open_files(leveldb_options_t*, int); LEVELDB_EXPORT void leveldb_options_set_write_buffer_size(leveldb_options_t*,
extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*); size_t);
extern void leveldb_options_set_block_size(leveldb_options_t*, size_t); LEVELDB_EXPORT void leveldb_options_set_max_open_files(leveldb_options_t*, int);
extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int); LEVELDB_EXPORT void leveldb_options_set_cache(leveldb_options_t*,
leveldb_cache_t*);
LEVELDB_EXPORT void leveldb_options_set_block_size(leveldb_options_t*, size_t);
LEVELDB_EXPORT void leveldb_options_set_block_restart_interval(
leveldb_options_t*, int);
enum { enum {
leveldb_no_compression = 0, leveldb_no_compression = 0,
leveldb_snappy_compression = 1 leveldb_snappy_compression = 1
}; };
extern void leveldb_options_set_compression(leveldb_options_t*, int); LEVELDB_EXPORT void leveldb_options_set_compression(leveldb_options_t*, int);
/* Comparator */ /* Comparator */
extern leveldb_comparator_t* leveldb_comparator_create( LEVELDB_EXPORT leveldb_comparator_t* leveldb_comparator_create(
void* state, void* state, void (*destructor)(void*),
void (*destructor)(void*), int (*compare)(void*, const char* a, size_t alen, const char* b,
int (*compare)( size_t blen),
void*,
const char* a, size_t alen,
const char* b, size_t blen),
const char* (*name)(void*)); const char* (*name)(void*));
extern void leveldb_comparator_destroy(leveldb_comparator_t*); LEVELDB_EXPORT void leveldb_comparator_destroy(leveldb_comparator_t*);
/* Filter policy */ /* Filter policy */
extern leveldb_filterpolicy_t* leveldb_filterpolicy_create( LEVELDB_EXPORT leveldb_filterpolicy_t* leveldb_filterpolicy_create(
void* state, void* state, void (*destructor)(void*),
void (*destructor)(void*), char* (*create_filter)(void*, const char* const* key_array,
char* (*create_filter)( const size_t* key_length_array, int num_keys,
void*,
const char* const* key_array, const size_t* key_length_array,
int num_keys,
size_t* filter_length), size_t* filter_length),
unsigned char (*key_may_match)( unsigned char (*key_may_match)(void*, const char* key, size_t length,
void*,
const char* key, size_t length,
const char* filter, size_t filter_length), const char* filter, size_t filter_length),
const char* (*name)(void*)); const char* (*name)(void*));
extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*); LEVELDB_EXPORT void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*);
extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom( LEVELDB_EXPORT leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(
int bits_per_key); int bits_per_key);
/* Read options */ /* Read options */
extern leveldb_readoptions_t* leveldb_readoptions_create(); LEVELDB_EXPORT leveldb_readoptions_t* leveldb_readoptions_create();
extern void leveldb_readoptions_destroy(leveldb_readoptions_t*); LEVELDB_EXPORT void leveldb_readoptions_destroy(leveldb_readoptions_t*);
extern void leveldb_readoptions_set_verify_checksums( LEVELDB_EXPORT void leveldb_readoptions_set_verify_checksums(
leveldb_readoptions_t*,
unsigned char);
extern void leveldb_readoptions_set_fill_cache(
leveldb_readoptions_t*, unsigned char); leveldb_readoptions_t*, unsigned char);
extern void leveldb_readoptions_set_snapshot( LEVELDB_EXPORT void leveldb_readoptions_set_fill_cache(leveldb_readoptions_t*,
leveldb_readoptions_t*, unsigned char);
LEVELDB_EXPORT void leveldb_readoptions_set_snapshot(leveldb_readoptions_t*,
const leveldb_snapshot_t*); const leveldb_snapshot_t*);
/* Write options */ /* Write options */
extern leveldb_writeoptions_t* leveldb_writeoptions_create(); LEVELDB_EXPORT leveldb_writeoptions_t* leveldb_writeoptions_create();
extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*); LEVELDB_EXPORT void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
extern void leveldb_writeoptions_set_sync( LEVELDB_EXPORT void leveldb_writeoptions_set_sync(leveldb_writeoptions_t*,
leveldb_writeoptions_t*, unsigned char); unsigned char);
/* Cache */ /* Cache */
extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity); LEVELDB_EXPORT leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
extern void leveldb_cache_destroy(leveldb_cache_t* cache); LEVELDB_EXPORT void leveldb_cache_destroy(leveldb_cache_t* cache);
/* Env */ /* Env */
extern leveldb_env_t* leveldb_create_default_env(); LEVELDB_EXPORT leveldb_env_t* leveldb_create_default_env();
extern void leveldb_env_destroy(leveldb_env_t*); LEVELDB_EXPORT void leveldb_env_destroy(leveldb_env_t*);
/* Utility */ /* Utility */
@ -275,13 +250,13 @@ extern void leveldb_env_destroy(leveldb_env_t*);
in this file. Note that in certain cases (typically on Windows), you in this file. Note that in certain cases (typically on Windows), you
may need to call this routine instead of free(ptr) to dispose of may need to call this routine instead of free(ptr) to dispose of
malloc()-ed memory returned by this library. */ malloc()-ed memory returned by this library. */
extern void leveldb_free(void* ptr); LEVELDB_EXPORT void leveldb_free(void* ptr);
/* Return the major version number for this release. */ /* Return the major version number for this release. */
extern int leveldb_major_version(); LEVELDB_EXPORT int leveldb_major_version();
/* Return the minor version number for this release. */ /* Return the minor version number for this release. */
extern int leveldb_minor_version(); LEVELDB_EXPORT int leveldb_minor_version();
#ifdef __cplusplus #ifdef __cplusplus
} /* end extern "C" */ } /* end extern "C" */

View File

@ -19,17 +19,18 @@
#define STORAGE_LEVELDB_INCLUDE_CACHE_H_ #define STORAGE_LEVELDB_INCLUDE_CACHE_H_
#include <stdint.h> #include <stdint.h>
#include "leveldb/export.h"
#include "leveldb/slice.h" #include "leveldb/slice.h"
namespace leveldb { namespace leveldb {
class Cache; class LEVELDB_EXPORT Cache;
// Create a new cache with a fixed size capacity. This implementation // Create a new cache with a fixed size capacity. This implementation
// of Cache uses a least-recently-used eviction policy. // of Cache uses a least-recently-used eviction policy.
extern Cache* NewLRUCache(size_t capacity); LEVELDB_EXPORT Cache* NewLRUCache(size_t capacity);
class Cache { class LEVELDB_EXPORT Cache {
public: public:
Cache() { } Cache() { }

View File

@ -6,6 +6,7 @@
#define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
#include <string> #include <string>
#include "leveldb/export.h"
namespace leveldb { namespace leveldb {
@ -15,7 +16,7 @@ class Slice;
// used as keys in an sstable or a database. A Comparator implementation // used as keys in an sstable or a database. A Comparator implementation
// must be thread-safe since leveldb may invoke its methods concurrently // must be thread-safe since leveldb may invoke its methods concurrently
// from multiple threads. // from multiple threads.
class Comparator { class LEVELDB_EXPORT Comparator {
public: public:
virtual ~Comparator(); virtual ~Comparator();
@ -56,7 +57,7 @@ class Comparator {
// Return a builtin comparator that uses lexicographic byte-wise // Return a builtin comparator that uses lexicographic byte-wise
// ordering. The result remains the property of this module and // ordering. The result remains the property of this module and
// must not be deleted. // must not be deleted.
extern const Comparator* BytewiseComparator(); LEVELDB_EXPORT const Comparator* BytewiseComparator();
} // namespace leveldb } // namespace leveldb

View File

@ -7,6 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "leveldb/export.h"
#include "leveldb/iterator.h" #include "leveldb/iterator.h"
#include "leveldb/options.h" #include "leveldb/options.h"
@ -24,13 +25,13 @@ class WriteBatch;
// Abstract handle to particular state of a DB. // Abstract handle to particular state of a DB.
// A Snapshot is an immutable object and can therefore be safely // A Snapshot is an immutable object and can therefore be safely
// accessed from multiple threads without any external synchronization. // accessed from multiple threads without any external synchronization.
class Snapshot { class LEVELDB_EXPORT Snapshot {
protected: protected:
virtual ~Snapshot(); virtual ~Snapshot();
}; };
// A range of keys // A range of keys
struct Range { struct LEVELDB_EXPORT Range {
Slice start; // Included in the range Slice start; // Included in the range
Slice limit; // Not included in the range Slice limit; // Not included in the range
@ -41,7 +42,7 @@ struct Range {
// A DB is a persistent ordered map from keys to values. // A DB is a persistent ordered map from keys to values.
// A DB is safe for concurrent access from multiple threads without // A DB is safe for concurrent access from multiple threads without
// any external synchronization. // any external synchronization.
class DB { class LEVELDB_EXPORT DB {
public: public:
// Open the database with the specified "name". // Open the database with the specified "name".
// Stores a pointer to a heap-allocated database in *dbptr and returns // Stores a pointer to a heap-allocated database in *dbptr and returns
@ -150,13 +151,15 @@ class DB {
// Destroy the contents of the specified database. // Destroy the contents of the specified database.
// Be very careful using this method. // Be very careful using this method.
Status DestroyDB(const std::string& name, const Options& options); LEVELDB_EXPORT Status DestroyDB(const std::string& name,
const Options& options);
// If a DB cannot be opened, you may attempt to call this method to // If a DB cannot be opened, you may attempt to call this method to
// resurrect as much of the contents of the database as possible. // resurrect as much of the contents of the database as possible.
// Some data may be lost, so be careful when calling this function // Some data may be lost, so be careful when calling this function
// on a database that contains important information. // on a database that contains important information.
Status RepairDB(const std::string& dbname, const Options& options); LEVELDB_EXPORT Status RepairDB(const std::string& dbname,
const Options& options);
} // namespace leveldb } // namespace leveldb

View File

@ -7,6 +7,7 @@
#include <string> #include <string>
#include "leveldb/env.h" #include "leveldb/env.h"
#include "leveldb/export.h"
#include "leveldb/status.h" #include "leveldb/status.h"
namespace leveldb { namespace leveldb {
@ -18,7 +19,8 @@ namespace leveldb {
// //
// Returns a non-OK result if fname does not name a leveldb storage // Returns a non-OK result if fname does not name a leveldb storage
// file, or if the file cannot be read. // file, or if the file cannot be read.
Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); LEVELDB_EXPORT Status DumpFile(Env* env, const std::string& fname,
WritableFile* dst);
} // namespace leveldb } // namespace leveldb

View File

@ -13,10 +13,11 @@
#ifndef STORAGE_LEVELDB_INCLUDE_ENV_H_ #ifndef STORAGE_LEVELDB_INCLUDE_ENV_H_
#define STORAGE_LEVELDB_INCLUDE_ENV_H_ #define STORAGE_LEVELDB_INCLUDE_ENV_H_
#include <string>
#include <vector>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h> #include <stdint.h>
#include <string>
#include <vector>
#include "leveldb/export.h"
#include "leveldb/status.h" #include "leveldb/status.h"
namespace leveldb { namespace leveldb {
@ -28,7 +29,7 @@ class SequentialFile;
class Slice; class Slice;
class WritableFile; class WritableFile;
class Env { class LEVELDB_EXPORT Env {
public: public:
Env() { } Env() { }
virtual ~Env(); virtual ~Env();
@ -169,7 +170,7 @@ class Env {
}; };
// A file abstraction for reading sequentially through a file // A file abstraction for reading sequentially through a file
class SequentialFile { class LEVELDB_EXPORT SequentialFile {
public: public:
SequentialFile() { } SequentialFile() { }
virtual ~SequentialFile(); virtual ~SequentialFile();
@ -200,7 +201,7 @@ class SequentialFile {
}; };
// A file abstraction for randomly reading the contents of a file. // A file abstraction for randomly reading the contents of a file.
class RandomAccessFile { class LEVELDB_EXPORT RandomAccessFile {
public: public:
RandomAccessFile() { } RandomAccessFile() { }
virtual ~RandomAccessFile(); virtual ~RandomAccessFile();
@ -226,7 +227,7 @@ class RandomAccessFile {
// A file abstraction for sequential writing. The implementation // A file abstraction for sequential writing. The implementation
// must provide buffering since callers may append small fragments // must provide buffering since callers may append small fragments
// at a time to the file. // at a time to the file.
class WritableFile { class LEVELDB_EXPORT WritableFile {
public: public:
WritableFile() { } WritableFile() { }
virtual ~WritableFile(); virtual ~WritableFile();
@ -243,7 +244,7 @@ class WritableFile {
}; };
// An interface for writing log messages. // An interface for writing log messages.
class Logger { class LEVELDB_EXPORT Logger {
public: public:
Logger() { } Logger() { }
virtual ~Logger(); virtual ~Logger();
@ -259,7 +260,7 @@ class Logger {
// Identifies a locked file. // Identifies a locked file.
class FileLock { class LEVELDB_EXPORT FileLock {
public: public:
FileLock() { } FileLock() { }
virtual ~FileLock(); virtual ~FileLock();
@ -277,17 +278,17 @@ extern void Log(Logger* info_log, const char* format, ...)
; ;
// A utility routine: write "data" to the named file. // A utility routine: write "data" to the named file.
extern Status WriteStringToFile(Env* env, const Slice& data, LEVELDB_EXPORT Status WriteStringToFile(Env* env, const Slice& data,
const std::string& fname); const std::string& fname);
// A utility routine: read contents of named file into *data // A utility routine: read contents of named file into *data
extern Status ReadFileToString(Env* env, const std::string& fname, LEVELDB_EXPORT Status ReadFileToString(Env* env, const std::string& fname,
std::string* data); std::string* data);
// An implementation of Env that forwards all calls to another Env. // An implementation of Env that forwards all calls to another Env.
// May be useful to clients who wish to override just part of the // May be useful to clients who wish to override just part of the
// functionality of another Env. // functionality of another Env.
class EnvWrapper : public Env { class LEVELDB_EXPORT EnvWrapper : public Env {
public: public:
// Initialize an EnvWrapper that delegates all calls to *t // Initialize an EnvWrapper that delegates all calls to *t
explicit EnvWrapper(Env* t) : target_(t) { } explicit EnvWrapper(Env* t) : target_(t) { }

33
include/leveldb/export.h Normal file
View File

@ -0,0 +1,33 @@
// Copyright (c) 2017 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#ifndef STORAGE_LEVELDB_INCLUDE_EXPORT_H_
#define STORAGE_LEVELDB_INCLUDE_EXPORT_H_
#if !defined(LEVELDB_EXPORT)
#if defined(LEVELDB_SHARED_LIBRARY)
#if defined(OS_WIN)
#if defined(LEVELDB_COMPILE_LIBRARY)
#define LEVELDB_EXPORT __declspec(dllexport)
#else
#define LEVELDB_EXPORT __declspec(dllimport)
#endif // defined(LEVELDB_COMPILE_LIBRARY)
#else // defined(OS_WIN)
#if defined(LEVELDB_COMPILE_LIBRARY)
#define LEVELDB_EXPORT __attribute__((visibility("default")))
#else
#define LEVELDB_EXPORT
#endif
#endif // defined(OS_WIN)
#else // defined(LEVELDB_SHARED_LIBRARY)
#define LEVELDB_EXPORT
#endif
#endif // !defined(LEVELDB_EXPORT)
#endif // STORAGE_LEVELDB_INCLUDE_EXPORT_H_

View File

@ -17,12 +17,13 @@
#define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ #define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_
#include <string> #include <string>
#include "leveldb/export.h"
namespace leveldb { namespace leveldb {
class Slice; class Slice;
class FilterPolicy { class LEVELDB_EXPORT FilterPolicy {
public: public:
virtual ~FilterPolicy(); virtual ~FilterPolicy();
@ -63,8 +64,7 @@ class FilterPolicy {
// ignores trailing spaces, it would be incorrect to use a // ignores trailing spaces, it would be incorrect to use a
// FilterPolicy (like NewBloomFilterPolicy) that does not ignore // FilterPolicy (like NewBloomFilterPolicy) that does not ignore
// trailing spaces in keys. // trailing spaces in keys.
extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key); LEVELDB_EXPORT const FilterPolicy* NewBloomFilterPolicy(int bits_per_key);
} }
#endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ #endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_

View File

@ -15,12 +15,13 @@
#ifndef STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ #ifndef STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
#define STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ #define STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
#include "leveldb/export.h"
#include "leveldb/slice.h" #include "leveldb/slice.h"
#include "leveldb/status.h" #include "leveldb/status.h"
namespace leveldb { namespace leveldb {
class Iterator { class LEVELDB_EXPORT Iterator {
public: public:
Iterator(); Iterator();
virtual ~Iterator(); virtual ~Iterator();
@ -90,10 +91,10 @@ class Iterator {
}; };
// Return an empty iterator (yields nothing). // Return an empty iterator (yields nothing).
extern Iterator* NewEmptyIterator(); LEVELDB_EXPORT Iterator* NewEmptyIterator();
// Return an empty iterator with the specified status. // Return an empty iterator with the specified status.
extern Iterator* NewErrorIterator(const Status& status); LEVELDB_EXPORT Iterator* NewErrorIterator(const Status& status);
} // namespace leveldb } // namespace leveldb

View File

@ -6,6 +6,7 @@
#define STORAGE_LEVELDB_INCLUDE_OPTIONS_H_ #define STORAGE_LEVELDB_INCLUDE_OPTIONS_H_
#include <stddef.h> #include <stddef.h>
#include "leveldb/export.h"
namespace leveldb { namespace leveldb {
@ -28,7 +29,7 @@ enum CompressionType {
}; };
// Options to control the behavior of a database (passed to DB::Open) // Options to control the behavior of a database (passed to DB::Open)
struct Options { struct LEVELDB_EXPORT Options {
// ------------------- // -------------------
// Parameters that affect behavior // Parameters that affect behavior
@ -158,7 +159,7 @@ struct Options {
}; };
// Options that control read operations // Options that control read operations
struct ReadOptions { struct LEVELDB_EXPORT ReadOptions {
// If true, all data read from underlying storage will be // If true, all data read from underlying storage will be
// verified against corresponding checksums. // verified against corresponding checksums.
// Default: false // Default: false
@ -184,7 +185,7 @@ struct ReadOptions {
}; };
// Options that control write operations // Options that control write operations
struct WriteOptions { struct LEVELDB_EXPORT WriteOptions {
// If true, the write will be flushed from the operating system // If true, the write will be flushed from the operating system
// buffer cache (by calling WritableFile::Sync()) before the write // buffer cache (by calling WritableFile::Sync()) before the write
// is considered complete. If this flag is true, writes will be // is considered complete. If this flag is true, writes will be

View File

@ -19,10 +19,11 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <string> #include <string>
#include "leveldb/export.h"
namespace leveldb { namespace leveldb {
class Slice { class LEVELDB_EXPORT Slice {
public: public:
// Create an empty slice. // Create an empty slice.
Slice() : data_(""), size_(0) { } Slice() : data_(""), size_(0) { }

View File

@ -14,11 +14,12 @@
#define STORAGE_LEVELDB_INCLUDE_STATUS_H_ #define STORAGE_LEVELDB_INCLUDE_STATUS_H_
#include <string> #include <string>
#include "leveldb/export.h"
#include "leveldb/slice.h" #include "leveldb/slice.h"
namespace leveldb { namespace leveldb {
class Status { class LEVELDB_EXPORT Status {
public: public:
// Create a success status. // Create a success status.
Status() : state_(NULL) { } Status() : state_(NULL) { }

View File

@ -6,6 +6,7 @@
#define STORAGE_LEVELDB_INCLUDE_TABLE_H_ #define STORAGE_LEVELDB_INCLUDE_TABLE_H_
#include <stdint.h> #include <stdint.h>
#include "leveldb/export.h"
#include "leveldb/iterator.h" #include "leveldb/iterator.h"
namespace leveldb { namespace leveldb {
@ -21,7 +22,7 @@ class TableCache;
// A Table is a sorted map from strings to strings. Tables are // A Table is a sorted map from strings to strings. Tables are
// immutable and persistent. A Table may be safely accessed from // immutable and persistent. A Table may be safely accessed from
// multiple threads without external synchronization. // multiple threads without external synchronization.
class Table { class LEVELDB_EXPORT Table {
public: public:
// Attempt to open the table that is stored in bytes [0..file_size) // Attempt to open the table that is stored in bytes [0..file_size)
// of "file", and read the metadata entries necessary to allow // of "file", and read the metadata entries necessary to allow

View File

@ -14,6 +14,7 @@
#define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ #define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
#include <stdint.h> #include <stdint.h>
#include "leveldb/export.h"
#include "leveldb/options.h" #include "leveldb/options.h"
#include "leveldb/status.h" #include "leveldb/status.h"
@ -23,7 +24,7 @@ class BlockBuilder;
class BlockHandle; class BlockHandle;
class WritableFile; class WritableFile;
class TableBuilder { class LEVELDB_EXPORT TableBuilder {
public: public:
// Create a builder that will store the contents of the table it is // Create a builder that will store the contents of the table it is
// building in *file. Does not close the file. It is up to the // building in *file. Does not close the file. It is up to the

View File

@ -22,13 +22,14 @@
#define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
#include <string> #include <string>
#include "leveldb/export.h"
#include "leveldb/status.h" #include "leveldb/status.h"
namespace leveldb { namespace leveldb {
class Slice; class Slice;
class WriteBatch { class LEVELDB_EXPORT WriteBatch {
public: public:
WriteBatch(); WriteBatch();
~WriteBatch(); ~WriteBatch();