ffi 1.0.12.pre-x86-mingw32 → 1.0.12.rc2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

@@ -1,112 +1 @@
1
- == 1.0.3 / 2010-12-28
2
- * Re-add support for ruby 1.8.x
3
-
4
- == 1.0.0 / 2010-11-30
5
- * Major improvements
6
- * Better handling of non-ruby thread callbacks
7
- * Support for releasing the GIL during C function calls
8
- * Minor improvements
9
- * code cleanups
10
-
11
- == 0.5.0 / 2009-10-06
12
-
13
- * Major improvements
14
- * New Function class
15
- * Structs can be passed and returned by value
16
- * Implement a custom trampoline for x86_64, resulting in roughly 30% speedup
17
- * Improve dispatch of functions which take (0..6) char/short/int/long/pointer arguments by between 50% and 200% on x86_64
18
- * Callbacks are now approximately 100% faster on x86_64
19
- * Minor improvements
20
- * Add support for MacOSX Snow Leopard
21
- * Improve support for Windows releasing fat binaries on rubyforge
22
- * Better introspection in structs:
23
- * Add StructLayout::Field#type, size, offset, alignment and name
24
- methods
25
- * Add StructLayout#fields which returns an array of
26
- StructLayout::Field objects
27
- * Add automagic deducing of library name from module name.
28
- Idea and prototype implementation from Matt Hulse
29
- * Callback fields in structs can now be both read and written
30
- * Add a bunch of new benchmarks
31
- * Lots of refactoring
32
- * Experimental features
33
- * blocking functions (i.e. native code that blocks the thread) support
34
- * Bug fixes
35
- * Fix RUBY-FFI_43 (rake gem dependency)
36
-
37
- == 0.4.0 / 2009-08-05
38
-
39
- * Major improvements
40
- * Add support for boolean types
41
- * Add support for methods as callbacks
42
- * Add FFI::IO.read as described in JRUBY-3636
43
- * Minor improvements
44
- * Add Pointer::NULL constant
45
- * Add AbstractMemory#get_array_of_string()
46
- * Implement Pointer.new(address) and Pointer.new(:type, address)
47
- * Bug fixes
48
- * Fix RUBY_FFI-38
49
- * Fix issues related to 1.9.1 build
50
- * Fix issues related to OSX build
51
- * Fix issues related to FreeBSD build
52
- * Fix issues related to OpenSolaris build
53
-
54
- == 0.3.5 / 2009-05-08
55
-
56
- * Bug fixes
57
- * Fix RUBY_FFI-17
58
- * Fix RUBY_FFI-21
59
-
60
- == 0.3.4 / 2009-05-01
61
-
62
- * Minor improvements
63
- * Add return statements to functions that call rb_raise(), in case
64
- rb_raise is not declared noreturn, to avoid gcc warnings.
65
-
66
- == 0.3.3 / 2009-04-27
67
-
68
- * Minor improvements
69
- * Implement RUBY_FFI-16 - Add support for anonymous callbacks
70
- * Add support for callback parameters in callbacks
71
- * Add support for function pointer return values
72
- * Callbacks can now coerce proc objects into function pointers for
73
- return values.
74
- * Implement FFI::Type and FFI::Type::Builtin
75
- * Add support for enumerations
76
- * Bug fixes
77
- * Fix RUBY_FFI-19
78
- * Fix RUBY_FFI-15
79
-
80
- == 0.3.2 / 2009-05-01
81
-
82
- * Bug fixes
83
- * Fix JRUBY-3527 by passing RTLD_GLOBAL instead of RTLD_LOCAL
84
-
85
- == 0.3.1 / 2009-03-23
86
-
87
- * Bug fixes
88
- * Correctly save errno/GetLastError after each call.
89
-
90
- == 0.3.0 / 2009-03-19
91
-
92
- * Switch compilation to rake-compiler
93
- * Makes cross-compilation from linux -> win32 super easy
94
- * win32 support is available now, but highly experimental
95
- * Performance improvements
96
- * struct field access approx 3x faster than 0.2.0
97
- * function invocation approx 20% faster than 0.2.0
98
- * A bunch of minor improvements
99
- * Struct instances can now be passed as :pointer parameters without calling
100
- Struct#pointer
101
- * Support for array struct members
102
- * Structs are now padded correctly to the alignment of the struct's
103
- largest field
104
- * Global library variables
105
- * Callbacks in global library variables
106
- * Strings passed in as :string arguments are scrubbed to avoid
107
- poison-null-byte attacks.
108
- * Union support
109
- * nil can be passed as a :string argument (passed as NULL)
110
- * Structs can now be fields inside another struct
111
- * Lots of internal cleanups and refactorings.
112
-
1
+ == See git log
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2010 Ruby-FFI contributors
1
+ Copyright (c) 2008-2012 Ruby-FFI contributors
2
2
  All rights reserved.
