summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-03-07 00:02:55 +0100
committerVicent Martí <tanoku@gmail.com>2012-03-07 00:11:43 +0100
commitcb8a79617b15e347f26d21cedde0f2b8670c1876 (patch)
tree459706192f41bbf15496f0c9bfe2e21b16a7e70b /src/util.h
parent9d160ba85539bbc593369f597a07d42c2770dff4 (diff)
downloadlibgit2-cb8a79617b15e347f26d21cedde0f2b8670c1876.tar.gz
error-handling: Repository
This also includes droping `git_buf_lasterror` because it makes no sense in the new system. Note that in most of the places were it has been dropped, the code needs cleanup. I.e. GIT_ENOMEM is going away, so instead it should return a generic `-1` and obviously not throw anything.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/util.h b/src/util.h
index f77c91dfd..803c63d73 100644
--- a/src/util.h
+++ b/src/util.h
@@ -7,6 +7,8 @@
#ifndef INCLUDE_util_h__
#define INCLUDE_util_h__
+#include "git2/errors.h"
+
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
@@ -23,7 +25,7 @@ GIT_INLINE(void *) git__malloc(size_t len)
{
void *ptr = malloc(len);
if (!ptr)
- git__throw(GIT_ENOMEM, "Out of memory. Failed to allocate %d bytes.", (int)len);
+ giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to allocate %d bytes.", (int)len);
return ptr;
}
@@ -31,7 +33,7 @@ GIT_INLINE(void *) git__calloc(size_t nelem, size_t elsize)
{
void *ptr = calloc(nelem, elsize);
if (!ptr)
- git__throw(GIT_ENOMEM, "Out of memory. Failed to allocate %d bytes.", (int)elsize);
+ giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to allocate %d bytes.", (int)nelem*elsize);
return ptr;
}
@@ -39,7 +41,7 @@ GIT_INLINE(char *) git__strdup(const char *str)
{
char *ptr = strdup(str);
if (!ptr)
- git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string");
+ giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to duplicate string");
return ptr;
}
@@ -54,7 +56,7 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
ptr = (char*)malloc(length + 1);
if (!ptr) {
- git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string");
+ giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to duplicate string");
return NULL;
}
@@ -68,7 +70,7 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
{
void *new_ptr = realloc(ptr, size);
if (!new_ptr)
- git__throw(GIT_ENOMEM, "Out of memory. Failed to allocate %d bytes.", (int)size);
+ giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to allocate %d bytes.", (int)size);
return new_ptr;
}