Commit 03dc6480 by Patrick Steinhardt

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.
parent 0ddc6094
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......@@ -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__ */
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment