From 97b16c067492506287a6f474e79ef6cbe0a30e49 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 24 Jun 2006 04:34:42 +0200 Subject: Git.pm: Better error handling So far, errors just killed the whole program and in case of an error inside of libgit it would be totally uncatchable. This patch makes Git.pm throw standard Perl exceptions instead. In the future we might subclass Error to Git::Error or something but for now Error::Simple is more than enough. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- perl/Git.xs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'perl/Git.xs') diff --git a/perl/Git.xs b/perl/Git.xs index d4608eb1c..9d247b713 100644 --- a/perl/Git.xs +++ b/perl/Git.xs @@ -8,6 +8,8 @@ #include "../cache.h" #include "../exec_cmd.h" +#define die perlyshadow_die__ + /* XS and Perl interface */ #include "EXTERN.h" #include "perl.h" @@ -15,11 +17,48 @@ #include "ppport.h" +#undef die + + +static char * +report_xs(const char *prefix, const char *err, va_list params) +{ + static char buf[4096]; + strcpy(buf, prefix); + vsnprintf(buf + strlen(prefix), 4096 - strlen(prefix), err, params); + return buf; +} + +void +die_xs(const char *err, va_list params) +{ + char *str; + str = report_xs("fatal: ", err, params); + croak(str); +} + +int +error_xs(const char *err, va_list params) +{ + char *str; + str = report_xs("error: ", err, params); + warn(str); + return -1; +} + MODULE = Git PACKAGE = Git PROTOTYPES: DISABLE + +BOOT: +{ + set_error_routine(error_xs); + set_die_routine(die_xs); +} + + # /* TODO: xs_call_gate(). See Git.pm. */ -- cgit v1.2.1