Skip to content

Commit

Permalink
Isolate interned strings from their dynamic environment to avoid call…
Browse files Browse the repository at this point in the history
…ing multiple times them with different text values yielding inconsistent results.
  • Loading branch information
adamreichold committed Apr 4, 2022
1 parent 7b99af9 commit 0958a78
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/once_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,18 @@ impl<T> GILOnceCell<T> {
#[macro_export]
macro_rules! intern {
($py: expr, $text: expr) => {{
static INTERNED: $crate::once_cell::GILOnceCell<$crate::Py<$crate::types::PyString>> =
$crate::once_cell::GILOnceCell::new();

INTERNED
.get_or_init($py, || {
$crate::conversion::IntoPy::into_py(
$crate::types::PyString::intern($py, $text),
$py,
)
})
.as_ref($py)
fn isolate_from_dyn_env(py: $crate::Python<'_>) -> &$crate::types::PyString {
static INTERNED: $crate::once_cell::GILOnceCell<$crate::Py<$crate::types::PyString>> =
$crate::once_cell::GILOnceCell::new();

INTERNED
.get_or_init(py, || {
$crate::conversion::IntoPy::into_py($crate::types::PyString::new(py, $text), py)
})
.as_ref(py)
}

isolate_from_dyn_env($py)
}};
}

Expand Down

0 comments on commit 0958a78

Please sign in to comment.