summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2012-11-13 06:08:10 +1000
committerWayne Meissner <wmeissner@gmail.com>2012-11-13 06:08:10 +1000
commit1f6f25f314f4e6797336d6ff750e52209a7016fa (patch)
treeaa7141dc71d118141381bf5c003f426f4a33a3ed
parent5d571833ef17ffa1511f97d18fc964f6ded3a391 (diff)
downloadffi-1f6f25f314f4e6797336d6ff750e52209a7016fa.tar.gz
Reject :varargs parameters for callbacks. Fixes #161
-rw-r--r--lib/ffi/library.rb4
-rw-r--r--spec/ffi/callback_spec.rb12
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/ffi/library.rb b/lib/ffi/library.rb
index 6612263..3aa781f 100644
--- a/lib/ffi/library.rb
+++ b/lib/ffi/library.rb
@@ -361,10 +361,12 @@ code
[ nil, args[0], args[1] ]
end
+ native_params = params.map { |e| find_type(e) }
+ raise ArgumentError, "callbacks cannot have variadic parameters" if native_params.include?(FFI::Type::VARARGS)
options = Hash.new
options[:convention] = ffi_convention
options[:enums] = @ffi_enums if defined?(@ffi_enums)
- cb = FFI::CallbackInfo.new(find_type(ret), params.map { |e| find_type(e) }, options)
+ cb = FFI::CallbackInfo.new(find_type(ret), native_params, options)
# Add to the symbol -> type map (unless there was no name)
unless name.nil?
diff --git a/spec/ffi/callback_spec.rb b/spec/ffi/callback_spec.rb
index 463e5e3..bec0121 100644
--- a/spec/ffi/callback_spec.rb
+++ b/spec/ffi/callback_spec.rb
@@ -665,4 +665,14 @@ describe "Callback with " do
v.pointer.should eq FFI::Pointer::NULL
end
-end # unless true
+ it "varargs parameters are rejected" do
+ lambda {
+ Module.new do
+ extend FFI::Library
+ ffi_lib TestLibrary::PATH
+ callback :cbVrL, [ :varargs ], :long
+ end
+ }.should raise_error(ArgumentError)
+ end
+
+end