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 89577a2
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/once_cell.rs
Expand Up @@ -148,17 +148,21 @@ 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::intern(py, $text),
py,
)
})
.as_ref(py)
}

isolate_from_dyn_env($py)
}};
}

Expand Down

0 comments on commit 89577a2

Please sign in to comment.