3
3
 
4
4
  This code is free software: you can redistribute it and/or modify it under
@@ -1,5 +1,4 @@
1
1
  ruby-ffi
2
- by Wayne Meissner
3
2
  http://wiki.github.com/ffi/ffi
4
3
 
5
4
  == DESCRIPTION:
@@ -28,7 +27,7 @@ using Ruby-FFI here[http://wiki.github.com/ffi/ffi/why-use-ffi].
28
27
  attach_function :puts, [ :string ], :int
29
28
  end
30
29
 
31
- MyLib.puts 'Hello boys using libc!'
30
+ MyLib.puts 'Hello, World using libc!'
32
31
 
33
32
  For less minimalistic and more sane examples you may look at:
34
33
 
@@ -52,19 +51,6 @@ or from the git repository on github:
52
51
  cd ffi
53
52
  rake gem:install
54
53
 
55
- == CREDITS:
56
-
57
- Special thanks to:
58
-
59
- * Yehuda Katz
60
- * Luc Heinrich
61
- * Andrea Fazzi
62
- * Mike Dalessio
63
- * Hongli Lai
64
- * Evan Phoenix
65
- * Aman Gupta
66
- * Beoran
67
-
68
54
  == LICENSE:
69
55
 
70
56
  See LICENSE file.
data/Rakefile CHANGED
@@ -75,7 +75,7 @@ PROJ.name = 'ffi'
75
75
  PROJ.authors = 'Wayne Meissner'
76
76
  PROJ.email = 'wmeissner@gmail.com'
77
77
  PROJ.url = 'http://wiki.github.com/ffi/ffi'
78
- PROJ.version = '1.0.12.pre'
78
+ PROJ.version = '1.0.12.rc2'
79
79
  PROJ.rubyforge.name = 'ffi'
80
80
  PROJ.readme_file = 'README.rdoc'
81
81
 
@@ -38,6 +38,7 @@ typedef int bool;
38
38
  #include "AbstractMemory.h"
39
39
  #include "Pointer.h"
40
40
  #include "Function.h"
41
+ #include "LongDouble.h"
41
42
 
42
43
 
43
44
  static inline char* memory_address(VALUE self);
@@ -242,6 +243,7 @@ NUM_OP(long, long, NUM2LONG, LONG2NUM, SWAPSLONG);
242
243
  NUM_OP(ulong, unsigned long, NUM2ULONG, ULONG2NUM, SWAPULONG);
243
244
  NUM_OP(float32, float, NUM2DBL, rb_float_new, NOSWAP);
244
245
  NUM_OP(float64, double, NUM2DBL, rb_float_new, NOSWAP);
246
+ NUM_OP(longdouble, long double, rbffi_num2longdouble, rbffi_longdouble_new, NOSWAP);
245
247
 
246
248
  static inline void*
247
249
  get_pointer_value(VALUE value)
@@ -652,6 +654,7 @@ MemoryOps rbffi_AbstractMemoryOps = {
652
654
  &memory_op_ulong, //.uslong
653
655
  &memory_op_float32, //.float32
654
656
  &memory_op_float64, //.float64
657
+ &memory_op_longdouble, //.longdouble
655
658
  &memory_op_pointer, //.pointer
656
659
  &memory_op_strptr, //.strptr
657
660
  &memory_op_bool //.boolOp
@@ -63,6 +63,7 @@ typedef struct {
63
63
  MemoryOp* uslong;
64
64
  MemoryOp* float32;
65
65
  MemoryOp* float64;
66
+ MemoryOp* longdouble;
66
67
  MemoryOp* pointer;
67
68
  MemoryOp* strptr;
68
69
  MemoryOp* boolOp;
@@ -138,6 +139,8 @@ get_memory_op(Type* type)
138
139
  return rbffi_AbstractMemoryOps.float32;
139
140
  case NATIVE_FLOAT64:
140
141
  return rbffi_AbstractMemoryOps.float64;
142
+ case NATIVE_LONGDOUBLE:
143
+ return rbffi_AbstractMemoryOps.longdouble;
141
144
  case NATIVE_POINTER:
142
145
  return rbffi_AbstractMemoryOps.pointer;
143
146
  case NATIVE_STRING:
@@ -52,6 +52,7 @@ typedef int bool;
52
52
  #include "Call.h"
53
53
  #include "MappedType.h"
54
54
  #include "Thread.h"
55
+ #include "LongDouble.h"
55
56
 
56
57
  #ifdef USE_RAW
57
58
  # ifndef __i386__
@@ -66,6 +67,7 @@ typedef int bool;
66
67
  #define FLOAT32_ADJ (4)
67
68
  #define FLOAT64_ADJ (8)
68
69
  #define ADDRESS_ADJ (sizeof(void *))
70
+ #define LONGDOUBLE_ADJ (ffi_type_longdouble.alignment)
69
71
 
70
72
  #endif /* USE_RAW */
71
73
 
@@ -211,6 +213,12 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
211
213
  ++argidx;
212
214
  break;
213
215
 
216
+ case NATIVE_LONGDOUBLE:
217
+ param->ld = rbffi_num2longdouble(argv[argidx]);
218
+ ADJ(param, LONGDOUBLE);
219
+ ++argidx;
220
+ break;
221
+
214
222
 
215
223
  case NATIVE_STRING:
216
224
  param->ptr = getString(argv[argidx++], type);
@@ -57,6 +57,7 @@ typedef union {
57
57
  void* ptr;
58
58
  float f32;
59
59
  double f64;
60
+ long double ld;
60
61
  } FFIStorage;
61
62
 
62
63
 
@@ -61,6 +61,7 @@ typedef int bool;
61
61
  #include "Function.h"
62
62
  #include "MappedType.h"
63
63
  #include "Thread.h"
64
+ #include "LongDouble.h"
64
65
 
65
66
  typedef struct Function_ {
66
67
  Pointer base;
@@ -774,6 +775,9 @@ callback_with_gvl(void* data)
774
775
  case NATIVE_FLOAT64:
775
776
  param = rb_float_new(*(double *) parameters[i]);
776
777
  break;
778
+ case NATIVE_LONGDOUBLE:
779
+ param = rbffi_longdouble_new(*(long double *) parameters[i]);
780
+ break;
777
781
  case NATIVE_STRING:
778
782
  param = (*(void **) parameters[i] != NULL) ? rb_tainted_str_new2(*(char **) parameters[i]) : Qnil;
779
783
  break;
@@ -0,0 +1,59 @@
1
+ #include "LongDouble.h"
2
+ #include <stdio.h>
3
+ #include <stdarg.h>
4
+ #include <float.h>
5
+
6
+ static VALUE rb_cBigDecimal = Qnil;
7
+ static VALUE bigdecimal_load(VALUE unused);
8
+ static VALUE bigdecimal_failed(VALUE value);
9
+
10
+ VALUE
11
+ rbffi_longdouble_new(long double ld)
12
+ {
13
+ if (!RTEST(rb_cBigDecimal)) {
14
+ /* allow fallback if the bigdecimal library is unavailable in future ruby versions */
15
+ rb_cBigDecimal = rb_rescue(bigdecimal_load, Qnil, bigdecimal_failed, rb_cObject);
16
+ }
17
+
18
+ if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject) {
19
+ char buf[128];
20
+ return rb_funcall(rb_cBigDecimal, rb_intern("new"), 1, rb_str_new(buf, sprintf(buf, "%.35Le", ld)));
21
+ }
22
+
23
+ /* Fall through to handling as a float */
24
+ return rb_float_new(ld);
25
+ }
26
+
27
+ long double
28
+ rbffi_num2longdouble(VALUE value)
29
+ {
30
+ if (TYPE(value) == T_FLOAT) {
31
+ return rb_num2dbl(value);
32
+ }
33
+
34
+ if (!RTEST(rb_cBigDecimal) && rb_const_defined(rb_cObject, rb_intern("BigDecimal"))) {
35
+ rb_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
36
+ }
37
+
38
+ if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject && RTEST(rb_obj_is_kind_of(value, rb_cBigDecimal))) {
39
+ VALUE s = rb_funcall(value, rb_intern("to_s"), 1, rb_str_new2("E"));
40
+ return strtold(RSTRING_PTR(s), NULL);
41
+ }
42
+
43
+ /* Fall through to handling as a float */
44
+ return rb_num2dbl(value);
45
+ }
46
+
47
+
48
+ static VALUE
49
+ bigdecimal_load(VALUE unused)
50
+ {
51
+ rb_require("bigdecimal");
52
+ return rb_const_get(rb_cObject, rb_intern("BigDecimal"));
53
+ }
54
+
55
+ static VALUE
56
+ bigdecimal_failed(VALUE value)
57
+ {
58
+ return value;
59
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright (c) 2012, Wayne Meissner
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #ifndef RBFFI_LONGDOUBLE_H
22
+ #define RBFFI_LONGDOUBLE_H
23
+
24
+ #include <ruby.h>
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+
31
+ extern VALUE rbffi_longdouble_new(long double ld);
32
+ extern long double rbffi_num2longdouble(VALUE value);
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif /* RBFFI_LONGDOUBLE_H */
39
+
@@ -292,6 +292,10 @@ ptr_equals(VALUE self, VALUE other)
292
292
 
293
293
  Data_Get_Struct(self, Pointer, ptr);
294
294
 
295
+ if (NIL_P(other)) {
296
+ return ptr->memory.address == NULL ? Qtrue : Qfalse;
297
+ }
298
+
295
299
  return ptr->memory.address == POINTER(other)->address ? Qtrue : Qfalse;
296
300
  }
297
301
 
@@ -382,6 +386,11 @@ ptr_free(VALUE self)
382
386
  ptr->storage = NULL;
383
387
  }
384
388
  ptr->allocated = false;
389
+
390
+ } else {
391
+ VALUE caller = rb_funcall(rb_funcall(Qnil, rb_intern("caller"), 0), rb_intern("first"), 0);
392
+
393
+ rb_warn("calling free on non allocated pointer %s from %s", RSTRING_PTR(ptr_inspect(self)), RSTRING_PTR(rb_str_to_str(caller)));
385
394
  }
