Skip to content

Commit 65aa893

Browse files
committed
fix_api
1 parent 0c32832 commit 65aa893

43 files changed

Lines changed: 657 additions & 617 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/ffi/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ crate-type = ["cdylib", "rlib"]
4444
# It increases build times and library binary size for users.
4545

4646
[dependencies]
47-
abi_stable = "0.11.3"
48-
stabby = "72.1.1"
4947
arrow = { workspace = true, features = ["ffi"] }
5048
arrow-schema = { workspace = true }
51-
async-ffi = { version = "0.5.0", features = ["abi_stable"] }
49+
async-ffi = { version = "0.5.0" }
5250
async-trait = { workspace = true }
5351
datafusion-catalog = { workspace = true }
5452
datafusion-common = { workspace = true }
@@ -70,6 +68,7 @@ futures = { workspace = true }
7068
log = { workspace = true }
7169
prost = { workspace = true }
7270
semver = "1.0.27"
71+
stabby = "72.1.1"
7372
tokio = { workspace = true }
7473

7574
[dev-dependencies]

datafusion/ffi/src/arrow_wrappers.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
use std::sync::Arc;
1919

20-
use abi_stable::StableAbi;
2120
use arrow::array::{ArrayRef, make_array};
2221
use arrow::datatypes::{Schema, SchemaRef};
2322
use arrow::error::ArrowError;
@@ -26,10 +25,10 @@ use datafusion_common::{DataFusionError, ScalarValue};
2625
use log::error;
2726

