fix stream.rs UB
This commit is contained in:
34
src/arena.rs
34
src/arena.rs
@@ -5,6 +5,7 @@ use crate::http::{HttpListener, HttpResponse};
|
|||||||
use crate::machine::loader::LiveLoadState;
|
use crate::machine::loader::LiveLoadState;
|
||||||
use crate::machine::machine_indices::*;
|
use crate::machine::machine_indices::*;
|
||||||
use crate::machine::streams::*;
|
use crate::machine::streams::*;
|
||||||
|
use crate::parser::char_reader::CharReader;
|
||||||
use crate::raw_block::*;
|
use crate::raw_block::*;
|
||||||
use crate::rcu::Rcu;
|
use crate::rcu::Rcu;
|
||||||
use crate::rcu::RcuRef;
|
use crate::rcu::RcuRef;
|
||||||
@@ -369,6 +370,12 @@ pub trait ArenaAllocated: Sized {
|
|||||||
|
|
||||||
allocated_ptr
|
allocated_ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// - ptr points to an allocated slab of the correct kind
|
||||||
|
unsafe fn dealloc(ptr: NonNull<TypedAllocSlab<Self>>) {
|
||||||
|
drop(unsafe { Box::from_raw(ptr.as_ptr()) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -655,9 +662,7 @@ impl Arena {
|
|||||||
unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>) {
|
unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>) {
|
||||||
macro_rules! drop_typed_slab_in_place {
|
macro_rules! drop_typed_slab_in_place {
|
||||||
($payload: ty, $value: expr) => {
|
($payload: ty, $value: expr) => {
|
||||||
drop(Box::from_raw(
|
<$payload as ArenaAllocated>::dealloc($value.cast::<TypedAllocSlab<$payload>>())
|
||||||
$value.as_ptr().cast::<TypedAllocSlab<$payload>>(),
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,34 +674,34 @@ unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>) {
|
|||||||
drop_typed_slab_in_place!(Rational, value);
|
drop_typed_slab_in_place!(Rational, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::InputFileStream => {
|
ArenaHeaderTag::InputFileStream => {
|
||||||
drop_typed_slab_in_place!(InputFileStream, value);
|
drop_typed_slab_in_place!(StreamLayout<CharReader<InputFileStream>>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::OutputFileStream => {
|
ArenaHeaderTag::OutputFileStream => {
|
||||||
drop_typed_slab_in_place!(OutputFileStream, value);
|
drop_typed_slab_in_place!(StreamLayout<OutputFileStream>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::NamedTcpStream => {
|
ArenaHeaderTag::NamedTcpStream => {
|
||||||
drop_typed_slab_in_place!(NamedTcpStream, value);
|
drop_typed_slab_in_place!(StreamLayout<CharReader<NamedTcpStream>>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::NamedTlsStream => {
|
ArenaHeaderTag::NamedTlsStream => {
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
drop_typed_slab_in_place!(NamedTlsStream, value);
|
drop_typed_slab_in_place!(StreamLayout<CharReader<NamedTlsStream>>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::HttpReadStream => {
|
ArenaHeaderTag::HttpReadStream => {
|
||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
drop_typed_slab_in_place!(HttpReadStream, value);
|
drop_typed_slab_in_place!(StreamLayout<CharReader<HttpReadStream>>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::HttpWriteStream => {
|
ArenaHeaderTag::HttpWriteStream => {
|
||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
drop_typed_slab_in_place!(HttpWriteStream, value);
|
drop_typed_slab_in_place!(StreamLayout<CharReader<HttpWriteStream>>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::ReadlineStream => {
|
ArenaHeaderTag::ReadlineStream => {
|
||||||
drop_typed_slab_in_place!(ReadlineStream, value);
|
drop_typed_slab_in_place!(StreamLayout<ReadlineStream>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::StaticStringStream => {
|
ArenaHeaderTag::StaticStringStream => {
|
||||||
drop_typed_slab_in_place!(StaticStringStream, value);
|
drop_typed_slab_in_place!(StreamLayout<StaticStringStream>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::ByteStream => {
|
ArenaHeaderTag::ByteStream => {
|
||||||
drop_typed_slab_in_place!(ByteStream, value);
|
drop_typed_slab_in_place!(StreamLayout<CharReader<ByteStream>>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::LiveLoadState | ArenaHeaderTag::InactiveLoadState => {
|
ArenaHeaderTag::LiveLoadState | ArenaHeaderTag::InactiveLoadState => {
|
||||||
drop_typed_slab_in_place!(LiveLoadState, value);
|
drop_typed_slab_in_place!(LiveLoadState, value);
|
||||||
@@ -714,10 +719,10 @@ unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>) {
|
|||||||
drop_typed_slab_in_place!(HttpResponse, value);
|
drop_typed_slab_in_place!(HttpResponse, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::StandardOutputStream => {
|
ArenaHeaderTag::StandardOutputStream => {
|
||||||
drop_typed_slab_in_place!(StandardOutputStream, value);
|
drop_typed_slab_in_place!(StreamLayout<StandardOutputStream>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::StandardErrorStream => {
|
ArenaHeaderTag::StandardErrorStream => {
|
||||||
drop_typed_slab_in_place!(StandardErrorStream, value);
|
drop_typed_slab_in_place!(StreamLayout<StandardErrorStream>, value);
|
||||||
}
|
}
|
||||||
ArenaHeaderTag::NullStream
|
ArenaHeaderTag::NullStream
|
||||||
| ArenaHeaderTag::IndexPtrUndefined
|
| ArenaHeaderTag::IndexPtrUndefined
|
||||||
@@ -778,7 +783,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
|
||||||
fn heap_cell_value_const_cast() {
|
fn heap_cell_value_const_cast() {
|
||||||
let mut wam = MockWAM::new();
|
let mut wam = MockWAM::new();
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
|
|||||||
@@ -1415,7 +1415,6 @@ mod tests {
|
|||||||
use crate::machine::mock_wam::*;
|
use crate::machine::mock_wam::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
|
||||||
fn arith_eval_by_metacall_tests() {
|
fn arith_eval_by_metacall_tests() {
|
||||||
let mut wam = MachineState::new();
|
let mut wam = MachineState::new();
|
||||||
let mut op_dir = default_op_dir();
|
let mut op_dir = default_op_dir();
|
||||||
|
|||||||
@@ -369,7 +369,6 @@ mod tests {
|
|||||||
use crate::machine::mock_wam::*;
|
use crate::machine::mock_wam::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
|
||||||
fn heap_marking_tests() {
|
fn heap_marking_tests() {
|
||||||
let mut wam = MockWAM::new();
|
let mut wam = MockWAM::new();
|
||||||
|
|
||||||
|
|||||||
@@ -260,7 +260,6 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
|
||||||
fn unify_tests() {
|
fn unify_tests() {
|
||||||
let mut wam = MachineState::new();
|
let mut wam = MachineState::new();
|
||||||
let mut op_dir = default_op_dir();
|
let mut op_dir = default_op_dir();
|
||||||
@@ -482,7 +481,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
|
||||||
fn test_unify_with_occurs_check() {
|
fn test_unify_with_occurs_check() {
|
||||||
let mut wam = MachineState::new();
|
let mut wam = MachineState::new();
|
||||||
let mut op_dir = default_op_dir();
|
let mut op_dir = default_op_dir();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use serial_test::serial;
|
|||||||
// issue #831
|
// issue #831
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn call_0() {
|
fn call_0() {
|
||||||
load_module_test(
|
load_module_test(
|
||||||
"tests-pl/issue831-call0.pl",
|
"tests-pl/issue831-call0.pl",
|
||||||
|
|||||||
@@ -3,35 +3,35 @@ use serial_test::serial;
|
|||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn builtins() {
|
fn builtins() {
|
||||||
load_module_test("src/tests/builtins.pl", "");
|
load_module_test("src/tests/builtins.pl", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn call_with_inference_limit() {
|
fn call_with_inference_limit() {
|
||||||
load_module_test("src/tests/call_with_inference_limit.pl", "");
|
load_module_test("src/tests/call_with_inference_limit.pl", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn facts() {
|
fn facts() {
|
||||||
load_module_test("src/tests/facts.pl", "");
|
load_module_test("src/tests/facts.pl", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn hello_world() {
|
fn hello_world() {
|
||||||
load_module_test("src/tests/hello_world.pl", "Hello World!\n");
|
load_module_test("src/tests/hello_world.pl", "Hello World!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn syntax_error() {
|
fn syntax_error() {
|
||||||
load_module_test(
|
load_module_test(
|
||||||
"tests-pl/syntax_error.pl",
|
"tests-pl/syntax_error.pl",
|
||||||
@@ -41,21 +41,21 @@ fn syntax_error() {
|
|||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn predicates() {
|
fn predicates() {
|
||||||
load_module_test("src/tests/predicates.pl", "");
|
load_module_test("src/tests/predicates.pl", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn rules() {
|
fn rules() {
|
||||||
load_module_test("src/tests/rules.pl", "");
|
load_module_test("src/tests/rules.pl", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn setup_call_cleanup_load() {
|
fn setup_call_cleanup_load() {
|
||||||
load_module_test(
|
load_module_test(
|
||||||
"src/tests/setup_call_cleanup.pl",
|
"src/tests/setup_call_cleanup.pl",
|
||||||
@@ -65,14 +65,14 @@ fn setup_call_cleanup_load() {
|
|||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn clpz_load() {
|
fn clpz_load() {
|
||||||
load_module_test("src/tests/clpz/test_clpz.pl", "");
|
load_module_test("src/tests/clpz/test_clpz.pl", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serial]
|
#[serial]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
|
#[cfg_attr(miri, ignore = "blocked on helper.rs UB")]
|
||||||
fn iso_conformity_tests() {
|
fn iso_conformity_tests() {
|
||||||
load_module_test("tests-pl/iso-conformity-tests.pl", "All tests passed");
|
load_module_test("tests-pl/iso-conformity-tests.pl", "All tests passed");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user