replace ref_thread_local::ref_thread_local! with std::thread_local!
removes `ref_thread_local` which was still at 0.0.0 released October 2018 while latest 0.1.1 was released mid November 2021 fixes libraries.rs UB
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -2297,12 +2297,6 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ref_thread_local"
|
|
||||||
version = "0.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d813022b2e00774a48eaf43caaa3c20b45f040ba8cbf398e2e8911a06668dbe6"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.10.2"
|
version = "1.10.2"
|
||||||
@@ -2605,7 +2599,6 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rand",
|
"rand",
|
||||||
"ref_thread_local",
|
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"ring 0.17.7",
|
"ring 0.17.7",
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ num-order = { version = "1.2.0" }
|
|||||||
ordered-float = "2.6.0"
|
ordered-float = "2.6.0"
|
||||||
phf = { version = "0.9", features = ["macros"] }
|
phf = { version = "0.9", features = ["macros"] }
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
ref_thread_local = "0.0.0"
|
|
||||||
regex = "1.9.1"
|
regex = "1.9.1"
|
||||||
ring = { version = "0.17.5", features = ["wasm32_unknown_unknown_js"] }
|
ring = { version = "0.17.5", features = ["wasm32_unknown_unknown_js"] }
|
||||||
ripemd160 = "0.8.0"
|
ripemd160 = "0.8.0"
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ use indexmap::IndexMap;\
|
|||||||
writeln!(
|
writeln!(
|
||||||
libraries,
|
libraries,
|
||||||
"\
|
"\
|
||||||
ref_thread_local::ref_thread_local! {{
|
std::thread_local!{{
|
||||||
pub(crate) static managed LIBRARIES: IndexMap<&'static str, &'static str> = {{
|
static LIBRARIES: IndexMap<&'static str, &'static str> = {{
|
||||||
let mut m = IndexMap::new();"
|
let mut m = IndexMap::new();"
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ mod tests {
|
|||||||
use crate::machine::{QueryMatch, QueryResolution, Value};
|
use crate::machine::{QueryMatch, QueryResolution, Value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on libraries.rs UB")]
|
#[cfg_attr(miri, ignore = "it takes too long to run")]
|
||||||
fn programatic_query() {
|
fn programatic_query() {
|
||||||
let mut machine = Machine::new_lib();
|
let mut machine = Machine::new_lib();
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::parser::ast::*;
|
|||||||
|
|
||||||
use fxhash::FxBuildHasher;
|
use fxhash::FxBuildHasher;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
pub use ref_thread_local::RefThreadLocal;
|
|
||||||
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@@ -1176,7 +1175,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
|||||||
ListingSource::File(filename, path_buf),
|
ListingSource::File(filename, path_buf),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ModuleSource::Library(library) => match LIBRARIES.borrow().get(&*library.as_str()) {
|
ModuleSource::Library(library) => match libraries::get(&library.as_str()) {
|
||||||
Some(code) => {
|
Some(code) => {
|
||||||
if let Some(module) = self.wam_prelude.indices.modules.get(&library) {
|
if let Some(module) = self.wam_prelude.indices.modules.get(&library) {
|
||||||
if let ListingSource::DynamicallyGenerated = &module.listing_src {
|
if let ListingSource::DynamicallyGenerated = &module.listing_src {
|
||||||
@@ -1257,7 +1256,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
|||||||
ListingSource::File(filename, path_buf),
|
ListingSource::File(filename, path_buf),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ModuleSource::Library(library) => match LIBRARIES.borrow().get(&*library.as_str()) {
|
ModuleSource::Library(library) => match libraries::get(&library.as_str()) {
|
||||||
Some(code) => {
|
Some(code) => {
|
||||||
if self.wam_prelude.indices.modules.contains_key(&library) {
|
if self.wam_prelude.indices.modules.contains_key(&library) {
|
||||||
return self.import_qualified_module(library, exports);
|
return self.import_qualified_module(library, exports);
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ impl<'a> LoadState<'a> for LiveLoadAndMachineState<'a> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn err_on_builtin_module_overwrite(module_name: Atom) -> Result<(), SessionError> {
|
fn err_on_builtin_module_overwrite(module_name: Atom) -> Result<(), SessionError> {
|
||||||
if LIBRARIES.borrow().contains_key(&*module_name.as_str()) {
|
if libraries::contains(&module_name.as_str()) {
|
||||||
Err(SessionError::CannotOverwriteBuiltInModule(module_name))
|
Err(SessionError::CannotOverwriteBuiltInModule(module_name))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -119,9 +119,25 @@ fn current_dir() -> PathBuf {
|
|||||||
|
|
||||||
mod libraries {
|
mod libraries {
|
||||||
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
||||||
|
|
||||||
|
pub(crate) fn contains(name: &str) -> bool {
|
||||||
|
LIBRARIES.with(|libs| libs.contains_key(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use libraries::LIBRARIES;
|
pub(crate) fn get(name: &str) -> Option<&'static str> {
|
||||||
|
LIBRARIES.with(|libs| libs.get(name).map(|&lib| lib))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
std::thread_local! {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
static LIBRARIES2 : IndexMap<&'static str, &'static str> = {
|
||||||
|
let mut m = IndexMap::new();
|
||||||
|
m.insert("test", "test2");
|
||||||
|
m
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
||||||
pub static INSTALL_VERIFY_ATTR_INTERRUPT: usize = 1;
|
pub static INSTALL_VERIFY_ATTR_INTERRUPT: usize = 1;
|
||||||
@@ -456,8 +472,6 @@ impl Machine {
|
|||||||
|
|
||||||
#[allow(clippy::new_without_default)]
|
#[allow(clippy::new_without_default)]
|
||||||
pub fn new(config: MachineConfig) -> Self {
|
pub fn new(config: MachineConfig) -> Self {
|
||||||
use ref_thread_local::RefThreadLocal;
|
|
||||||
|
|
||||||
let args = MachineArgs::new();
|
let args = MachineArgs::new();
|
||||||
let mut machine_st = MachineState::new();
|
let mut machine_st = MachineState::new();
|
||||||
|
|
||||||
@@ -496,7 +510,8 @@ impl Machine {
|
|||||||
|
|
||||||
bootstrapping_compile(
|
bootstrapping_compile(
|
||||||
Stream::from_static_string(
|
Stream::from_static_string(
|
||||||
libraries::LIBRARIES.borrow()["ops_and_meta_predicates"],
|
libraries::get("ops_and_meta_predicates")
|
||||||
|
.expect("library ops_and_meta_predicates should exist"),
|
||||||
&mut wam.machine_st.arena,
|
&mut wam.machine_st.arena,
|
||||||
),
|
),
|
||||||
&mut wam,
|
&mut wam,
|
||||||
@@ -508,7 +523,10 @@ impl Machine {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
bootstrapping_compile(
|
bootstrapping_compile(
|
||||||
Stream::from_static_string(LIBRARIES.borrow()["builtins"], &mut wam.machine_st.arena),
|
Stream::from_static_string(
|
||||||
|
libraries::get("builtins").expect("library builtins should exist"),
|
||||||
|
&mut wam.machine_st.arena,
|
||||||
|
),
|
||||||
&mut wam,
|
&mut wam,
|
||||||
ListingSource::from_file_and_path(atom!("builtins.pl"), lib_path.clone()),
|
ListingSource::from_file_and_path(atom!("builtins.pl"), lib_path.clone()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ use ordered_float::OrderedFloat;
|
|||||||
use fxhash::{FxBuildHasher, FxHasher};
|
use fxhash::{FxBuildHasher, FxHasher};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
|
||||||
pub(crate) use ref_thread_local::RefThreadLocal;
|
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
@@ -105,6 +103,8 @@ use warp::hyper::{HeaderMap, Method};
|
|||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
use warp::{Buf, Filter};
|
use warp::{Buf, Filter};
|
||||||
|
|
||||||
|
use super::libraries;
|
||||||
|
|
||||||
#[cfg(feature = "repl")]
|
#[cfg(feature = "repl")]
|
||||||
pub(crate) fn get_key() -> KeyEvent {
|
pub(crate) fn get_key() -> KeyEvent {
|
||||||
let key;
|
let key;
|
||||||
@@ -7998,10 +7998,7 @@ impl Machine {
|
|||||||
pub(crate) fn load_library_as_stream(&mut self) -> CallResult {
|
pub(crate) fn load_library_as_stream(&mut self) -> CallResult {
|
||||||
let library_name = cell_as_atom!(self.deref_register(1));
|
let library_name = cell_as_atom!(self.deref_register(1));
|
||||||
|
|
||||||
use crate::machine::LIBRARIES;
|
let lib = libraries::get(&library_name.as_str());
|
||||||
|
|
||||||
let lib_ref = LIBRARIES.borrow();
|
|
||||||
let lib = lib_ref.get(&*library_name.as_str());
|
|
||||||
match lib {
|
match lib {
|
||||||
Some(library) => {
|
Some(library) => {
|
||||||
let lib_stream = Stream::from_static_string(library, &mut self.machine_st.arena);
|
let lib_stream = Stream::from_static_string(library, &mut self.machine_st.arena);
|
||||||
|
|||||||
Reference in New Issue
Block a user