Skip to content

Commit

Permalink
Updated ErrorBuffer.
Browse files Browse the repository at this point in the history
* Removed the JRuby workaround since it has been fixed.
  http://jira.codehaus.org/browse/JRUBY-4519
  • Loading branch information
postmodern committed Jul 24, 2012
1 parent ed3222d commit e84bf97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
38 changes: 7 additions & 31 deletions 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

#
Expand All @@ -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
4 changes: 1 addition & 3 deletions spec/error_buffer_spec.rb
@@ -1,16 +1,14 @@
require 'spec_helper'

describe ErrorBuffer do
subject { ErrorBuffer.create }

it "should have a default size of 256" do
subject.size.should == 256
end

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
Expand Down

0 comments on commit e84bf97

Please sign in to comment.