Hash :
03dc6480
Author :
Date :
2019-01-02T09:27:44
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.
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_hash_mbedtld_h__
#define INCLUDE_hash_mbedtld_h__
#include <mbedtls/sha1.h>
struct git_hash_ctx {
mbedtls_sha1_context c;
};
#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__ */