filiptepper-leveldb-ruby 0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/LICENSE +24 -0
  2. data/README +72 -0
  3. data/ext/leveldb/extconf.rb +14 -0
  4. data/ext/leveldb/leveldb.cc +530 -0
  5. data/ext/leveldb/platform.rb +83 -0
  6. data/leveldb/Makefile +191 -0
  7. data/leveldb/build_detect_platform +160 -0
  8. data/leveldb/db/builder.cc +88 -0
  9. data/leveldb/db/builder.h +34 -0
  10. data/leveldb/db/c.cc +581 -0
  11. data/leveldb/db/corruption_test.cc +359 -0
  12. data/leveldb/db/db_bench.cc +970 -0
  13. data/leveldb/db/db_impl.cc +1448 -0
  14. data/leveldb/db/db_impl.h +194 -0
  15. data/leveldb/db/db_iter.cc +299 -0
  16. data/leveldb/db/db_iter.h +26 -0
  17. data/leveldb/db/db_test.cc +1901 -0
  18. data/leveldb/db/dbformat.cc +140 -0
  19. data/leveldb/db/dbformat.h +227 -0
  20. data/leveldb/db/dbformat_test.cc +112 -0
  21. data/leveldb/db/filename.cc +139 -0
  22. data/leveldb/db/filename.h +80 -0
  23. data/leveldb/db/filename_test.cc +122 -0
  24. data/leveldb/db/log_format.h +35 -0
  25. data/leveldb/db/log_reader.cc +259 -0
  26. data/leveldb/db/log_reader.h +108 -0
  27. data/leveldb/db/log_test.cc +500 -0
  28. data/leveldb/db/log_writer.cc +103 -0
  29. data/leveldb/db/log_writer.h +48 -0
  30. data/leveldb/db/memtable.cc +145 -0
  31. data/leveldb/db/memtable.h +91 -0
  32. data/leveldb/db/repair.cc +389 -0
  33. data/leveldb/db/skiplist.h +379 -0
  34. data/leveldb/db/skiplist_test.cc +378 -0
  35. data/leveldb/db/snapshot.h +66 -0
  36. data/leveldb/db/table_cache.cc +121 -0
  37. data/leveldb/db/table_cache.h +61 -0
  38. data/leveldb/db/version_edit.cc +266 -0
  39. data/leveldb/db/version_edit.h +107 -0
  40. data/leveldb/db/version_edit_test.cc +46 -0
  41. data/leveldb/db/version_set.cc +1402 -0
  42. data/leveldb/db/version_set.h +370 -0
  43. data/leveldb/db/version_set_test.cc +179 -0
  44. data/leveldb/db/write_batch.cc +147 -0
  45. data/leveldb/db/write_batch_internal.h +49 -0
  46. data/leveldb/db/write_batch_test.cc +120 -0
  47. data/leveldb/helpers/memenv/memenv.cc +374 -0
  48. data/leveldb/helpers/memenv/memenv.h +20 -0
  49. data/leveldb/helpers/memenv/memenv_test.cc +232 -0
  50. data/leveldb/include/leveldb/c.h +275 -0
  51. data/leveldb/include/leveldb/cache.h +99 -0
  52. data/leveldb/include/leveldb/comparator.h +63 -0
  53. data/leveldb/include/leveldb/db.h +161 -0
  54. data/leveldb/include/leveldb/env.h +323 -0
  55. data/leveldb/include/leveldb/filter_policy.h +70 -0
  56. data/leveldb/include/leveldb/iterator.h +100 -0
  57. data/leveldb/include/leveldb/options.h +195 -0
  58. data/leveldb/include/leveldb/slice.h +109 -0
  59. data/leveldb/include/leveldb/status.h +106 -0
  60. data/leveldb/include/leveldb/table.h +85 -0
  61. data/leveldb/include/leveldb/table_builder.h +92 -0
  62. data/leveldb/include/leveldb/write_batch.h +64 -0
  63. data/leveldb/port/atomic_pointer.h +144 -0
  64. data/leveldb/port/port.h +21 -0
  65. data/leveldb/port/port_android.cc +64 -0
  66. data/leveldb/port/port_android.h +159 -0
  67. data/leveldb/port/port_example.h +125 -0
  68. data/leveldb/port/port_posix.cc +50 -0
  69. data/leveldb/port/port_posix.h +129 -0
  70. data/leveldb/port/win/stdint.h +24 -0
  71. data/leveldb/table/block.cc +267 -0
  72. data/leveldb/table/block.h +44 -0
  73. data/leveldb/table/block_builder.cc +109 -0
  74. data/leveldb/table/block_builder.h +57 -0
  75. data/leveldb/table/filter_block.cc +111 -0
  76. data/leveldb/table/filter_block.h +68 -0
  77. data/leveldb/table/filter_block_test.cc +128 -0
  78. data/leveldb/table/format.cc +145 -0
  79. data/leveldb/table/format.h +108 -0
  80. data/leveldb/table/iterator.cc +67 -0
  81. data/leveldb/table/iterator_wrapper.h +63 -0
  82. data/leveldb/table/merger.cc +197 -0
  83. data/leveldb/table/merger.h +26 -0
  84. data/leveldb/table/table.cc +276 -0
  85. data/leveldb/table/table_builder.cc +270 -0
  86. data/leveldb/table/table_test.cc +838 -0
  87. data/leveldb/table/two_level_iterator.cc +182 -0
  88. data/leveldb/table/two_level_iterator.h +34 -0
  89. data/leveldb/util/arena.cc +68 -0
  90. data/leveldb/util/arena.h +68 -0
  91. data/leveldb/util/arena_test.cc +68 -0
  92. data/leveldb/util/bloom.cc +95 -0
  93. data/leveldb/util/bloom_test.cc +159 -0
  94. data/leveldb/util/cache.cc +328 -0
  95. data/leveldb/util/cache_test.cc +186 -0
  96. data/leveldb/util/coding.cc +194 -0
  97. data/leveldb/util/coding.h +104 -0
  98. data/leveldb/util/coding_test.cc +173 -0
  99. data/leveldb/util/comparator.cc +76 -0
  100. data/leveldb/util/crc32c.cc +332 -0
  101. data/leveldb/util/crc32c.h +45 -0
  102. data/leveldb/util/crc32c_test.cc +72 -0
  103. data/leveldb/util/env.cc +96 -0
  104. data/leveldb/util/env_posix.cc +609 -0
  105. data/leveldb/util/env_test.cc +104 -0
  106. data/leveldb/util/filter_policy.cc +11 -0
  107. data/leveldb/util/hash.cc +45 -0
  108. data/leveldb/util/hash.h +19 -0
  109. data/leveldb/util/histogram.cc +139 -0
  110. data/leveldb/util/histogram.h +42 -0
  111. data/leveldb/util/logging.cc +81 -0
  112. data/leveldb/util/logging.h +47 -0
  113. data/leveldb/util/mutexlock.h +39 -0
  114. data/leveldb/util/options.cc +29 -0
  115. data/leveldb/util/posix_logger.h +98 -0
  116. data/leveldb/util/random.h +59 -0
  117. data/leveldb/util/status.cc +75 -0
  118. data/leveldb/util/testharness.cc +77 -0
  119. data/leveldb/util/testharness.h +138 -0
  120. data/leveldb/util/testutil.cc +51 -0
  121. data/leveldb/util/testutil.h +53 -0
  122. data/lib/leveldb.rb +76 -0
  123. metadata +175 -0
