Isolate interned strings from their dynamic environment to avoid calling multiple times them with different text values yielding inconsistent results.
This commit is contained in:
parent
7b99af9b34
commit
89577a27d9
|
@ -148,17 +148,21 @@ impl<T> GILOnceCell<T> {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! intern {
|
macro_rules! intern {
|
||||||
($py: expr, $text: expr) => {{
|
($py: expr, $text: expr) => {{
|
||||||
static INTERNED: $crate::once_cell::GILOnceCell<$crate::Py<$crate::types::PyString>> =
|
fn isolate_from_dyn_env(py: $crate::Python<'_>) -> &$crate::types::PyString {
|
||||||
$crate::once_cell::GILOnceCell::new();
|
static INTERNED: $crate::once_cell::GILOnceCell<$crate::Py<$crate::types::PyString>> =
|
||||||
|
$crate::once_cell::GILOnceCell::new();
|
||||||
|
|
||||||
INTERNED
|
INTERNED
|
||||||
.get_or_init($py, || {
|
.get_or_init(py, || {
|
||||||
$crate::conversion::IntoPy::into_py(
|
$crate::conversion::IntoPy::into_py(
|
||||||
$crate::types::PyString::intern($py, $text),
|
$crate::types::PyString::intern(py, $text),
|
||||||
$py,
|
py,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.as_ref($py)
|
.as_ref(py)
|
||||||
|
}
|
||||||
|
|
||||||
|
isolate_from_dyn_env($py)
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue