summaryrefslogtreecommitdiff
path: root/src/hash
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2012-11-12 19:22:49 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2012-11-13 10:23:05 -0600
commit603bee07918b50051d7bb45722932fc409b38a67 (patch)
tree99951bc2c5470bc429d42eb9eb6151b2de6b08be /src/hash
parentd6fb09240913c9756de5f4a2462062008ebac252 (diff)
downloadlibgit2-603bee07918b50051d7bb45722932fc409b38a67.tar.gz
Remove git_hash_ctx_new - callers now _ctx_init()
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/hash_generic.c17
-rw-r--r--src/hash/hash_generic.h3
-rw-r--r--src/hash/hash_openssl.h19
-rw-r--r--src/hash/hash_ppc.c17
-rw-r--r--src/hash/hash_ppc.h3
-rw-r--r--src/hash/hash_win32.c57
6 files changed, 30 insertions, 86 deletions
diff --git a/src/hash/hash_generic.c b/src/hash/hash_generic.c
index cab5469d7..30d7a5d1e 100644
--- a/src/hash/hash_generic.c
+++ b/src/hash/hash_generic.c
@@ -221,18 +221,6 @@ static void hash__block(git_hash_ctx *ctx, const unsigned int *data)
ctx->H[4] += E;
}
-git_hash_ctx *git_hash_ctx_new(void)
-{
- git_hash_ctx *ctx = git__malloc(sizeof(git_hash_ctx));
-
- if (!ctx)
- return NULL;
-
- git_hash_init(ctx);
-
- return ctx;
-}
-
int git_hash_init(git_hash_ctx *ctx)
{
ctx->size = 0;
@@ -298,8 +286,3 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
return 0;
}
-void git_hash_ctx_free(git_hash_ctx *ctx)
-{
- if (ctx)
- git__free(ctx);
-}
diff --git a/src/hash/hash_generic.h b/src/hash/hash_generic.h
index 400c7edcc..c5891c164 100644
--- a/src/hash/hash_generic.h
+++ b/src/hash/hash_generic.h
@@ -16,4 +16,7 @@ struct git_hash_ctx {
unsigned int W[16];
};
+#define git_hash_ctx_init(ctx) git_hash_init(ctx)
+#define git_hash_ctx_cleanup(ctx)
+
#endif /* INCLUDE_hash_generic_h__ */
diff --git a/src/hash/hash_openssl.h b/src/hash/hash_openssl.h
index b416db50c..0d37f135b 100644
--- a/src/hash/hash_openssl.h
+++ b/src/hash/hash_openssl.h
@@ -16,23 +16,8 @@ struct git_hash_ctx {
SHA_CTX c;
};
-GIT_INLINE(git_hash_ctx *) git_hash_ctx_new(void)
-{
- git_hash_ctx *ctx = git__malloc(sizeof(git_hash_ctx));
-
- if (!ctx)
- return NULL;
-
- SHA1_Init(&ctx->c);
-
- return ctx;
-}
-
-GIT_INLINE(void) git_hash_ctx_free(git_hash_ctx *ctx)
-{
- if (ctx)
- git__free(ctx);
-}
+#define git_hash_ctx_init(ctx) git_hash_init(ctx)
+#define git_hash_ctx_cleanup(ctx)
GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
{
diff --git a/src/hash/hash_ppc.c b/src/hash/hash_ppc.c
index 95ad3b1a1..de89e9f5e 100644
--- a/src/hash/hash_ppc.c
+++ b/src/hash/hash_ppc.c
@@ -14,18 +14,6 @@
extern void hash_ppc_core(uint32_t *hash, const unsigned char *p,
unsigned int nblocks);
-git_hash_ctx *git_hash_ctx_new(void)
-{
- git_hash_ctx *ctx = git__malloc(sizeof(git_hash_ctx));
-
- if (!ctx)
- return NULL;
-
- git_hash_init(ctx);
-
- return ctx;
-}
-
int git_hash_init(git_hash_ctx *c)
{
c->hash[0] = 0x67452301;
@@ -84,8 +72,3 @@ int git_hash_final(git_oid *oid, git_hash_ctx *c)
return 0;
}
-void git_hash_ctx_free(git_hash_ctx *ctx)
-{
- if (ctx)
- git__free(ctx);
-}
diff --git a/src/hash/hash_ppc.h b/src/hash/hash_ppc.h
index 200d19310..df78d9135 100644
--- a/src/hash/hash_ppc.h
+++ b/src/hash/hash_ppc.h
@@ -20,4 +20,7 @@ struct git_hash_ctx {
} buf;
};
+#define git_hash_ctx_init(ctx) git_hash_init(ctx)
+#define git_hash_ctx_cleanup(ctx)
+
#endif /* INCLUDE_hash_generic_h__ */
diff --git a/src/hash/hash_win32.c b/src/hash/hash_win32.c
index 26b3554b5..1fac45273 100644
--- a/src/hash/hash_win32.c
+++ b/src/hash/hash_win32.c
@@ -100,22 +100,12 @@ static int hash_win32_prov_init(git_hash_prov *prov)
/* CryptoAPI: available in Windows XP and newer */
-GIT_INLINE(git_hash_ctx *) hash_ctx_cryptoapi_new(git_hash_prov *prov)
+GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx, git_hash_prov *prov)
{
- git_hash_ctx *ctx;
-
- if ((ctx = git__calloc(1, sizeof(git_hash_ctx))) == NULL)
- return NULL;
-
ctx->type = CRYPTOAPI;
ctx->prov = prov;
- if (git_hash_init(ctx) < 0) {
- git__free(ctx);
- return NULL;
- }
-
- return ctx;
+ return git_hash_init(ctx);
}
GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
@@ -158,7 +148,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
return error;
}
-GIT_INLINE(void) hash_cryptoapi_free(git_hash_ctx *ctx)
+GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx)
{
if (ctx->ctx.cryptoapi.valid)
CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
@@ -166,24 +156,20 @@ GIT_INLINE(void) hash_cryptoapi_free(git_hash_ctx *ctx)
/* CNG: Available in Windows Server 2008 and newer */
-GIT_INLINE(git_hash_ctx *) hash_ctx_cng_new(git_hash_prov *prov)
+GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx, git_hash_prov *prov)
{
- git_hash_ctx *ctx;
-
- if ((ctx = git__calloc(1, sizeof(git_hash_ctx))) == NULL ||
- (ctx->ctx.cng.hash_object = git__malloc(prov->prov.cng.hash_object_size)) == NULL)
- return NULL;
+ if ((ctx->ctx.cng.hash_object = git__malloc(prov->prov.cng.hash_object_size)) == NULL)
+ return -1;
if (prov->prov.cng.create_hash(prov->prov.cng.handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, prov->prov.cng.hash_object_size, NULL, 0, 0) < 0) {
git__free(ctx->ctx.cng.hash_object);
- git__free(ctx);
- return NULL;
+ return -1;
}
ctx->type = CNG;
ctx->prov = prov;
- return ctx;
+ return 0;
}
GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
@@ -220,7 +206,7 @@ GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
return 0;
}
-GIT_INLINE(void) hash_cng_free(git_hash_ctx *ctx)
+GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
{
ctx->prov->prov.cng.destroy_hash(ctx->ctx.cng.hash_handle);
git__free(ctx->ctx.cng.hash_object);
@@ -228,20 +214,24 @@ GIT_INLINE(void) hash_cng_free(git_hash_ctx *ctx)
/* Indirection between CryptoAPI and CNG */
-git_hash_ctx *git_hash_ctx_new()
+int git_hash_ctx_init(git_hash_ctx *ctx)
{
git_global_st *global_state;
git_hash_prov *hash_prov;
+
+ assert(ctx);
+
+ memset(ctx, 0x0, sizeof(git_hash_ctx));
if ((global_state = git__global_state()) == NULL)
- return NULL;
+ return -1;
hash_prov = &global_state->hash_prov;
if (hash_prov->type == INVALID && hash_win32_prov_init(hash_prov) < 0)
- return NULL;
+ return -1;
- return (hash_prov->type == CNG) ? hash_ctx_cng_new(hash_prov) : hash_ctx_cryptoapi_new(hash_prov);
+ return (hash_prov->type == CNG) ? hash_ctx_cng_init(ctx, hash_prov) : hash_ctx_cryptoapi_init(ctx, hash_prov);
}
int git_hash_init(git_hash_ctx *ctx)
@@ -262,15 +252,12 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx);
}
-void git_hash_ctx_free(git_hash_ctx *ctx)
+void git_hash_ctx_cleanup(git_hash_ctx *ctx)
{
- if (ctx == NULL)
- return;
+ assert(ctx);
if (ctx->type == CNG)
- hash_cng_free(ctx);
- else
- hash_cryptoapi_free(ctx);
-
- git__free(ctx);
+ hash_ctx_cng_cleanup(ctx);
+ else if(ctx->type == CRYPTOAPI)
+ hash_ctx_cryptoapi_cleanup(ctx);
}