Fix builds.

This commit is contained in:
Stephen Chung
2022-01-07 12:19:01 +08:00
parent a267ac5e54
commit 047e65223d
11 changed files with 1052 additions and 1011 deletions

View File

@@ -4,8 +4,11 @@ use crate::api::custom_syntax::CustomSyntax;
use crate::func::native::{OnDebugCallback, OnParseTokenCallback, OnPrintCallback, OnVarCallback};
use crate::packages::{Package, StandardPackage};
use crate::tokenizer::Token;
use crate::types::dynamic::map_std_type_name;
use crate::{Identifier, ImmutableString, Module, Position, RhaiError, Shared, StaticVec, ERR};
use crate::types::dynamic::{map_std_type_name, Union};
use crate::{
Dynamic, Identifier, ImmutableString, Module, Position, RhaiError, RhaiResult, Shared,
StaticVec, ERR,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
@@ -287,6 +290,31 @@ impl Engine {
self.empty_string.clone()
}
/// Check a result to ensure that it is valid.
pub(crate) fn check_return_value(&self, mut result: RhaiResult, pos: Position) -> RhaiResult {
let _pos = pos;
match result {
Ok(ref mut r) => {
// Concentrate all empty strings into one instance to save memory
if let Dynamic(Union::Str(s, _, _)) = r {
if s.is_empty() {
if !s.ptr_eq(&self.empty_string) {
*s = self.const_empty_string();
}
return result;
}
}
#[cfg(not(feature = "unchecked"))]
self.check_data_size(&r, _pos)?;
}
_ => (),
}
result
}
/// Pretty-print a type name.
///
/// If a type is registered via [`register_type_with_name`][Engine::register_type_with_name],