Skip to content

Commit 942426c

Browse files
committed
use old c.h and bindgen to gen ffi rs code
step 1 finished. Signed-off-by: fredchenbj <[email protected]>
1 parent 4ad6d0a commit 942426c

21 files changed

+654
-2512
lines changed

librocksdb_sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sse = ["libtitan_sys/sse"]
2323
[build-dependencies]
2424
cc = "1.0.3"
2525
cmake = "0.1"
26+
bindgen = "0.52"
2627

2728
[dependencies.jemalloc-sys]
2829
version = "0.1.8"

librocksdb_sys/build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14+
extern crate bindgen;
1415
extern crate cc;
1516
extern crate cmake;
1617

@@ -134,6 +135,17 @@ fn build_rocksdb() -> Build {
134135
build.define("OS_FREEBSD", None);
135136
}
136137

138+
let bindings = bindgen::Builder::default()
139+
.header("crocksdb/crocksdb/c.h")
140+
.ctypes_prefix("libc")
141+
.generate()
142+
.expect("unable to generate rocksdb bindings");
143+
144+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
145+
bindings
146+
.write_to_file(out_path.join("bindings.rs"))
147+
.expect("unable to write rocksdb bindings");
148+
137149
let cur_dir = env::current_dir().unwrap();
138150
build.include(cur_dir.join("rocksdb").join("include"));
139151
build.include(cur_dir.join("rocksdb"));

