Wrapped customer error classes in function so they work in C and C++

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8343 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Charlie Savage 2006-01-10 03:38:08 +00:00
commit 7d44f269fb

View file

@ -14,10 +14,27 @@
/* Define custom exceptions for errors that do not map to existing Ruby
exceptions. Note this only works for C++ since a global cannot be
initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/
#ifdef __cplusplus
static VALUE rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
static VALUE rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
#endif
VALUE getNullReferenceError() {
static int init = 0;
static VALUE rb_eNullReferenceError ;
if (!init) {
init = 1;
rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
}
return rb_eNullReferenceError;
}
VALUE getObjectPreviouslyDeletedError() {
static int init = 0;
static VALUE rb_eObjectPreviouslyDeleted ;
if (!init) {
init = 1;
rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
}
return rb_eObjectPreviouslyDeleted;
}
SWIGINTERN VALUE
SWIG_Ruby_ErrorType(int SWIG_code) {
@ -56,14 +73,12 @@ SWIG_Ruby_ErrorType(int SWIG_code) {
case SWIG_AttributeError:
type = rb_eRuntimeError;
break;
#ifdef __cplusplus
case SWIG_NullReferenceError:
type = rb_eNullReferenceError;
type = getNullReferenceError();
break;
case SWIG_ObjectPreviouslyDeletedError:
type = rb_eObjectPreviouslyDeleted;
type = getObjectPreviouslyDeletedError();
break;
#endif
case SWIG_UnknownError:
type = rb_eRuntimeError;
break;