2827
/// This is a wrapper struct around FFI_ArrowSchema simply to indicate
29-
/// to the StableAbi macros that the underlying struct is FFI safe.
28+
/// that the underlying struct is FFI safe.
3029
#[repr(C)]
31-
#[derive(Debug, StableAbi)]
32-
pub struct WrappedSchema(#[sabi(unsafe_opaque_field)] pub FFI_ArrowSchema);
30+
#[derive(Debug)]
31+
pub struct WrappedSchema(pub FFI_ArrowSchema);
3332

3433
impl From<SchemaRef> for WrappedSchema {
3534
fn from(value: SchemaRef) -> Self {
@@ -66,15 +65,13 @@ impl From<WrappedSchema> for SchemaRef {
6665
}
6766
}
6867

69-
/// This is a wrapper struct for FFI_ArrowArray to indicate to StableAbi
68+
/// This is a wrapper struct for FFI_ArrowArray to indicate
7069
/// that the struct is FFI Safe. For convenience, we also include the
7170
/// schema needed to create a record batch from the array.
7271
#[repr(C)]
73-
#[derive(Debug, StableAbi)]
72+
#[derive(Debug)]
7473
pub struct WrappedArray {
75-
#[sabi(unsafe_opaque_field)]
7674
pub array: FFI_ArrowArray,
77-
7875
pub schema: WrappedSchema,
7976
}
8077

datafusion/ffi/src/catalog_provider.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ use std::any::Any;
1919
use std::ffi::c_void;
2020
use std::sync::Arc;
2121

22-
use abi_stable::StableAbi;
23-
use abi_stable::std_types::{ROption, RResult, RString, RVec};
2422
use datafusion_catalog::{CatalogProvider, SchemaProvider};
2523
use datafusion_common::error::Result;
2624
use datafusion_proto::logical_plan::{
2725
DefaultLogicalExtensionCodec, LogicalExtensionCodec,
2826
};
27+
use stabby::option::Option as StabbyOption;
28+
use stabby::result::Result as StabbyResult;
29+
use stabby::string::String as StabbyString;
30+
use stabby::vec::Vec as StabbyVec;
2931
use tokio::runtime::Handle;
3032

3133
use crate::execution::FFI_TaskContextProvider;
@@ -36,28 +38,28 @@ use crate::{df_result, rresult_return};
3638

3739
/// A stable struct for sharing [`CatalogProvider`] across FFI boundaries.
3840
#[repr(C)]
39-
#[derive(Debug, StableAbi)]
41+
#[derive(Debug)]
4042
pub struct FFI_CatalogProvider {
41-
pub schema_names: unsafe extern "C" fn(provider: &Self) -> RVec<RString>,
43+
pub schema_names: unsafe extern "C" fn(provider: &Self) -> StabbyVec<StabbyString>,
4244

4345
pub schema: unsafe extern "C" fn(
4446
provider: &Self,
45-
name: RString,
46-
) -> ROption<FFI_SchemaProvider>,
47-
48-
pub register_schema: unsafe extern "C" fn(
49-
provider: &Self,
50-
name: RString,
51-
schema: &FFI_SchemaProvider,
52-
)
53-
-> FFIResult<ROption<FFI_SchemaProvider>>,
54-
55-
pub deregister_schema: unsafe extern "C" fn(
56-
provider: &Self,
57-
name: RString,
58-
cascade: bool,
59-
)
60-
-> FFIResult<ROption<FFI_SchemaProvider>>,
47+
name: StabbyString,
48+
) -> StabbyOption<FFI_SchemaProvider>,
49+
50+
pub register_schema:
51+
unsafe extern "C" fn(
52+
provider: &Self,
53+
name: StabbyString,
54+
schema: &FFI_SchemaProvider,
55+
) -> FFIResult<StabbyOption<FFI_SchemaProvider>>,
56+
57+
pub deregister_schema:
58+
unsafe extern "C" fn(
59+
provider: &Self,
60+
name: StabbyString,
61+
cascade: bool,
62+
) -> FFIResult<StabbyOption<FFI_SchemaProvider>>,
6163

6264
pub logical_codec: FFI_LogicalExtensionCodec,
6365

@@ -107,7 +109,7 @@ impl FFI_CatalogProvider {
107109

108110
unsafe extern "C" fn schema_names_fn_wrapper(
109111
provider: &FFI_CatalogProvider,
110-
) -> RVec<RString> {
112+
) -> StabbyVec<StabbyString> {
111113
unsafe {
112114
let names = provider.inner().schema_names();
113115
names.into_iter().map(|s| s.into()).collect()
@@ -116,8 +118,8 @@ unsafe extern "C" fn schema_names_fn_wrapper(
116118

117119
unsafe extern "C" fn schema_fn_wrapper(
118120
provider: &FFI_CatalogProvider,
119-
name: RString,
120-
) -> ROption<FFI_SchemaProvider> {
121+
name: StabbyString,
122+
) -> StabbyOption<FFI_SchemaProvider> {
121123
unsafe {
122124
let maybe_schema = provider.inner().schema(name.as_str());
123125
maybe_schema
@@ -134,9 +136,9 @@ unsafe extern "C" fn schema_fn_wrapper(
134136

135137
unsafe extern "C" fn register_schema_fn_wrapper(
136138
provider: &FFI_CatalogProvider,
137-
name: RString,
139+
name: StabbyString,
138140
schema: &FFI_SchemaProvider,
139-
) -> FFIResult<ROption<FFI_SchemaProvider>> {
141+
) -> FFIResult<StabbyOption<FFI_SchemaProvider>> {
140142
unsafe {
141143
let runtime = provider.runtime();
142144
let inner_provider = provider.inner();
@@ -153,23 +155,23 @@ unsafe extern "C" fn register_schema_fn_wrapper(
153155
})
154156
.into();
155157

156-
RResult::ROk(returned_schema)
158+
StabbyResult::Ok(returned_schema)
157159
}
158160
}
159161

160162
unsafe extern "C" fn deregister_schema_fn_wrapper(
161163
provider: &FFI_CatalogProvider,
162-
name: RString,
164+
name: StabbyString,
163165
cascade: bool,
164-
) -> FFIResult<ROption<FFI_SchemaProvider>> {
166+
) -> FFIResult<StabbyOption<FFI_SchemaProvider>> {
165167
unsafe {
166168
let runtime = provider.runtime();
167169
let inner_provider = provider.inner();
168170

169171
let maybe_schema =
170172
rresult_return!(inner_provider.deregister_schema(name.as_str(), cascade));
171173

172-
RResult::ROk(
174+
StabbyResult::Ok(
173175
maybe_schema
174176
.map(|schema| {
175177
FFI_SchemaProvider::new_with_ffi_codec(

datafusion/ffi/src/catalog_provider_list.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ use std::any::Any;
1919
use std::ffi::c_void;
2020
use std::sync::Arc;
2121

22-
use abi_stable::StableAbi;
23-
use abi_stable::std_types::{ROption, RString, RVec};
2422
use datafusion_catalog::{CatalogProvider, CatalogProviderList};
2523
use datafusion_proto::logical_plan::{
2624
DefaultLogicalExtensionCodec, LogicalExtensionCodec,
2725
};
26+
use stabby::option::Option as StabbyOption;
27+
use stabby::string::String as StabbyString;
28+
use stabby::vec::Vec as StabbyVec;
2829
use tokio::runtime::Handle;
2930

3031
use crate::catalog_provider::{FFI_CatalogProvider, ForeignCatalogProvider};
@@ -33,21 +34,23 @@ use crate::proto::logical_extension_codec::FFI_LogicalExtensionCodec;
3334

3435
/// A stable struct for sharing [`CatalogProviderList`] across FFI boundaries.
3536
#[repr(C)]
36-
#[derive(Debug, StableAbi)]
37+
#[derive(Debug)]
3738
pub struct FFI_CatalogProviderList {
3839
/// Register a catalog
3940
pub register_catalog: unsafe extern "C" fn(
4041
&Self,
41-
name: RString,
42+
name: StabbyString,
4243
catalog: &FFI_CatalogProvider,
43-
) -> ROption<FFI_CatalogProvider>,
44+
) -> StabbyOption<FFI_CatalogProvider>,
4445

4546
/// List of existing catalogs
46-
pub catalog_names: unsafe extern "C" fn(&Self) -> RVec<RString>,
47+
pub catalog_names: unsafe extern "C" fn(&Self) -> StabbyVec<StabbyString>,
4748

4849
/// Access a catalog
49-
pub catalog:
50-
unsafe extern "C" fn(&Self, name: RString) -> ROption<FFI_CatalogProvider>,
50+
pub catalog: unsafe extern "C" fn(
51+
&Self,
52+
name: StabbyString,
53+
) -> StabbyOption<FFI_CatalogProvider>,
5154

5255
pub logical_codec: FFI_LogicalExtensionCodec,
5356

@@ -97,7 +100,7 @@ impl FFI_CatalogProviderList {
97100

98101
unsafe extern "C" fn catalog_names_fn_wrapper(
99102
provider: &FFI_CatalogProviderList,
100-
) -> RVec<RString> {
103+
) -> StabbyVec<StabbyString> {
101104
unsafe {
102105
let names = provider.inner().catalog_names();
103106
names.into_iter().map(|s| s.into()).collect()
@@ -106,9 +109,9 @@ unsafe extern "C" fn catalog_names_fn_wrapper(
106109

107110
unsafe extern "C" fn register_catalog_fn_wrapper(
108111
provider: &FFI_CatalogProviderList,
109-
name: RString,
112+
name: StabbyString,
110113
catalog: &FFI_CatalogProvider,
111-
) -> ROption<FFI_CatalogProvider> {
114+
) -> StabbyOption<FFI_CatalogProvider> {
112115
unsafe {
113116
let runtime = provider.runtime();
114117
let inner_provider = provider.inner();
@@ -129,8 +132,8 @@ unsafe extern "C" fn register_catalog_fn_wrapper(
129132

130133
unsafe extern "C" fn catalog_fn_wrapper(
131134
provider: &FFI_CatalogProviderList,
132-
name: RString,
133-
) -> ROption<FFI_CatalogProvider> {
135+
name: StabbyString,
136+
) -> StabbyOption<FFI_CatalogProvider> {
134137
unsafe {
135138
let runtime = provider.runtime();
136139
let inner_provider = provider.inner();

datafusion/ffi/src/config/extension_options.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ use std::any::Any;
1919
use std::collections::HashMap;
2020
use std::ffi::c_void;
2121

22-
use abi_stable::StableAbi;
23-
use abi_stable::std_types::{RResult, RStr, RString, RVec, Tuple2};
2422
use datafusion_common::config::{ConfigEntry, ConfigExtension, ExtensionOptions};
2523
use datafusion_common::{Result, exec_err};
24+
use stabby::result::Result as StabbyResult;
25+
use stabby::str::Str as StabbyStr;
26+
use stabby::string::String as StabbyString;
27+
use stabby::vec::Vec as StabbyVec;
2628

2729
use crate::df_result;
2830

@@ -38,17 +40,20 @@ use crate::df_result;
3840
/// are stored with the full path prefix to avoid overwriting values when using
3941
/// multiple extensions.
4042
#[repr(C)]
41-
#[derive(Debug, StableAbi)]
43+
#[derive(Debug)]
4244
pub struct FFI_ExtensionOptions {
4345
/// Return a deep clone of this [`ExtensionOptions`]
4446
pub cloned: unsafe extern "C" fn(&Self) -> FFI_ExtensionOptions,
4547

4648
/// Set the given `key`, `value` pair
47-
pub set:
48-
unsafe extern "C" fn(&mut Self, key: RStr, value: RStr) -> RResult<(), RString>,
49+
pub set: unsafe extern "C" fn(
50+
&mut Self,
51+
key: StabbyStr,
52+
value: StabbyStr,
53+
) -> StabbyResult<(), StabbyString>,
4954

5055
/// Returns the [`ConfigEntry`] stored in this [`ExtensionOptions`]
51-
pub entries: unsafe extern "C" fn(&Self) -> RVec<Tuple2<RString, RString>>,
56+
pub entries: unsafe extern "C" fn(&Self) -> StabbyVec<(StabbyString, StabbyString)>,
5257

5358
/// Release the memory of the private data when it is no longer being used.
5459
pub release: unsafe extern "C" fn(&mut Self),
@@ -91,20 +96,22 @@ unsafe extern "C" fn cloned_fn_wrapper(
9196

9297
unsafe extern "C" fn set_fn_wrapper(
9398
options: &mut FFI_ExtensionOptions,
94-
key: RStr,
95-
value: RStr,
96-
) -> RResult<(), RString> {
97-
let _ = options.inner_mut().insert(key.into(), value.into());
98-
RResult::ROk(())
99+
key: StabbyStr,
100+
value: StabbyStr,
101+
) -> StabbyResult<(), StabbyString> {
102+
let _ = options
103+
.inner_mut()
104+
.insert(key.as_str().into(), value.as_str().into());
105+
StabbyResult::Ok(())
99106
}
100107

101108
unsafe extern "C" fn entries_fn_wrapper(
102109
options: &FFI_ExtensionOptions,
103-
) -> RVec<Tuple2<RString, RString>> {
110+
) -> StabbyVec<(StabbyString, StabbyString)> {
104111
options
105112
.inner()
106113
.iter()
107-
.map(|(key, value)| (key.to_owned().into(), value.to_owned().into()).into())
114+
.map(|(key, value)| (key.to_owned().into(), value.to_owned().into()))
108115
.collect()
109116
}
110117

0 commit comments

Comments
 (0)