Added SWIG_ObjectPreviouslyDeletedError for Ruby. This error happens when a Ruby object's underlying C++ object has been freed. This can happen if a Ruby/C++ object is put into a C++ container that then frees its objects when it goes out of scope, leaving a dangling reference in Ruby.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8340 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Charlie Savage 2006-01-10 00:52:37 +00:00
commit 1256774cd5
2 changed files with 18 additions and 9 deletions

View file

@ -4,12 +4,19 @@
%insert("runtime") "swigerrors.swg"
/* Define some additional error types */
%insert("runtime") %{
#define SWIG_ObjectPreviouslyDeletedError -100
%}
%insert("header") %{
/* 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
/* Define custom error for SWIG_NullReferenceError since Ruby does not have a
built-in error that seems appropriate. */
static VALUE rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
static VALUE rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
#endif
SWIGINTERN VALUE
@ -49,13 +56,14 @@ SWIG_Ruby_ErrorType(int SWIG_code) {
case SWIG_AttributeError:
type = rb_eRuntimeError;
break;
case SWIG_NullReferenceError:
#ifdef __cplusplus
case SWIG_NullReferenceError:
type = rb_eNullReferenceError;
#else
type = rb_eRuntimeError;
#endif
break;
case SWIG_ObjectPreviouslyDeletedError:
type = rb_eObjectPreviouslyDeleted;
break;
#endif
case SWIG_UnknownError:
type = rb_eRuntimeError;
break;

View file

@ -229,10 +229,11 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags,
if (ty->clientdata) {
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
if (vptr == 0) {
return SWIG_ERROR;
/* The object has already been deleted */
return SWIG_ObjectPreviouslyDeletedError;
}
*ptr = vptr;
return SWIG_OK;
*ptr = vptr;
return SWIG_OK;
}
}
if ((c = SWIG_MangleStr(obj)) == NULL) {