386
395
 
387
396
  return self;
@@ -146,10 +146,7 @@ struct_initialize_copy(VALUE self, VALUE other)
146
146
  // be longer than just this struct.
147
147
  //
148
148
  if (src->pointer->address != NULL) {
149
- memargs[0] = INT2FIX(1);
150
- memargs[1] = INT2FIX(src->layout->size);
151
- memargs[2] = Qfalse;
152
- dst->rbPointer = rb_class_new_instance(2, memargs, rbffi_MemoryPointerClass);
149
+ dst->rbPointer = rbffi_MemoryPointer_NewInstance(1, src->layout->size, false);
153
150
  dst->pointer = MEMORY(dst->rbPointer);
154
151
  memcpy(dst->pointer->address, src->pointer->address, src->layout->size);
155
152
  } else {
@@ -373,6 +373,7 @@ rbffi_Type_Init(VALUE moduleFFI)
373
373
  A(FLOAT32, FLOAT);
374
374
  T(FLOAT64, &ffi_type_double);
375
375
  A(FLOAT64, DOUBLE);
376
+ T(LONGDOUBLE, &ffi_type_longdouble);
376
377
  T(POINTER, &ffi_type_pointer);
377
378
  T(STRING, &ffi_type_pointer);
378
379
  T(BUFFER_IN, &ffi_type_pointer);
@@ -29,6 +29,7 @@
29
29
  #include "Struct.h"
30
30
  #include "MappedType.h"
31
31
  #include "MemoryPointer.h"
32
+ #include "LongDouble.h"
32
33
 
33
34
  static ID id_from_native = 0;
34
35
 
@@ -65,6 +66,10 @@ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr)
65
66
  return rb_float_new(*(float *) ptr);
