From: Nathan Sidwell Date: Mon, 25 Apr 2022 17:50:36 +0000 (-0700) Subject: Header file cleanup for C++20 header-units X-Git-Tag: openssl-3.2.0-alpha1~2686 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eab9dbbdd1f102dc1a26549a77fcc5c167385cd5;p=thirdparty%2Fopenssl.git Header file cleanup for C++20 header-units C++20 adds 'header units' as a stepping-stone to modules. Header units are regular header-files that have a 'self-contained' property -- they do not require previously-included headers to provide typedefs and what not. This addresses 2 problems discovered when using clang modules (as a proxy for C++20 header-units). a) Some headers that pay attention to OPENSSL_NO_STDIO to determine whether to declare certain FILE*-taking functions do not #include themselves, relying on their includer already having done that. That breaks the above mentioned encapuslation requirement. Fixed by conditionally including stdio.h in those headers. I chose to always include stdio.h in such headers, even when they included another such header that transitively included stdio. That way they do not rely on an artifact of that intermediate header's behaviour. b) Some headers have #includes inside 'extern "C" { ... }' regions. That has a bad code-smell, but GCC and clang have extensions to permit it with implementation-defined effects. Clang needs annotation on the included files to know that they themselves are entirely inside a similar region. GCC behavesq as-if there's an extern "C++" region wrapping the included header (which must therefore wrap its contents in extern "C", if that is what it wants. In effect the includer's extern "C" region is just misleading. I didn't audit all the headers for this, only those I noticed when addressing #a. \#a is necessary to build the headers as a set of clang-modules. #b is not necessary, but as I mentioned, avoids potentially implementation-defined behaviour. Reviewed-by: Todd Short Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/18221) --- diff --git a/include/openssl/asn1.h.in b/include/openssl/asn1.h.in index 6d5094a3ff7..550e0c2c25d 100644 --- a/include/openssl/asn1.h.in +++ b/include/openssl/asn1.h.in @@ -22,6 +22,9 @@ use OpenSSL::stackhash qw(generate_stack_macros); # define HEADER_ASN1_H # endif +# ifndef OPENSSL_NO_STDIO +# include +# endif # include # include # include diff --git a/include/openssl/conf.h.in b/include/openssl/conf.h.in index b0bd579aa48..5663287089c 100644 --- a/include/openssl/conf.h.in +++ b/include/openssl/conf.h.in @@ -28,6 +28,9 @@ use OpenSSL::stackhash qw(generate_stack_macros generate_lhash_macros); # include # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/dh.h b/include/openssl/dh.h index b97871eca7f..2c6219e7c2a 100644 --- a/include/openssl/dh.h +++ b/include/openssl/dh.h @@ -79,6 +79,9 @@ int EVP_PKEY_CTX_get0_dh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm); # define EVP_PKEY_DH_KDF_NONE 1 # define EVP_PKEY_DH_KDF_X9_42 2 +# ifndef OPENSSL_NO_STDIO +# include +# endif # ifndef OPENSSL_NO_DH # include # include diff --git a/include/openssl/dsa.h b/include/openssl/dsa.h index 5c0e4cddfa8..109878e6886 100644 --- a/include/openssl/dsa.h +++ b/include/openssl/dsa.h @@ -19,12 +19,27 @@ # include # include +# include + +# ifndef OPENSSL_NO_DSA +# include +# include +# include +# include +# include +# ifndef OPENSSL_NO_DEPRECATED_1_1_0 +# include +# endif +# include +# ifndef OPENSSL_NO_STDIO +# include +# endif +# endif + # ifdef __cplusplus extern "C" { # endif -# include - int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits); int EVP_PKEY_CTX_set_dsa_paramgen_q_bits(EVP_PKEY_CTX *ctx, int qbits); int EVP_PKEY_CTX_set_dsa_paramgen_md_props(EVP_PKEY_CTX *ctx, @@ -42,16 +57,6 @@ int EVP_PKEY_CTX_set_dsa_paramgen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); # define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3) # ifndef OPENSSL_NO_DSA -# include -# include -# include -# include -# include -# ifndef OPENSSL_NO_DEPRECATED_1_1_0 -# include -# endif -# include - # ifndef OPENSSL_DSA_MAX_MODULUS_BITS # define OPENSSL_DSA_MAX_MODULUS_BITS 10000 # endif diff --git a/include/openssl/ec.h b/include/openssl/ec.h index 44d71932db6..be9fb2f0892 100644 --- a/include/openssl/ec.h +++ b/include/openssl/ec.h @@ -88,6 +88,9 @@ typedef enum { const char *OSSL_EC_curve_nid2name(int nid); +# ifndef OPENSSL_NO_STDIO +# include +# endif # ifndef OPENSSL_NO_EC # include # include diff --git a/include/openssl/lhash.h.in b/include/openssl/lhash.h.in index febefa3c4ac..e9bb2590a07 100644 --- a/include/openssl/lhash.h.in +++ b/include/openssl/lhash.h.in @@ -26,6 +26,9 @@ use OpenSSL::stackhash qw(generate_lhash_macros); # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/pem.h b/include/openssl/pem.h index 80940dfa969..ed50f081fa2 100644 --- a/include/openssl/pem.h +++ b/include/openssl/pem.h @@ -22,6 +22,9 @@ # include # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/pkcs12.h.in b/include/openssl/pkcs12.h.in index c98eebfb398..2f95dafd5ef 100644 --- a/include/openssl/pkcs12.h.in +++ b/include/openssl/pkcs12.h.in @@ -26,6 +26,9 @@ use OpenSSL::stackhash qw(generate_stack_macros); # include # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/pkcs7.h.in b/include/openssl/pkcs7.h.in index f5c55a3fbe5..a6d1752491d 100644 --- a/include/openssl/pkcs7.h.in +++ b/include/openssl/pkcs7.h.in @@ -29,6 +29,9 @@ use OpenSSL::stackhash qw(generate_stack_macros); # include # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/rsa.h b/include/openssl/rsa.h index a55c9727c6b..fa300d02612 100644 --- a/include/openssl/rsa.h +++ b/include/openssl/rsa.h @@ -27,6 +27,9 @@ # endif # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif # ifdef __cplusplus extern "C" { diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in index 84a5760ef78..0c062ded3ed 100644 --- a/include/openssl/ssl.h.in +++ b/include/openssl/ssl.h.in @@ -43,6 +43,9 @@ use OpenSSL::stackhash qw(generate_stack_macros generate_const_stack_macros); # include # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/ts.h b/include/openssl/ts.h index 5136e4e974a..b09b646dffe 100644 --- a/include/openssl/ts.h +++ b/include/openssl/ts.h @@ -30,13 +30,15 @@ # include # include # include +# include +# include +# ifndef OPENSSL_NO_STDIO +# include +# endif # ifdef __cplusplus extern "C" { # endif -# include -# include - typedef struct TS_msg_imprint_st TS_MSG_IMPRINT; typedef struct TS_req_st TS_REQ; typedef struct TS_accuracy_st TS_ACCURACY; diff --git a/include/openssl/x509.h.in b/include/openssl/x509.h.in index 56b8829ca12..0a94303ed94 100644 --- a/include/openssl/x509.h.in +++ b/include/openssl/x509.h.in @@ -41,6 +41,9 @@ use OpenSSL::stackhash qw(generate_stack_macros); # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" { diff --git a/include/openssl/x509v3.h.in b/include/openssl/x509v3.h.in index d00a66a3430..7d7e4718b6d 100644 --- a/include/openssl/x509v3.h.in +++ b/include/openssl/x509v3.h.in @@ -26,6 +26,9 @@ use OpenSSL::stackhash qw(generate_stack_macros); # include # include # include +# ifndef OPENSSL_NO_STDIO +# include +# endif #ifdef __cplusplus extern "C" {