Skip to content
Permalink
Browse files
Moved autorelease methods to FFI::Pointer
This allows code to alter the autorelease behaviour of regular
Rubinius::FFI::Pointer instances. As an example, rubysl-socket returns a
bunch of ifaddr pointers which are freed using freeifaddrs(). By default
these pointers have auto-releasing enabled which results in Rubinius
attempting to finalize/free already free'd pointers which in turn
segfaults Rubinius.
  • Loading branch information
YorickPeterse committed Dec 26, 2015
1 parent dfa4f06 commit a84783dc3d0c408d078f763c4c4259be0b8712ba
Showing with 15 additions and 16 deletions.
  1. +15 −16 kernel/platform/pointer.rb
@@ -253,6 +253,21 @@ def primitive_write_pointer(obj)
raise PrimitiveFailure, "FFI::Pointer#primitive_write_pointer primitive failed"
end

##
# If +val+ is true, this Pointer object will call
# free() on it's address when it is garbage collected.
def autorelease=(val)
Rubinius.primitive :pointer_set_autorelease
raise PrimitiveFailure, "FFI::Pointer#autorelease= primitive failed"
end

##
# Returns true if autorelease is enabled, otherwise false.
def autorelease?
Rubinius.primitive :pointer_autorelease_p
raise PrimitiveFailure, "FFI::Pointer#pointer_autorelease_p primitive failed"
end

NULL = Pointer.new(0x0)
end

@@ -370,22 +385,6 @@ def free
Rubinius.primitive :pointer_free
raise PrimitiveFailure, "FFI::MemoryPointer#free primitive failed"
end

##
# If +val+ is true, this MemoryPointer object will call
# free() on it's address when it is garbage collected.
def autorelease=(val)
Rubinius.primitive :pointer_set_autorelease
raise PrimitiveFailure, "FFI::MemoryPointer#autorelease= primitive failed"
end

##
# Returns true if autorelease is enabled, otherwise false.
def autorelease?
Rubinius.primitive :pointer_autorelease_p
raise PrimitiveFailure, "FFI::MemoryPointer#pointer_autorelease_p primitive failed"
end

end

class DynamicLibrary::Symbol < Pointer

0 comments on commit a84783d

Please sign in to comment.