66
67
  case NATIVE_FLOAT64:
67
68
  return rb_float_new(*(double *) ptr);
69
+
70
+ case NATIVE_LONGDOUBLE:
71
+ return rbffi_longdouble_new(*(long double *) ptr);
72
+
68
73
  case NATIVE_STRING:
69
74
  return (*(void **) ptr != NULL) ? rb_tainted_str_new2(*(char **) ptr) : Qnil;
70
75
  case NATIVE_POINTER:
@@ -40,6 +40,7 @@ typedef enum {
40
40
  NATIVE_ULONG,
41
41
  NATIVE_FLOAT32,
42
42
  NATIVE_FLOAT64,
43
+ NATIVE_LONGDOUBLE,
43
44
  NATIVE_POINTER,
44
45
  NATIVE_CALLBACK,
45
46
  NATIVE_FUNCTION,
@@ -34,6 +34,8 @@ $(LIBFFI):
34
34
  cd "$(LIBFFI_BUILD_DIR)" && $(MAKE)
35
35
 
36
36
  else
37
+ LIBTARGETS = $(foreach arch,$(ARCHES),"$(BUILD_DIR)"/libffi-$(arch)/.libs/libffi_convenience.a)
38
+
37
39
  # Build a fat binary and assemble
38
40
  build_ffi = \
39
41
  mkdir -p "$(BUILD_DIR)"/libffi-$(1); \
@@ -45,8 +47,23 @@ build_ffi = \
45
47
  fi); \
