ffi 1.16.2 → 1.16.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 219fb8a79026817360b4dc5b79840d000a9272beed3df581e7bac83c6fff5f4e
4
- data.tar.gz: 128fb48ada0bfc52d6806e0a5520b4d07127121d6c9353403fdf8f29606f7578
3
+ metadata.gz: 5920bab18c2bfca946febdf9d31aae894569dd1a293d816631a077696f7db8fa
4
+ data.tar.gz: 7aa17dd90399d15bd149573ab4b9857907028beae4f84409f76f50e9508aaba2
5
5
  SHA512:
6
- metadata.gz: d6f1168f0979ad74551670c5db3b5ee3a0887c1e4154aa2998150d19fa2b6084c798735e3ba4a378123d6f3ae33f126d44c83220863b896fb433ee01b28e9b7a
7
- data.tar.gz: e0bb7f8c3d0a1f9fc1385bd74ba162f4b54c2e038484d1f61d3a9fe5ddc48c90b747fedd714fca58f6f41ed8e35a60003602aaf54029ae057be3e4c3b14edbe9
6
+ metadata.gz: dd42730736988cac47f45485f4a8b200c26759066fe156a89ef7736cd6ac80f404e8aaced28a8f10f9b22b43436ed3e248cb191f1c457ccabc19299b91b49174
7
+ data.tar.gz: '0252969e7a324d530c1d704e2d408f1bd7283f320de90b4c98f20bb49f9d32733ac45609d78a40f821cd5335e102e80576fd446cd5de863babea041d0eb3c780'
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ 1.16.3 / 2023-10-04
2
+ -------------------
3
+
4
+ Fixed:
5
+ * Fix gcc error when building on CentOS 7. #1052
6
+ * Avoid trying to store new DataConverter type in frozen TypeDefs hash. #1057
7
+
8
+
1
9
  1.16.2 / 2023-09-25
2
10
  -------------------
3
11
 
