Under 5.5.1, and after compiling with polyc, the code below gives an assertion violation and core dump:
$ ./a.out In parent - reading Assertion failed: (save_vec_addr < save_vec+1000), function push, file save_vec.cpp, line 70. Abort trap: 6
(That's the OSX wording. I get something very similar under Linux.)
I may well be making a hash of my POSIX programming, but I'd still hope for an exception rather than a core dump.
Michael
- - - -
fun mkTIO_instream fd = let open Posix.IO val (flags,_) = getfl fd val rdr = mkTextReader { fd = fd, name = "", initBlkMode = O.anySet (flags, O.nonblock) } in TextIO.mkInstream (TextIO.StreamIO.mkInstream (rdr, "")) end
fun main() = let open Posix.Process Posix.IO val {infd,outfd} = pipe() in case fork () of NONE => let val () = dup2{old = outfd, new = Posix.FileSys.stdout} val () = List.app close [infd, outfd] in exec("/bin/ls", ["ls", "."]) end | SOME pid => let val _ = print "In parent - reading\n" val strm = mkTIO_instream infd fun recurse () = case TextIO.inputLine strm of NONE => () | SOME s => (print ("Child: " ^ s); recurse()) in recurse(); wait(); print "Seen child's exit\n" end
end
- - - -
________________________________
The information in this e-mail may be confidential and subject to legal professional privilege and/or copyright. National ICT Australia Limited accepts no liability for any damage caused by this email or its attachments.
On 18/03/2016 02:40, Michael Norrish wrote:
Under 5.5.1, and after compiling with polyc, the code below gives an assertion violation and core dump:
This was a bug that has been fixed in the current version, 5.6.
Exceptions are raised in the run-time system when it detects errors such as invalid parameters. Assertions are used for errors in the run-time system itself. The idea is to be slightly more helpful than just a segfault with no other information.
David
On 18 Mar 2016, at 13:13, David Matthews <David.Matthews at prolingua.co.uk> wrote:
On 18/03/2016 02:40, Michael Norrish wrote:
Under 5.5.1, and after compiling with polyc, the code below gives an assertion violation and core dump:
This was a bug that has been fixed in the current version, 5.6.
Exceptions are raised in the run-time system when it detects errors such as invalid parameters. Assertions are used for errors in the run-time system itself. The idea is to be slightly more helpful than just a segfault with no other information.
I tried Michael?s example on 5.6. It didn?t raise an exception, but it also didn?t terminate: it hangs in the call to TextIO.inputLine in the parent process, so I think there is something else wrong (as the call is reading from a pipe whose writer has exited, so I'd expect it to return NONE).
Regards,
Rob.
On 18/03/2016 14:25, Rob Arthan wrote:
On 18 Mar 2016, at 13:13, David Matthews <David.Matthews at prolingua.co.uk> wrote:
On 18/03/2016 02:40, Michael Norrish wrote:
Under 5.5.1, and after compiling with polyc, the code below gives an assertion violation and core dump:
This was a bug that has been fixed in the current version, 5.6.
Exceptions are raised in the run-time system when it detects errors such as invalid parameters. Assertions are used for errors in the run-time system itself. The idea is to be slightly more helpful than just a segfault with no other information.
I tried Michael?s example on 5.6. It didn?t raise an exception, but it also didn?t terminate: it hangs in the call to TextIO.inputLine in the parent process, so I think there is something else wrong (as the call is reading from a pipe whose writer has exited, so I'd expect it to return NONE).
The problem is that the output side of the pipe has not been closed in the parent. That means that both sides of the pipe are open in the parent so the input side doesn't see end-of-stream. Adding "close outfd" in the "SOME pid" branch fixes this.
David