46
48
  env MACOSX_DEPLOYMENT_TARGET=10.4 $(MAKE) -C "$(BUILD_DIR)"/libffi-$(1)
47
49
 
48
- $(LIBFFI):
49
- @for arch in $(ARCHES); do $(call build_ffi,$$arch);done
50
+ target_ffi = "$(BUILD_DIR)"/libffi-$(1)/.libs/libffi_convenience.a:; $(call build_ffi,$(1))
51
+
52
+ # Work out which arches we need to compile the lib for
53
+ ifneq ($(findstring ppc,$(ARCHES)),)
54
+ $(call target_ffi,ppc)
55
+ endif
56
+
57
+ ifneq ($(findstring i386,$(ARCHES)),)
58
+ $(call target_ffi,i386)
59
+ endif
60
+
61
+ ifneq ($(findstring x86_64,$(ARCHES)),)
62
+ $(call target_ffi,x86_64)
63
+ endif
64
+
65
+
66
+ $(LIBFFI): $(LIBTARGETS)
50
67
  # Assemble into a FAT (x86_64, i386, ppc) library
51
68
  @mkdir -p "$(BUILD_DIR)"/libffi/.libs
52
69
  /usr/bin/libtool -static -o $@ \
Binary file
@@ -71,6 +71,7 @@ module FFI
71
71
  Type::UINT64,
72
72
  Type::FLOAT32,
73
73
  Type::FLOAT64,
74
+ Type::LONGDOUBLE,
74
75
  Type::BOOL,
75
76
  ]
76
77
 
@@ -46,12 +46,15 @@ module FFI
46
46
  Tempfile.open 'ffi_types_generator' do |io|
47
47
  io.puts <<-C
48
48
  #include <sys/types.h>
49
+ #if !(defined(WIN32))
49
50
  #include <sys/socket.h>
50
51
  #include <sys/resource.h>
52
+ #endif
51
53
  C
52
54
 
53
55
  io.close
54
- cmd = "gcc -E -x c #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c"
56
+ cc = ENV['CC'] || 'gcc'
57
+ cmd = "#{cc} -E -x c #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c"
55
58
  if options[:input]
56
59
  typedefs = File.read(options[:input])
57
60
  elsif options[:remote]
@@ -102,6 +102,9 @@ module FFI
102
102
  # C double precision float
103
103
  :double => Type::DOUBLE,
104
104
 
105
+ # C long double
106
+ :long_double => Type::LONGDOUBLE,
107
+
105
108
  # Native memory address
106
109
  :pointer => Type::POINTER,
107
110
 
@@ -0,0 +1,41 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
18
+ require 'bigdecimal'
19
+
20
+ describe ":long_double arguments and return values" do
21
+ module LibTest
22
+ extend FFI::Library
23
+ ffi_lib TestLibrary::PATH
24
+ attach_function :add_f128, [ :long_double, :long_double ], :long_double
25
+ attach_function :ret_f128, [ :long_double ], :long_double
26
+ end
27
+
28
+ it "returns first parameter" do
29
+ LibTest.ret_f128(0.1).should be_within(0.01).of(0.1)
30
+ end
31
+
32
+ it "returns first parameter with high precision" do
33
+ ld = BigDecimal.new("1.234567890123456789")
34
+ tolerance = BigDecimal.new("0.0000000000000000001")
35
+ LibTest.ret_f128(ld).should be_within(tolerance).of(ld)
36
+ end
37
+
38
+ it "add two long double numbers" do
39
+ LibTest.add_f128(0.1, 0.2).should be_within(0.01).of(0.3)
40
+ end
41
+ end
@@ -105,6 +105,9 @@ describe "Pointer" do
105
105
  lambda { null_ptr.read_int }.should raise_error(FFI::NullPointerError)
