If there's still not enough room after a GC, grow the heap and do it
again so that there is enough room. (This is a quick hack to fix a rare
issue with large buffers!)
This is for getting the time at a finer granularity than seconds. I
want this for getting approximate wall clock time measurements for run
time of fragments of programs, so the interface is very basic, but I am
open to better, more sophisticated APIs!
I expect this won't work on Windows, so it's #ifdefed out and always
returns 0. If you know how to fix this, please do!
SLIDE needs to use 'memmove' rather than 'memcpy' because in the case
that the called function has more arguments than the current stack
frame, the regions will overlap, which would lead to undefined
behaviour.
Some threads exit by finishing the runThread function, and some finish
by calling idris_stopThread. The test io003 triggered the assert in
runThread. Bring back calling terminate from the end of runThread.
Valgrind detected this memory leak amongst others:
$ valgrind --leak-check=full --show-leak-kinds=all --trace-children=yes ./coop
==32242== 32 bytes in 1 blocks are still reachable in loss record 1 of 4
==32242== at 0x483880B: malloc (vg_replace_malloc.c:309)
==32242== by 0x409888: vmThread (idris_rts.c:825)
==32242== by 0x404683: _idris_System_46_Concurrency_46_Channels_46_spawn (in /home/l337/OpenSource/Haskell/Idris-dev/coop)
==32242== by 0x4031A3: _idris_Main_46_main (in /home/l337/OpenSource/Haskell/Idris-dev/coop)
==32242== by 0x4066E9: _idris__123_runMain_95_0_125_ (in /home/l337/OpenSource/Haskell/Idris-dev/coop)
==32242== by 0x408D0C: main (in /home/l337/OpenSource/Haskell/Idris-dev/coop)
If we allocate space for a substring, and that triggers a gc, the
original string won't be in the same place, so we need to account for
this in idris_substr.
Otherwise, we're just guessing on the size, and that way lies segfaults.
It turns out the size in Buffer.idr might have been correct once, but
isn't now, and so unless we're lucky registering the pointer will copy
memory we don't have access to. If the RTS does the registering of the
pointer, at least it knows the size.
(It's likely this is doable without the malloc, using iallocate
directly, but this required fewer changes.)
This means we can turn off the clang optimiser and still have working
code generated. It does mean that the code generated is a bit slower
(there's a small overhead for the trampolines) but it compiles much
faster, which is a big deal for developing larger systems!
We need a way to turn the clang optimiser back on - probably just a
compiler flag.