Header file cleanup for C++20 header-units
authorNathan Sidwell <nathan@acm.org>
Mon, 25 Apr 2022 17:50:36 +0000 (10:50 -0700)
committerPauli <pauli@openssl.org>
Mon, 9 May 2022 00:04:58 +0000 (10:04 +1000)
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
<stdio.h> 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 <todd.short@me.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18221)

14 files changed:
include/openssl/asn1.h.in
include/openssl/conf.h.in
include/openssl/dh.h
include/openssl/dsa.h
include/openssl/ec.h
include/openssl/lhash.h.in
include/openssl/pem.h
include/openssl/pkcs12.h.in
include/openssl/pkcs7.h.in
include/openssl/rsa.h
include/openssl/ssl.h.in
include/openssl/ts.h
include/openssl/x509.h.in
include/openssl/x509v3.h.in

index 6d5094a3ff7d3482d0e033425539e966ef18be12..550e0c2c25de06508cb9daa5e6270adc7993a77e 100644 (file)
@@ -22,6 +22,9 @@ use OpenSSL::stackhash qw(generate_stack_macros);
 #  define HEADER_ASN1_H
 # endif
 
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 # include <time.h>
 # include <openssl/e_os2.h>
 # include <openssl/opensslconf.h>
index b0bd579aa48910a213cc007a909eced956bc4f2c..5663287089c9eca1afc7b902caa0cacb51211a1f 100644 (file)
@@ -28,6 +28,9 @@ use OpenSSL::stackhash qw(generate_stack_macros generate_lhash_macros);
 # include <openssl/e_os2.h>
 # include <openssl/types.h>
 # include <openssl/conferr.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef  __cplusplus
 extern "C" {
index b97871eca7faa56cd33c1ff757f18fb758d90eec..2c6219e7c2a6bc1e2ab8b822211efe9325a2287f 100644 (file)
@@ -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 <stdio.h>
+# endif
 # ifndef OPENSSL_NO_DH
 #  include <openssl/e_os2.h>
 #  include <openssl/bio.h>
index 5c0e4cddfa8e572756a66c7184fa950ff07af610..109878e68863e9cd580386ddf19354c46288d699 100644 (file)
 # include <openssl/opensslconf.h>
 # include <openssl/types.h>
 
+# include <stdlib.h>
+
+# ifndef OPENSSL_NO_DSA
+#  include <openssl/e_os2.h>
+#  include <openssl/asn1.h>
+#  include <openssl/bio.h>
+#  include <openssl/crypto.h>
+#  include <openssl/bn.h>
+#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
+#   include <openssl/dh.h>
+#  endif
+#  include <openssl/dsaerr.h>
+#  ifndef OPENSSL_NO_STDIO
+#   include <stdio.h>
+#  endif
+# endif
+
 # ifdef  __cplusplus
 extern "C" {
 # endif
 
-# include <stdlib.h>
-
 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 <openssl/e_os2.h>
-#  include <openssl/asn1.h>
-#  include <openssl/bio.h>
-#  include <openssl/crypto.h>
-#  include <openssl/bn.h>
-#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
-#   include <openssl/dh.h>
-#  endif
-#  include <openssl/dsaerr.h>
-
 #  ifndef OPENSSL_DSA_MAX_MODULUS_BITS
 #   define OPENSSL_DSA_MAX_MODULUS_BITS   10000
 #  endif
index 44d71932db631edb69f963e7d88c7d11ae262191..be9fb2f08923e645bd78df94604b3ad389ac40ae 100644 (file)
@@ -88,6 +88,9 @@ typedef enum {
 
 const char *OSSL_EC_curve_nid2name(int nid);
 
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 # ifndef OPENSSL_NO_EC
 #  include <openssl/asn1.h>
 #  include <openssl/symhacks.h>
index febefa3c4ac6d84b08a70adc50072a1f36aa83d0..e9bb2590a07c2c5261c8ed5fb92b3b7a007cf5e4 100644 (file)
@@ -26,6 +26,9 @@ use OpenSSL::stackhash qw(generate_lhash_macros);
 
 # include <openssl/e_os2.h>
 # include <openssl/bio.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef  __cplusplus
 extern "C" {
index 80940dfa969b262ad63d3b2546619c19c6d092c2..ed50f081fa21ee919e60c873603ac1b48b2c80d0 100644 (file)
@@ -22,6 +22,9 @@
 # include <openssl/evp.h>
 # include <openssl/x509.h>
 # include <openssl/pemerr.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef  __cplusplus
 extern "C" {
index c98eebfb39887538c7d93a7bac2d3e3300bd6221..2f95dafd5efd0440ea18f17a5d3ff416ad1a4ed3 100644 (file)
@@ -26,6 +26,9 @@ use OpenSSL::stackhash qw(generate_stack_macros);
 # include <openssl/core.h>
 # include <openssl/x509.h>
 # include <openssl/pkcs12err.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef __cplusplus
 extern "C" {
index f5c55a3fbe57610f4ef301bcd989d3dc433c126e..a6d1752491d3e1a461ed3fd78a1a948c61e581c8 100644 (file)
@@ -29,6 +29,9 @@ use OpenSSL::stackhash qw(generate_stack_macros);
 # include <openssl/symhacks.h>
 # include <openssl/types.h>
 # include <openssl/pkcs7err.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef  __cplusplus
 extern "C" {
index a55c9727c6b9b87b27f79ec16ef008d0c6f884f3..fa300d02612707405767992c0c2cbceade4c97d1 100644 (file)
@@ -27,6 +27,9 @@
 # endif
 # include <openssl/rsaerr.h>
 # include <openssl/safestack.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 # ifdef  __cplusplus
 extern "C" {
index 84a5760ef78960b28d1c3f62ca380a0ec50e2dfa..0c062ded3edf082d83011b60ba14b83d06a8c19d 100644 (file)
@@ -43,6 +43,9 @@ use OpenSSL::stackhash qw(generate_stack_macros generate_const_stack_macros);
 # include <openssl/ct.h>
 # include <openssl/sslerr.h>
 # include <openssl/prov_ssl.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef  __cplusplus
 extern "C" {
index 5136e4e974af431b5a34c95d86fd59b3d57dfed7..b09b646dffe1f3e453ee54779690c8243803e708 100644 (file)
 # include <openssl/dh.h>
 # include <openssl/tserr.h>
 # include <openssl/ess.h>
+# include <openssl/x509.h>
+# include <openssl/x509v3.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 # ifdef  __cplusplus
 extern "C" {
 # endif
 
-# include <openssl/x509.h>
-# include <openssl/x509v3.h>
-
 typedef struct TS_msg_imprint_st TS_MSG_IMPRINT;
 typedef struct TS_req_st TS_REQ;
 typedef struct TS_accuracy_st TS_ACCURACY;
index 56b8829ca12043d922b13096ae34d637734d77d3..0a94303ed94725d61108fb8172eb8f79c205a74e 100644 (file)
@@ -41,6 +41,9 @@ use OpenSSL::stackhash qw(generate_stack_macros);
 
 # include <openssl/sha.h>
 # include <openssl/x509err.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef  __cplusplus
 extern "C" {
index d00a66a343010afdb3b583c27fe697b80874e6ea..7d7e4718b6db2bcbcfe523ed068b87b43755d304 100644 (file)
@@ -26,6 +26,9 @@ use OpenSSL::stackhash qw(generate_stack_macros);
 # include <openssl/x509.h>
 # include <openssl/conf.h>
 # include <openssl/x509v3err.h>
+# ifndef OPENSSL_NO_STDIO
+#  include <stdio.h>
+# endif
 
 #ifdef __cplusplus
 extern "C" {