lib: feature deprecation warnings in gcc >= 4.3

Add a deprecated attribute to functions and enum values that should not
be used anymore.
This uses a gcc 4.3 dialect, thus is only available for this version of
gcc and newer. Note that the _Pragma() keyword is introduced by C99, but
is available as part of the gcc dialect even when compiling in C89 mode.

It is still possible to disable deprecation at a calling module compile
time by defining CURL_DISABLE_DEPRECATION.

Gcc type checking macros are made aware of possible deprecations.

Some testing support Perl programs are adapted to the extended
declaration syntax.

Several test and unit test C programs intentionally use deprecated
functions/options and are annotated to not generate a warning.

New test 1222 checks the deprecation status in doc and header files.

Closes #9667
This commit is contained in:
Patrick Monnerat 2022-11-14 15:21:34 +01:00 committed by Daniel Stenberg
parent 980510926d
commit 6967571bf2
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
39 changed files with 771 additions and 243 deletions

View file

@ -71,7 +71,9 @@ int test(char *URL)
/* include headers */
easy_setopt(curl[i], CURLOPT_HEADER, 1L);
easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
CURL_IGNORE_DEPRECATION(
easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
)
}
/* make the first one populate the GLOBAL cache */

View file

@ -59,8 +59,10 @@ int test(char *URL)
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_TIMEOUT, (long)7);
easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressKiller);
easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
CURL_IGNORE_DEPRECATION(
easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressKiller);
easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
)
easy_setopt(curl, CURLOPT_NOPROGRESS, (long)0);
res = curl_easy_perform(curl);

View file

@ -40,7 +40,9 @@ int test(char *URL)
/* Test that protocol is properly initialized on curl_easy_init.
*/
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
)
if(res) {
fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
@ -65,7 +67,9 @@ int test(char *URL)
/* Test that a protocol is properly set after receiving an HTTP resource.
*/
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
)
if(res) {
fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
@ -90,7 +94,9 @@ int test(char *URL)
goto test_cleanup;
}
res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
)
if(res) {
fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
@ -109,7 +115,9 @@ int test(char *URL)
curl_easy_reset(curl);
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
)
if(res) {
fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));

View file

@ -64,8 +64,10 @@ int test(char *URL)
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_TIMEOUT, (long)7);
easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
CURL_IGNORE_DEPRECATION(
easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
)
easy_setopt(curl, CURLOPT_NOPROGRESS, (long)0);
res = curl_easy_perform(curl);

View file

@ -44,7 +44,9 @@ int test(char *URL)
goto test_cleanup;
}
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
)
if(res) {
fprintf(stderr, "curl_easy_getinfo() returned %d (%s)\n",
res, curl_easy_strerror(res));

View file

@ -101,7 +101,7 @@ int test(char *URL)
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PUT, 1L);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
test_setopt(curl, CURLOPT_TRAILERFUNCTION, trailers_callback);
test_setopt(curl, CURLOPT_TRAILERDATA, NULL);

View file

@ -61,16 +61,18 @@ int test(char *URL)
/*
* Whitelist string options that are safe for abuse
*/
switch(o->id) {
case CURLOPT_PROXY_TLSAUTH_TYPE:
case CURLOPT_TLSAUTH_TYPE:
case CURLOPT_RANDOM_FILE:
case CURLOPT_EGDSOCKET:
continue;
default:
/* check this */
break;
}
CURL_IGNORE_DEPRECATION(
switch(o->id) {
case CURLOPT_PROXY_TLSAUTH_TYPE:
case CURLOPT_TLSAUTH_TYPE:
case CURLOPT_RANDOM_FILE:
case CURLOPT_EGDSOCKET:
continue;
default:
/* check this */
break;
}
)
/* This is a string. Make sure that passing in a string longer
CURL_MAX_INPUT_LENGTH returns an error */

View file

