Merge pull request #1177 from Sigill/sigabrt_rubyunlinkobject_fix

Do not abort when unlinking non-data ruby objects
This commit is contained in:
William S Fulton 2018-01-07 12:23:47 +00:00 • committed by GitHub
commit c44adff7b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -39,7 +39,11 @@ GC.start
# C++ object # C++ object
ok = false ok = false
begin begin
puts tiger2.get_name # Let's stress the GC a bit, a single pass might not be enough.
10.times {
GC.start
puts tiger2.get_name
}
rescue ObjectPreviouslyDeleted => error rescue ObjectPreviouslyDeleted => error
ok = true ok = true
end end

View file

@ -101,13 +101,14 @@ SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) {
/* This is a helper method that unlinks a Ruby object from its /* This is a helper method that unlinks a Ruby object from its
underlying C++ object. This is needed if the lifetime of the underlying C++ object. This is needed if the lifetime of the
Ruby object is longer than the C++ object */ Ruby object is longer than the C++ object. */
SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) { SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) {
VALUE object = SWIG_RubyInstanceFor(ptr); VALUE object = SWIG_RubyInstanceFor(ptr);
if (object != Qnil) { if (object != Qnil) {
if (TYPE(object) != T_DATA) // object might have the T_ZOMBIE type, but that's just
abort(); // because the GC has flagged it as such for a deferred
// destruction. Until then, it's still a T_DATA object.
DATA_PTR(object) = 0; DATA_PTR(object) = 0;
} }
} }