ffi 1.1.0.rc3 → 1.1.0.rc4

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.

data/Rakefile CHANGED
@@ -74,7 +74,7 @@ PROJ.name = 'ffi'
74
74
  PROJ.authors = 'Wayne Meissner'
75
75
  PROJ.email = 'wmeissner@gmail.com'
76
76
  PROJ.url = 'http://wiki.github.com/ffi/ffi'
77
- PROJ.version = '1.1.0.rc3'
77
+ PROJ.version = '1.1.0.rc4'
78
78
  PROJ.rubyforge.name = 'ffi'
79
79
  PROJ.readme_file = 'README.rdoc'
80
80
 
@@ -357,7 +357,7 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
357
357
  layout->fieldCount = (int) RARRAY_LEN(fields);
358
358
  layout->rbFieldMap = rb_hash_new();
359
359
  layout->rbFieldNames = rb_ary_new2(layout->fieldCount);
360
- layout->size = NUM2INT(size);
360
+ layout->size = FFI_ALIGN(NUM2INT(size), NUM2INT(align));
361
361
  layout->align = NUM2INT(align);
362
362
  layout->fields = xcalloc(layout->fieldCount, sizeof(StructField *));
363
363
  layout->ffiTypes = xcalloc(layout->fieldCount + 1, sizeof(ffi_type *));
@@ -410,6 +410,40 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
410
410
  return self;
411
411
  }
412
412
 
413
+ static VALUE
414
+ struct_layout_union_bang(VALUE self)
415
+ {
416
+ static const ffi_type *alignment_types[] = { &ffi_type_sint8, &ffi_type_sint16, &ffi_type_sint32, &ffi_type_sint64,
417
+ &ffi_type_float, &ffi_type_double, &ffi_type_longdouble, NULL };
418
+ StructLayout* layout;
419
+ ffi_type *t = NULL;
420
+ int count, i;
421
+
422
+ Data_Get_Struct(self, StructLayout, layout);
423
+
424
+ for (i = 0; alignment_types[i] != NULL; ++i) {
425
+ if (alignment_types[i]->alignment == layout->align) {
426
+ t = alignment_types[i];
427
+ break;
428
+ }
429
+ }
430
+ if (t == NULL) {
431
+ rb_raise(rb_eRuntimeError, "cannot create libffi union representation for alignment %d", layout->align);
432
+ return Qnil;
433
+ }
434
+
435
+ count = layout->size / t->size;
436
+ xfree(layout->ffiTypes);
437
+ layout->ffiTypes = xcalloc(count + 1, sizeof(ffi_type *));
438
+ layout->base.ffiType->elements = layout->ffiTypes;
439
+
440
+ for (i = 0; i < count; ++i) {
441
+ layout->ffiTypes[i] = t;
442
+ }
443
+
444
+ return self;
445
+ }
446
+
413
447
  static VALUE
414
448
  struct_layout_aref(VALUE self, VALUE field)
415
449
  {
@@ -515,6 +549,7 @@ rbffi_StructLayout_Init(VALUE moduleFFI)
515
549
  rb_define_method(rbffi_StructLayoutClass, "fields", struct_layout_fields, 0);
516
550
  rb_define_method(rbffi_StructLayoutClass, "members", struct_layout_members, 0);
517
551
  rb_define_method(rbffi_StructLayoutClass, "to_a", struct_layout_to_a, 0);
552
+ rb_define_method(rbffi_StructLayoutClass, "__union!", struct_layout_union_bang, 0);
518
553
 
519
554
  }
520
555
 
@@ -108,7 +108,9 @@ module FFI
108
108
  # Add tail padding if the struct is not packed
109
109
  size = @packed ? @size : align(@size, @alignment)
110
110
 
111
- StructLayout.new(@fields, size, @alignment)
111
+ layout = StructLayout.new(@fields, size, @alignment)
112
+ layout.__union! if @union
113
+ layout
112
114
  end
113
115
 
114
116
  private
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.rc3
4
+ version: 1.1.0.rc4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-21 00:00:00.000000000 Z
12
+ date: 2012-05-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Ruby-FFI is a ruby extension for programmatically loading dynamic
15
15