@@ -0,0 +1,83 @@
1
+ ## here lies some platform-specific C++ compile and link environment
2
+ ## variable hacking.
3
+ ##
4
+ ## this code is entirely stolen from eventmachine's extconf.rb. many
5
+ ## thanks to @tmm1 for the pointer.
6
+
7
+ def check_libs libs=[], fatal=false
8
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
9
+ end
10
+
11
+ def check_heads heads=[], fatal=false
12
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
13
+ end
14
+
15
+ def add_define name; $defs.push "-D#{name}" end
16
+
17
+ def set_platform_specific_variables!
18
+ puts "setting build environment for #{RUBY_PLATFORM}..."
19
+ case RUBY_PLATFORM
20
+ when /mswin32/, /mingw32/, /bccwin32/
21
+ check_heads(%w[windows.h winsock.h], true)
22
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
23
+
24
+ if GNU_CHAIN
25
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
26
+ else
27
+ $defs.push "-EHs"
28
+ $defs.push "-GR"
29
+ end
30
+
31
+ when /solaris/
32
+ add_define 'OS_SOLARIS8'
33
+ check_libs(%w[nsl socket], true)
34
+
35
+ if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
36
+ # SUN CHAIN
37
+ add_define 'CC_SUNWspro'
38
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
39
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
40
+ CONFIG['CCDLFLAGS'] = "-KPIC"
41
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
42
+ else
43
+ # GNU CHAIN
44
+ # on Unix we need a g++ link, not gcc.
45
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
46
+ end
47
+
48
+ when /openbsd/
49
+ # OpenBSD branch contributed by Guillaume Sellier.
50
+
51
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
52
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
53
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
54
+
55
+ when /darwin/
56
+ # on Unix we need a g++ link, not gcc.
57
+ # Ff line contributed by Daniel Harple.
58
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
59
+
60
+ when /linux/
61
+ add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
62
+
63
+ # on Unix we need a g++ link, not gcc.
64
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
65
+
66
+ when /aix/
67
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
68
+
69
+ when /cygwin/
70
+ # For rubies built with Cygwin, CXX may be set to CC, which is just
71
+ # a wrapper for gcc.
72
+ # This will compile, but it will not link to the C++ std library.
73
+ # Explicitly set CXX to use g++.
74
+ CONFIG['CXX'] = "g++"
75
+ # on Unix we need a g++ link, not gcc.
76
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
77
+
78
+ else
79
+ # on Unix we need a g++ link, not gcc.
80
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
81
+ end
82
+ end
83
+
@@ -0,0 +1,191 @@
1
+ # Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file. See the AUTHORS file for names of contributors.
4
+
5
+ # Inherit some settings from environment variables, if available
6
+ CXX ?= g++
7
+ CC ?= gcc
8
+ INSTALL_PATH ?= $(CURDIR)
9
+
10
+ #-----------------------------------------------
11
+ # Uncomment exactly one of the lines labelled (A), (B), and (C) below
12
+ # to switch between compilation modes.
13
+
14
+ OPT ?= -O2 -DNDEBUG -fPIC # (A) Production use (optimized mode)
15
+ # OPT ?= -g2 # (B) Debug mode, w/ full line-level debugging symbols
16
+ # OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols
17
+ #-----------------------------------------------
18
+
19
+ # detect what platform we're building on
20
+ $(shell ./build_detect_platform build_config.mk)
21
+ # this file is generated by the previous line to set build flags and sources
22
+ include build_config.mk
23
+
24
+ CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
25
+ CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
26
+
27
+ LDFLAGS += $(PLATFORM_LDFLAGS)
28
+
29
+ LIBOBJECTS = $(SOURCES:.cc=.o)
30
+ MEMENVOBJECTS = $(MEMENV_SOURCES:.cc=.o)
31
+
32
+ TESTUTIL = ./util/testutil.o
33
+ TESTHARNESS = ./util/testharness.o $(TESTUTIL)
34
+
35
+ TESTS = \
36
+ arena_test \
37
+ bloom_test \
38
+ c_test \
39
+ cache_test \
40
+ coding_test \
41
+ corruption_test \
42
+ crc32c_test \
43
+ db_test \
44
+ dbformat_test \
45
+ env_test \
46
+ filename_test \
47
+ filter_block_test \
48
+ log_test \
49
+ memenv_test \
50
+ skiplist_test \
51
+ table_test \
52
+ version_edit_test \
53
+ version_set_test \
54
+ write_batch_test
55
+
56
+ PROGRAMS = db_bench $(TESTS)
57
+ BENCHMARKS = db_bench_sqlite3 db_bench_tree_db
58
+
59
+ LIBRARY = libleveldb.a
60
+ MEMENVLIBRARY = libmemenv.a
61
+
62
+ default: all
63
+
64
+ # Should we build shared libraries?
65
+ ifneq ($(PLATFORM_SHARED_EXT),)
66
+ # Update db.h if you change these.
67
+ SHARED_MAJOR = 1
68
+ SHARED_MINOR = 4
69
+ SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
70
+ SHARED2 = $(SHARED1).$(SHARED_MAJOR)
71
+ SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
72
+ SHARED = $(SHARED1) $(SHARED2) $(SHARED3)
73
+ $(SHARED3):
74
+ $(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(INSTALL_PATH)/$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3)
75
+ $(SHARED2): $(SHARED3)
76
+ ln -fs $(SHARED3) $(SHARED2)
77
+ $(SHARED1): $(SHARED3)
78
+ ln -fs $(SHARED3) $(SHARED1)
79
+ endif
80
+
81
+ all: $(SHARED) $(LIBRARY)
82
+
83
+ check: all $(PROGRAMS) $(TESTS)
84
+ for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done
85
+
86
+ clean:
87
+ -rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o build_config.mk
88
+ -rm -rf ios-x86/* ios-arm/*
89
+
90
+ $(LIBRARY): $(LIBOBJECTS)
91
+ rm -f $@
92
+ $(AR) -rs $@ $(LIBOBJECTS)
93
+
94
+ db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL)
95
+ $(CXX) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LDFLAGS)
96
+
97
+ db_bench_sqlite3: doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL)
98
+ $(CXX) doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LDFLAGS) -lsqlite3
99
+
100
+ db_bench_tree_db: doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL)
101
+ $(CXX) doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LDFLAGS) -lkyotocabinet
102
+
103
+ arena_test: util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS)
104
+ $(CXX) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
105
+
106
+ bloom_test: util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS)
107
+ $(CXX) util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
108
+
109
+ c_test: db/c_test.o $(LIBOBJECTS) $(TESTHARNESS)
110
+ $(CXX) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
111
+
112
+ cache_test: util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS)
113
+ $(CXX) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
114
+
115
+ coding_test: util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS)
116
+ $(CXX) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
117
+
118
+ corruption_test: db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS)
119
+ $(CXX) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
120
+
121
+ crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS)
122
+ $(CXX) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
123
+
124
+ db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS)
125
+ $(CXX) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
126
+
127
+ dbformat_test: db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS)
128
+ $(CXX) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
129
+
130
+ env_test: util/env_test.o $(LIBOBJECTS) $(TESTHARNESS)
131
+ $(CXX) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
132
+
133
+ filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS)
134
+ $(CXX) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
135
+
136
+ filter_block_test: table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS)
137
+ $(CXX) table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
138
+
139
+ log_test: db/log_test.o $(LIBOBJECTS) $(TESTHARNESS)
140
+ $(CXX) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
141
+
142
+ table_test: table/table_test.o $(LIBOBJECTS) $(TESTHARNESS)
143
+ $(CXX) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
144
+
145
+ skiplist_test: db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS)
146
+ $(CXX) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
147
+
148
+ version_edit_test: db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS)
149
+ $(CXX) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
150
+
151
+ version_set_test: db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS)
152
+ $(CXX) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
153
+
154
+ write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS)
155
+ $(CXX) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LDFLAGS)
156
+
157
+ $(MEMENVLIBRARY) : $(MEMENVOBJECTS)
158
+ rm -f $@
159
+ $(AR) -rs $@ $(MEMENVOBJECTS)
160
+
161
+ memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS)
162
+ $(CXX) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ $(LDFLAGS)
163
+
164
+ ifeq ($(PLATFORM), IOS)
165
+ # For iOS, create universal object files to be used on both the simulator and
166
+ # a device.
167
+ SIMULATORROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
168
+ DEVICEROOT=/Developer/Platforms/iPhoneOS.platform/Developer
169
+ IOSVERSION=$(shell defaults read /Developer/Platforms/iPhoneOS.platform/version CFBundleShortVersionString)
170
+
171
+ .cc.o:
172
+ mkdir -p ios-x86/$(dir $@)
173
+ $(SIMULATORROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
174
+ mkdir -p ios-arm/$(dir $@)
175
+ $(DEVICEROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
176
+ lipo ios-x86/$@ ios-arm/$@ -create -output $@
177
+
178
+ .c.o:
179
+ mkdir -p ios-x86/$(dir $@)
180
+ $(SIMULATORROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
181
+ mkdir -p ios-arm/$(dir $@)
182
+ $(DEVICEROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
183
+ lipo ios-x86/$@ ios-arm/$@ -create -output $@
184
+
185
+ else
186
+ .cc.o:
187
+ $(CXX) $(CXXFLAGS) -c $< -o $@
188
+
189
+ .c.o:
190
+ $(CC) $(CFLAGS) -c $< -o $@
191
+ endif
@@ -0,0 +1,160 @@
1
+ #!/bin/sh
2
+ #
3
+ # Detects OS we're compiling on and outputs a file specified by the first
4
+ # argument, which in turn gets read while processing Makefile.
5
+ #
6
+ # The output will set the following variables:
7
+ # PLATFORM_LDFLAGS Linker flags
8
+ # PLATFORM_SHARED_EXT Extension for shared libraries
9
+ # PLATFORM_SHARED_LDFLAGS Flags for building shared library
10
+ # PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library
11
+ # PLATFORM_CCFLAGS C compiler flags
12
+ # PLATFORM_CXXFLAGS C++ compiler flags. Will contain:
13
+ # -DLEVELDB_PLATFORM_POSIX if cstdatomic is present
14
+ # -DLEVELDB_PLATFORM_NOATOMIC if it is not
15
+
16
+ OUTPUT=$1
17
+ if test -z "$OUTPUT"; then
18
+ echo "usage: $0 <output-filename>"
19
+ exit 1
20
+ fi
21
+
22
+ # Delete existing output, if it exists
23
+ rm -f $OUTPUT
24
+ touch $OUTPUT
25
+
26
+ if test -z "$CXX"; then
27
+ CXX=g++
28
+ fi
29
+
30
+ # Detect OS
31
+ if test -z "$TARGET_OS"; then
32
+ TARGET_OS=`uname -s`
33
+ fi
34
+
35
+ COMMON_FLAGS=
36
+ PLATFORM_CCFLAGS=
37
+ PLATFORM_CXXFLAGS=
38
+ PLATFORM_LDFLAGS=
39
+ PLATFORM_SHARED_EXT="so"
40
+ PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
41
+ PLATFORM_SHARED_CFLAGS="-fPIC"
42
+
43
+ # On GCC, we pick libc's memcmp over GCC's memcmp via -fno-builtin-memcmp
44
+ case "$TARGET_OS" in
45
+ Darwin)
46
+ PLATFORM=OS_MACOSX
47
+ COMMON_FLAGS="-fno-builtin-memcmp -DOS_MACOSX"
48
+ PLATFORM_SHARED_EXT=dylib
49
+ PLATFORM_SHARED_LDFLAGS="-dynamiclib -install_name "
50
+ PORT_FILE=port/port_posix.cc
51
+ ;;
52
+ Linux)
53
+ PLATFORM=OS_LINUX
54
+ COMMON_FLAGS="-fno-builtin-memcmp -pthread -DOS_LINUX"
55
+ PLATFORM_LDFLAGS="-pthread"
56
+ PORT_FILE=port/port_posix.cc
57
+ ;;
58
+ SunOS)
59
+ PLATFORM=OS_SOLARIS
60
+ COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_SOLARIS"
61
+ PLATFORM_LDFLAGS="-lpthread -lrt"
62
+ PORT_FILE=port/port_posix.cc
63
+ ;;
64
+ FreeBSD)
65
+ PLATFORM=OS_FREEBSD
66
+ COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_FREEBSD"
67
+ PLATFORM_LDFLAGS="-lpthread"
68
+ PORT_FILE=port/port_posix.cc
69
+ ;;
70
+ NetBSD)
71
+ PLATFORM=OS_NETBSD
72
+ COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_NETBSD"
73
+ PLATFORM_LDFLAGS="-lpthread -lgcc_s"
74
+ PORT_FILE=port/port_posix.cc
75
+ ;;
76
+ OpenBSD)
77
+ PLATFORM=OS_OPENBSD
78
+ COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_OPENBSD"
79
+ PLATFORM_LDFLAGS="-pthread"
80
+ PORT_FILE=port/port_posix.cc
81
+ ;;
82
+ DragonFly)
83
+ PLATFORM=OS_DRAGONFLYBSD
84
+ COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_DRAGONFLYBSD"
85
+ PLATFORM_LDFLAGS="-lpthread"
86
+ PORT_FILE=port/port_posix.cc
87
+ ;;
88
+ OS_ANDROID_CROSSCOMPILE)
89
+ PLATFORM="$TARGET_OS"
90
+ COMMON_FLAGS=""
91
+ PLATFORM_LDFLAGS=""
92
+ PORT_FILE=port/port_android.cc
93
+ ;;
94
+ *)
95
+ echo "Unknown platform!"
96
+ exit 1
97
+ esac
98
+
99
+ # We want to make a list of all cc files within util, db, table, and helpers
100
+ # except for the test and benchmark files. By default, find will output a list
101
+ # of all files matching either rule, so we need to append -print to make the
102
+ # prune take effect.
103
+ DIRS="util db table"
104
+ set -f # temporarily disable globbing so that our patterns aren't expanded
105
+ PRUNE_TEST="-name *test*.cc -prune"
106
+ PRUNE_BENCH="-name *_bench.cc -prune"
107
+ PORTABLE_FILES=`find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o -name '*.cc' -print | sort | tr "\n" " "`
108
+ set +f # re-enable globbing
109
+
110
+ # The sources consist of the portable files, plus the platform-specific port
111
+ # file.
112
+ echo "SOURCES=$PORTABLE_FILES $PORT_FILE" >> $OUTPUT
113
+ echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> $OUTPUT
114
+
115
+ if [ "$PLATFORM" = "OS_ANDROID_CROSSCOMPILE" ]; then
116
+ # Cross-compiling; do not try any compilation tests.
117
+ true
118
+ else
119
+ # If -std=c++0x works, use <cstdatomic>. Otherwise use port_posix.h.
120
+ $CXX $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
121
+ #include <cstdatomic>
122
+ int main() {}
123
+ EOF
124
+ if [ "$?" = 0 ]; then
125
+ COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT"
126
+ PLATFORM_CXXFLAGS="-std=c++0x"
127
+ else
128
+ COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX"
129
+ fi
130
+
131
+ # Test whether Snappy library is installed
132
+ # http://code.google.com/p/snappy/
133
+ $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
134
+ #include <snappy.h>
135
+ int main() {}
136
+ EOF
137
+ if [ "$?" = 0 ]; then
138
+ COMMON_FLAGS="$COMMON_FLAGS -DSNAPPY"
139
+ PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lsnappy"
140
+ fi
141
+
142
+ # Test whether tcmalloc is available
143
+ $CXX $CFLAGS -x c++ - -o /dev/null -ltcmalloc 2>/dev/null <<EOF
144
+ int main() {}
145
+ EOF
146
+ if [ "$?" = 0 ]; then
147
+ PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -ltcmalloc"
148
+ fi
149
+ fi
150
+
151
+ PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
152
+ PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
153
+
154
+ echo "PLATFORM=$PLATFORM" >> $OUTPUT
155
+ echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
156
+ echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
157
+ echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
158
+ echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
159
+ echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
160
+ echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT
@@ -0,0 +1,88 @@
1
+ // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file. See the AUTHORS file for names of contributors.
4
+
5
+ #include "db/builder.h"
6
+
7
+ #include "db/filename.h"
8
+ #include "db/dbformat.h"
9
+ #include "db/table_cache.h"
10
+ #include "db/version_edit.h"
11
+ #include "leveldb/db.h"
12
+ #include "leveldb/env.h"
13
+ #include "leveldb/iterator.h"
14
+
15
+ namespace leveldb {
16
+
17
+ Status BuildTable(const std::string& dbname,
18
+ Env* env,
19
+ const Options& options,
20
+ TableCache* table_cache,
21
+ Iterator* iter,
22
+ FileMetaData* meta) {
23
+ Status s;
24
+ meta->file_size = 0;
25
+ iter->SeekToFirst();
26
+
27
+ std::string fname = TableFileName(dbname, meta->number);
28
+ if (iter->Valid()) {
29
+ WritableFile* file;
30
+ s = env->NewWritableFile(fname, &file);
31
+ if (!s.ok()) {
32
+ return s;
33
+ }
34
+
35
+ TableBuilder* builder = new TableBuilder(options, file);
36
+ meta->smallest.DecodeFrom(iter->key());
37
+ for (; iter->Valid(); iter->Next()) {
38
+ Slice key = iter->key();
39
+ meta->largest.DecodeFrom(key);
40
+ builder->Add(key, iter->value());
41
+ }
42
+
43
+ // Finish and check for builder errors
44
+ if (s.ok()) {
45
+ s = builder->Finish();
46
+ if (s.ok()) {
47
+ meta->file_size = builder->FileSize();
48
+ assert(meta->file_size > 0);
49
+ }
50
+ } else {
51
+ builder->Abandon();
52
+ }
53
+ delete builder;
54
+
55
+ // Finish and check for file errors
56
+ if (s.ok()) {
57
+ s = file->Sync();
58
+ }
59
+ if (s.ok()) {
60
+ s = file->Close();
61
+ }
62
+ delete file;
63
+ file = NULL;
64
+
65
+ if (s.ok()) {
66
+ // Verify that the table is usable
67
+ Iterator* it = table_cache->NewIterator(ReadOptions(),
68
+ meta->number,
69
+ meta->file_size);
70
+ s = it->status();
71
+ delete it;
72
+ }
73
+ }
74
+
75
+ // Check for input iterator errors
76
+ if (!iter->status().ok()) {
77
+ s = iter->status();
78
+ }
79
+
80
+ if (s.ok() && meta->file_size > 0) {
81
+ // Keep it
82
+ } else {
83
+ env->DeleteFile(fname);
84
+ }
85
+ return s;
86
+ }
87
+
88
+ } // namespace leveldb