diff options
author | Adam Langley <agl@google.com> | 2019-04-18 09:56:13 -0700 |
---|---|---|
committer | CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org> | 2019-04-22 21:49:12 +0000 |
commit | 7540cc2ec0a5c29306ed852483f833c61eddf133 (patch) | |
tree | 493c1837b51458408661edef6492c38203cb881a /ssl/ssl_c_test.c | |
parent | c67076d653f7501136f7b208df4b011a7275e8f5 (diff) | |
download | boringssl-7540cc2ec0a5c29306ed852483f833c61eddf133.zip boringssl-7540cc2ec0a5c29306ed852483f833c61eddf133.tar.gz boringssl-7540cc2ec0a5c29306ed852483f833c61eddf133.tar.bz2 |
Predeclare enums in base.h
Including ssl.h is quite a chunk of code and #defines, so we've tried to
limit its spread internally in the interests of code hygine given that
we have a multi-billion-line repo.
However, header files that mention enums from ssl.h currently need to
include ssl.h. For example, your class may have static class member
functions intended to be callbacks, and they need to be class members
because they'll call other private methods.
C cannot predeclare enums, but C++ can if you explicitly type them.
Sadly C doesn't support explicit types. So option one is to move the
enums into base.h. That works, but the enums properly live in ssl.h and
reading the header file is a lot clearer if you don't have to jump
around to see all the pieces.
So option two (this change) is to explicitly type and predelcare the
enums in base.h for C++ only. The worry now is that C and C++ might
disagree about the type of the enums. However, this has already
happened: at least for |ssl_private_key_result_t|, g++ thinks that it's
an |int| (without any explicit type) and gcc thinks that it's an
|unsigned|. At least they're the same length, I guess?
So, to make sure that this doesn't slip any more, this change also adds
|ssl_test_c.c| which tests that C views the enums as having the same
size as an |int|, at least.
Change-Id: I8248583ec997021f8226d5a798609f6afc96dac4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/35664
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Diffstat (limited to 'ssl/ssl_c_test.c')
-rw-r--r-- | ssl/ssl_c_test.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ssl/ssl_c_test.c b/ssl/ssl_c_test.c new file mode 100644 index 0000000..02f8655 --- /dev/null +++ b/ssl/ssl_c_test.c @@ -0,0 +1,15 @@ +#include <openssl/ssl.h> + +int BORINGSSL_enum_c_type_test(void); + +int BORINGSSL_enum_c_type_test(void) { +#if defined(__cplusplus) +#error "This is testing the behaviour of the C compiler." +#error "It's pointless to build it in C++ mode." +#endif + + // In C++, the enums in ssl.h are explicitly typed as ints to allow them to + // be predeclared. This function confirms that the C compiler believes them + // to be the same size as ints. They may differ in signedness, however. + return sizeof(enum ssl_private_key_result_t) == sizeof(int); +} |