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/SWIG@8340 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e3822ad9d4
commit
7e96a9e2d5
2 changed files with 18 additions and 9 deletions
|
|
@ -4,12 +4,19 @@
|
||||||
|
|
||||||
%insert("runtime") "swigerrors.swg"
|
%insert("runtime") "swigerrors.swg"
|
||||||
|
|
||||||
|
/* Define some additional error types */
|
||||||
|
%insert("runtime") %{
|
||||||
|
#define SWIG_ObjectPreviouslyDeletedError -100
|
||||||
|
%}
|
||||||
|
|
||||||
%insert("header") %{
|
%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
|
#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_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
|
||||||
|
static VALUE rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SWIGINTERN VALUE
|
SWIGINTERN VALUE
|
||||||
|
|
@ -49,13 +56,14 @@ SWIG_Ruby_ErrorType(int SWIG_code) {
|
||||||
case SWIG_AttributeError:
|
case SWIG_AttributeError:
|
||||||
type = rb_eRuntimeError;
|
type = rb_eRuntimeError;
|
||||||
break;
|
break;
|
||||||
case SWIG_NullReferenceError:
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
case SWIG_NullReferenceError:
|
||||||
type = rb_eNullReferenceError;
|
type = rb_eNullReferenceError;
|
||||||
#else
|
|
||||||
type = rb_eRuntimeError;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
case SWIG_ObjectPreviouslyDeletedError:
|
||||||
|
type = rb_eObjectPreviouslyDeleted;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case SWIG_UnknownError:
|
case SWIG_UnknownError:
|
||||||
type = rb_eRuntimeError;
|
type = rb_eRuntimeError;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -229,10 +229,11 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags,
|
||||||
if (ty->clientdata) {
|
if (ty->clientdata) {
|
||||||
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
||||||
if (vptr == 0) {
|
if (vptr == 0) {
|
||||||
return SWIG_ERROR;
|
/* The object has already been deleted */
|
||||||
|
return SWIG_ObjectPreviouslyDeletedError;
|
||||||
}
|
}
|
||||||
*ptr = vptr;
|
*ptr = vptr;
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue