Skip to content

Commit

Permalink
add feature flag for infinite recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
OlofBlomqvist committed Jul 19, 2023
1 parent 04647eb commit 32de863
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ time = "0.3.23"
chrono = { version = "0.4.26", features = ["wasmbind"] }
#aiken-lang = "*"
js-sys = { version = "0.3.59", optional=true}
serde_stacker = {version= "0.1.10"}
serde_stacker = {version= "0.1.10",optional = true}
proc-macro2 = "1.0.66"

#pallas-primitives = { path = "c:/users/oblink/documents/github/pallas/pallas-primitives" }
Expand All @@ -42,7 +42,8 @@ pallas = "0.18.1"

[features]
bin-features = ["clap","utils","unstable"]
default = ["utils"]
infinite-recursion = ["serde_stacker"]
default = ["utils","infinite-recursion"]
unstable = []
wasi = []
utils = [
Expand Down
13 changes: 10 additions & 3 deletions src/lib/deserialization/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::collections::HashMap;
use serde::Deserialize;
use crate::types::marlowe::*;


#[cfg(feature="infinite-recursion")]
pub fn deserialize<T>(json:String) -> Result<T,String>
where T : serde::de::DeserializeOwned + std::marker::Send + 'static {
let work = std::thread::Builder::new().stack_size(32 * 1024 * 1024).spawn(move ||{
let mut deserializer = serde_json::Deserializer::from_str(&json);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
T::deserialize(deserializer)
});
match work {
Expand All @@ -27,6 +27,13 @@ where T : serde::de::DeserializeOwned + std::marker::Send + 'static {
}
}


#[cfg(not(feature="infinite-recursion"))]
pub fn deserialize<T>(json:String) -> Result<T,String>
where T : serde::de::DeserializeOwned + std::marker::Send + 'static {
serde_json::de::from_str(&json).map_err(|e| format!("{e:?}"))
}

struct TimeoutVisitor;
impl<'de> serde::de::Visitor<'de> for TimeoutVisitor {
type Value = Timeout;
Expand Down
11 changes: 5 additions & 6 deletions src/lib/extras/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ use plutus_data::FromPlutusData;
pub fn basic_deserialize<'a,T : 'static>(json:&str) -> Result<T,serde_json::Error>
where T : serde::de::DeserializeOwned + std::marker::Send{
let j = json.to_owned();

let mut deserializer = serde_json::Deserializer::from_str(&j);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
let value = T::deserialize(deserializer).unwrap();
Ok(value)
let mut deserializer = serde_json::Deserializer::from_str(&j);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
let value = T::deserialize(deserializer).unwrap();
Ok(value)

}

Expand Down

0 comments on commit 32de863

Please sign in to comment.