peer review: refactor HAVE_ANONYMOUS_INLINE_AGGREGATES and HAVE_EMPTY_AGGREGATES to conform to wolfssl convention -- defined() for true, !defined() for false -- while retaining ability for user override-off by passing in explicit 0 definition.

This commit is contained in:
Daniel Pouzzner
2024-12-06 12:53:03 -06:00
parent 447d5ea6ee
commit 0381a47d7e
2 changed files with 30 additions and 18 deletions

View File

@@ -104,12 +104,12 @@ enum wc_CryptoCbCmdType {
/* Crypto Information Structure for callbacks */ /* Crypto Information Structure for callbacks */
typedef struct wc_CryptoInfo { typedef struct wc_CryptoInfo {
int algo_type; /* enum wc_AlgoType */ int algo_type; /* enum wc_AlgoType */
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif #endif
struct { struct {
int type; /* enum wc_PkType */ int type; /* enum wc_PkType */
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif #endif
#ifndef NO_RSA #ifndef NO_RSA
@@ -279,7 +279,7 @@ typedef struct wc_CryptoInfo {
int type; /* enum wc_PqcSignatureType */ int type; /* enum wc_PqcSignatureType */
} pqc_sig_check; } pqc_sig_check;
#endif #endif
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif #endif
} pk; } pk;
@@ -287,7 +287,7 @@ typedef struct wc_CryptoInfo {
struct { struct {
int type; /* enum wc_CipherType */ int type; /* enum wc_CipherType */
int enc; int enc;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif #endif
#ifdef HAVE_AESGCM #ifdef HAVE_AESGCM
@@ -375,7 +375,7 @@ typedef struct wc_CryptoInfo {
} des3; } des3;
#endif #endif
void* ctx; void* ctx;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif #endif
} cipher; } cipher;
@@ -387,7 +387,7 @@ typedef struct wc_CryptoInfo {
const byte* in; const byte* in;
word32 inSz; word32 inSz;
byte* digest; byte* digest;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif #endif
#ifndef NO_SHA #ifndef NO_SHA
@@ -409,7 +409,7 @@ typedef struct wc_CryptoInfo {
wc_Sha3* sha3; wc_Sha3* sha3;
#endif #endif
void* ctx; void* ctx;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif #endif
} hash; } hash;
@@ -454,7 +454,7 @@ typedef struct wc_CryptoInfo {
void *ctx; void *ctx;
} cmd; } cmd;
#endif #endif
#if HAVE_ANONYMOUS_INLINE_AGGREGATES #ifdef HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif #endif
} wc_CryptoInfo; } wc_CryptoInfo;

View File

