Fix builds.
This commit is contained in:
parent
cc6a0571e7
commit
31ef7e6c69
@ -1,6 +1,6 @@
|
||||
//! Helper module which defines the [`Any`] trait to to allow dynamic value handling.
|
||||
|
||||
use crate::fn_native::{shared_write_lock, SendSync};
|
||||
use crate::fn_native::SendSync;
|
||||
use crate::r#unsafe::{unsafe_cast_box, unsafe_try_cast};
|
||||
use crate::{FnPtr, ImmutableString, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
@ -1590,7 +1590,7 @@ impl Dynamic {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, _, _) => {
|
||||
let value = shared_write_lock(cell);
|
||||
let value = crate::fn_native::shared_write_lock(cell);
|
||||
|
||||
if (*value).type_id() != TypeId::of::<T>()
|
||||
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
||||
|
@ -5,8 +5,8 @@ use crate::custom_syntax::CustomSyntax;
|
||||
use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant};
|
||||
use crate::fn_hash::get_hasher;
|
||||
use crate::fn_native::{
|
||||
shared_write_lock, CallableFunction, IteratorFn, Locked, OnDebugCallback, OnParseTokenCallback,
|
||||
OnPrintCallback, OnVarCallback,
|
||||
CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback,
|
||||
OnVarCallback,
|
||||
};
|
||||
use crate::module::NamespaceRef;
|
||||
use crate::packages::{Package, StandardPackage};
|
||||
@ -73,10 +73,14 @@ pub struct Imports {
|
||||
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
||||
fn_hash_indexing: (u64, u64),
|
||||
/// Embedded module resolver.
|
||||
///
|
||||
/// Not available under `no_module`.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub embedded_module_resolver: Option<Shared<crate::module::resolvers::StaticModuleResolver>>,
|
||||
/// Cache of globally-defined constants.
|
||||
global_constants: Option<Shared<Locked<BTreeMap<Identifier, Dynamic>>>>,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
global_constants: Option<Shared<crate::Locked<BTreeMap<Identifier, Dynamic>>>>,
|
||||
}
|
||||
|
||||
impl Imports {
|
||||
@ -94,6 +98,8 @@ impl Imports {
|
||||
embedded_module_resolver: None,
|
||||
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
||||
fn_hash_indexing: (0, 0),
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
global_constants: None,
|
||||
}
|
||||
}
|
||||
@ -201,24 +207,28 @@ impl Imports {
|
||||
.find_map(|m| m.get_qualified_iter(id))
|
||||
}
|
||||
/// Get a mutable reference to the cache of globally-defined constants.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[must_use]
|
||||
pub(crate) fn global_constants_mut<'a>(
|
||||
&'a mut self,
|
||||
) -> Option<impl DerefMut<Target = BTreeMap<Identifier, Dynamic>> + 'a> {
|
||||
if let Some(ref global_constants) = self.global_constants {
|
||||
Some(shared_write_lock(global_constants))
|
||||
Some(crate::fn_native::shared_write_lock(global_constants))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// Set a constant into the cache of globally-defined constants.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub(crate) fn set_global_constant(&mut self, name: &str, value: Dynamic) {
|
||||
if self.global_constants.is_none() {
|
||||
let dict: Locked<_> = BTreeMap::new().into();
|
||||
let dict: crate::Locked<_> = BTreeMap::new().into();
|
||||
self.global_constants = Some(dict.into());
|
||||
}
|
||||
|
||||
shared_write_lock(
|
||||
crate::fn_native::shared_write_lock(
|
||||
self.global_constants
|
||||
.as_mut()
|
||||
.expect("`global_constants` is `Some`"),
|
||||
@ -1204,6 +1214,7 @@ impl Engine {
|
||||
Expr::Variable(None, _var_pos, v) => match v.as_ref() {
|
||||
// Normal variable access
|
||||
(_, None, _) => self.search_scope_only(scope, mods, state, lib, this_ptr, expr),
|
||||
|
||||
// Qualified variable access
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
(_, Some((namespace, hash_var)), var_name) => {
|
||||
@ -1265,6 +1276,7 @@ impl Engine {
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "no_module")]
|
||||
(_, Some((_, _)), _) => unreachable!("qualified access under no_module"),
|
||||
},
|
||||
|
@ -34,31 +34,23 @@ pub use std::rc::Rc as Shared;
|
||||
pub use std::sync::Arc as Shared;
|
||||
|
||||
/// Synchronized shared object.
|
||||
///
|
||||
/// Not available under `no_closure`.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "sync"))]
|
||||
#[allow(dead_code)]
|
||||
pub use std::cell::RefCell as Locked;
|
||||
|
||||
/// Lock guard for synchronized shared object.
|
||||
///
|
||||
/// Not available under `no_closure`.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "sync"))]
|
||||
#[allow(dead_code)]
|
||||
pub type LockGuard<'a, T> = std::cell::RefMut<'a, T>;
|
||||
|
||||
/// Synchronized shared object.
|
||||
///
|
||||
/// Not available under `no_closure`.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(feature = "sync")]
|
||||
#[allow(dead_code)]
|
||||
pub use std::sync::RwLock as Locked;
|
||||
|
||||
/// Lock guard for synchronized shared object.
|
||||
///
|
||||
/// Not available under `no_closure`.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(feature = "sync")]
|
||||
#[allow(dead_code)]
|
||||
pub type LockGuard<'a, T> = std::sync::RwLockWriteGuard<'a, T>;
|
||||
|
||||
/// Context of a native Rust function call.
|
||||
@ -277,6 +269,7 @@ impl<'a> NativeCallContext<'a> {
|
||||
/// If the resource is shared (i.e. has other outstanding references), a cloned copy is used.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn shared_make_mut<T: Clone>(value: &mut Shared<T>) -> &mut T {
|
||||
Shared::make_mut(value)
|
||||
}
|
||||
@ -284,12 +277,14 @@ pub fn shared_make_mut<T: Clone>(value: &mut Shared<T>) -> &mut T {
|
||||
/// Consume a [`Shared`] resource if is unique (i.e. not shared), or clone it otherwise.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn shared_take_or_clone<T: Clone>(value: Shared<T>) -> T {
|
||||
shared_try_take(value).unwrap_or_else(|v| v.as_ref().clone())
|
||||
}
|
||||
|
||||
/// Consume a [`Shared`] resource if is unique (i.e. not shared).
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
pub fn shared_try_take<T>(value: Shared<T>) -> Result<T, Shared<T>> {
|
||||
Shared::try_unwrap(value)
|
||||
}
|
||||
@ -301,14 +296,17 @@ pub fn shared_try_take<T>(value: Shared<T>) -> Result<T, Shared<T>> {
|
||||
/// Panics if the resource is shared (i.e. has other outstanding references).
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn shared_take<T>(value: Shared<T>) -> T {
|
||||
shared_try_take(value)
|
||||
.ok()
|
||||
.expect("no outstanding references")
|
||||
}
|
||||
|
||||
/// Lock a [`Shared`] resource.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn shared_write_lock<'a, T>(value: &'a Locked<T>) -> LockGuard<'a, T> {
|
||||
#[cfg(not(feature = "sync"))]
|
||||
return value.borrow_mut();
|
||||
|
@ -171,8 +171,8 @@ pub type Identifier = ImmutableString;
|
||||
/// Alias to [`Rc`][std::rc::Rc] or [`Arc`][std::sync::Arc] depending on the `sync` feature flag.
|
||||
pub use fn_native::Shared;
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
use fn_native::Locked;
|
||||
//// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
|
||||
pub use fn_native::Locked;
|
||||
|
||||
pub(crate) use fn_hash::{
|
||||
calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,
|
||||
|
Loading…
Reference in New Issue
Block a user