Skip to content

Commit caeac2e

Browse files
committed
Add private app_data container for mlua internal use
1 parent 3d52616 commit caeac2e

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/chunk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl Chunk<'_> {
637637
if let Ok(ref source) = self.source {
638638
if self.detect_mode() == ChunkMode::Text {
639639
let lua = self.lua.lock();
640-
if let Some(cache) = lua.app_data_ref_unguarded::<ChunksCache>() {
640+
if let Some(cache) = lua.priv_app_data_ref::<ChunksCache>() {
641641
if let Some(data) = cache.0.get(source.as_ref()) {
642642
self.source = Ok(Cow::Owned(data.clone()));
643643
self.mode = Some(ChunkMode::Binary);
@@ -654,12 +654,12 @@ impl Chunk<'_> {
654654
if let Ok(ref binary_source) = self.source {
655655
if self.detect_mode() == ChunkMode::Binary {
656656
let lua = self.lua.lock();
657-
if let Some(mut cache) = lua.app_data_mut_unguarded::<ChunksCache>() {
657+
if let Some(mut cache) = lua.priv_app_data_mut::<ChunksCache>() {
658658
cache.0.insert(text_source, binary_source.to_vec());
659659
} else {
660660
let mut cache = ChunksCache(HashMap::new());
661661
cache.0.insert(text_source, binary_source.to_vec());
662-
let _ = lua.try_set_app_data(cache);
662+
lua.set_priv_app_data(cache);
663663
};
664664
}
665665
}

src/state/extra.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ pub(crate) struct ExtraData {
4444
// When Lua instance dropped, setting `None` would prevent collecting `RegistryKey`s
4545
pub(super) registry_unref_list: Arc<Mutex<Option<Vec<c_int>>>>,
4646

47-
// Container to store arbitrary data (extensions)
47+
// Containers to store arbitrary data (extensions)
4848
pub(super) app_data: AppData,
49+
pub(super) app_data_priv: AppData,
4950

5051
pub(super) safe: bool,
5152
pub(super) libs: StdLib,
@@ -159,6 +160,7 @@ impl ExtraData {
159160
last_checked_userdata_mt: (ptr::null(), None),
160161
registry_unref_list: Arc::new(Mutex::new(Some(Vec::new()))),
161162
app_data: AppData::default(),
163+
app_data_priv: AppData::default(),
162164
safe: false,
163165
libs: StdLib::NONE,
164166
skip_memory_check: false,

src/state/raw.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::mem;
55
use std::os::raw::{c_char, c_int, c_void};
66
use std::panic::resume_unwind;
77
use std::ptr::{self, NonNull};
8-
use std::result::Result as StdResult;
98
use std::sync::Arc;
109

1110
use crate::chunk::ChunkMode;
@@ -307,27 +306,27 @@ impl RawLua {
307306
res
308307
}
309308

310-
/// See [`Lua::try_set_app_data`]
309+
/// Private version of [`Lua::try_set_app_data`]
311310
#[inline]
312-
pub(crate) fn try_set_app_data<T: MaybeSend + 'static>(&self, data: T) -> StdResult<Option<T>, T> {
311+
pub(crate) fn set_priv_app_data<T: MaybeSend + 'static>(&self, data: T) -> Option<T> {
313312
let extra = unsafe { &*self.extra.get() };
314-
extra.app_data.try_insert(data)
313+
extra.app_data_priv.insert(data)
315314
}
316315

317-
/// See [`Lua::app_data_ref`]
316+
/// Private version of [`Lua::app_data_ref`]
318317
#[track_caller]
319318
#[inline]
320-
pub(crate) fn app_data_ref_unguarded<T: 'static>(&self) -> Option<AppDataRef<T>> {
319+
pub(crate) fn priv_app_data_ref<T: 'static>(&self) -> Option<AppDataRef<T>> {
321320
let extra = unsafe { &*self.extra.get() };
322-
extra.app_data.borrow(None)
321+
extra.app_data_priv.borrow(None)
323322
}
324323

325-
/// See [`Lua::app_data_mut`]
324+
/// Private version of [`Lua::app_data_mut`]
326325
#[track_caller]
327326
#[inline]
328-
pub(crate) fn app_data_mut_unguarded<T: 'static>(&self) -> Option<AppDataRefMut<T>> {
327+
pub(crate) fn priv_app_data_mut<T: 'static>(&self) -> Option<AppDataRefMut<T>> {
329328
let extra = unsafe { &*self.extra.get() };
330-
extra.app_data.borrow_mut(None)
329+
extra.app_data_priv.borrow_mut(None)
331330
}
332331

333332
/// See [`Lua::create_registry_value`]

0 commit comments

Comments
 (0)