Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt at a reproducer for the first-class-function mistake I made w…
…hich caused the IO module to fail
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |