[teyjus] r1165 committed - input behaves correctly when accessing an already closed stream

2 views
Skip to first unread message

tey...@googlecode.com

unread,
Jan 8, 2015, 8:36:06 AM1/8/15
to teyju...@googlegroups.com
Revision: 1165
Author: fafo...@gmail.com
Date: Thu Jan 8 13:35:44 2015 UTC
Log: input behaves correctly when accessing an already closed stream

https://code.google.com/p/teyjus/source/detail?r=1165

Modified:
/branches/ocaml-builtins/TODO_IO
/branches/ocaml-builtins/source/front/io.ml
/branches/ocaml-builtins/source/simulator/builtins/io.c

=======================================
--- /branches/ocaml-builtins/TODO_IO Wed Jan 7 14:21:34 2015 UTC
+++ /branches/ocaml-builtins/TODO_IO Thu Jan 8 13:35:44 2015 UTC
@@ -41,6 +41,7 @@
* reading over multiple lines
* input several times on the same stream
* TODO: from std_in
+ * trying to read whereas the stream is closed


string_to_term
=======================================
--- /branches/ocaml-builtins/source/front/io.ml Wed Jan 7 14:21:34 2015 UTC
+++ /branches/ocaml-builtins/source/front/io.ml Thu Jan 8 13:35:44 2015 UTC
@@ -102,10 +102,11 @@
let closeFile fname =
try
let chan = Hashtbl.find htFiles fname in
- Hashtbl.remove htFiles fname ;
(match chan with
| In(chan) -> close_in chan
- | Out(chan) | OutApp(chan) -> close_out chan) ; 1
+ | Out(chan) | OutApp(chan) -> close_out chan) ;
+ Hashtbl.remove htFiles fname ;
+ 1
with
Not_found -> -1

=======================================
--- /branches/ocaml-builtins/source/simulator/builtins/io.c Tue Jan 6
20:06:46 2015 UTC
+++ /branches/ocaml-builtins/source/simulator/builtins/io.c Thu Jan 8
13:35:44 2015 UTC
@@ -315,9 +315,6 @@
if (num <= 1) EM_error(BI_ERROR_NEGATIVE_VALUE, num);

tmPtr= ((DF_TermPtr)(AM_reg(1)));
- // Necessary?
- HN_hnorm(tmPtr);
- tmPtr = DF_termDeref(tmPtr);

finfo = BIIO_getFinfoFromTerm(tmPtr);
if (finfo != NULL) {
@@ -326,9 +323,15 @@

buffer = FRONT_IO_inputNChars(fname, num);

- if (buffer == "") {
- // An error occured in the OCaml part while reading
- EM_error(BI_ERROR_READING_STREAM, (DF_TermPtr)AM_reg(1));
+ if (strcmp(buffer, "") != 0) {
+ /* There were two kind of errors when IO was managed in C.
+ * However the BI_ERROR_READING_STREAM was impossible to be thrown
+ * since it required to input in a stream which didn't have the
+ * STREAML_readCharacters field. But since only in_stream are
+ * given to STREAM_readCharacters, this is impossible.
+ * Conclusion: it's fine to have the empty string denoting the single
+ * possible error: the stream is already closed */
+ EM_error(BI_ERROR_ILLEGAL_STREAM);
}

length = strlen(buffer);
Reply all
Reply to author
Forward
0 new messages