Add checks for is_empty.
This commit is contained in:
@@ -288,7 +288,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
||||
OP_CONTAINS => Some(|_, args| {
|
||||
let blob = &*args[0].read_lock::<Blob>().expect(BUILTIN);
|
||||
let x = (args[1].as_int().expect("`INT`") & 0x000000ff) as u8;
|
||||
Ok(blob.contains(&x).into())
|
||||
Ok((!blob.is_empty() && blob.contains(&x)).into())
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
|
@@ -1353,7 +1353,7 @@ impl Engine {
|
||||
|
||||
let module = self
|
||||
.search_imports(global, state, namespace)
|
||||
.ok_or_else(|| ERR::ErrorModuleNotFound(namespace.to_string(), namespace[0].pos))?;
|
||||
.ok_or_else(|| ERR::ErrorModuleNotFound(namespace.to_string(), namespace.position()))?;
|
||||
|
||||
// First search in script-defined functions (can override built-in)
|
||||
let func = match module.get_qualified_fn(hash) {
|
||||
|
@@ -41,20 +41,30 @@ pub use std::sync::Arc as Shared;
|
||||
#[allow(dead_code)]
|
||||
pub use std::cell::RefCell as Locked;
|
||||
|
||||
/// Lock guard for synchronized shared object.
|
||||
/// Read-only lock guard for synchronized shared object.
|
||||
#[cfg(not(feature = "sync"))]
|
||||
#[allow(dead_code)]
|
||||
pub type LockGuard<'a, T> = std::cell::RefMut<'a, T>;
|
||||
pub type LockGuard<'a, T> = std::cell::Ref<'a, T>;
|
||||
|
||||
/// Mutable lock guard for synchronized shared object.
|
||||
#[cfg(not(feature = "sync"))]
|
||||
#[allow(dead_code)]
|
||||
pub type LockGuardMut<'a, T> = std::cell::RefMut<'a, T>;
|
||||
|
||||
/// Synchronized shared object.
|
||||
#[cfg(feature = "sync")]
|
||||
#[allow(dead_code)]
|
||||
pub use std::sync::RwLock as Locked;
|
||||
|
||||
/// Lock guard for synchronized shared object.
|
||||
/// Read-only lock guard for synchronized shared object.
|
||||
#[cfg(feature = "sync")]
|
||||
#[allow(dead_code)]
|
||||
pub type LockGuard<'a, T> = std::sync::RwLockWriteGuard<'a, T>;
|
||||
pub type LockGuard<'a, T> = std::sync::RwLockReadGuard<'a, T>;
|
||||
|
||||
/// Mutable lock guard for synchronized shared object.
|
||||
#[cfg(feature = "sync")]
|
||||
#[allow(dead_code)]
|
||||
pub type LockGuardMut<'a, T> = std::sync::RwLockWriteGuard<'a, T>;
|
||||
|
||||
/// Context of a native Rust function call.
|
||||
#[derive(Debug)]
|
||||
@@ -374,11 +384,23 @@ pub fn shared_take<T>(value: Shared<T>) -> T {
|
||||
shared_try_take(value).ok().expect("not shared")
|
||||
}
|
||||
|
||||
/// Lock a [`Locked`] resource.
|
||||
/// Lock a [`Locked`] resource for mutable access.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn locked_write<'a, T>(value: &'a Locked<T>) -> LockGuard<'a, T> {
|
||||
pub fn locked_read<'a, T>(value: &'a Locked<T>) -> LockGuard<'a, T> {
|
||||
#[cfg(not(feature = "sync"))]
|
||||
return value.borrow();
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
return value.read().unwrap();
|
||||
}
|
||||
|
||||
/// Lock a [`Locked`] resource for mutable access.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn locked_write<'a, T>(value: &'a Locked<T>) -> LockGuardMut<'a, T> {
|
||||
#[cfg(not(feature = "sync"))]
|
||||
return value.borrow_mut();
|
||||
|
||||
|
Reference in New Issue
Block a user