librocksdb_sys/crocksdb/c.cc

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ struct crocksdb_sst_file_meta_data_t {
266266
struct crocksdb_compaction_options_t {
267267
CompactionOptions rep;
268268
};
269+
struct crocksdb_compaction_reason_t {
270+
CompactionReason rep;
271+
};
269272

270273
struct crocksdb_map_property_t {
271274
std::map<std::string, std::string> rep;
@@ -746,7 +749,7 @@ crocksdb_t* crocksdb_open_column_families_with_ttl(
746749
const char** column_family_names,
747750
const crocksdb_options_t** column_family_options,
748751
const int32_t* ttl_array,
749-
bool read_only,
752+
unsigned char read_only,
750753
crocksdb_column_family_handle_t** column_family_handles,
751754
char** errptr) {
752755
std::vector<ColumnFamilyDescriptor> column_families;
@@ -1139,7 +1142,7 @@ void crocksdb_destroy_map_property(crocksdb_map_property_t* info) {
11391142
delete info;
11401143
}
11411144

1142-
bool crocksdb_get_map_property_cf(
1145+
unsigned char crocksdb_get_map_property_cf(
11431146
crocksdb_t* db,
11441147
crocksdb_column_family_handle_t* column_family,
11451148
const char* property,
@@ -1916,11 +1919,11 @@ const crocksdb_table_properties_t* crocksdb_flushjobinfo_table_properties(
19161919
&info->rep.table_properties);
19171920
}
19181921

1919-
bool crocksdb_flushjobinfo_triggered_writes_slowdown(const crocksdb_flushjobinfo_t* info) {
1922+
unsigned char crocksdb_flushjobinfo_triggered_writes_slowdown(const crocksdb_flushjobinfo_t* info) {
19201923
return info->rep.triggered_writes_slowdown;
19211924
}
19221925

1923-
bool crocksdb_flushjobinfo_triggered_writes_stop(const crocksdb_flushjobinfo_t* info) {
1926+
unsigned char crocksdb_flushjobinfo_triggered_writes_stop(const crocksdb_flushjobinfo_t* info) {
19241927
return info->rep.triggered_writes_stop;
19251928
}
19261929

@@ -2003,9 +2006,9 @@ uint64_t crocksdb_compactionjobinfo_total_output_bytes(
20032006
return info->rep.stats.total_output_bytes;
20042007
}
20052008

2006-
CompactionReason crocksdb_compactionjobinfo_compaction_reason(
2009+
const crocksdb_compaction_reason_t* crocksdb_compactionjobinfo_compaction_reason(
20072010
const crocksdb_compactionjobinfo_t* info) {
2008-
return info->rep.compaction_reason;
2011+
return reinterpret_cast<const crocksdb_compaction_reason_t*>(&info->rep.compaction_reason);
20092012
}
20102013

20112014
/* ExternalFileIngestionInfo */
@@ -2895,11 +2898,11 @@ void crocksdb_options_set_vector_memtable_factory(crocksdb_options_t* opt, uint6
28952898
opt->rep.memtable_factory.reset(new VectorRepFactory(reserved_bytes));
28962899
}
28972900

2898-
bool crocksdb_load_latest_options(const char* dbpath, crocksdb_env_t* env,
2901+
unsigned char crocksdb_load_latest_options(const char* dbpath, crocksdb_env_t* env,
28992902
crocksdb_options_t* db_options,
29002903
crocksdb_column_family_descriptor*** cf_descs,
29012904
size_t* cf_descs_len,
2902-
bool ignore_unknown_options, char** errptr) {
2905+
unsigned char ignore_unknown_options, char** errptr) {
29032906
std::vector<ColumnFamilyDescriptor> tmp_cf_descs;
29042907
Status s = rocksdb::LoadLatestOptions(dbpath, env->rep, &db_options->rep,
29052908
&tmp_cf_descs, ignore_unknown_options);
@@ -2934,7 +2937,7 @@ crocksdb_ratelimiter_t* crocksdb_ratelimiter_create_with_auto_tuned(
29342937
int64_t refill_period_us,
29352938
int32_t fairness,
29362939
crocksdb_ratelimiter_mode_t mode,
2937-
bool auto_tuned) {
2940+
unsigned char auto_tuned) {
29382941
crocksdb_ratelimiter_t* rate_limiter = new crocksdb_ratelimiter_t;
29392942
RateLimiter::Mode m = RateLimiter::Mode::kWritesOnly;
29402943
switch (mode) {
@@ -3437,7 +3440,7 @@ void crocksdb_lru_cache_options_set_num_shard_bits(
34373440
}
34383441

34393442
void crocksdb_lru_cache_options_set_strict_capacity_limit(
3440-
crocksdb_lru_cache_options_t* opt, bool strict_capacity_limit) {
3443+
crocksdb_lru_cache_options_t* opt, unsigned char strict_capacity_limit) {
34413444
opt->rep.strict_capacity_limit = strict_capacity_limit;
34423445
}
34433446

@@ -3785,7 +3788,7 @@ void crocksdb_ingest_external_file_cf(
37853788
SaveError(errptr, db->rep->IngestExternalFile(handle->rep, files, opt->rep));
37863789
}
37873790

3788-
bool crocksdb_ingest_external_file_optimized(
3791+
unsigned char crocksdb_ingest_external_file_optimized(
37893792
crocksdb_t* db, crocksdb_column_family_handle_t* handle,
37903793
const char* const* file_list, const size_t list_len,
37913794
const crocksdb_ingestexternalfileoptions_t* opt, char** errptr) {
@@ -3947,7 +3950,7 @@ void crocksdb_fifo_compaction_options_set_max_table_files_size(
39473950
}
39483951

39493952
void crocksdb_fifo_compaction_options_set_allow_compaction(
3950-
crocksdb_fifo_compaction_options_t* fifo_opts, bool allow_compaction) {
3953+
crocksdb_fifo_compaction_options_t* fifo_opts, unsigned char allow_compaction) {
39513954
fifo_opts->rep.allow_compaction = allow_compaction;
39523955
}
39533956

@@ -4026,7 +4029,7 @@ void crocksdb_delete_files_in_range(
40264029
crocksdb_t* db,
40274030
const char* start_key, size_t start_key_len,
40284031
const char* limit_key, size_t limit_key_len,
4029-
bool include_end, char** errptr) {
4032+
unsigned char include_end, char** errptr) {
40304033
Slice a, b;
40314034
SaveError(
40324035
errptr,
@@ -4041,7 +4044,7 @@ void crocksdb_delete_files_in_range_cf(
40414044
crocksdb_t* db, crocksdb_column_family_handle_t* column_family,
40424045
const char* start_key, size_t start_key_len,
40434046
const char* limit_key, size_t limit_key_len,
4044-
bool include_end, char** errptr) {
4047+
unsigned char include_end, char** errptr) {
40454048
Slice a, b;
40464049
SaveError(
40474050
errptr,
@@ -4056,7 +4059,7 @@ void crocksdb_delete_files_in_ranges_cf(
40564059
crocksdb_t* db, crocksdb_column_family_handle_t* cf,
40574060
const char* const* start_keys, const size_t* start_keys_lens,
40584061
const char* const* limit_keys, const size_t* limit_keys_lens,
4059-
size_t num_ranges, bool include_end, char** errptr) {
4062+
size_t num_ranges, unsigned char include_end, char** errptr) {
40604063
std::vector<Slice> starts(num_ranges);
40614064
std::vector<Slice> limits(num_ranges);
40624065
std::vector<RangePtr> ranges(num_ranges);
@@ -5246,12 +5249,12 @@ void ctitandb_decode_blob_index(const char* value, size_t value_size,
52465249
index->blob_size = bi.blob_handle.size;
52475250
}
52485251

5249-
void ctitandb_encode_blob_index(const ctitandb_blob_index_t& index,
5252+
void ctitandb_encode_blob_index(const ctitandb_blob_index_t* index,
52505253
char** value, size_t* value_size) {
52515254
BlobIndex bi;
5252-
bi.file_number = index.file_number;
5253-
bi.blob_handle.offset = index.blob_offset;
5254-
bi.blob_handle.size = index.blob_size;
5255+
bi.file_number = index->file_number;
5256+
bi.blob_handle.offset = index->blob_offset;
5257+
bi.blob_handle.size = index->blob_size;
52555258
std::string result;
52565259
bi.EncodeTo(&result);
52575260
*value = CopyString(result);
@@ -5372,12 +5375,12 @@ void ctitandb_readoptions_destroy(ctitandb_readoptions_t* opts) {
53725375
delete opts;
53735376
}
53745377

5375-
bool ctitandb_readoptions_key_only(ctitandb_readoptions_t* opts) {
5378+
unsigned char ctitandb_readoptions_key_only(ctitandb_readoptions_t* opts) {
53765379
return opts->rep.key_only;
53775380
}
53785381

53795382
void ctitandb_readoptions_set_key_only(ctitandb_readoptions_t* opts,
5380-
bool v) {
5383+
unsigned char v) {
53815384
opts->rep.key_only = v;
53825385
}
53835386

@@ -5449,7 +5452,7 @@ void ctitandb_delete_files_in_range(
54495452
crocksdb_t* db,
54505453
const char* start_key, size_t start_key_len,
54515454
const char* limit_key, size_t limit_key_len,
5452-
bool include_end, char** errptr) {
5455+
unsigned char include_end, char** errptr) {
54535456
Slice a, b;
54545457
RangePtr range(
54555458
start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr,
@@ -5467,7 +5470,7 @@ void ctitandb_delete_files_in_range_cf(
54675470
crocksdb_t* db, crocksdb_column_family_handle_t* column_family,
54685471
const char* start_key, size_t start_key_len,
54695472
const char* limit_key, size_t limit_key_len,
5470-
bool include_end, char** errptr) {
5473+
unsigned char include_end, char** errptr) {
54715474
Slice a, b;
54725475
RangePtr range(
54735476
start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr,
@@ -5485,7 +5488,7 @@ void ctitandb_delete_files_in_ranges_cf(
54855488
crocksdb_t* db, crocksdb_column_family_handle_t* cf,
54865489
const char* const* start_keys, const size_t* start_keys_lens,
54875490
const char* const* limit_keys, const size_t* limit_keys_lens,
5488-
size_t num_ranges, bool include_end, char** errptr) {
5491+
size_t num_ranges, unsigned char include_end, char** errptr) {
54895492
std::vector<Slice> starts(num_ranges);
54905493
std::vector<Slice> limits(num_ranges);
54915494
std::vector<RangePtr> ranges(num_ranges);

0 commit comments

Comments
 (0)