summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortduehr <td@matasano.com>2015-08-06 10:54:14 -0500
committertduehr <td@matasano.com>2015-08-06 10:54:14 -0500
commitfc00f561cb060aa4dd4e89cf2e548dfc629fc9fa (patch)
tree5bb27d2ffbbf3fb12e56a8a22d6b335e2c8c9a37
parent198f3ac484f2df4e33eba2707b384c9a2d4b4614 (diff)
parent71687cb91e4174307c087ed6ffac938a974f6f4f (diff)
downloadffi-fc00f561cb060aa4dd4e89cf2e548dfc629fc9fa.tar.gz
Merge pull request #450 from larskanis/appveyor
Add appveyor.yml for ci-tests on Windows.
-rw-r--r--Rakefile9
-rw-r--r--appveyor.yml17
-rw-r--r--libtest/FunctionTest.c2
-rw-r--r--libtest/VariadicTest.c37
-rw-r--r--spec/ffi/fixtures/ClosureTest.c15
-rw-r--r--spec/ffi/fixtures/FunctionTest.c16
-rw-r--r--spec/ffi/rbx/attach_function_spec.rb43
7 files changed, 111 insertions, 28 deletions
diff --git a/Rakefile b/Rakefile
index e671f91..10839e2 100644
--- a/Rakefile
+++ b/Rakefile
@@ -177,13 +177,14 @@ if USE_RAKE_COMPILER
ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.3:2.0.0:2.1.5:2.2.1'
+ # To reduce the gem file size strip mingw32 dlls before packaging
ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
- task "copy:ffi_c:i386-mingw32:#{ruby_version}" do |t|
- sh "i686-w64-mingw32-strip -S #{BUILD_DIR}/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
+ task "build/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" do |t|
+ sh "i686-w64-mingw32-strip -S build/i386-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
end
- task "copy:ffi_c:x64-mingw32:#{ruby_version}" do |t|
- sh "x86_64-w64-mingw32-strip -S #{BUILD_DIR}/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
+ task "build/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so" do |t|
+ sh "x86_64-w64-mingw32-strip -S build/x64-mingw32/stage/lib/#{ruby_version[/^\d+\.\d+/]}/ffi_c.so"
end
end
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..c82a9e4
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,17 @@
+install:
+ - SET PATH=C:\%RUBYVER%\bin;%PATH%
+ - SET RAKEOPT=-rdevkit
+ - gem install bundler --quiet --no-ri --no-rdoc
+ - bundle install
+build: off
+test_script:
+ - bundle exec rake test
+environment:
+ matrix:
+ - RUBYVER: Ruby193
+ - RUBYVER: Ruby200
+ - RUBYVER: Ruby200-x64
+ - RUBYVER: Ruby21
+ - RUBYVER: Ruby21-x64
+ - RUBYVER: Ruby22
+ - RUBYVER: Ruby22-x64
diff --git a/libtest/FunctionTest.c b/libtest/FunctionTest.c
index eafad89..8cde5f1 100644
--- a/libtest/FunctionTest.c
+++ b/libtest/FunctionTest.c
@@ -6,7 +6,7 @@
#ifdef _WIN32
#include <windows.h>
-#define sleep(x) Sleep(x)
+#define sleep(x) Sleep((x)*1000)
#endif
#ifndef _WIN32
diff --git a/libtest/VariadicTest.c b/libtest/VariadicTest.c
index fea6c3b..2f3d801 100644
--- a/libtest/VariadicTest.c
+++ b/libtest/VariadicTest.c
@@ -60,3 +60,40 @@ void pack_varargs(s64* buf, const char* fmt, ...)
va_end(ap);
}
+int pack_varargs2(s64* buf, int retval, const char* fmt, ...)
+{
+ va_list ap;
+ int c;
+ double d;
+ va_start(ap, fmt);
+ while ((c = *fmt++)) {
+ switch (c) {
+ case 'c':
+ case 's':
+ case 'i':
+ *buf++ = va_arg(ap, s32);
+ break;
+ case 'l':
+ *buf++ = va_arg(ap, long);
+ break;
+ case 'j':
+ *buf++ = va_arg(ap, s64);
+ break;
+ case 'f':
+ case 'd':
+ d = va_arg(ap, double);
+ memcpy(buf++, &d, sizeof(d));
+ break;
+ case 'C':
+ case 'S':
+ case 'I':
+ *buf++ = va_arg(ap, u32);
+ break;
+ case 'L':
+ *buf++ = va_arg(ap, unsigned long);
+ break;
+ }
+ }
+ va_end(ap);
+ return retval + 1;
+}
diff --git a/spec/ffi/fixtures/ClosureTest.c b/spec/ffi/fixtures/ClosureTest.c
index 64ea2b4..dfeabde 100644
--- a/spec/ffi/fixtures/ClosureTest.c
+++ b/spec/ffi/fixtures/ClosureTest.c
@@ -50,6 +50,21 @@ P(D, double);
P(P, const void*);
P(UL, unsigned long);
+#if defined(_WIN32) && !defined(_WIN64)
+bool __stdcall testClosureStdcall(long *a1, void __stdcall(*closure)(void *, long), long a2) { \
+ void* sp_pre;
+ void* sp_post;
+
+ asm volatile (" movl %%esp,%0" : "=g" (sp_pre));
+ (*closure)(a1, a2);
+ asm volatile (" movl %%esp,%0" : "=g" (sp_post));
+
+ /* %esp before pushing parameters on the stack and after the call returns
+ * should be equal, if both sides respects the stdcall convention */
+ return sp_pre == sp_post;
+}
+#endif
+
void testOptionalClosureBrV(void (*closure)(char), char a1)
{
if (closure) {
diff --git a/spec/ffi/fixtures/FunctionTest.c b/spec/ffi/fixtures/FunctionTest.c
index b4d45bb..5310ab0 100644
--- a/spec/ffi/fixtures/FunctionTest.c
+++ b/spec/ffi/fixtures/FunctionTest.c
@@ -6,7 +6,7 @@
#ifdef _WIN32
#include <windows.h>
-#define sleep(x) Sleep(x)
+#define sleep(x) Sleep((x)*1000)
#endif
#ifndef _WIN32
@@ -55,4 +55,16 @@ void testAsyncCallback(void (*fn)(int), int value)
#else
(*fn)(value);
#endif
-}
+}
+
+#if defined(_WIN32) && !defined(_WIN64)
+struct StructUCDP {
+ unsigned char a1;
+ double a2;
+ void *a3;
+};
+
+void __stdcall testStdcallManyParams(long *a1, char a2, short int a3, int a4, __int64 a5,
+ struct StructUCDP a6, struct StructUCDP *a7, float a8, double a9) {
+}
+#endif
diff --git a/spec/ffi/rbx/attach_function_spec.rb b/spec/ffi/rbx/attach_function_spec.rb
index e90f535..7593662 100644
--- a/spec/ffi/rbx/attach_function_spec.rb
+++ b/spec/ffi/rbx/attach_function_spec.rb
@@ -5,29 +5,30 @@
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
-class Timeval < FFI::Struct
- layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4
-end
-
-module LibC
- extend FFI::Library
- ffi_lib FFI::Library::LIBC
+unless FFI::Platform.windows?
+ class Timeval < FFI::Struct
+ layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4
+ end
- attach_function :gettimeofday, [:pointer, :pointer], :int
-end
+ module LibC
+ extend FFI::Library
+ ffi_lib FFI::Library::LIBC
-describe FFI::Library, "#attach_function" do
- it "correctly returns a value for gettimeofday" do
- t = Timeval.new
- time = LibC.gettimeofday(t.pointer, nil)
- expect(time).to be_kind_of(Integer)
+ attach_function :gettimeofday, [:pointer, :pointer], :int
end
-
- it "correctly populates a struct for gettimeofday" do
- t = Timeval.new
- LibC.gettimeofday(t.pointer, nil)
- expect(t[:tv_sec]).to be_kind_of(Numeric)
- expect(t[:tv_usec]).to be_kind_of(Numeric)
+
+ describe FFI::Library, "#attach_function" do
+ it "correctly returns a value for gettimeofday" do
+ t = Timeval.new
+ time = LibC.gettimeofday(t.pointer, nil)
+ expect(time).to be_kind_of(Integer)
+ end
+
+ it "correctly populates a struct for gettimeofday" do
+ t = Timeval.new
+ LibC.gettimeofday(t.pointer, nil)
+ expect(t[:tv_sec]).to be_kind_of(Numeric)
+ expect(t[:tv_usec]).to be_kind_of(Numeric)
+ end
end
end
-