]> Repositorios git - scryer-prolog.git/commitdiff
move error handling to Prolog by using the new '$first_non_octet'/2
authorMarkus Triska <[email protected]>
Thu, 4 Nov 2021 17:30:39 +0000 (18:30 +0100)
committerMarkus Triska <[email protected]>
Thu, 4 Nov 2021 17:35:22 +0000 (18:35 +0100)
src/lib/charsio.pl
src/lib/format.pl
src/machine/system_calls.rs

index 92d3c4433049a4f58d06f1b0985bf651e22d0673..2109da5006d46f2c52a9f16ab18656bf992327c8 100644 (file)
@@ -239,7 +239,10 @@ chars_base64(Cs, Bs, Options) :-
             must_be_characters(Bs),
             '$chars_base64'(Cs, Bs, Padding, Charset)
         ;   must_be_characters(Cs),
-            '$chars_base64'(Cs, Bs, Padding, Charset)
+            (   '$first_non_octet'(Cs, N) ->
+                domain_error(byte_char, N, chars_base64/3)
+            ;   '$chars_base64'(Cs, Bs, Padding, Charset)
+            )
         ).
 
 must_be_characters(Cs) :-
index e89643044c7b6280ae303bb15af61a222459fdb1..db5eb48f3e4ff7ff6f2ad1bb96b7b50613d0c1e2 100644 (file)
@@ -390,6 +390,13 @@ format(Fs, Args) :-
 
 format(Stream, Fs, Args) :-
         phrase(format_(Fs, Args), Cs),
+        (   stream_property(Stream, type(binary)) ->
+            (   '$first_non_octet'(Cs, N) ->
+                domain_error(byte_char, N, format/3)
+            ;   true
+            )
+        ;   true
+        ),
         % we use a specialised internal predicate that uses only a
         % single "write" operation for efficiency. It is equivalent to
         % maplist(put_char(Stream), Cs). It also works for binary streams.
index d8c835c6ece5c53bc122588d4466f4d3d3c5c4f5..3a12b8bc12d88e950784abf9fbecc43258334625 100644 (file)
@@ -2042,18 +2042,6 @@ impl MachineState {
 
                 if stream.options().stream_type == StreamType::Binary {
                     for c in string.chars() {
-                        if c as u32 > 255 {
-                            let stub = MachineError::functor_stub(clause_name!("$put_chars"), 2);
-
-                            let err = MachineError::type_error(
-                                self.heap.h(),
-                                ValidType::Byte,
-                                Addr::Char(c),
-                            );
-
-                            return Err(self.error_form(err, stub));
-                        }
-
                         bytes.push(c as u8);
                     }
                 } else {
@@ -5486,18 +5474,6 @@ impl MachineState {
                 } else {
                     let mut bytes = vec![];
                     for c in self.heap_pstr_iter(self[temp_v!(1)]).to_string().chars() {
-                        if c as u32 > 255 {
-                            let stub = MachineError::functor_stub(clause_name!("chars_base64"), 3);
-
-                            let err = MachineError::type_error(
-                                self.heap.h(),
-                                ValidType::Byte,
-                                Addr::Char(c),
-                            );
-
-                            return Err(self.error_form(err, stub));
-                        }
-
                         bytes.push(c as u8);
                     }
                     let b64 = base64::encode_config(bytes, config);