Skip to content

Commit

Permalink
refactor: Mark 'register_startup' as unsafe (#20841)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Jan 22, 2025
1 parent 20979a0 commit 9c1637c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion crates/polars-python/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ pub fn register_plugin_function(
#[pyfunction]
pub fn __register_startup_deps() {
#[cfg(feature = "object")]
crate::on_startup::register_startup_deps(true)
unsafe {
crate::on_startup::register_startup_deps(true)
}
}
12 changes: 7 additions & 5 deletions crates/polars-python/src/on_startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ fn warning_function(msg: &str, warning: PolarsWarning) {
});
}

pub fn register_startup_deps(check_python_signals: bool) {
/// # Safety
/// Caller must ensure that no other threads read the objects set by this registration.
pub unsafe fn register_startup_deps(check_python_signals: bool) {
set_polars_allow_extension(true);
if !registry::is_object_builder_registered() {
// Stack frames can get really large in debug mode.
Expand All @@ -95,11 +97,11 @@ pub fn register_startup_deps(check_python_signals: bool) {
let physical_dtype = ArrowDataType::FixedSizeBinary(object_size);
registry::register_object_builder(object_builder, object_converter, physical_dtype);
// register SERIES UDF
unsafe { python_udf::CALL_COLUMNS_UDF_PYTHON = Some(python_function_caller_series) }
python_udf::CALL_COLUMNS_UDF_PYTHON = Some(python_function_caller_series);
// register DATAFRAME UDF
unsafe { python_udf::CALL_DF_UDF_PYTHON = Some(python_function_caller_df) }
python_udf::CALL_DF_UDF_PYTHON = Some(python_function_caller_df);
// register warning function for `polars_warn!`
unsafe { polars_error::set_warning_function(warning_function) };
polars_error::set_warning_function(warning_function);

if check_python_signals {
fn signals_function() -> PolarsResult<()> {
Expand All @@ -109,7 +111,7 @@ pub fn register_startup_deps(check_python_signals: bool) {
})
}

unsafe { set_signals_function(signals_function) };
set_signals_function(signals_function);
}

Python::with_gil(|py| {
Expand Down

0 comments on commit 9c1637c

Please sign in to comment.