Unverified Commit 637c236d authored by yiwu-arbug's avatar yiwu-arbug Committed by GitHub

fix mac build (#644)

It appears on MacOS with Clang, `bool` is not supported in C, causing compile error. Changing it to `char`.
Signed-off-by: 's avatarYi Wu <yiwu@pingcap.com>
parent 91befd07
......@@ -436,7 +436,7 @@ struct crocksdb_compactionfilterfactory_t : public CompactionFilterFactory {
void (*destructor_)(void*);
crocksdb_compactionfilter_t* (*create_compaction_filter_)(
void*, crocksdb_compactionfiltercontext_t* context);
bool (*should_filter_table_file_creation_)(void*, int reason);
unsigned char (*should_filter_table_file_creation_)(void*, int reason);
const char* (*name_)(void*);
virtual ~crocksdb_compactionfilterfactory_t() { (*destructor_)(state_); }
......@@ -3453,7 +3453,7 @@ crocksdb_compactionfilterfactory_t* crocksdb_compactionfilterfactory_create(
void* state, void (*destructor)(void*),
crocksdb_compactionfilter_t* (*create_compaction_filter)(
void*, crocksdb_compactionfiltercontext_t* context),
bool (*should_filter_table_file_creation)(void*, int reason),
unsigned char (*should_filter_table_file_creation)(void*, int reason),
const char* (*name)(void*)) {
crocksdb_compactionfilterfactory_t* result =
new crocksdb_compactionfilterfactory_t;
......@@ -3687,7 +3687,8 @@ struct TableFilter {
// several times, so we need use shared_ptr to control the ctx_ resource
// destroy ctx_ only when the last ReadOptions out of its life time.
TableFilter(void* ctx,
int (*table_filter)(void*, const crocksdb_table_properties_t*),
unsigned char (*table_filter)(void*,
const crocksdb_table_properties_t*),
void (*destroy)(void*))
: ctx_(std::make_shared<TableFilterCtx>(ctx, destroy)),
table_filter_(table_filter) {}
......@@ -3702,7 +3703,7 @@ struct TableFilter {
}
shared_ptr<TableFilterCtx> ctx_;
int (*table_filter_)(void*, const crocksdb_table_properties_t*);
unsigned char (*table_filter_)(void*, const crocksdb_table_properties_t*);
private:
TableFilter() {}
......@@ -3710,7 +3711,7 @@ struct TableFilter {
void crocksdb_readoptions_set_table_filter(
crocksdb_readoptions_t* opt, void* ctx,
int (*table_filter)(void*, const crocksdb_table_properties_t*),
unsigned char (*table_filter)(void*, const crocksdb_table_properties_t*),
void (*destroy)(void*)) {
opt->rep.table_filter = TableFilter(ctx, table_filter, destroy);
}
......
......@@ -1398,7 +1398,7 @@ crocksdb_compactionfilterfactory_create(
void* state, void (*destructor)(void*),
crocksdb_compactionfilter_t* (*create_compaction_filter)(
void*, crocksdb_compactionfiltercontext_t* context),
bool (*should_filter_table_file_creation)(void*, int reasion),
unsigned char (*should_filter_table_file_creation)(void*, int reason),
const char* (*name)(void*));
extern C_ROCKSDB_LIBRARY_API void crocksdb_compactionfilterfactory_destroy(
crocksdb_compactionfilterfactory_t*);
......@@ -1494,7 +1494,7 @@ crocksdb_readoptions_set_ignore_range_deletions(crocksdb_readoptions_t*,
unsigned char);
extern C_ROCKSDB_LIBRARY_API void crocksdb_readoptions_set_table_filter(
crocksdb_readoptions_t*, void*,
int (*table_filter)(void*, const crocksdb_table_properties_t*),
unsigned char (*table_filter)(void*, const crocksdb_table_properties_t*),
void (*destory)(void*));
/* Write options */
......
......@@ -997,7 +997,7 @@ extern "C" {
pub fn crocksdb_readoptions_set_table_filter(
readopts: *mut DBReadOptions,
ctx: *mut c_void,
filter: extern "C" fn(*mut c_void, *const DBTableProperties) -> c_int,
filter: extern "C" fn(*mut c_void, *const DBTableProperties) -> c_uchar,
destroy: extern "C" fn(*mut c_void),
);
......@@ -1591,7 +1591,7 @@ extern "C" {
should_filter_table_file_creation: extern "C" fn(
*const c_void,
DBTableFileCreationReason,
) -> bool,
) -> c_uchar,
name: extern "C" fn(*mut c_void) -> *const c_char,
) -> *mut DBCompactionFilterFactory;
pub fn crocksdb_compactionfilterfactory_destroy(factory: *mut DBCompactionFilterFactory);
......
......@@ -8,7 +8,7 @@ pub use crocksdb_ffi::DBCompactionFilter;
use crocksdb_ffi::{
self, DBCompactionFilterContext, DBCompactionFilterFactory, DBTableFileCreationReason,
};
use libc::{c_char, c_int, c_void, malloc, memcpy, size_t};
use libc::{c_char, c_int, c_uchar, c_void, malloc, memcpy, size_t};
/// Decision used in `CompactionFilter::filter`.
pub enum CompactionFilterDecision {
......@@ -210,9 +210,9 @@ pub trait CompactionFilterFactory {
/// Returns whether a thread creating table files for the specified `reason`
/// should have invoke `create_compaction_filter` and pass KVs through the returned
/// filter.
fn should_filter_table_file_creation(&self, reason: DBTableFileCreationReason) -> bool {
fn should_filter_table_file_creation(&self, reason: DBTableFileCreationReason) -> c_uchar {
// For compatibility, `CompactionFilter`s by default apply during compaction.
matches!(reason, DBTableFileCreationReason::Compaction)
matches!(reason, DBTableFileCreationReason::Compaction) as c_uchar
}
}
......@@ -225,7 +225,7 @@ struct CompactionFilterFactoryProxy {
mod factory {
use super::{CompactionFilterContext, CompactionFilterFactoryProxy};
use crocksdb_ffi::{DBCompactionFilter, DBCompactionFilterContext};
use libc::{c_char, c_void};
use libc::{c_char, c_uchar, c_void};
use librocksdb_sys::DBTableFileCreationReason;
pub(super) extern "C" fn name(factory: *mut c_void) -> *const c_char {
......@@ -255,7 +255,7 @@ mod factory {
pub(super) extern "C" fn should_filter_table_file_creation(
factory: *const c_void,
reason: DBTableFileCreationReason,
) -> bool {
) -> c_uchar {
unsafe {
let factory = &*(factory as *const CompactionFilterFactoryProxy);
let reason: DBTableFileCreationReason = reason as DBTableFileCreationReason;
......@@ -298,6 +298,7 @@ pub unsafe fn new_compaction_filter_factory(
#[cfg(test)]
mod tests {
use libc::c_uchar;
use std::ffi::CString;
use std::sync::mpsc::{self, SyncSender};
use std::time::Duration;
......@@ -343,8 +344,8 @@ mod tests {
}
impl CompactionFilterFactory for FlushFactory {
fn should_filter_table_file_creation(&self, reason: DBTableFileCreationReason) -> bool {
matches!(reason, DBTableFileCreationReason::Flush)
fn should_filter_table_file_creation(&self, reason: DBTableFileCreationReason) -> c_uchar {
matches!(reason, DBTableFileCreationReason::Flush) as c_uchar
}
fn create_compaction_filter(
......
......@@ -12,7 +12,7 @@
// limitations under the License.
use crocksdb_ffi::DBTableProperties;
use libc::{c_int, c_void};
use libc::{c_uchar, c_void};
use table_properties::TableProperties;
pub trait TableFilter {
......@@ -24,11 +24,11 @@ pub trait TableFilter {
fn table_filter(&self, props: &TableProperties) -> bool;
}
pub extern "C" fn table_filter(ctx: *mut c_void, props: *const DBTableProperties) -> c_int {
pub extern "C" fn table_filter(ctx: *mut c_void, props: *const DBTableProperties) -> c_uchar {
unsafe {
let filter = &*(ctx as *mut Box<dyn TableFilter>);
let props = &*(props as *const TableProperties);
filter.table_filter(props) as c_int
filter.table_filter(props) as c_uchar
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment