I am trying to make a simple http request using Libcurl version 7.85.0 with Vfx Forth version 5.11 (Win32). I have set up a callback function for libcurl to send me the http data. The callback works as expected (it prints the webpage), except it crashes on return.
**Edit: This code is working on Vfx Forth 5.20 (64-bit) on Linux and Windows.
Library: libcurl.so.4
Extern: char * "C" curl_version( );
Extern: void * "C" curl_easy_init( );
Extern: long "C" curl_easy_setopt( void * handle, long option, void * param );
Extern: long "C" curl_easy_perform( void * handle );
Extern: char * "C" curl_easy_strerror( long code );
Extern: void "C" curl_easy_cleanup( void * handle );
curl_version zcount type
: show-error curl_easy_strerror zcount type ;
: check-errors dup 0<> if show-error else drop then ;
98 constant CURLOPT_BUFFERSIZE
10001 constant CURLOPT_WRITEDATA
10002 constant CURLOPT_URL
20011 constant CURLOPT_WRITEFUNCTION
100 KB Buffer: myBuf
variable curl_handle
curl_easy_init curl_handle !
curl_handle @ CURLOPT_BUFFERSIZE 100 KB curl_easy_setopt check-errors
curl_handle @ CURLOPT_WRITEDATA myBuf curl_easy_setopt check-errors
: (WriteFunc) \ cstring size byteCount userData -- bytesProcessed
.s
drop \ don't need userData
swap drop \ don't need size (always 1 according to docs)
over over \ stack: address len
type \ or dump
swap drop \ leave only return value on stack
.s
." Made it to the end. "
;
4 1 CallBack: &WriteFunc
assign (WriteFunc) to-callback &WriteFunc
curl_handle @ CURLOPT_WRITEFUNCTION &WriteFunc curl_easy_setopt check-errors
curl_handle @ curl_easy_perform
curl_handle @ curl_easy_cleanup