detect source_sink domain error in open/4 (#480)

This commit is contained in:
Mark Thom
2020-05-10 13:19:14 -06:00
parent fa8a1faeb3
commit ea5771c442
2 changed files with 43 additions and 1 deletions

View File

@@ -539,6 +539,7 @@ pub enum DomainErrorType {
IOMode,
NotLessThanZero,
Order,
SourceSink,
Stream,
StreamOrAlias,
}
@@ -549,6 +550,7 @@ impl DomainErrorType {
DomainErrorType::IOMode => "io_mode",
DomainErrorType::NotLessThanZero => "not_less_than_zero",
DomainErrorType::Order => "order",
DomainErrorType::SourceSink => "source_sink",
DomainErrorType::Stream => "stream",
DomainErrorType::StreamOrAlias => "stream_or_alias",
}

View File

@@ -3090,7 +3090,47 @@ impl MachineState {
self.to_stream_options(alias, eof_action, reposition, stream_type);
let file_spec =
atom_from!(self, indices, self.store(self.deref(self[temp_v!(1)])));
match self.store(self.deref(self[temp_v!(1)])) {
Addr::Con(h) if self.heap.atom_at(h) => {
match &self.heap[h] {
&HeapCellValue::Atom(ref atom, _) => {
atom.clone()
}
_ => {
unreachable!()
}
}
}
Addr::PStrLocation(h, n) => {
match &self.heap[h] {
&HeapCellValue::PartialString(_, true) => {
let mut heap_pstr_iter =
self.heap_pstr_iter(Addr::PStrLocation(h, n));
clause_name!(
heap_pstr_iter.to_string(),
indices.atom_tbl.clone()
)
}
_ => {
clause_name!("")
}
}
}
_ => {
clause_name!("")
}
};
if file_spec.as_str().is_empty() {
let stub = MachineError::functor_stub(clause_name!("open"), 4);
let err = MachineError::domain_error(
DomainErrorType::SourceSink,
self[temp_v!(1)],
);
return Err(self.error_form(err, stub));
}
// 8.11.5.3l)
if let Some(ref alias) = &options.alias {