From e84bf979a7a17f6a81df5c5b1715be11ec021201 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 23 Jul 2012 18:09:30 -0700 Subject: [PATCH] Updated ErrorBuffer. * Removed the JRuby workaround since it has been fixed. http://jira.codehaus.org/browse/JRUBY-4519 --- lib/ffi/pcap/error_buffer.rb | 38 +++++++----------------------------- spec/error_buffer_spec.rb | 4 +--- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/lib/ffi/pcap/error_buffer.rb b/lib/ffi/pcap/error_buffer.rb index 1b6c240..fbdc816 100644 --- a/lib/ffi/pcap/error_buffer.rb +++ b/lib/ffi/pcap/error_buffer.rb @@ -1,32 +1,20 @@ module FFI module PCap - class ErrorBuffer < FFI::MemoryPointer + class ErrorBuffer < FFI::Buffer # Size of the error buffers SIZE = 256 - # - # Creates a new {ErrorBuffer} object. Because of wierdness in JRuby - # when trying to subclass `FFI::Buffer`, always use this instead of - # {#initialize}. - # - # @see http://github.com/ffi/ffi/issues#issue/27 - # - def self.create() - new(SIZE) - end - # # Creates a new {ErrorBuffer} object. # - # @param [Object] nil - # The argument is nil and is only present for compatability with - # JRuby. - # - # @see http://github.com/ffi/ffi/issues#issue/27 + # @param [FFI::Pointer] ptr + # Optional pointer to an existing {ErrorBuffer}. # - def initialize(arg=nil) - super(SIZE) + def initialize(ptr=nil) + if ptr then super(ptr) + else super(SIZE) + end end # @@ -36,18 +24,6 @@ def to_s get_string(0) end - # - # Older JRuby/ffi versions of MemoryPointer and Buffer don't have a - # size method. We override it here to ensure we can use it. - # - def size - begin - super() - rescue NoMethodError - SIZE - end - end - end end end diff --git a/spec/error_buffer_spec.rb b/spec/error_buffer_spec.rb index c083fa6..5246126 100644 --- a/spec/error_buffer_spec.rb +++ b/spec/error_buffer_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe ErrorBuffer do - subject { ErrorBuffer.create } - it "should have a default size of 256" do subject.size.should == 256 end @@ -10,7 +8,7 @@ it "should return an error message with to_s" do subject.to_s.should be_empty - FFI::PCap.pcap_open_offline("/this/file/wont/exist",subject) + PCap.pcap_open_offline("/this/file/wont/exist",subject) subject.to_s.should_not be_empty end