Skip to content

Commit 262697e

Browse files
committed
refactor: replace CString with pyo3::ffi::c_str! for FFI table provider names
1 parent 18617c4 commit 262697e

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

docs/source/contributor-guide/ffi.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ for our provider thusly:
161161

162162
.. code-block:: rust
163163
164-
let name = CString::new("datafusion_table_provider")?;
165-
let my_capsule = PyCapsule::new_bound(py, provider, Some(name))?;
164+
let name = pyo3::ffi::c_str!("datafusion_table_provider");
165+
let my_capsule = PyCapsule::new_bound(py, provider, Some(name.to_owned()))?;
166166
167167
On the receiving side, turn this pycapsule object into the ``FFI_TableProvider``, which
168168
can then be turned into a ``ForeignTableProvider`` the associated code is:

docs/source/user-guide/io/table_provider.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ A complete example can be found in the `examples folder <https://github.com/apac
3737
&self,
3838
py: Python<'py>,
3939
) -> PyResult<Bound<'py, PyCapsule>> {
40-
let name = CString::new("datafusion_table_provider").unwrap();
40+
let name = pyo3::ffi::c_str!("datafusion_table_provider");
4141
4242
let provider = Arc::new(self.clone())
4343
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
4444
let provider = FFI_TableProvider::new(Arc::new(provider), false);
4545
46-
PyCapsule::new_bound(py, provider, Some(name.clone()))
46+
PyCapsule::new_bound(py, provider, Some(name.to_owned()))
4747
}
4848
}
4949

src/dataframe.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717

1818
use std::collections::HashMap;
19-
use std::ffi::CString;
2019
use std::sync::Arc;
2120
use tokio::sync::Mutex;
2221

@@ -85,12 +84,12 @@ impl PyTableProvider {
8584
&self,
8685
py: Python<'py>,
8786
) -> PyResult<Bound<'py, PyCapsule>> {
88-
let name = CString::new("datafusion_table_provider").unwrap();
87+
let name = pyo3::ffi::c_str!("datafusion_table_provider");
8988

9089
let runtime = get_tokio_runtime().0.handle().clone();
9190
let provider = FFI_TableProvider::new(Arc::clone(&self.provider), false, Some(runtime));
9291

93-
PyCapsule::new(py, provider, Some(name.clone()))
92+
PyCapsule::new(py, provider, Some(name.to_owned()))
9493
}
9594
}
9695

@@ -994,9 +993,10 @@ impl PyDataFrame {
994993
let reader: Box<dyn RecordBatchReader + Send> = Box::new(reader);
995994

996995
let stream = FFI_ArrowArrayStream::new(reader);
997-
let name = CString::new("arrow_array_stream").unwrap();
996+
let name = pyo3::ffi::c_str!("arrow_array_stream");
998997

999-
let capsule = PyCapsule::new(py, stream, Some(name)).map_err(py_datafusion_err)?;
998+
let capsule =
999+
PyCapsule::new(py, stream, Some(name.to_owned())).map_err(py_datafusion_err)?;
10001000
Ok(capsule)
10011001
}
10021002

0 commit comments

Comments
 (0)