From 206b4bda41f2f245d9dfb8a3f72bd09b91aada39 Mon Sep 17 00:00:00 2001 From: Martin Elsman Date: Wed, 3 Jul 2019 12:55:56 +0200 Subject: [PATCH] bug fix setStackSize (#32) * bug fix setStackSize * fix * debug * debug * fix new macos set-stacksize bad behaviour --- src/Runtime/Runtime.c | 10 ++++-- src/Tools/Tester/CompilerTimings.sml | 33 +++++++++---------- src/Tools/Tester/Tester.sml | 48 +++++++++++++++------------- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/Runtime/Runtime.c b/src/Runtime/Runtime.c index d2800aef5..5c7887b49 100644 --- a/src/Runtime/Runtime.c +++ b/src/Runtime/Runtime.c @@ -68,14 +68,17 @@ setStackSize(rlim_t size) res = setrlimit(RLIMIT_STACK, &lim); if (res == -1) { - bad = strerror(errno); - die2("setStackSize(2)", bad); + return; // return silently in case of an error; on + // macOS, the call fails, but the stack should already be + // big in size (set during linking) + //bad = strerror(errno); + //die2("setStackSize(2)", bad); } res = getrlimit(RLIMIT_STACK, &limit); if (res == -1) { bad = strerror(errno); - die2("setStackSize(2)", bad); + die2("setStackSize(3)", bad); } // printf("Stack size: %llu; %lluMb\n", limit.rlim_cur, limit.rlim_cur / 1024 / 1024); return; @@ -363,6 +366,7 @@ main(int argc, char *argv[]) if ((((double)Max_Int) != Max_Int_d) || (((double)Min_Int) != Min_Int_d)) die("main - integer configuration is erroneous"); + // try to set stack size setStackSizeUnlimited(); parseCmdLineArgs(argc, argv); /* also initializes ml-access to args */ diff --git a/src/Tools/Tester/CompilerTimings.sml b/src/Tools/Tester/CompilerTimings.sml index 332219108..9a5ea7efe 100644 --- a/src/Tools/Tester/CompilerTimings.sml +++ b/src/Tools/Tester/CompilerTimings.sml @@ -10,7 +10,7 @@ structure CompilerTimings : COMPILER_TIMINGS = struct fun pr [] = () - | pr ((n,t)::rest) = (print (n ^ ": " ^ Time.toString t ^ "\n"); pr rest) + | pr ((n,t)::rest) = (print (n ^ ": " ^ Time.toString t ^ "\n"); pr rest) exception ReadTimingsError of string @@ -23,33 +23,34 @@ structure CompilerTimings : COMPILER_TIMINGS = fun read_entry is : (string * Time.time) option = case TextIO.scanStream scanChars is - of SOME name => - (case TextIO.scanStream Time.scan is - of SOME t => SOME(name,t) - | NONE => raise ReadTimingsError "time expected") + of SOME name => + ((case TextIO.scanStream Time.scan is + of SOME t => SOME(name,t) + | NONE => raise ReadTimingsError "time expected") + handle Time.Time => raise ReadTimingsError "Time raised when trying to read time value") | NONE => NONE - + fun read is = case read_entry is of SOME e => e :: read is - | NONE => nil + | NONE => nil (* Compressing timings *) fun compress (ss : (string * Time.time) list) : (string * Time.time) list = - let + let fun unref [] = [] | unref ((n,ref t)::rest) = (n,t):: unref rest - + fun insert ((n,t),nts) = - let + let fun loop [] = nts@[(n,ref t)] | loop ((n', r as ref t')::rest) = if n = n' then (r:= Time.+(t,t'); nts) else loop rest in loop nts end - + fun loop ([],nts) = unref nts | loop (e::rest,nts) = loop(rest,insert(e,nts)) @@ -58,16 +59,16 @@ structure CompilerTimings : COMPILER_TIMINGS = fun from_file s : (string * Time.time) list = - let val is = (TextIO.openIn s) + let val is = (TextIO.openIn s) handle _ => raise ReadTimingsError ("failed to open compiler timings file `" ^ s ^ "'.\n") - in let val ss = (read is) - handle ReadTimingsError s => + in let val ss = (read is) + handle ReadTimingsError s => (TextIO.closeIn is; - raise ReadTimingsError ("error when trying to read compiler timings: " ^ s ^ ".\n")) + raise ReadTimingsError ("error when trying to read compiler timings: " ^ s ^ ".\n")) val ss = compress ss in TextIO.closeIn is; ss - end + end end end diff --git a/src/Tools/Tester/Tester.sml b/src/Tools/Tester/Tester.sml index b6ec1fbcc..efd11533d 100644 --- a/src/Tools/Tester/Tester.sml +++ b/src/Tools/Tester/Tester.sml @@ -99,6 +99,7 @@ structure Tester : TESTER = let val entries = CompilerTimings.from_file "KITtimings" in TestReport.add_comptime_line {name=filepath, entries=entries} end handle CompilerTimings.ReadTimingsError s => (msgErr s; ()) + | Time.Time => (msgErr "Time raised by maybe_report_comptimes"; ()) else () val exe_file = "./runexe" @@ -131,6 +132,9 @@ structure Tester : TESTER = end handle Fail s => (msgErr (exe_file ^ " failure: " ^ s); TestReport.add_runtime_bare_line(file_label,false)) + | Time.Time => + (msgErr ("Time raised during execution of " ^ exe_file); + TestReport.add_runtime_bare_line(file_label,false)) else let val res = OS.Process.system (exe_file ^ " > " ^ file ^ out_file ^ " 2>&1" (*".out"*)) in @@ -165,29 +169,29 @@ structure Tester : TESTER = \ compilation.\n") fun main (progname, args) = - case process_args args - of SOME (kitexe,testfile,flags) => - let val _ = (reset_error_counter()) - handle Time.Time => (print "bad time4\n" ; raise Fail "bad") - val _ = (TestReport.reset()) - handle Time.Time => (print "bad time5\n" ; raise Fail "bad") - in (msglog:=TextIO.openOut(log); - case TestFile.parse testfile - of NONE => OS.Process.failure - | SOME (testfile_string,entries) => - let val entries = map (fn TestFile.SML (filepath,opt) => (filepath,opt,kitexe) + case process_args args of + SOME (kitexe,testfile,flags) => + let val _ = (reset_error_counter()) + handle Time.Time => (print "bad time4\n" ; raise Fail "bad") + val _ = (TestReport.reset()) + handle Time.Time => (print "bad time5\n" ; raise Fail "bad") + in (msglog:=TextIO.openOut(log); + case TestFile.parse testfile + of NONE => OS.Process.failure + | SOME (testfile_string,entries) => + let val entries = map (fn TestFile.SML (filepath,opt) => (filepath,opt,kitexe) | TestFile.MLB (filepath,opt) => (filepath,opt,kitexe)) entries - in (app (process_entry flags) entries) - handle Time.Time => (print "bad time2\n" ; raise Fail "bad2") ; - msgErrors(); - (TestReport.export {errors=noOfErrors(),testfile_string=testfile_string, kitexe=kitexe}) - handle Time.Time => (print "bad time1\n" ; raise Fail "bad1") - ; -(* if noOfErrors() = 0 then OS.Process.success else OS.Process.failure *) - OS.Process.success (* to make make work! mael 2001-10-22 *) - end) before (TextIO.closeOut (!msglog)) - end - | NONE => (print_usage progname; OS.Process.failure) + in (app (process_entry flags) entries) + handle Time.Time => (print "bad time2\n" ; raise Fail "bad2") ; + msgErrors(); + (TestReport.export {errors=noOfErrors(),testfile_string=testfile_string, kitexe=kitexe}) + handle Time.Time => (print "bad time1\n" ; raise Fail "bad1") + ; + (* if noOfErrors() = 0 then OS.Process.success else OS.Process.failure *) + OS.Process.success (* to make make work! mael 2001-10-22 *) + end) before (TextIO.closeOut (!msglog)) + end + | NONE => (print_usage progname; OS.Process.failure) (* fun install() =