data/README.md CHANGED
@@ -15,7 +15,7 @@ using Ruby-FFI](https://github.com/ffi/ffi/wiki/why-use-ffi).
15
15
  * C structs (also nested), enums and global variables
16
16
  * Callbacks from C to Ruby
17
17
  * Automatic garbage collection of native memory
18
- * Usable in Ractor
18
+ * Usable in Ractor: [How-to-use-FFI-in-Ruby-Ractors](https://github.com/ffi/ffi/wiki/Ractors)
19
19
 
20
20
  ## Synopsis
21
21
 
@@ -350,6 +350,7 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
350
350
  AbstractMemory* ptr;
351
351
  VALUE nType;
352
352
  Type *type;
353
+ MemoryOp *op;
353
354
 
354
355
  nType = rbffi_Type_Lookup(type_name);
355
356
  if(NIL_P(nType)) goto undefined_type;
@@ -357,7 +358,7 @@ memory_get(VALUE self, VALUE type_name, VALUE offset)
357
358
  TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
358
359
  TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
359
360
 
360
- MemoryOp *op = get_memory_op(type);
361
+ op = get_memory_op(type);
361
362
  if(op == NULL) goto undefined_type;
362
363
 
363
364
  return op->get(ptr, NUM2LONG(offset));
@@ -382,6 +383,7 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
382
383
  AbstractMemory* ptr;
383
384
  VALUE nType;
384
385
  Type *type;
386
+ MemoryOp *op;
385
387
 
386
388
  nType = rbffi_Type_Lookup(type_name);
387
389
  if(NIL_P(nType)) goto undefined_type;
@@ -389,7 +391,7 @@ memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
389
391
  TypedData_Get_Struct(self, AbstractMemory, &rbffi_abstract_memory_data_type, ptr);
390
392
  TypedData_Get_Struct(nType, Type, &rbffi_type_data_type, type);
391
393
 
392
- MemoryOp *op = get_memory_op(type);
394
+ op = get_memory_op(type);
393
395
  if(op == NULL) goto undefined_type;
394
396
 
395
397
  op->put(ptr, NUM2LONG(offset), value);
data/ext/ffi_c/Call.c CHANGED
@@ -427,8 +427,10 @@ getPointer(VALUE value, int type)
427
427
  } else if (type == T_DATA && rb_obj_is_kind_of(value, rbffi_StructClass)) {
428
428
 
429
429
  Struct* s;
430
+ AbstractMemory* memory;
431
+
430
432
  TypedData_Get_Struct(value, Struct, &rbffi_struct_data_type, s);
431
- AbstractMemory* memory = s->pointer;
433
+ memory = s->pointer;
432
434
  return memory != NULL ? memory->address : NULL;
433
435
 
434
436
  } else if (type == T_STRING) {
@@ -464,7 +466,9 @@ rbffi_GetInvoker(FunctionType *fnInfo)
464
466
  static void*
465
467
  callback_param(VALUE proc, VALUE cbInfo)
466
468
  {
467
- VALUE callback ;
469
+ VALUE callback;
470
+ AbstractMemory *mem;
471
+
468
472
  if (unlikely(proc == Qnil)) {
469
473
  return NULL ;
470
474
  }
@@ -479,7 +483,6 @@ callback_param(VALUE proc, VALUE cbInfo)
479
483
  callback = rbffi_Function_ForProc(cbInfo, proc);
480
484
  RB_GC_GUARD(callback);
481
485
 
482
- AbstractMemory *mem;
483
486
  TypedData_Get_Struct(callback, AbstractMemory, &rbffi_abstract_memory_data_type, mem);
484
487
  return mem->address;
485
488
  }
data/ext/ffi_c/Function.c CHANGED
@@ -953,10 +953,10 @@ invoke_callback(VALUE data)
953
953
 
954
954
  } else if (rb_obj_is_kind_of(rbReturnValue, rb_cProc) || rb_respond_to(rbReturnValue, id_call)) {
955
955
  VALUE function;
956
+ AbstractMemory* memory;
956
957
 
957
958
  function = rbffi_Function_ForProc(rbReturnType, rbReturnValue);
958
959
 
959
- AbstractMemory* memory;
960
960
  TypedData_Get_Struct(function, AbstractMemory, &rbffi_abstract_memory_data_type, memory);
961
961
 
962
962
  *((void **) retval) = memory->address;
@@ -968,8 +968,10 @@ invoke_callback(VALUE data)
968
968
  case NATIVE_STRUCT:
969
969
  if (TYPE(rbReturnValue) == T_DATA && rb_obj_is_kind_of(rbReturnValue, rbffi_StructClass)) {
970
970
  Struct* s;
971
+ AbstractMemory* memory;
972
+
971
973
  TypedData_Get_Struct(rbReturnValue, Struct, &rbffi_struct_data_type, s);
972
- AbstractMemory* memory = s->pointer;
974
+ memory = s->pointer;
973
975
 
974
976
  if (memory->address != NULL) {
975
977
  memcpy(retval, memory->address, returnType->ffiType->size);
@@ -97,7 +97,8 @@ fntype_mark(void *data)
97
97
  rb_gc_mark_movable(fnInfo->rbParameterTypes);
98
98
  rb_gc_mark_movable(fnInfo->rbEnums);
99
99
  if (fnInfo->callbackCount > 0 && fnInfo->callbackParameters != NULL) {
100
- for (size_t index = 0; index < fnInfo->callbackCount; index++) {
100
+ size_t index;
101
+ for (index = 0; index < fnInfo->callbackCount; index++) {
101
102
  rb_gc_mark_movable(fnInfo->callbackParameters[index]);
102
103
  }
103
104
  }
@@ -111,7 +112,8 @@ fntype_compact(void *data)
111
112
  ffi_gc_location(fnInfo->rbParameterTypes);
112
113
  ffi_gc_location(fnInfo->rbEnums);
113
114
  if (fnInfo->callbackCount > 0 && fnInfo->callbackParameters != NULL) {
114
- for (size_t index = 0; index < fnInfo->callbackCount; index++) {
115
+ size_t index;
116
+ for (index = 0; index < fnInfo->callbackCount; index++) {
115
117
  ffi_gc_location(fnInfo->callbackParameters[index]);
116
118
  }
117
119
  }
data/ext/ffi_c/Struct.c CHANGED
@@ -189,9 +189,11 @@ struct_initialize_copy(VALUE self, VALUE other)
189
189
  }
190
190
 
191
191
  if (src->layout->referenceFieldCount > 0) {
192
+ size_t index;
193
+
192
194
  dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount);
193
195
  memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE));
194
- for (size_t index = 0; index < dst->layout->referenceFieldCount; index++) {
196
+ for ( index = 0; index < dst->layout->referenceFieldCount; index++) {
195
197
  RB_OBJ_WRITTEN(self, Qundef, &dst->rbReferences[index]);
196
198
  }
197
199
  }
@@ -268,7 +270,8 @@ struct_mark(void *data)
268
270
  rb_gc_mark_movable(s->rbPointer);
269
271
  rb_gc_mark_movable(s->rbLayout);
270
272
  if (s->rbReferences != NULL) {
271
- for (size_t index = 0; index < s->layout->referenceFieldCount; index++) {
273
+ size_t index;
274
+ for (index = 0; index < s->layout->referenceFieldCount; index++) {
272
275
  rb_gc_mark_movable(s->rbReferences[index]);
273
276
  }
274
277
  }
@@ -281,7 +284,8 @@ struct_compact(void *data)
281
284
  ffi_gc_location(s->rbPointer);
282
285
  ffi_gc_location(s->rbLayout);
283
286
  if (s->rbReferences != NULL) {
284
- for (size_t index = 0; index < s->layout->referenceFieldCount; index++) {
287
+ size_t index;
288
+ for (index = 0; index < s->layout->referenceFieldCount; index++) {
285
289
  ffi_gc_location(s->rbReferences[index]);
286
290
  }
287
291
  }
@@ -1,9 +1,9 @@
1
1
  #! /bin/sh
2
2
  # Wrapper for compilers which do not understand '-c -o'.
3
3
 
4
- scriptversion=2012-10-14.11; # UTC
4
+ scriptversion=2018-03-07.03; # UTC
5
5
 
6
- # Copyright (C) 1999-2014 Free Software Foundation, Inc.
6
+ # Copyright (C) 1999-2021 Free Software Foundation, Inc.
7
7
  # Written by Tom Tromey <tromey@cygnus.com>.
8
8
  #
9
9
  # This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@ scriptversion=2012-10-14.11; # UTC
17
17
  # GNU General Public License for more details.
18
18
  #
19
19
  # You should have received a copy of the GNU General Public License
20
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
21
21
 
22
22
  # As a special exception to the GNU General Public License, if you
23
23
  # distribute this file as part of a program that contains a
@@ -53,7 +53,7 @@ func_file_conv ()
53
53
  MINGW*)
54
54
  file_conv=mingw
55
55
  ;;
56
- CYGWIN*)
56
+ CYGWIN* | MSYS*)
57
57
  file_conv=cygwin
58
58
  ;;
59
59
  *)
@@ -67,7 +67,7 @@ func_file_conv ()
67
67
  mingw/*)
68
68
  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
69
69
  ;;
70
- cygwin/*)
70
+ cygwin/* | msys/*)
71
71
  file=`cygpath -m "$file" || echo "$file"`
72
72
  ;;
73
73
  wine/*)
@@ -255,7 +255,8 @@ EOF
255
255
  echo "compile $scriptversion"
256
256
  exit $?
257
257
  ;;
258
- cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
258
+ cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
259
+ icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
259
260
  func_cl_wrapper "$@" # Doesn't return...
260
261
  ;;
261
262
  esac
@@ -339,9 +340,9 @@ exit $ret
339
340
  # Local Variables:
340
341
  # mode: shell-script
341
342
  # sh-indentation: 2
342
- # eval: (add-hook 'write-file-hooks 'time-stamp)
343
+ # eval: (add-hook 'before-save-hook 'time-stamp)
343
344
  # time-stamp-start: "scriptversion="
344
345
  # time-stamp-format: "%:y-%02m-%02d.%02H"
345
- # time-stamp-time-zone: "UTC"
346
+ # time-stamp-time-zone: "UTC0"
346
347
  # time-stamp-end: "; # UTC"
347
348
  # End:
data/lib/ffi/types.rb CHANGED
@@ -87,7 +87,8 @@ module FFI
87
87
  TypeDefs[name]
88
88
 
89
89
  elsif name.is_a?(DataConverter)
90
- (type_map || TypeDefs)[name] = Type::Mapped.new(name)
90
+ tm = (type_map || custom_typedefs)
91
+ tm[name] = Type::Mapped.new(name)
91
92
  else
92
93
  raise TypeError, "unable to resolve type '#{name}'"
93
94
  end
data/lib/ffi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FFI
2
- VERSION = '1.16.2'
2
+ VERSION = '1.16.3'
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'ffi'
2
+
3
+ module Foo
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ attach_function("cputs", "puts", [ :string ], :int)
7
+ freeze
8
+ end
9
+ Ractor.new do
10
+ Foo.cputs("Hello, World via libc puts using FFI in a Ractor")
11
+ end.take
@@ -0,0 +1,28 @@
1
+ require 'ffi'
2
+
3
+ module LibC
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ callback :qsort_cmp, [ :pointer, :pointer ], :int
7
+ attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int
8
+
9
+ freeze # Freeze the module variables, so that it can be shared across ractors.
10
+ end
11
+
12
+ p = FFI::MemoryPointer.new(:int, 3)
13
+ p.put_array_of_int32(0, [ 2, 3, 1 ]) # Write some unsorted data into the memory
14
+ # Ractor.make_shareable(p) # freeze the pointer to be shared between ractors instead of copied
15
+ puts "main -ptr=#{p.inspect}"
16
+ res = Ractor.new(p) do |p|
17
+ puts "ractor-ptr=#{p.inspect}"
18
+ puts "Before qsort #{p.get_array_of_int32(0, 3).join(', ')}"
19
+ LibC.qsort(p, 3, 4) do |p1, p2|
20
+ i1 = p1.get_int32(0)
21
+ i2 = p2.get_int32(0)
22
+ puts "In block: comparing #{i1} and #{i2}"
23
+ i1 < i2 ? -1 : i1 > i2 ? 1 : 0
24
+ end
25
+ puts "After qsort #{p.get_array_of_int32(0, 3).join(', ')}"
26
+ end.take
27
+
28
+ puts "After ractor termination #{p.get_array_of_int32(0, 3).join(', ')}"
data.tar.gz.sig CHANGED
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.16.2
4
+ version: 1.16.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne Meissner
@@ -33,7 +33,7 @@ cert_chain:
33
33
  Dzx/gFSOrRoCt2mXNgrmcAfr386AfaMvCh7cXqdxZwmVo7ILZCYXck0pajvubsDd
34
34
  NUIIFkVXvd1odFyK9LF1RFAtxn/iAmpx
35
35
  -----END CERTIFICATE-----
36
- date: 2023-09-25 00:00:00.000000000 Z
36
+ date: 2023-10-04 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rake
@@ -712,9 +712,11 @@ files:
712
712
  - samples/getpid.rb
713
713
  - samples/gettimeofday.rb
714
714
  - samples/hello.rb
715
+ - samples/hello_ractor.rb
715
716
  - samples/inotify.rb
716
717
  - samples/pty.rb
717
718
  - samples/qsort.rb
719
+ - samples/qsort_ractor.rb
718
720
  homepage: https://github.com/ffi/ffi/wiki
719
721
  licenses:
720
722
  - BSD-3-Clause
metadata.gz.sig CHANGED
Binary file