Unverified Commit 42bacbc6 by Edward Thomson Committed by GitHub

Merge pull request #5121 from pks-t/pks/variadic-errors

Variadic macros
parents b0692d6b 1721ab04
......@@ -24,9 +24,6 @@
#include "reader.h"
#include "index.h"
#define apply_err(...) \
( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), GIT_EAPPLYFAIL )
typedef struct {
/* The lines that we allocate ourself are allocated out of the pool.
* (Lines may have been allocated out of the diff.)
......@@ -35,6 +32,18 @@ typedef struct {
git_vector lines;
} patch_image;
static int apply_err(const char *fmt, ...) GIT_FORMAT_PRINTF(1, 2);
static int apply_err(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
git_error_vset(GIT_ERROR_PATCH, fmt, ap);
va_end(ap);
return GIT_EAPPLYFAIL;
}
static void patch_line_init(
git_diff_line *out,
const char *in,
......
......@@ -49,9 +49,17 @@ void git_error_set_oom(void)
GIT_GLOBAL->last_error = &g_git_oom_error;
}
void git_error_set(int error_class, const char *string, ...)
void git_error_set(int error_class, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
git_error_vset(error_class, fmt, ap);
va_end(ap);
}
void git_error_vset(int error_class, const char *fmt, va_list ap)
{
va_list arglist;
#ifdef GIT_WIN32
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
#endif
......@@ -59,11 +67,8 @@ void git_error_set(int error_class, const char *string, ...)
git_buf *buf = &GIT_GLOBAL->error_buf;
git_buf_clear(buf);
if (string) {
va_start(arglist, string);
git_buf_vprintf(buf, string, arglist);
va_end(arglist);
if (fmt) {
git_buf_vprintf(buf, fmt, ap);
if (error_class == GIT_ERROR_OS)
git_buf_PUTS(buf, ": ");
}
......
......@@ -14,8 +14,8 @@
/*
* Set the error message for this thread, formatting as needed.
*/
void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3);
void git_error_vset(int error_class, const char *fmt, va_list ap);
/**
* Set the error message for a regex failure, using the internal regex
......
......@@ -28,9 +28,6 @@ typedef struct {
int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len);
void git_parse_ctx_clear(git_parse_ctx *ctx);
#define git_parse_err(...) \
( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), -1 )
#define git_parse_ctx_contains_s(ctx, str) \
git_parse_ctx_contains(ctx, str, sizeof(str) - 1)
......
......@@ -33,6 +33,18 @@ typedef struct {
char *old_prefix, *new_prefix;
} git_patch_parsed;
static int git_parse_err(const char *fmt, ...) GIT_FORMAT_PRINTF(1, 2);
static int git_parse_err(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
git_error_vset(GIT_ERROR_PATCH, fmt, ap);
va_end(ap);
return -1;
}
static size_t header_path_len(git_patch_parse_ctx *ctx)
{
bool inquote = 0;
......
......@@ -59,7 +59,7 @@ GIT_INLINE(int) p_fsync(int fd)
#define p_strcasecmp(s1, s2) strcasecmp(s1, s2)
#define p_strncasecmp(s1, s2, c) strncasecmp(s1, s2, c)
#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
#define p_snprintf(b, c, ...) snprintf(b, c, __VA_ARGS__)
#define p_snprintf snprintf
#define p_mkstemp(p) mkstemp(p)
#define p_chdir(p) chdir(p)
#define p_chmod(p,m) chmod(p, m)
......
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