@@ -123,36 +123,49 @@ decouple library dependencies with standard string, memory and so on.
#ifndef HAVE_ANONYMOUS_INLINE_AGGREGATES #ifndef HAVE_ANONYMOUS_INLINE_AGGREGATES
/* if a version is available, pivot on the version, otherwise guess it's /* if a version is available, pivot on the version, otherwise guess it's
* allowed, subject to override. * disallowed, subject to override.
*/ */
#if !defined(WOLF_C89) && (!defined(__STDC__) \ #if !defined(WOLF_C89) && (!defined(__STDC__) \
|| (!defined(__STDC_VERSION__) && !defined(__cplusplus)) \ || (!defined(__STDC_VERSION__) && !defined(__cplusplus)) \
|| (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201101L)) \ || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201101L)) \
|| (defined(__cplusplus) && (__cplusplus >= 201103L))) || (defined(__cplusplus) && (__cplusplus >= 201103L)))
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 1 #define HAVE_ANONYMOUS_INLINE_AGGREGATES 1
#else
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 0
#endif #endif
#elif ~(~HAVE_ANONYMOUS_INLINE_AGGREGATES + 1) == 1
/* forced on with empty value -- remap to 1 */
#undef HAVE_ANONYMOUS_INLINE_AGGREGATES
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 1
#elif HAVE_ANONYMOUS_INLINE_AGGREGATES
/* forced on with explicit nonzero value -- leave as-is. */
#else
/* forced off with explicit zero value -- remap to undef. */
#undef HAVE_ANONYMOUS_INLINE_AGGREGATES
#endif #endif
#ifndef HAVE_EMPTY_AGGREGATES #ifndef HAVE_EMPTY_AGGREGATES
/* The C standards don't define empty aggregates, but gcc and clang do. /* The C standards don't define empty aggregates, but gcc and clang do.
* We need to accommodate them for one of the same reasons C++ does -- * We need to accommodate them for one of the same reasons C++ does --
* templates that conditionally result in empty aggregates, e.g. in * conditionally empty aggregates, e.g. in hash.h.
* hash.h.
*/ */
#if !defined(WOLF_C89) && defined(__GNUC__) && \ #if !defined(WOLF_C89) && defined(__GNUC__) && \
!defined(__STRICT_ANSI__) && \ !defined(__STRICT_ANSI__) && \
HAVE_ANONYMOUS_INLINE_AGGREGATES + 0 == 1 defined(HAVE_ANONYMOUS_INLINE_AGGREGATES)
#define HAVE_EMPTY_AGGREGATES 1 #define HAVE_EMPTY_AGGREGATES 1
#else
#define HAVE_EMPTY_AGGREGATES 0
#endif #endif
#elif ~(~HAVE_EMPTY_AGGREGATES + 1) == 1
/* forced on with empty value -- remap to 1 */
#undef HAVE_EMPTY_AGGREGATES
#define HAVE_EMPTY_AGGREGATES 1
#elif HAVE_EMPTY_AGGREGATES
/* forced on with explicit nonzero value -- leave as-is. */
#else
/* forced off with explicit zero value -- remap to undef. */
#undef HAVE_EMPTY_AGGREGATES
#endif #endif
#define _WOLF_AGG_DUMMY_MEMBER_HELPER2(a, b, c) a ## b ## c #define _WOLF_AGG_DUMMY_MEMBER_HELPER2(a, b, c) a ## b ## c
#define _WOLF_AGG_DUMMY_MEMBER_HELPER(a, b, c) _WOLF_AGG_DUMMY_MEMBER_HELPER2(a, b, c) #define _WOLF_AGG_DUMMY_MEMBER_HELPER(a, b, c) _WOLF_AGG_DUMMY_MEMBER_HELPER2(a, b, c)
#if HAVE_EMPTY_AGGREGATES + 0 == 1 #ifdef HAVE_EMPTY_AGGREGATES
/* swallow the semicolon with a zero-sized array (language extension /* swallow the semicolon with a zero-sized array (language extension
* specific to gcc/clang). * specific to gcc/clang).
*/ */
@@ -185,7 +198,6 @@ decouple library dependencies with standard string, memory and so on.
* without disrupting clean flow/syntax when some enum values are * without disrupting clean flow/syntax when some enum values are
* preprocessor-gated. * preprocessor-gated.
*/ */
#define WC_VALUE_OF(x) x
#if defined(WOLF_C89) || defined(WOLF_NO_TRAILING_ENUM_COMMAS) #if defined(WOLF_C89) || defined(WOLF_NO_TRAILING_ENUM_COMMAS)
#define _WOLF_ENUM_DUMMY_LAST_ELEMENT_HELPER2(a, b, c, d, e) a ## b ## c ## d ## e #define _WOLF_ENUM_DUMMY_LAST_ELEMENT_HELPER2(a, b, c, d, e) a ## b ## c ## d ## e
#define _WOLF_ENUM_DUMMY_LAST_ELEMENT_HELPER(a, b, c, d, e) _WOLF_ENUM_DUMMY_LAST_ELEMENT_HELPER2(a, b, c, d, e) #define _WOLF_ENUM_DUMMY_LAST_ELEMENT_HELPER(a, b, c, d, e) _WOLF_ENUM_DUMMY_LAST_ELEMENT_HELPER2(a, b, c, d, e)