I want to create a little application using the curl library.
Sadly I have not been able to get it working - still the same issue I had last year (viewtopic.php?f=13&t=41482).
This time I did even a fresh debian squeeze (amd64) install on my pc, simply to make sure this is not a configuration issue.
The curl-ssl library has been updated since my last test, the issue still remains.
I thought first, well then import the library by using Import(C), again the same damn issue. I ended up by using the "classic GetFunction() way" --> the same again...
Curl itself is working perfectly - I can't explain it to myself, am I missing something?
Test Code:
Code: Select all
;PB 5.10b3.
;curltest
Procedure ErrorHandler()
ErrorMessage$ = "A program error was detected:" + #CRLF$
ErrorMessage$ + #CRLF$
ErrorMessage$ + "Error Message: " + ErrorMessage() + #CRLF$
ErrorMessage$ + "Error Code: " + Str(ErrorCode()) + #CRLF$
ErrorMessage$ + "Code Address: " + Str(ErrorAddress()) + #CRLF$
If ErrorCode() = #PB_OnError_InvalidMemory
ErrorMessage$ + "Target Address: " + Str(ErrorTargetAddress()) + #CRLF$
EndIf
If ErrorLine() = -1
ErrorMessage$ + "Sourcecode line: Enable OnError lines support to get code line information." + #CRLF$
Else
ErrorMessage$ + "Sourcecode line: " + Str(ErrorLine()) + #CRLF$
ErrorMessage$ + "Sourcecode file: " + ErrorFile() + #CRLF$
EndIf
ErrorMessage$ + #CRLF$
ErrorMessage$ + "Register content:" + #CRLF$
ErrorMessage$ + "RAX = " + Str(ErrorRegister(#PB_OnError_RAX)) + #CRLF$
ErrorMessage$ + "RBX = " + Str(ErrorRegister(#PB_OnError_RBX)) + #CRLF$
ErrorMessage$ + "RCX = " + Str(ErrorRegister(#PB_OnError_RCX)) + #CRLF$
ErrorMessage$ + "RDX = " + Str(ErrorRegister(#PB_OnError_RDX)) + #CRLF$
ErrorMessage$ + "RBP = " + Str(ErrorRegister(#PB_OnError_RBP)) + #CRLF$
ErrorMessage$ + "RSI = " + Str(ErrorRegister(#PB_OnError_RSI)) + #CRLF$
ErrorMessage$ + "RDI = " + Str(ErrorRegister(#PB_OnError_RDI)) + #CRLF$
ErrorMessage$ + "RSP = " + Str(ErrorRegister(#PB_OnError_RSP)) + #CRLF$
ErrorMessage$ + "Display of registers R8-R15 skipped." + #CRLF$
PrintN(ErrorMessage$)
End
EndProcedure
Procedure RW_LibCurl_WriteFunction(*ptr, Size, NMemB, *Stream)
;retreives utf-8/ascii encoded data
Protected SizeProper.i = Size & 255
Protected NMemBProper.i = NMemB
Protected MyDataS.s
Shared ReceivedData.s
MyDataS = PeekS(*ptr, SizeProper * NMemBProper)
ReceivedData + MyDataS
;Debug "> " + MyDataS
;Debug "# " + Str(Len(MyDataS))
;Debug "@ " + Str(Len(ReceivedData))
ProcedureReturn SizeProper * NMemBProper
EndProcedure
Procedure.s RW_LibCurl_GetData()
Shared ReceivedData.s
Protected ReturnData.s
ReturnData.s = ReceivedData.s
ReceivedData.s = ""
ProcedureReturn ReturnData.s
EndProcedure
OpenConsole()
Library = OpenLibrary(#PB_Any,"libcurl.so")
If Library
curl = CallCFunction(Library,"curl_easy_init")
If curl
OnErrorCall(@ErrorHandler())
PrintN("curl is open! --> h="+curl)
*opt_func = GetFunction(Library,"curl_easy_setopt")
*pef_func = GetFunction(Library,"curl_easy_perform")
PrintN("@"+*opt_func)
PrintN("@"+*pef_func)
;CallFunctionFast(*opt_func,curl,10002,#NULL,0) ;should work --> IS NOT
;CallFunctionFast(*opt_func,curl,64,0) ;should work --> IS NOT
;CallFunctionFast(*opt_func,curl,81,0) ;should work --> IS NOT
CallCFunctionFast(*opt_func,curl,20011,@RW_LibCurl_WriteFunction()) ;should work --> IS NOT
CallCFunctionFast(*pef_func,curl)
PrintN(RW_LibCurl_GetData())
CallCFunction(Library,"curl_easy_cleanup",curl)
EndIf
CloseLibrary(Library)
EndIf
Code: Select all
ehead@wsdebnix:/home/ehead/curl# pbcompiler -l ct.pb -e run.me
******************************************
PureBasic 5.10 Beta 3 (Linux - x64)
******************************************
Loading external modules...
Starting compilation...
119 lines processed.
Creating the executable.
- Feel the ..PuRe.. Power -
ehead@wsdebnix:/home/ehead/curl# ./run.me
curl is open! --> h=30454176
@140376225321408
@140376225321168
A program error was detected:
Error Message: Segmentation violation
Error Code: 11
Code Address: 140376225320740
Target Address: 1672
Sourcecode line: 112
Sourcecode file: ct.pb
Register content:
RAX = 35777
RBX = 0
RCX = 115056
RDX = 140376231132824
RBP = 0
RSI = 0
RDI = 140376231132736
RSP = 140734046701376
Display of registers R8-R15 skipped.
Code: Select all
ehead@wsdebnix:/home/ehead/curl# ldconfig -p | grep curl
libcurl.so.4 (libc6,x86-64) => /usr/lib/libcurl.so.4
libcurl.so (libc6,x86-64) => /usr/lib/libcurl.so
libcurl-gnutls.so.4 (libc6,x86-64) => /usr/lib/libcurl-gnutls.so.4