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 { ...@@ -436,7 +436,7 @@ struct crocksdb_compactionfilterfactory_t : public CompactionFilterFactory {
void (*destructor_)(void*); void (*destructor_)(void*);
crocksdb_compactionfilter_t* (*create_compaction_filter_)( crocksdb_compactionfilter_t* (*create_compaction_filter_)(
void*, crocksdb_compactionfiltercontext_t* context); 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*); const char* (*name_)(void*);
virtual ~crocksdb_compactionfilterfactory_t() { (*destructor_)(state_); } virtual ~crocksdb_compactionfilterfactory_t() { (*destructor_)(state_); }
...@@ -3453,7 +3453,7 @@ crocksdb_compactionfilterfactory_t* crocksdb_compactionfilterfactory_create( ...@@ -3453,7 +3453,7 @@ crocksdb_compactionfilterfactory_t* crocksdb_compactionfilterfactory_create(
void* state, void (*destructor)(void*), void* state, void (*destructor)(void*),
crocksdb_compactionfilter_t* (*create_compaction_filter)( crocksdb_compactionfilter_t* (*create_compaction_filter)(
void*, crocksdb_compactionfiltercontext_t* context), 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*)) { const char* (*name)(void*)) {
crocksdb_compactionfilterfactory_t* result = crocksdb_compactionfilterfactory_t* result =
new crocksdb_compactionfilterfactory_t; new crocksdb_compactionfilterfactory_t;
...@@ -3687,7 +3687,8 @@ struct TableFilter { ...@@ -3687,7 +3687,8 @@ struct TableFilter {
// several times, so we need use shared_ptr to control the ctx_ resource // 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. // destroy ctx_ only when the last ReadOptions out of its life time.
TableFilter(void* ctx, 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*)) void (*destroy)(void*))
: ctx_(std::make_shared<TableFilterCtx>(ctx, destroy)), : ctx_(std::make_shared<TableFilterCtx>(ctx, destroy)),
table_filter_(table_filter) {} table_filter_(table_filter) {}
...@@ -3702,7 +3703,7 @@ struct TableFilter { ...@@ -3702,7 +3703,7 @@ struct TableFilter {
} }
shared_ptr<TableFilterCtx> ctx_; shared_ptr<TableFilterCtx> ctx_;
int (*table_filter_)(void*, const crocksdb_table_properties_t*); unsigned char (*table_filter_)(void*, const crocksdb_table_properties_t*);
private: private:
TableFilter() {} TableFilter() {}
...@@ -3710,7 +3711,7 @@ struct TableFilter { ...@@ -3710,7 +3711,7 @@ struct TableFilter {
void crocksdb_readoptions_set_table_filter( void crocksdb_readoptions_set_table_filter(
crocksdb_readoptions_t* opt, void* ctx, 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*)) { void (*destroy)(void*)) {
opt->rep.table_filter = TableFilter(ctx, table_filter, destroy); opt->rep.table_filter = TableFilter(ctx, table_filter, destroy);
} }
......
...@@ -1398,7 +1398,7 @@ crocksdb_compactionfilterfactory_create( ...@@ -1398,7 +1398,7 @@ crocksdb_compactionfilterfactory_create(
void* state, void (*destructor)(void*), void* state, void (*destructor)(void*),
crocksdb_compactionfilter_t* (*create_compaction_filter)( crocksdb_compactionfilter_t* (*create_compaction_filter)(
void*, crocksdb_compactionfiltercontext_t* context), 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*)); const char* (*name)(void*));
extern C_ROCKSDB_LIBRARY_API void crocksdb_compactionfilterfactory_destroy( extern C_ROCKSDB_LIBRARY_API void crocksdb_compactionfilterfactory_destroy(
crocksdb_compactionfilterfactory_t*); crocksdb_compactionfilterfactory_t*);
...@@ -1494,7 +1494,7 @@ crocksdb_readoptions_set_ignore_range_deletions(crocksdb_readoptions_t*, ...@@ -1494,7 +1494,7 @@ crocksdb_readoptions_set_ignore_range_deletions(crocksdb_readoptions_t*,
unsigned char); unsigned char);
extern C_ROCKSDB_LIBRARY_API void crocksdb_readoptions_set_table_filter( extern C_ROCKSDB_LIBRARY_API void crocksdb_readoptions_set_table_filter(
crocksdb_readoptions_t*, void*, 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*)); void (*destory)(void*));
/* Write options */ /* Write options */
......
...@@ -997,7 +997,7 @@ extern "C" { ...@@ -997,7 +997,7 @@ extern "C" {
pub fn crocksdb_readoptions_set_table_filter( pub fn crocksdb_readoptions_set_table_filter(
readopts: *mut DBReadOptions, readopts: *mut DBReadOptions,
ctx: *mut c_void, 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), destroy: extern "C" fn(*mut c_void),
); );
...@@ -1591,7 +1591,7 @@ extern "C" { ...@@ -1591,7 +1591,7 @@ extern "C" {
should_filter_table_file_creation: extern "C" fn( should_filter_table_file_creation: extern "C" fn(
*const c_void, *const c_void,
DBTableFileCreationReason, DBTableFileCreationReason,
) -> bool, ) -> c_uchar,
name: extern "C" fn(*mut c_void) -> *const c_char, name: extern "C" fn(*mut c_void) -> *const c_char,
) -> *mut DBCompactionFilterFactory; ) -> *mut DBCompactionFilterFactory;
pub fn crocksdb_compactionfilterfactory_destroy(factory: *mut DBCompactionFilterFactory); pub fn crocksdb_compactionfilterfactory_destroy(factory: *mut DBCompactionFilterFactory);
......
...@@ -8,7 +8,7 @@ pub use crocksdb_ffi::DBCompactionFilter; ...@@ -8,7 +8,7 @@ pub use crocksdb_ffi::DBCompactionFilter;
use crocksdb_ffi::{ use crocksdb_ffi::{
self, DBCompactionFilterContext, DBCompactionFilterFactory, DBTableFileCreationReason, 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`. /// Decision used in `CompactionFilter::filter`.
pub enum CompactionFilterDecision { pub enum CompactionFilterDecision {
...@@ -210,9 +210,9 @@ pub trait CompactionFilterFactory { ...@@ -210,9 +210,9 @@ pub trait CompactionFilterFactory {
/// Returns whether a thread creating table files for the specified `reason` /// Returns whether a thread creating table files for the specified `reason`
/// should have invoke `create_compaction_filter` and pass KVs through the returned /// should have invoke `create_compaction_filter` and pass KVs through the returned
/// filter. /// 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. // 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 { ...@@ -225,7 +225,7 @@ struct CompactionFilterFactoryProxy {
mod factory { mod factory {
use super::{CompactionFilterContext, CompactionFilterFactoryProxy}; use super::{CompactionFilterContext, CompactionFilterFactoryProxy};
use crocksdb_ffi::{DBCompactionFilter, DBCompactionFilterContext}; use crocksdb_ffi::{DBCompactionFilter, DBCompactionFilterContext};
use libc::{c_char, c_void}; use libc::{c_char, c_uchar, c_void};
use librocksdb_sys::DBTableFileCreationReason; use librocksdb_sys::DBTableFileCreationReason;
pub(super) extern "C" fn name(factory: *mut c_void) -> *const c_char { pub(super) extern "C" fn name(factory: *mut c_void) -> *const c_char {
...@@ -255,7 +255,7 @@ mod factory { ...@@ -255,7 +255,7 @@ mod factory {
pub(super) extern "C" fn should_filter_table_file_creation( pub(super) extern "C" fn should_filter_table_file_creation(
factory: *const c_void, factory: *const c_void,
reason: DBTableFileCreationReason, reason: DBTableFileCreationReason,
) -> bool { ) -> c_uchar {
unsafe { unsafe {
let factory = &*(factory as *const CompactionFilterFactoryProxy); let factory = &*(factory as *const CompactionFilterFactoryProxy);
let reason: DBTableFileCreationReason = reason as DBTableFileCreationReason; let reason: DBTableFileCreationReason = reason as DBTableFileCreationReason;
...@@ -298,6 +298,7 @@ pub unsafe fn new_compaction_filter_factory( ...@@ -298,6 +298,7 @@ pub unsafe fn new_compaction_filter_factory(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use libc::c_uchar;
use std::ffi::CString; use std::ffi::CString;
use std::sync::mpsc::{self, SyncSender}; use std::sync::mpsc::{self, SyncSender};
use std::time::Duration; use std::time::Duration;
...@@ -343,8 +344,8 @@ mod tests { ...@@ -343,8 +344,8 @@ mod tests {
} }
impl CompactionFilterFactory for FlushFactory { impl CompactionFilterFactory for FlushFactory {
fn should_filter_table_file_creation(&self, reason: DBTableFileCreationReason) -> bool { fn should_filter_table_file_creation(&self, reason: DBTableFileCreationReason) -> c_uchar {
matches!(reason, DBTableFileCreationReason::Flush) matches!(reason, DBTableFileCreationReason::Flush) as c_uchar
} }
fn create_compaction_filter( fn create_compaction_filter(
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// limitations under the License. // limitations under the License.
use crocksdb_ffi::DBTableProperties; use crocksdb_ffi::DBTableProperties;
use libc::{c_int, c_void}; use libc::{c_uchar, c_void};
use table_properties::TableProperties; use table_properties::TableProperties;
pub trait TableFilter { pub trait TableFilter {
...@@ -24,11 +24,11 @@ pub trait TableFilter { ...@@ -24,11 +24,11 @@ pub trait TableFilter {
fn table_filter(&self, props: &TableProperties) -> bool; 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 { unsafe {
let filter = &*(ctx as *mut Box<dyn TableFilter>); let filter = &*(ctx as *mut Box<dyn TableFilter>);
let props = &*(props as *const TableProperties); 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