Customizable error handlers
PATCH 1/1 Customizable error handlers
This patch makes the usage(), die() and error() handlers customizable. Nothing in the git code itself uses that but many other libgit users (like Git.pm) will.
This is implemented using the mutator functions primarily because you cannot directly modifying global variables of libgit from a program that dlopen()ed it, apparently. But having functions for that is a better API anyway.
---
git-compat-util.h | 10 +++++++--- usage.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-)
git-compat-util.h +7 -3
@@ -36,9 +36,13 @@ #endif#endif /* General helper functions */ -extern void usage(const char *err) NORETURN; -extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); -extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +void usage(const char *err) NORETURN; +void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); + +void set_usage_routine (void (*routine)(const char *err)NORETURN ); +void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN ); +void set_error_routine (int (*routine)(const char *err,va_list params));#ifdef NO_MMAP
usage.c +45 -5
73 lines not on this page · raw message
Dear diary, on Fri, Jun 23, 2006 at 03:32:27PM CEST, I got a letter where Petr Baudis <[email protected]> said that...
Quoted 5 lines
git-compat-util.h +0
-0
git-compat-util.h #endif · line 41
Quoted 9 lines
git-compat-util.h +3
-3@@ -36,9 +36,13 @@ #endif#endif /* General helper functions */ -extern void usage(const char *err) NORETURN; -extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); -extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +void usage(const char *err) NORETURN; +void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));
Wah, this kind of slipped through. Below is a patch without the externs removed. Sorry about the noise.
git-compat-util.h #endif
Quoted 12 lines
git-compat-util.h +3
-2int error (const char *err, ...) {va_list params; +int ret;va_start (params, err); -report ("error: " , err, params); + ret =error_routine (err, params);va_end (params); -return -1 ; +return ret; }
BTW, I don't mind if you just force the return value to -1 here. It might be saner.
---
[PATCH] Customizable error handlers
This patch makes the usage(), die() and error() handlers customizable. Nothing in the git code itself uses that but many other libgit users (like Git.pm) will.
This is implemented using the mutator functions primarily because you cannot directly modifying global variables of libgit from a program that dlopen()ed it, apparently. But having functions for that is a better API anyway.
---
git-compat-util.h +4 -0
@@ -40,6 +40,10 @@ extern void usage(const char *err) NORET extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern void set_usage_routine (void (*routine)(const char *err)NORETURN ); +extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN ); +extern void set_error_routine (int (*routine)(const char *err,va_list params)); +#ifdef NO_MMAP #ifndef PROT_READ
usage.c +45 -5
73 lines not on this page · raw message
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ A person is just about as big as the things that make them angry.
Quoted 9 lines · Petr Baudis
Dear diary, on Fri, Jun 23, 2006 at 03:32:27PM CEST, I got a letter where Petr Baudis <[email protected]> said that...
Quoted 7 lines
git-compat-util.h +0
-0@@ -36,9 +36,13 @@ #endif#endif
Quoted 10 lines
git-compat-util.h #endif · line 41
Quoted 7 lines
git-compat-util.h +3
-3/* General helper functions */ -extern void usage(const char *err) NORETURN; -extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); -extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +void usage(const char *err) NORETURN; +void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));Wah, this kind of slipped through. Below is a patch without the externs removed.
Oh, I first thought you did that on purpose as a cleanup. After all don't they mean the same thing?
Dear diary, on Sat, Jun 24, 2006 at 01:14:07AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...
Quoted 22 lines
Quoted 9 lines · Petr Baudis
Dear diary, on Fri, Jun 23, 2006 at 03:32:27PM CEST, I got a letter where Petr Baudis <[email protected]> said that...
Quoted 7 lines
git-compat-util.h +0
-0@@ -36,9 +36,13 @@ #endif#endif Quoted 10 lines
git-compat-util.h #endif · line 41
Quoted 7 lines
git-compat-util.h +3
-3/* General helper functions */ -extern void usage(const char *err) NORETURN; -extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); -extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +void usage(const char *err) NORETURN; +void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));Wah, this kind of slipped through. Below is a patch without the externs removed.
Quoted 2 lines
Oh, I first thought you did that on purpose as a cleanup. After all don't they mean the same thing?
AFAIK they do, but we use extern everywhere and I personally consider it good style to externize declarations of, well, external functions.
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ A person is just about as big as the things that make them angry.