106
106
  lambda { null_ptr.write_int(0xff1) }.should raise_error(FFI::NullPointerError)
107
107
  end
108
+ it 'returns true when compared with nil' do
109
+ (FFI::Pointer::NULL == nil).should be_true
110
+ end
108
111
  end
109
112
 
110
113
  end
@@ -513,6 +513,8 @@ describe FFI::Struct, ' by value' do
513
513
  attach_function :struct_s8s32_get_s32, [ S8S32.by_value ], :int
514
514
  attach_function :struct_s8s32_s32_ret_s32, [ S8S32.by_value, :int ], :int
515
515
  attach_function :struct_s8s32_s64_ret_s64, [ S8S32.by_value, :long_long ], :long_long
516
+ attach_function :struct_s8s32_ret_s8s32, [ S8S32.by_value ], S8S32.by_value
517
+ attach_function :struct_s32_ptr_s32_s8s32_ret_s32, [ :int, :pointer, :int, S8S32.by_value ], :int
516
518
  attach_function :struct_varargs_ret_struct_string, [ :int, :varargs ], StructString.by_value
517
519
  end
518
520
 
@@ -548,8 +550,34 @@ describe FFI::Struct, ' by value' do
548
550
  s = LibTest::S8S32.new
549
551
  s[:s8] = 0x12
550
552
  s[:s32] = 0x34567890
553
+ end
554
+
555
+ it 'parameter with preceding s32,ptr,s32' do
556
+ s = LibTest::S8S32.new
557
+ s[:s8] = 0x12
558
+ s[:s32] = 0x34567890
559
+ out = LibTest::S8S32.new
560
+ LibTest.struct_s32_ptr_s32_s8s32_ret_s32(0x1000000, out, 0x1eafbeef, s).should eq 0x34567890
561
+ out[:s8].should eq s[:s8]
562
+ out[:s32].should eq s[:s32]
563
+ end
564
+
565
+ it 'parameter with preceding s32,string,s32' do
566
+ s = LibTest::S8S32.new
567
+ s[:s8] = 0x12
568
+ s[:s32] = 0x34567890
569
+ out = 0.chr * 32
570
+ LibTest.struct_s32_ptr_s32_s8s32_ret_s32(0x1000000, out, 0x1eafbeef, s).should eq 0x34567890
571
+ end
572
+
573
+ it 'parameter, returning struct by value' do
574
+ s = LibTest::S8S32.new
575
+ s[:s8] = 0x12
576
+ s[:s32] = 0x34567890
551
577
 
552
- LibTest.struct_s8s32_s64_ret_s64(s, 0xdeadcafebabe).should eq 0xdeadcafebabe
578
+ ret = LibTest.struct_s8s32_ret_s8s32(s)
579
+ ret[:s8].should eq s[:s8]
580
+ ret[:s32].should eq s[:s32]
553
581
  end
554
582
 
555
583
  it 'varargs returning a struct' do
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: -913866008
4
+ hash: 3008988971
5
5
  prerelease: 7
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 12
10
- - pre
11
- version: 1.0.12.pre
10
+ - rc
11
+ - 2
12
+ version: 1.0.12.rc2
12
13
  platform: x86-mingw32
13
14
  authors:
14
15
  - Wayne Meissner
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2012-02-16 00:00:00 +10:00
20
+ date: 2012-04-02 00:00:00 +10:00
20
21
  default_executable:
21
22
  dependencies: []
22
23
 
@@ -337,6 +338,8 @@ files:
337
338
  - ext/ffi_c/libffi.mk
338
339
  - ext/ffi_c/libffi.vc.mk
339
340
  - ext/ffi_c/libffi.vc64.mk
341
+ - ext/ffi_c/LongDouble.c
342
+ - ext/ffi_c/LongDouble.h
340
343
  - ext/ffi_c/MappedType.c
341
344
  - ext/ffi_c/MappedType.h
342
345
  - ext/ffi_c/MemoryPointer.c
@@ -425,6 +428,7 @@ files:
425
428
  - spec/ffi/ffi_spec.rb
426
429
  - spec/ffi/function_spec.rb
427
430
  - spec/ffi/library_spec.rb
431
+ - spec/ffi/long_double.rb
428
432
  - spec/ffi/managed_struct_spec.rb
429
433
  - spec/ffi/number_spec.rb
430
434
  - spec/ffi/pointer_spec.rb