Skip to content

Commit d348b98

Browse files
committed
Add cstr dependency and refactor Arrow array stream capsule name handling
1 parent 31fdc0f commit d348b98

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ mimalloc = { version = "0.1", optional = true, default-features = false, feature
6666
"local_dynamic_tls",
6767
] }
6868
async-trait = "0.1.89"
69-
once_cell = "1.18"
7069
futures = "0.3"
70+
cstr = "0.2"
7171
object_store = { version = "0.12.3", features = [
7272
"aws",
7373
"gcp",

src/dataframe.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use once_cell::sync::Lazy;
18+
use cstr::cstr;
1919
use std::collections::HashMap;
20-
use std::ffi::CString;
20+
use std::ffi::{CStr, CString};
2121
use std::sync::Arc;
2222

2323
use arrow::array::{new_null_array, RecordBatch, RecordBatchReader};
@@ -60,9 +60,8 @@ use crate::{
6060
expr::{sort_expr::PySortExpr, PyExpr},
6161
};
6262

63-
/// File-level static CString for the Arrow array stream capsule name.
64-
static ARROW_ARRAY_STREAM_NAME: Lazy<CString> =
65-
Lazy::new(|| CString::new("arrow_array_stream").unwrap());
63+
/// File-level static CStr for the Arrow array stream capsule name.
64+
static ARROW_ARRAY_STREAM_NAME: &CStr = cstr!("arrow_array_stream");
6665

6766
// https://github.com/apache/datafusion-python/pull/1016#discussion_r1983239116
6867
// - we have not decided on the table_provider approach yet
@@ -972,7 +971,8 @@ impl PyDataFrame {
972971
// destructor provided by PyO3 will drop the stream unless ownership is
973972
// transferred to PyArrow during import.
974973
let stream = FFI_ArrowArrayStream::new(reader);
975-
let capsule = PyCapsule::new(py, stream, Some(ARROW_ARRAY_STREAM_NAME.clone()))?;
974+
let name = CString::new(ARROW_ARRAY_STREAM_NAME.to_bytes()).unwrap();
975+
let capsule = PyCapsule::new(py, stream, Some(name))?;
976976
Ok(capsule)
977977
}
978978

0 commit comments

Comments
 (0)