diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-01-02 09:27:44 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-01-02 09:27:44 +0100 |
commit | 03dc6480b41bdfa33911784d772d612f8e5c023b (patch) | |
tree | 62c72fd063fea277a4450841c10ace2ff3cd49f8 /src | |
parent | 0ddc60944ca4727246414e8bcf3170fe8286f854 (diff) | |
download | libgit2-03dc6480b41bdfa33911784d772d612f8e5c023b.tar.gz |
hash: convert `global_init` macros to real function
The `git_hash_global_init` function is simply defined as a macro to zero
for most of the different hash implementations. This makes it impossible
to treat it like a function pointer, which is required for a later
commit where we want to improve the way global initialization works.
Fix the issue by converting all no-op macros to an inline function
returning zero.
There's a small gotcha here, though: as most hash implementations only
have a header file, but not a corresponding implementation file, we
cannot declare the function as non-static. But declaring it as `static
inline` fails, too, as there is a previous declaration as non-static. So
we have to move the function declaration after the include that brings
in the function definition, as it is allowed to have a non-static
declaration after a static definition, but not the other way round.
Diffstat (limited to 'src')
-rw-r--r-- | src/hash.h | 3 | ||||
-rw-r--r-- | src/hash/hash_collisiondetect.h | 6 | ||||
-rw-r--r-- | src/hash/hash_common_crypto.h | 6 | ||||
-rw-r--r-- | src/hash/hash_generic.h | 6 | ||||
-rw-r--r-- | src/hash/hash_mbedtls.h | 6 | ||||
-rw-r--r-- | src/hash/hash_openssl.h | 6 |
6 files changed, 27 insertions, 6 deletions
diff --git a/src/hash.h b/src/hash.h index 93765adf3..0502e352e 100644 --- a/src/hash.h +++ b/src/hash.h @@ -14,7 +14,6 @@ typedef struct git_hash_prov git_hash_prov; typedef struct git_hash_ctx git_hash_ctx; -int git_hash_global_init(void); int git_hash_ctx_init(git_hash_ctx *ctx); void git_hash_ctx_cleanup(git_hash_ctx *ctx); @@ -32,6 +31,8 @@ void git_hash_ctx_cleanup(git_hash_ctx *ctx); # include "hash/hash_generic.h" #endif +int git_hash_global_init(void); + typedef struct { void *data; size_t len; diff --git a/src/hash/hash_collisiondetect.h b/src/hash/hash_collisiondetect.h index 4c5e3c302..4e4c7da55 100644 --- a/src/hash/hash_collisiondetect.h +++ b/src/hash/hash_collisiondetect.h @@ -15,10 +15,14 @@ struct git_hash_ctx { SHA1_CTX c; }; -#define git_hash_global_init() 0 #define git_hash_ctx_init(ctx) git_hash_init(ctx) #define git_hash_ctx_cleanup(ctx) +GIT_INLINE(int) git_hash_global_init(void) +{ + return 0; +} + GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) { assert(ctx); diff --git a/src/hash/hash_common_crypto.h b/src/hash/hash_common_crypto.h index 5c3887dba..ce352a633 100644 --- a/src/hash/hash_common_crypto.h +++ b/src/hash/hash_common_crypto.h @@ -18,10 +18,14 @@ struct git_hash_ctx { #define CC_LONG_MAX ((CC_LONG)-1) -#define git_hash_global_init() 0 #define git_hash_ctx_init(ctx) git_hash_init(ctx) #define git_hash_ctx_cleanup(ctx) +GIT_INLINE(int) git_hash_global_init(void) +{ + return 0; +} + GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) { assert(ctx); diff --git a/src/hash/hash_generic.h b/src/hash/hash_generic.h index 21a042807..fb0009ccf 100644 --- a/src/hash/hash_generic.h +++ b/src/hash/hash_generic.h @@ -18,8 +18,12 @@ struct git_hash_ctx { unsigned int W[16]; }; -#define git_hash_global_init() 0 #define git_hash_ctx_init(ctx) git_hash_init(ctx) #define git_hash_ctx_cleanup(ctx) +GIT_INLINE(int) git_hash_global_init(void) +{ + return 0; +} + #endif diff --git a/src/hash/hash_mbedtls.h b/src/hash/hash_mbedtls.h index 24196c5bf..7f3decd7d 100644 --- a/src/hash/hash_mbedtls.h +++ b/src/hash/hash_mbedtls.h @@ -14,7 +14,11 @@ struct git_hash_ctx { mbedtls_sha1_context c; }; -#define git_hash_global_init() 0 #define git_hash_ctx_init(ctx) git_hash_init(ctx) +GIT_INLINE(int) git_hash_global_init(void) +{ + return 0; +} + #endif /* INCLUDE_hash_mbedtld_h__ */ diff --git a/src/hash/hash_openssl.h b/src/hash/hash_openssl.h index eb2dcb02f..9a32cba2a 100644 --- a/src/hash/hash_openssl.h +++ b/src/hash/hash_openssl.h @@ -16,10 +16,14 @@ struct git_hash_ctx { SHA_CTX c; }; -#define git_hash_global_init() 0 #define git_hash_ctx_init(ctx) git_hash_init(ctx) #define git_hash_ctx_cleanup(ctx) +GIT_INLINE(int) git_hash_global_init(void) +{ + return 0; +} + GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) { assert(ctx); |