perl5 error handling improvements

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12873 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Robert Stone 2011-12-10 18:33:04 +00:00
commit e7a4f42877
4 changed files with 23 additions and 37 deletions

View file

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.5 (in progress) Version 2.0.5 (in progress)
=========================== ===========================
2011-12-10: talby
[perl5] SWIG_error() now gets decorated with perl source file/line number.
[perl5] error handling now conforms to public XS api (fixes perl v5.14 issue).
2011-12-10: wsfulton 2011-12-10: wsfulton
[Android/Java] Fix directors to compile on Android. [Android/Java] Fix directors to compile on Android.

View file

@ -4,46 +4,31 @@
SWIGINTERN const char* SWIGINTERN const char*
SWIG_Perl_ErrorType(int code) { SWIG_Perl_ErrorType(int code) {
const char* type = 0;
switch(code) { switch(code) {
case SWIG_MemoryError: case SWIG_MemoryError:
type = "MemoryError"; return "MemoryError";
break;
case SWIG_IOError: case SWIG_IOError:
type = "IOError"; return "IOError";
break;
case SWIG_RuntimeError: case SWIG_RuntimeError:
type = "RuntimeError"; return "RuntimeError";
break;
case SWIG_IndexError: case SWIG_IndexError:
type = "IndexError"; return "IndexError";
break;
case SWIG_TypeError: case SWIG_TypeError:
type = "TypeError"; return "TypeError";
break;
case SWIG_DivisionByZero: case SWIG_DivisionByZero:
type = "ZeroDivisionError"; return "ZeroDivisionError";
break;
case SWIG_OverflowError: case SWIG_OverflowError:
type = "OverflowError"; return "OverflowError";
break;
case SWIG_SyntaxError: case SWIG_SyntaxError:
type = "SyntaxError"; return "SyntaxError";
break;
case SWIG_ValueError: case SWIG_ValueError:
type = "ValueError"; return "ValueError";
break;
case SWIG_SystemError: case SWIG_SystemError:
type = "SystemError"; return "SystemError";
break;
case SWIG_AttributeError: case SWIG_AttributeError:
type = "AttributeError"; return "AttributeError";
break;
default: default:
type = "RuntimeError"; return "RuntimeError";
} }
return type;
} }

View file

@ -47,7 +47,7 @@
/* Error manipulation */ /* Error manipulation */
#define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code) #define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code)
#define SWIG_Error(code, msg) sv_setpvf(GvSV(PL_errgv),"%s %s\n", SWIG_ErrorType(code), msg) #define SWIG_Error(code, msg) sv_setpvf(get_sv("@", GV_ADD), "%s %s", SWIG_ErrorType(code), msg)
#define SWIG_fail goto fail #define SWIG_fail goto fail
/* Perl-specific SWIG API */ /* Perl-specific SWIG API */
@ -141,8 +141,6 @@ typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
#endif /* MULTIPLICITY */ #endif /* MULTIPLICITY */
#endif /* PERL_OBJECT */ #endif /* PERL_OBJECT */
/* Workaround for bug in perl 5.6.x croak and earlier */
#if (PERL_VERSION < 8)
# ifdef PERL_OBJECT # ifdef PERL_OBJECT
# define SWIG_croak_null() SWIG_Perl_croak_null(pPerl) # define SWIG_croak_null() SWIG_Perl_croak_null(pPerl)
static void SWIG_Perl_croak_null(CPerlObj *pPerl) static void SWIG_Perl_croak_null(CPerlObj *pPerl)
@ -150,17 +148,16 @@ static void SWIG_Perl_croak_null(CPerlObj *pPerl)
static void SWIG_croak_null() static void SWIG_croak_null()
# endif # endif
{ {
SV *err=ERRSV; SV *err = get_sv("@", GV_ADD);
# if (PERL_VERSION < 6) # if (PERL_VERSION < 6)
croak("%_", err); croak("%_", err);
# else # else
if (SvOK(err) && !SvROK(err)) croak("%_", err); if (sv_isobject(err))
croak(Nullch); croak(0);
else
croak("%s", SvPV_nolen(err));
# endif # endif
} }
#else
# define SWIG_croak_null() croak(Nullch)
#endif
/* /*

View file

@ -69,7 +69,7 @@
%end_block %enddef %end_block %enddef
/* raise exception */ /* raise exception */
%define %raise(obj, type, desc) sv_setsv(GvSV(PL_errgv), obj); SWIG_fail %enddef %define %raise(obj, type, desc) sv_setsv(get_sv("@", GV_ADD), obj); SWIG_fail %enddef
/* Include the unified typemap library */ /* Include the unified typemap library */
%include <typemaps/swigtypemaps.swg> %include <typemaps/swigtypemaps.swg>