Recently,i want to use the httpclient module of the Nim to speed up my Ruby's spider application,but when i frequently send the http request or use the function "downloadfile" which is in the httpclient module,it usually tend to occur a serious error which was shown as follow.
Traceback (most recent call last) sotest.nim(25) download sotest.nim(8) downloadFile2 (this is my own code file.)
httpclient.nim(495) getContent httpclient.nim(476) get httpclient.nim(449) request system.nim(349) request httpclient.nim(211) parseResponse net.nim(859) readLine gc.nim(577) growObj system.nim(349) growObj SIGSEGV: Illegal storage access. (Attempt to read from nil?)
How to solve the problem ,please?
Hello!
Any chance you could show us your code?
Thanks for all who replied me, especially @andrea.
I had solved my problem by switching the options of the compile in this afternoon.
nim c -d:release --gc:markAndSweep --app:lib ./sotest.nim
In fact,i still don't know the deep reason of this error,but only realized that it is related to the Garbage Collector.
Your code
proc download(fullpath:cstring,url:cstring) {.exportc: "download".} =
var path:string
path = splitPath($fullpath)[0]
if not existsDir(path):
echo "No such dir, but i had made it!"
createDir(path)
downloadFile2($url, $fullpath,
userAgent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
)
means that you export c function and declare new download(fullpath:cstring,url:cstring) function. You could just export that function:
proc download(fullpath:cstring,url:cstring) {.exportc: "download".}
or declare it without exporting
proc download(fullpath:cstring,url:cstring) =
var path:string
path = splitPath($fullpath)[0]
if not existsDir(path):
echo "No such dir, but i had made it!"
createDir(path)
downloadFile2($url, $fullpath,
userAgent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
)
@karatin You may read the manual (or fix it if it is wrong):
Exportc pragma
The exportc pragma provides a means to export a type, a variable, or a procedure to C. Enums and constants can't be exported. The optional argument is a string containing the C identifier. If the argument is missing, the C name is the Nim identifier exactly as spelled:
proc callme(formatstr: cstring) {.exportc: "callMe", varargs.}
Note that this pragma is somewhat of a misnomer: Other backends will provide the same feature under the same name.