Skip to content

Commit 48926f9

Browse files
committed
migrate_abi_to_stabby_fix_review_comments
1 parent 21246e2 commit 48926f9

30 files changed

Lines changed: 411 additions & 401 deletions

datafusion-examples/examples/ffi/ffi_module_loader/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ async fn main() -> Result<()> {
4343
"so"
4444
};
4545

46+
let build_type = if cfg!(debug_assertions) {
47+
"debug"
48+
} else {
49+
"release"
50+
};
51+
4652
let library_path = format!(
47-
"../../../../target/debug/{lib_prefix}ffi_example_table_provider.{lib_ext}"
53+
"../../../../target/{build_type}/{lib_prefix}ffi_example_table_provider.{lib_ext}"
4854
);
4955

5056
// Load the library using libloading

datafusion/ffi/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ to work across Rust libraries. In general, you can use Rust's [FFI] to
6565
operate across different programming languages, but that is not the design
6666
intent of this crate. Instead, we are using external crates that provide
6767
stable interfaces that closely mirror the Rust native approach. To learn more
68-
about this approach see the [abi_stable] and [async-ffi] crates.
68+
about this approach see the [stabby] and [async-ffi] crates.
6969

7070
If you have a library in another language that you wish to interface to
7171
DataFusion the recommendation is to create a Rust wrapper crate to interface
@@ -197,7 +197,7 @@ and it is easy to implement on any struct that implements `Session`.
197197
[api docs]: http://docs.rs/datafusion-ffi/latest
198198
[rust abi]: https://doc.rust-lang.org/reference/abi.html
199199
[ffi]: https://doc.rust-lang.org/nomicon/ffi.html
200-
[abi_stable]: https://crates.io/crates/abi_stable
200+
[stabby]: https://crates.io/crates/stabby
201201
[async-ffi]: https://crates.io/crates/async-ffi
202202
[bindgen]: https://crates.io/crates/bindgen
203203
[`datafusion-python`]: https://datafusion.apache.org/python/

datafusion/ffi/src/catalog_provider.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use tokio::runtime::Handle;
3131
use crate::execution::FFI_TaskContextProvider;
3232
use crate::proto::logical_extension_codec::FFI_LogicalExtensionCodec;
3333
use crate::schema_provider::{FFI_SchemaProvider, ForeignSchemaProvider};
34-
use crate::util::{FFIResult, FfiOption, FfiResult};
35-
use crate::{df_result, rresult_return};
34+
use crate::util::{FFI_Option, FFI_Result, FFIResult};
35+
use crate::{df_result, sresult_return};
3636

3737
/// A stable struct for sharing [`CatalogProvider`] across FFI boundaries.
3838
#[repr(C)]
@@ -43,21 +43,21 @@ pub struct FFI_CatalogProvider {
4343
pub schema: unsafe extern "C" fn(
4444
provider: &Self,
4545
name: SString,
46-
) -> FfiOption<FFI_SchemaProvider>,
46+
) -> FFI_Option<FFI_SchemaProvider>,
4747

48-
pub register_schema: unsafe extern "C" fn(
49-
provider: &Self,
50-
name: SString,
51-
schema: &FFI_SchemaProvider,
52-
)
53-
-> FFIResult<FfiOption<FFI_SchemaProvider>>,
48+
pub register_schema:
49+
unsafe extern "C" fn(
50+
provider: &Self,
51+
name: SString,
52+
schema: &FFI_SchemaProvider,
53+
) -> FFIResult<FFI_Option<FFI_SchemaProvider>>,
5454

5555
pub deregister_schema:
5656
unsafe extern "C" fn(
5757
provider: &Self,
5858
name: SString,
5959
cascade: bool,
60-
) -> FFIResult<FfiOption<FFI_SchemaProvider>>,
60+
) -> FFIResult<FFI_Option<FFI_SchemaProvider>>,
6161

6262
pub logical_codec: FFI_LogicalExtensionCodec,
6363

@@ -117,7 +117,7 @@ unsafe extern "C" fn schema_names_fn_wrapper(
117117
unsafe extern "C" fn schema_fn_wrapper(
118118
provider: &FFI_CatalogProvider,
119119
name: SString,
120-
) -> FfiOption<FFI_SchemaProvider> {
120+
) -> FFI_Option<FFI_SchemaProvider> {
121121
unsafe {
122122
let maybe_schema = provider.inner().schema(name.as_str());
123123
maybe_schema
@@ -136,14 +136,14 @@ unsafe extern "C" fn register_schema_fn_wrapper(
136136
provider: &FFI_CatalogProvider,
137137
name: SString,
138138
schema: &FFI_SchemaProvider,
139-
) -> FFIResult<FfiOption<FFI_SchemaProvider>> {
139+
) -> FFIResult<FFI_Option<FFI_SchemaProvider>> {
140140
unsafe {
141141
let runtime = provider.runtime();
142142
let inner_provider = provider.inner();
143143
let schema: Arc<dyn SchemaProvider + Send> = schema.into();
144144

145145
let returned_schema =
146-
rresult_return!(inner_provider.register_schema(name.as_str(), schema))
146+
sresult_return!(inner_provider.register_schema(name.as_str(), schema))
147147
.map(|schema| {
148148
FFI_SchemaProvider::new_with_ffi_codec(
149149
schema,
@@ -153,23 +153,23 @@ unsafe extern "C" fn register_schema_fn_wrapper(
153153
})
154154
.into();
155155

156-
FfiResult::Ok(returned_schema)
156+
FFI_Result::Ok(returned_schema)
157157
}
158158
}
159159

160160
unsafe extern "C" fn deregister_schema_fn_wrapper(
161161
provider: &FFI_CatalogProvider,
162162
name: SString,
163163
cascade: bool,
164-
) -> FFIResult<FfiOption<FFI_SchemaProvider>> {
164+
) -> FFIResult<FFI_Option<FFI_SchemaProvider>> {
165165
unsafe {
166166
let runtime = provider.runtime();
167167
let inner_provider = provider.inner();
168168

169169
let maybe_schema =
170-
rresult_return!(inner_provider.deregister_schema(name.as_str(), cascade));
170+
sresult_return!(inner_provider.deregister_schema(name.as_str(), cascade));
171171

172-
FfiResult::Ok(
172+
FFI_Result::Ok(
173173
maybe_schema
174174
.map(|schema| {
175175
FFI_SchemaProvider::new_with_ffi_codec(

datafusion/ffi/src/catalog_provider_list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tokio::runtime::Handle;
3030
use crate::catalog_provider::{FFI_CatalogProvider, ForeignCatalogProvider};
3131
use crate::execution::FFI_TaskContextProvider;
3232
use crate::proto::logical_extension_codec::FFI_LogicalExtensionCodec;
33-
use crate::util::FfiOption;
33+
use crate::util::FFI_Option;
3434

3535
/// A stable struct for sharing [`CatalogProviderList`] across FFI boundaries.
3636
#[repr(C)]
@@ -41,14 +41,14 @@ pub struct FFI_CatalogProviderList {
4141
&Self,
4242
name: SString,
4343
catalog: &FFI_CatalogProvider,
44-
) -> FfiOption<FFI_CatalogProvider>,
44+
) -> FFI_Option<FFI_CatalogProvider>,
4545

4646
/// List of existing catalogs
4747
pub catalog_names: unsafe extern "C" fn(&Self) -> SVec<SString>,
4848

4949
/// Access a catalog
5050
pub catalog:
51-
unsafe extern "C" fn(&Self, name: SString) -> FfiOption<FFI_CatalogProvider>,
51+
unsafe extern "C" fn(&Self, name: SString) -> FFI_Option<FFI_CatalogProvider>,
5252

5353
pub logical_codec: FFI_LogicalExtensionCodec,
5454

@@ -109,7 +109,7 @@ unsafe extern "C" fn register_catalog_fn_wrapper(
109109
provider: &FFI_CatalogProviderList,
110110
name: SString,
111111
catalog: &FFI_CatalogProvider,
112-
) -> FfiOption<FFI_CatalogProvider> {
112+
) -> FFI_Option<FFI_CatalogProvider> {
113113
unsafe {
114114
let runtime = provider.runtime();
115115
let inner_provider = provider.inner();
@@ -131,7 +131,7 @@ unsafe extern "C" fn register_catalog_fn_wrapper(
131131
unsafe extern "C" fn catalog_fn_wrapper(
132132
provider: &FFI_CatalogProviderList,
133133
name: SString,
134-
) -> FfiOption<FFI_CatalogProvider> {
134+
) -> FFI_Option<FFI_CatalogProvider> {
135135
unsafe {
136136
let runtime = provider.runtime();
137137
let inner_provider = provider.inner();

datafusion/ffi/src/config/extension_options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use stabby::string::String as SString;
2727
use stabby::vec::Vec as SVec;
2828

2929
use crate::df_result;
30-
use crate::util::{FFIResult, FfiResult};
30+
use crate::util::{FFI_Result, FFIResult};
3131

3232
/// A stable struct for sharing [`ExtensionOptions`] across FFI boundaries.
3333
///
@@ -99,7 +99,7 @@ unsafe extern "C" fn set_fn_wrapper(
9999
let _ = options
100100
.inner_mut()
101101
.insert(key.as_str().into(), value.as_str().into());
102-
FfiResult::Ok(())
102+
FFI_Result::Ok(())
103103
}
104104

105105
unsafe extern "C" fn entries_fn_wrapper(

datafusion/ffi/src/execution/task_ctx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::session::config::FFI_SessionConfig;
3232
use crate::udaf::FFI_AggregateUDF;
3333
use crate::udf::FFI_ScalarUDF;
3434
use crate::udwf::FFI_WindowUDF;
35-
use crate::util::FfiOption;
35+
use crate::util::FFI_Option;
3636

3737
/// A stable struct for sharing [`TaskContext`] across FFI boundaries.
3838
#[repr(C)]
@@ -42,7 +42,7 @@ pub struct FFI_TaskContext {
4242
pub session_id: unsafe extern "C" fn(&Self) -> SString,
4343

4444
/// Return the task ID.
45-
pub task_id: unsafe extern "C" fn(&Self) -> FfiOption<SString>,
45+
pub task_id: unsafe extern "C" fn(&Self) -> FFI_Option<SString>,
4646

4747
/// Return the session configuration.
4848
pub session_config: unsafe extern "C" fn(&Self) -> FFI_SessionConfig,
@@ -90,7 +90,7 @@ unsafe extern "C" fn session_id_fn_wrapper(ctx: &FFI_TaskContext) -> SString {
9090
}
9191
}
9292

93-
unsafe extern "C" fn task_id_fn_wrapper(ctx: &FFI_TaskContext) -> FfiOption<SString> {
93+
unsafe extern "C" fn task_id_fn_wrapper(ctx: &FFI_TaskContext) -> FFI_Option<SString> {
9494
unsafe {
9595
let ctx = ctx.inner();
9696
ctx.task_id().map(|s| s.as_str().into()).into()

datafusion/ffi/src/execution/task_ctx_provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use datafusion_execution::{TaskContext, TaskContextProvider};
2323

2424
use crate::execution::task_ctx::FFI_TaskContext;
2525
use crate::util::FFIResult;
26-
use crate::{df_result, rresult};
26+
use crate::{df_result, sresult};
2727

2828
/// Struct for accessing the [`TaskContext`]. This method contains a weak
2929
/// reference, so there are no guarantees that the [`TaskContext`] remains
@@ -76,7 +76,7 @@ unsafe extern "C" fn task_ctx_fn_wrapper(
7676
ctx_provider: &FFI_TaskContextProvider,
7777
) -> FFIResult<FFI_TaskContext> {
7878
unsafe {
79-
rresult!(
79+
sresult!(
8080
ctx_provider
8181
.inner()
8282
.map(FFI_TaskContext::from)

datafusion/ffi/src/execution_plan.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::config::FFI_ConfigOptions;
3434
use crate::execution::FFI_TaskContext;
3535
use crate::plan_properties::FFI_PlanProperties;
3636
use crate::record_batch_stream::FFI_RecordBatchStream;
37-
use crate::util::{FFIResult, FfiOption};
38-
use crate::{df_result, rresult, rresult_return};
37+
use crate::util::{FFI_Option, FFIResult};
38+
use crate::{df_result, sresult, sresult_return};
3939

4040
/// A stable struct for sharing a [`ExecutionPlan`] across FFI boundaries.
4141
#[repr(C)]
@@ -66,7 +66,7 @@ pub struct FFI_ExecutionPlan {
6666
target_partitions: usize,
6767
config: FFI_ConfigOptions,
6868
)
69-
-> FFIResult<FfiOption<FFI_ExecutionPlan>>,
69+
-> FFIResult<FFI_Option<FFI_ExecutionPlan>>,
7070

7171
/// Used to create a clone on the provider of the execution plan. This should
7272
/// only need to be called by the receiver of the plan.
@@ -114,16 +114,12 @@ unsafe extern "C" fn properties_fn_wrapper(
114114
unsafe extern "C" fn children_fn_wrapper(
115115
plan: &FFI_ExecutionPlan,
116116
) -> SVec<FFI_ExecutionPlan> {
117-
unsafe {
118-
let private_data = plan.private_data as *const ExecutionPlanPrivateData;
119-
let plan = &(*private_data).plan;
120-
let runtime = &(*private_data).runtime;
121-
122-
plan.children()
123-
.into_iter()
124-
.map(|child| FFI_ExecutionPlan::new(Arc::clone(child), runtime.clone()))
125-
.collect()
126-
}
117+
let runtime = plan.runtime();
118+
plan.inner()
119+
.children()
120+
.into_iter()
121+
.map(|child| FFI_ExecutionPlan::new(Arc::clone(child), runtime.clone()))
122+
.collect()
127123
}
128124

129125
unsafe extern "C" fn with_new_children_fn_wrapper(
@@ -138,10 +134,10 @@ unsafe extern "C" fn with_new_children_fn_wrapper(
138134
.map(<Arc<dyn ExecutionPlan>>::try_from)
139135
.collect();
140136

141-
let children = rresult_return!(children);
142-
let new_plan = rresult_return!(inner_plan.with_new_children(children));
137+
let children = sresult_return!(children);
138+
let new_plan = sresult_return!(inner_plan.with_new_children(children));
143139

144-
crate::ffi_option::FfiResult::Ok(FFI_ExecutionPlan::new(new_plan, runtime))
140+
crate::ffi_option::FFI_Result::Ok(FFI_ExecutionPlan::new(new_plan, runtime))
145141
}
146142

147143
unsafe extern "C" fn execute_fn_wrapper(
@@ -155,7 +151,7 @@ unsafe extern "C" fn execute_fn_wrapper(
155151

156152
let _runtime_guard = runtime.as_ref().map(|rt| rt.enter());
157153

158-
rresult!(
154+
sresult!(
159155
plan.execute(partition, ctx)
160156
.map(|rbs| FFI_RecordBatchStream::new(rbs, runtime))
161157
)
@@ -165,13 +161,13 @@ unsafe extern "C" fn repartitioned_fn_wrapper(
165161
plan: &FFI_ExecutionPlan,
166162
target_partitions: usize,
167163
config: FFI_ConfigOptions,
168-
) -> FFIResult<FfiOption<FFI_ExecutionPlan>> {
164+
) -> FFIResult<FFI_Option<FFI_ExecutionPlan>> {
169165
let maybe_config: Result<ConfigOptions, DataFusionError> = config.try_into();
170-
let config = rresult_return!(maybe_config);
166+
let config = sresult_return!(maybe_config);
171167
let runtime = plan.runtime();
172168
let plan = plan.inner();
173169

174-
rresult!(
170+
sresult!(
175171
plan.repartitioned(target_partitions, &config)
176172
.map(|maybe_plan| maybe_plan
177173
.map(|plan| FFI_ExecutionPlan::new(plan, runtime))

0 commit comments

Comments
 (0)