From: Mark Thom Date: Sun, 28 Nov 2021 21:53:39 +0000 (-0700) Subject: don't allow [] as a stream alias, restore domain error on source sink for open/{3,4} X-Git-Tag: v0.9.0^2~114 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=529c401eee00cf267a36bf9abf3967973da0fd07;p=scryer-prolog.git don't allow [] as a stream alias, restore domain error on source sink for open/{3,4} --- diff --git a/src/machine/streams.rs b/src/machine/streams.rs index 8e2e2c13..047f9112 100644 --- a/src/machine/streams.rs +++ b/src/machine/streams.rs @@ -1231,7 +1231,12 @@ impl MachineState { let alias = read_heap_cell!(self.store(MachineState::deref(self, alias)), (HeapCellValueTag::Atom, (name, arity)) => { debug_assert_eq!(arity, 0); - Some(name) + + if name != atom!("[]") { + Some(name) + } else { + None + } } _ => { None diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 3d33d921..2d699a06 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -2977,8 +2977,16 @@ impl MachineState { let options = self.to_stream_options(alias, eof_action, reposition, stream_type); let src_sink = self.store(self.deref(self.registers[1])); - if let Some(atom_or_string) = self.value_to_str_like(src_sink) { - let file_spec = self.atom_tbl.build_with(atom_or_string.as_str()); + if let Some(str_like) = self.value_to_str_like(src_sink) { + let file_spec = match str_like { + AtomOrString::Atom(atom) => { + atom + } + AtomOrString::String(string) => { + self.atom_tbl.build_with(&string) + } + }; + let mut stream = self.stream_from_file_spec(file_spec, indices, &options)?; *stream.options_mut() = options;