Buy commercial curl support from WolfSSL. We help you work
out your issues, debug your libcurl applications, use the API, port to new
platforms, add new features and more. With a team lead by the curl founder
himself.
Re: CURLOPT_WRITEFUNCTION issues - warning: curl_easy_setopt expects a curl_write_callback argument
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Gavin Henry via curl-library <curl-library_at_lists.haxx.se>
Date: Fri, 21 Jan 2022 12:17:35 +0000
On Fri, 21 Jan 2022 at 11:36, Timothe Litt via curl-library
<curl-library_at_lists.haxx.se> wrote:
>
> Casting isn't the answer. Read the error carefully. You're returning a size_t (integer) from a function declared to return a function pointer. The pointer is supposed to be to a function that returns a size_t.
>
> multiplying 2 size_t variables results in a size_t, not a function pointer.
>
> curl_write_callback declares a pointer to the callback function. Your function (as in the example) needs to be the actual function - I assumed that was obvious. Sorry that I wasn't explicit.
>
> So your callback wants to be a
>
> typedef size_t (curl_write_callback_action)(char *buffer,
> size_t size,
> size_t nitems,
> void *outstream);
>
> note the omitted "*" vs. the original.
>
> Perhaps curl.h should include typedefs for the callback actions as well as for the pointers...
Thanks for time here Timothe (sorry, I shortened to TIm before).
So confirm, the only difference in the example vs my usage is the last
argument to my callback isn't a pointer to void, but to json_t.
Switching that to void removes the error:
This is fine, which made me look extra hard at my function:
gcc -Wall -Werror -Wextra -Wpedantic -pedantic -Wformat=2
-Wno-unused-parameter -Wshadow -Wwrite-strings -Wstrict-prototypes
-Wold-style-definition -Wredundant-decls -Wnested-externs
-Wmissing-include-dirs -std=c18 -D_FORTIFY_SOURCE=2 -fpie -fpic -g3
-O2 -fstack-protector-strong -grecord-gcc-switches
-Werror=format-security -Werror=implicit-function-declaration
-Wmisleading-indentation -O2 -flto=auto -ffat-lto-objects
-fexceptions -g -grecord-gcc-switches -pipe -Wall
-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-Wp,-D_GLIBCXX_ASSERTIONS
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
-fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
-m64 -mtune=generic -fasynchronous-unwind-tables
-fstack-clash-protection -fcf-protection -Wl,-z,relro -Wl,--as-needed
-Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -g -O2 -o gitmemory
gitmemory.c -lcurl
Mine was:
static size_t curl_to_jansson_to_version(void *buffer, size_t size,
size_t nmemb, json_t *json)
{
and is now:
static size_t curl_to_jansson_to_version(void *buffer, size_t size,
size_t nmemb, void *json)
{
so the error has gone.
Thanks for explaining.
Gavin.
Date: Fri, 21 Jan 2022 12:17:35 +0000
On Fri, 21 Jan 2022 at 11:36, Timothe Litt via curl-library
<curl-library_at_lists.haxx.se> wrote:
>
> Casting isn't the answer. Read the error carefully. You're returning a size_t (integer) from a function declared to return a function pointer. The pointer is supposed to be to a function that returns a size_t.
>
> multiplying 2 size_t variables results in a size_t, not a function pointer.
>
> curl_write_callback declares a pointer to the callback function. Your function (as in the example) needs to be the actual function - I assumed that was obvious. Sorry that I wasn't explicit.
>
> So your callback wants to be a
>
> typedef size_t (curl_write_callback_action)(char *buffer,
> size_t size,
> size_t nitems,
> void *outstream);
>
> note the omitted "*" vs. the original.
>
> Perhaps curl.h should include typedefs for the callback actions as well as for the pointers...
Thanks for time here Timothe (sorry, I shortened to TIm before).
So confirm, the only difference in the example vs my usage is the last
argument to my callback isn't a pointer to void, but to json_t.
Switching that to void removes the error:
This is fine, which made me look extra hard at my function:
gcc -Wall -Werror -Wextra -Wpedantic -pedantic -Wformat=2
-Wno-unused-parameter -Wshadow -Wwrite-strings -Wstrict-prototypes
-Wold-style-definition -Wredundant-decls -Wnested-externs
-Wmissing-include-dirs -std=c18 -D_FORTIFY_SOURCE=2 -fpie -fpic -g3
-O2 -fstack-protector-strong -grecord-gcc-switches
-Werror=format-security -Werror=implicit-function-declaration
-Wmisleading-indentation -O2 -flto=auto -ffat-lto-objects
-fexceptions -g -grecord-gcc-switches -pipe -Wall
-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-Wp,-D_GLIBCXX_ASSERTIONS
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
-fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
-m64 -mtune=generic -fasynchronous-unwind-tables
-fstack-clash-protection -fcf-protection -Wl,-z,relro -Wl,--as-needed
-Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -g -O2 -o gitmemory
gitmemory.c -lcurl
Mine was:
static size_t curl_to_jansson_to_version(void *buffer, size_t size,
size_t nmemb, json_t *json)
{
and is now:
static size_t curl_to_jansson_to_version(void *buffer, size_t size,
size_t nmemb, void *json)
{
so the error has gone.
Thanks for explaining.
Gavin.
-- Kind Regards, Gavin Henry. https://sentrypeer.org -- Unsubscribe: https://lists.haxx.se/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.htmlReceived on 2022-01-21