@ -39,42 +39,44 @@ int test(char *URL)
for(o = curl_easy_option_next(NULL);
o;
o = curl_easy_option_next(o)) {
/* Test for mismatch OR missing typecheck macros */
if(curlcheck_long_option(o->id) !=
(o->type == CURLOT_LONG || o->type == CURLOT_VALUES)) {
print_err(o->name, "CURLOT_LONG or CURLOT_VALUES");
error++;
}
if(curlcheck_off_t_option(o->id) != (o->type == CURLOT_OFF_T)) {
print_err(o->name, "CURLOT_OFF_T");
error++;
}
if(curlcheck_string_option(o->id) != (o->type == CURLOT_STRING)) {
print_err(o->name, "CURLOT_STRING");
error++;
}
if(curlcheck_slist_option(o->id) != (o->type == CURLOT_SLIST)) {
print_err(o->name, "CURLOT_SLIST");
error++;
}
if(curlcheck_cb_data_option(o->id) != (o->type == CURLOT_CBPTR)) {
print_err(o->name, "CURLOT_CBPTR");
error++;
}
/* From here: only test that the type matches if macro is known */
if(curlcheck_write_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) {
print_err(o->name, "CURLOT_FUNCTION");
error++;
}
if(curlcheck_conv_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) {
print_err(o->name, "CURLOT_FUNCTION");
error++;
}
if(curlcheck_postfields_option(o->id) && (o->type != CURLOT_OBJECT)) {
print_err(o->name, "CURLOT_OBJECT");
error++;
}
/* Todo: no gcc typecheck for CURLOPTTYPE_BLOB types? */
CURL_IGNORE_DEPRECATION(
/* Test for mismatch OR missing typecheck macros */
if(curlcheck_long_option(o->id) !=
(o->type == CURLOT_LONG || o->type == CURLOT_VALUES)) {
print_err(o->name, "CURLOT_LONG or CURLOT_VALUES");
error++;
}
if(curlcheck_off_t_option(o->id) != (o->type == CURLOT_OFF_T)) {
print_err(o->name, "CURLOT_OFF_T");
error++;
}
if(curlcheck_string_option(o->id) != (o->type == CURLOT_STRING)) {
print_err(o->name, "CURLOT_STRING");
error++;
}
if(curlcheck_slist_option(o->id) != (o->type == CURLOT_SLIST)) {
print_err(o->name, "CURLOT_SLIST");
error++;
}
if(curlcheck_cb_data_option(o->id) != (o->type == CURLOT_CBPTR)) {
print_err(o->name, "CURLOT_CBPTR");
error++;
}
/* From here: only test that the type matches if macro is known */
if(curlcheck_write_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) {
print_err(o->name, "CURLOT_FUNCTION");
error++;
}
if(curlcheck_conv_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) {
print_err(o->name, "CURLOT_FUNCTION");
error++;
}
if(curlcheck_postfields_option(o->id) && (o->type != CURLOT_OBJECT)) {
print_err(o->name, "CURLOT_OBJECT");
error++;
}
/* Todo: no gcc typecheck for CURLOPTTYPE_BLOB types? */
)
}
#endif
(void)URL;

View file

@ -44,7 +44,9 @@ int test(char *URL)
/* First set the URL that is about to receive our POST. */
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HTTPPOST, NULL);
CURL_IGNORE_DEPRECATION(
test_setopt(curl, CURLOPT_HTTPPOST, NULL);
)
test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */

View file

@ -100,8 +100,10 @@ int test(char *URL)
test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
#else
/* 547 style, which means reading the POST data from a callback */
test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
CURL_IGNORE_DEPRECATION(
test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
)
test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
test_setopt(curl, CURLOPT_READDATA, &counter);
/* We CANNOT do the POST fine without setting the size (or choose

View file

@ -200,7 +200,9 @@ int test(char *URL)
test_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
/* Ioctl function */
test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
CURL_IGNORE_DEPRECATION(
test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
)
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);

View file

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_DISABLE_DEPRECATION /* Using and testing the form api */
#include "test.h"
#include "memdebug.h"

View file

@ -95,8 +95,10 @@ int test(char *URL)
easy_setopt(curl, CURLOPT_HEADER, 1L);
/* read the POST data from a callback */
easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
CURL_IGNORE_DEPRECATION(
easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
)
easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
easy_setopt(curl, CURLOPT_READDATA, &counter);
/* We CANNOT do the POST fine without setting the size (or choose

View file

@ -51,8 +51,10 @@ int test(char *URL)
if(!res) {
FILE *moo;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
&content_length);
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
&content_length);
)
moo = fopen(libtest_arg2, "wb");
if(moo) {
fprintf(moo, "CL %.0f\n", content_length);

View file

@ -78,10 +78,10 @@ int test(char *URL)
test_setopt(curl, CURLOPT_POSTFIELDS, data);
/* we want to use our own progress function */
test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
/* pointer to pass to our read function */
CURL_IGNORE_DEPRECATION(
test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
)
/* get verbose debug output please */
test_setopt(curl, CURLOPT_VERBOSE, 1L);

View file

@ -139,7 +139,9 @@ int test(char *URL)
/* we want to use our own progress function */
test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
CURL_IGNORE_DEPRECATION(
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
)
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);

View file

