Skip to content

Commit

Permalink
Fix builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Feb 11, 2024
1 parent b2fc03d commit d87eb2a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
26 changes: 0 additions & 26 deletions src/api/limits.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Settings for [`Engine`]'s limitations.
#![cfg(not(feature = "unchecked"))]

use crate::func::{locked_read, locked_write};
use crate::types::StringsInterner;
use crate::Engine;
use std::num::{NonZeroU64, NonZeroUsize};
#[cfg(feature = "no_std")]
Expand All @@ -22,8 +20,6 @@ pub mod default_limits {
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
pub const MAX_FUNCTION_EXPR_DEPTH: usize = 16;
/// Maximum number of strings interned.
pub const MAX_STRINGS_INTERNED: usize = 256;
}
#[cfg(not(debug_assertions))]
pub mod default_limits {
Expand Down Expand Up @@ -350,26 +346,4 @@ impl Engine {
#[cfg(feature = "no_object")]
return 0;
}
/// Set the maximum number of strings to be interned.
#[inline(always)]
pub fn set_max_strings_interned(&mut self, max: usize) -> &mut Self {
if max == 0 {
self.interned_strings = None;
} else if let Some(ref interner) = self.interned_strings {
if let Some(mut guard) = locked_write(interner) {
guard.set_max(max);
}
} else {
self.interned_strings = Some(StringsInterner::new(self.max_strings_interned()).into());
}
self
}
/// The maximum number of strings to be interned.
#[inline(always)]
#[must_use]
pub fn max_strings_interned(&self) -> usize {
self.interned_strings.as_ref().map_or(0, |interner| {
locked_read(interner).map_or(0, |guard| guard.max())
})
}
}
27 changes: 27 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub mod definitions;

pub mod deprecated;

use crate::func::{locked_read, locked_write};
use crate::types::StringsInterner;
use crate::{Dynamic, Engine, Identifier};

#[cfg(feature = "no_std")]
Expand All @@ -46,9 +48,34 @@ pub mod default_limits {

/// Maximum number of parameters in functions with [`Dynamic`][crate::Dynamic] support.
pub const MAX_DYNAMIC_PARAMETERS: usize = 16;
/// Maximum number of strings interned.
pub const MAX_STRINGS_INTERNED: usize = 256;
}

impl Engine {
/// Set the maximum number of strings to be interned.
#[inline(always)]
pub fn set_max_strings_interned(&mut self, max: usize) -> &mut Self {
if max == 0 {
self.interned_strings = None;
} else if let Some(ref interner) = self.interned_strings {
if let Some(mut guard) = locked_write(interner) {
guard.set_max(max);
}
} else {
self.interned_strings = Some(StringsInterner::new(self.max_strings_interned()).into());
}
self
}
/// The maximum number of strings to be interned.
#[inline(always)]
#[must_use]
pub fn max_strings_interned(&self) -> usize {
self.interned_strings.as_ref().map_or(0, |interner| {
locked_read(interner).map_or(0, |guard| guard.max())
})
}

/// The module resolution service used by the [`Engine`].
///
/// Not available under `no_module`.
Expand Down
2 changes: 1 addition & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Main module defining the script evaluation [`Engine`].
use crate::api::limits::default_limits::MAX_STRINGS_INTERNED;
use crate::api::default_limits::MAX_STRINGS_INTERNED;
use crate::api::options::LangOptions;
use crate::func::native::{
locked_write, OnDebugCallback, OnDefVarCallback, OnParseTokenCallback, OnPrintCallback,
Expand Down

0 comments on commit d87eb2a

Please sign in to comment.