summaryrefslogtreecommitdiff
path: root/lib/ffi/variadic.rb
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2023-05-05 23:56:47 +0200
committerLars Kanis <lars@greiz-reinsdorf.de>2023-05-07 21:12:42 +0200
commitfe556f176d8239887fb583db2f3bb78f92a8cec2 (patch)
tree9a7eb9ed2d872ab6328a32e0a8c3f88c69bbd628 /lib/ffi/variadic.rb
parent23e88be86d5031649c4df71f75b17f33ab0a4934 (diff)
downloadffi-fe556f176d8239887fb583db2f3bb78f92a8cec2.tar.gz
Freeze immutable objects and add explicit make_shareable to make library definitions Ractor usable
Freeze objects which are immutable from the start are now freezed. This allows these objects to be used by Ractor without make_shareable. This partially reverts commit 4fc6a8c5ec8a9a720330946af9d1103015c62942 in such a way, that functions are stored in a module variable @ffi_functions. Enums are implemented per FFI::Library not per attached function. To make them shareable they would have to be copied and freezed per function. This would increase memory footprint for the sake of Ractor support. IMHO it's better to mark the module explicit as finished by .freeze to allow its use in a Ractor. This also enables querying the enum definitions from a Ractor. Using a Hash instead of per-function variables allow to use foo! and bar? methods as wished in #971. Fixes #971
Diffstat (limited to 'lib/ffi/variadic.rb')
-rw-r--r--lib/ffi/variadic.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/ffi/variadic.rb b/lib/ffi/variadic.rb
index 800d121..246b52f 100644
--- a/lib/ffi/variadic.rb
+++ b/lib/ffi/variadic.rb
@@ -54,11 +54,12 @@ module FFI
invoker = self
params = "*args"
call = "call"
- mod.module_eval <<-code
- @ffi_function_#{mname} = invoker
+ mod.module_eval <<-code, __FILE__, __LINE__
+ @ffi_functions = {} unless defined?(@ffi_functions)
+ @ffi_functions[#{mname.inspect}] = invoker
def self.#{mname}(#{params})
- @ffi_function_#{mname}.#{call}(#{params})
+ @ffi_functions[#{mname.inspect}].#{call}(#{params})
end
define_method(#{mname.inspect}, &method(:#{mname}))