summaryrefslogtreecommitdiff
path: root/src/errors.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-02-17 00:13:34 +0100
committerVicent Martí <tanoku@gmail.com>2012-03-06 00:43:10 +0100
commit1a48112342932e9fcd45a1ff5935f1c9c53b83d1 (patch)
treefbb18cfe64e65025c6e1790972d1a106eea4cc54 /src/errors.c
parent45d387ac78bcf3167d69b736d0b322717bc492d4 (diff)
downloadlibgit2-1a48112342932e9fcd45a1ff5935f1c9c53b83d1.tar.gz
error-handling: References
Yes, this is error handling solely for `refs.c`, but some of the abstractions leak all ofer the code base.
Diffstat (limited to 'src/errors.c')
-rw-r--r--src/errors.c54
1 files changed, 17 insertions, 37 deletions
diff --git a/src/errors.c b/src/errors.c
index 0105c2538..548e44a32 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -108,20 +108,24 @@ void git_clearerror(void)
* New error handling
********************************************/
-void giterr_set(git_error **error_out, int error_class, const char *string, ...)
+static git_error g_git_oom_error = {
+ "Out of memory",
+ GITERR_NOMEMORY
+};
+
+void giterr_set_oom(void)
+{
+ GIT_GLOBAL->last_error = &g_git_oom_error;
+}
+
+void giterr_set(int error_class, const char *string, ...)
{
char error_str[1024];
va_list arglist;
git_error *error;
- if (error_out == NULL)
- return;
-
- error = git__malloc(sizeof(git_error));
- if (!error) {
- giterr_set_oom(error_out);
- return;
- }
+ error = &GIT_GLOBAL->error_t;
+ free(error->message);
va_start(arglist, string);
p_vsnprintf(error_str, sizeof(error_str), string, arglist);
@@ -131,38 +135,14 @@ void giterr_set(git_error **error_out, int error_class, const char *string, ...)
error->klass = error_class;
if (error->message == NULL) {
- free(error);
- giterr_set_oom(error_out);
+ giterr_set_oom();
return;
}
- *error_out = error;
-}
-
-static git_error g_git_oom_error = {
- "Out of memory",
- GITERR_NOMEMORY
-};
-
-void giterr_set_oom(git_error **error)
-{
- if (error != NULL)
- *error = &g_git_oom_error;
-}
-
-void giterr_free(git_error *error)
-{
- if (error == NULL || error == &g_git_oom_error)
- return;
-
- free(error->message);
- free(error);
+ GIT_GLOBAL->last_error = error;
}
-void giterr_clear(git_error **error)
+void giterr_clear(void)
{
- if (error != NULL) {
- giterr_free(*error);
- *error = NULL;
- }
+ GIT_GLOBAL->last_error = NULL;
}