@ -64,7 +64,9 @@ int test(char *URL)
/* we want to use our own progress function */
test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
CURL_IGNORE_DEPRECATION(
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
)
/* get verbose debug output please */
test_setopt(curl, CURLOPT_VERBOSE, 1L);
@ -80,8 +82,10 @@ int test(char *URL)
if(!res) {
FILE *moo;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
CURL_IGNORE_DEPRECATION(
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
&content_length);
)
moo = fopen(libtest_arg2, "wb");
if(moo) {
fprintf(moo, "CL %.0f\n", content_length);

View file

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_DISABLE_DEPRECATION /* Using and testing the form api */
#include "test.h"
#include "memdebug.h"

View file

@ -21,6 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_DISABLE_DEPRECATION /* Using and testing the form api */
#include "test.h"
#include "memdebug.h"

View file

@ -24,6 +24,10 @@
#include <time.h>
#if !defined(LIB670) && !defined(LIB671)
#define CURL_DISABLE_DEPRECATION /* Using and testing the form api */
#endif
#include "test.h"
#include "memdebug.h"

View file

@ -50,7 +50,9 @@ static size_t callback(char *ptr, size_t size, size_t nmemb, void *data)
counter[idx] += (int)(size * nmemb);
/* Get socket being used for this easy handle, otherwise CURL_SOCKET_BAD */
code = curl_easy_getinfo(easy[idx], CURLINFO_LASTSOCKET, &longdata);
CURL_IGNORE_DEPRECATION(
code = curl_easy_getinfo(easy[idx], CURLINFO_LASTSOCKET, &longdata);
)
if(CURLE_OK != code) {
fprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
"with code %d (%s)\n",

View file

@ -31,6 +31,8 @@ my $minlong = "LONG_MIN";
my $maxlong = "LONG_MAX";
# maximum long unsigned value
my $maxulong = "ULONG_MAX";
my $line = "";
my $incomment = 0;
print <<HEADER
/***************************************************************************
@ -56,6 +58,7 @@ print <<HEADER
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_DISABLE_DEPRECATION /* Deprecated options are tested too */
#include "test.h"
#include "memdebug.h"
#include <limits.h>
@ -182,7 +185,54 @@ HEADER
;
while(<STDIN>) {
if($_ =~ /^ CURLOPT\(([^ ]*), ([^ ]*), (\d*)\)/) {
s/^\s*(.*?)\s*$/$1/; # Trim.
# Remove multi-line comment trail.
if($incomment) {
if($_ !~ /.*?\*\/\s*(.*)$/) {
next;
}
$_ = $1;
$incomment = 0;
}
if($line ne "") {
# Unfold line.
$_ = "$line $1";
$line = "";
}
# Remove comments.
while($_ =~ /^(.*?)\/\*.*?\*\/(.*)$/) {
$_ = "$1 $2";
}
s/^\s*(.*?)\s*$/$1/; # Trim again.
if($_ =~ /^(.*)\/\*/) {
$_ = $1;
$incomment = 1;
}
# Ignore preprocessor directives and blank lines.
if($_ =~ /^(?:#|$)/) {
next;
}
# Handle lines that may be continued as if they were folded.
if($_ !~ /[;,{}]$/) {
# Folded line.
$line = $_;
next;
}
if($_ =~ / CURL_DEPRECATED\(/) {
# Drop deprecation info.
if($_ !~ /^(.*?) CURL_DEPRECATED\(.*?"\)(.*)$/) {
# Needs unfolding.
$line = $_;
next;
}
$_ = $1 . $2;
}
if($_ =~ /^CURLOPT(?:DEPRECATED)?\(/ && $_ !~ /\),$/) {
# Multi-line CURLOPTs need unfolding.
$line = $_;
next;
}
if($_ =~ /^CURLOPT(?:DEPRECATED)?\(([^ ]*), ([^ ]*), (\d*)[,)]/) {
my ($name, $type, $val)=($1, $2, $3);
my $w=" ";
my $pref = "${w}res = curl_easy_setopt(curl, $name,";
@ -258,11 +308,11 @@ while(<STDIN>) {
exit 22; # exit to make this noticed!
}
}
elsif($_ =~ /^ CURLINFO_NONE/) {
elsif($_ =~ /^CURLINFO_NONE/) {
$infomode = 1;
}
elsif($infomode &&
($_ =~ /^ CURLINFO_([^ ]*) *= *CURLINFO_([^ ]*)/)) {
($_ =~ /^CURLINFO_([^ ]*) *= *CURLINFO_([^ ]*)/)) {
my ($info, $type)=($1, $2);
my $c = " res = curl_easy_getinfo(curl, CURLINFO_$info,";
my $check = " if(UNEX(res)) {\n geterr(\"$info\", res, __LINE__);\n goto test_cleanup;\n }\n";