prolog: Memory overflows cannot be caught
What is really nice is that you have chosen current_prolog_flag(max_arity, unbounded)
!
?- length(_,E), N is 2^E, writeq(N),nl, catch(functor(F,f,N), Error, true), nonv
ar(Error).
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
fatal error: runtime: out of memory
Expected: Error = error(resource_error(memory), _Imp_def).
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (9 by maintainers)
Here is a case where this limit is not respected:
Merged the fix and released as
v0.15.1
.You can, but Go runtime immediately
exit(2)
when it reached to the limit.I’m preparing a fix to respect Go’s builtin soft memory limit in #279. You can set the limit with an environment variable
GOMEMLIMIT
.functor/3
andlength/2
will respect the limit and when they are likely to breach the limit, they’ll throwerror(resource_error(memory), _)
.When combined with
ulimit -v
, Go’s official document recommends a 5-10% buffer.You can always resort to that at least for standard conformity. For that matter, you can even claim
exit 1
to be a conforming system. See this for more. But by this you are reducing the domain of applicability of your system. Non-termination and thus such overflows are happening all the time to (at least) beginners. And a crashing system isn’t helpful in such situations.Limiting
max_arity
means that you are putting the burden onto the programmer. So the programs have to be more complex than otherwise necessary. Instead of a simplearg/3
one has to program something more complex.Well, it is up to you to decide which way you want to go.