Permalink
Browse files

Slightly different fix to issue #140 that takes into account passing …

…Proc/Method instances as the 'proc' parameter to initialize()
  • Loading branch information...
1 parent 098dcfb commit 4941384eda6711d7c209f27e47b38e848e89019c Wayne Meissner committed Aug 30, 2011
Showing with 15 additions and 10 deletions.
  1. +15 −10 lib/ffi/autopointer.rb
View
@@ -83,28 +83,33 @@ def initialize(ptr, proc)
end
def free
- raise RuntimeError.new("pointer already freed") unless @ptr
- @autorelease = false
- @ptr = nil
- @proc = nil
+ if @ptr
+ release(@ptr)
+ @autorelease = false
+ @ptr = nil
+ @proc = nil
+ end
end
def autorelease=(autorelease)
- raise RuntimeError.new("pointer already freed") unless @ptr
- @autorelease = autorelease
+ @autorelease = autorelease if @ptr
+ end
+
+ def call(*args)
+ release(@ptr) if @autorelease && @ptr
end
end
class DefaultReleaser < Releaser
- def call(*args)
- @proc.release(@ptr) if @autorelease && @ptr
+ def release(ptr)
+ @proc.release(ptr)
end
end
class CallableReleaser < Releaser
- def call(*args)
- @proc.call(@ptr) if @autorelease && @ptr
+ def release(ptr)
+ @proc.call(ptr)
end
end

0 comments on commit 4941384

Please sign in to comment.