Skip to content

Commit

Permalink
attempt at a reproducer for the first-class-function mistake I made w…
Browse files Browse the repository at this point in the history
…hich caused the IO module to fail
  • Loading branch information
mhmerrill committed Nov 15, 2019
1 parent 81d420b commit eeea0b9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Binary file added toys/repro
Binary file not shown.
50 changes: 50 additions & 0 deletions toys/repro.chpl
@@ -0,0 +1,50 @@
module repro
{
use Memory;

config const perLocaleMemLimit = 80;

class ErrorWithMsg: Error {
var msg: string;
}

/*
Get the memory limit for this server run
returns a percentage of the physical memory per locale
*/
proc getMemLimit():uint {
return ((perLocaleMemLimit:real / 100.0) * here.physicalMemory()):uint; // checks on locale-0
}

/*
check used + amount is over the memory limit
throw error if we would go over the limit
*/
proc overMemLimit(additionalAmount:int) throws {
// must set config var "-smemTrack=true"(compile time) or "--memTrack=true" (run time)
// to use memoryUsed() procedure from Chapel's Memory module
if (memTrack) {
var total = memoryUsed() + additionalAmount:uint;
if total > getMemLimit() {
throw new owned ErrorWithMsg("Error: Operation would exceed memory limit ("
+total:string+","+getMemLimit:string+")");
}
}
}

proc main() {
var repMsg:string = "None";

try {
overMemLimit(2**40);
repMsg = "Something";
} catch (e: ErrorWithMsg) {
repMsg = e.msg;
} catch {
repMsg = "Error: Unkown";
}

writeln(repMsg);
}

}

0 comments on commit eeea0b9

Please sign in to comment.