Closed MCRusher closed 1 year ago
Thanks for reporting the issue. I do not want to address this the way your code has since it results in allocations taking those slices. An easier fix is to just add {.gcsafe.}:
block to tell the compiler to go away, reading is perfectly safe. It also keeps the non-allocation. I'll sit down and add this soon.
yeah it'd be nice if startsWith took an offset to avoid it, I was hoping the compiler would elide the allocation somehow.
alright, thanks a lot
I learned recently Nim's std/strutils
does have continuesWith
https://nim-lang.org/docs/strutils.html#continuesWith%2Cstring%2Cstring%2CNatural but I still prefer a very explicit comparison.
A smarter Nim compiler could in theory skip the alloc for the slices in theory, and it has been discussed but it doesn't work now, and even if it could, it's then "how do I prove this is not getting copied" since recvBuf could be arbitrarily large.
It's not so easy since all it would take is a .cstring or something like that anywhere in the procs to trigger a copy (though maybe the compiler could delay it until then or something?).
Anyway, it may be low level but equalMem is extremely simple and predictable so I'm in.
I have merged the fix into #head but will not be tagging a release for a bit yet as I'm ironing out the HTTP multipart handling before tagging it. Will comment here again when it is tagged.
This is tagged in release 0.3.0 https://github.com/guzba/mummy/releases/tag/0.3.0
http10
andhttp11
are declared as global let variables inmummy.nim
which prevents callingserve
in another thread usingcreateThread
since anything that uses them are non-gcsafesimple example program that doesn't compile:
I took a crack at fixing it and this is what I did to get it (seemingly) working
for comparison, it used to be: