summaryrefslogtreecommitdiff
path: root/lib/ffi
diff options
context:
space:
mode:
authormaierru <github@maier.ru>2022-01-04 16:03:29 +0300
committermaierru <github@maier.ru>2022-01-04 16:03:29 +0300
commit95522535295ea6dceaafe50c4375dbf445f4945e (patch)
tree36ca40977ea657a0dba132488d591fecf95377ce /lib/ffi
parent517b658f5f72407e1a9e61db0344a9f85dfbc230 (diff)
downloadffi-95522535295ea6dceaafe50c4375dbf445f4945e.tar.gz
prevent usage same binary file simultaneously
Diffstat (limited to 'lib/ffi')
-rw-r--r--lib/ffi/tools/const_generator.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/ffi/tools/const_generator.rb b/lib/ffi/tools/const_generator.rb
index b681e44..70ba9c2 100644
--- a/lib/ffi/tools/const_generator.rb
+++ b/lib/ffi/tools/const_generator.rb
@@ -105,9 +105,10 @@ module FFI
# @return [nil]
# @raise if a constant is missing and +:required+ was set to +true+ (see {#initialize})
def calculate(options = {})
- binary = File.join Dir.tmpdir, "rb_const_gen_bin_#{Process.pid}"
+ binary_path = nil
Tempfile.open("#{@prefix}.const_generator") do |f|
+ binary_path = f.path + ".bin"
@includes.each do |inc|
f.puts "#include <#{inc}>"
end
@@ -125,7 +126,7 @@ module FFI
f.flush
cc = ENV['CC'] || 'gcc'
- output = `#{cc} #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary} 2>&1`
+ output = `#{cc} #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary_path} 2>&1`
unless $?.success? then
output = output.split("\n").map { |l| "\t#{l}" }.join "\n"
@@ -133,8 +134,8 @@ module FFI
end
end
- output = `#{binary}`
- File.unlink(binary + (FFI::Platform.windows? ? ".exe" : ""))
+ output = `#{binary_path}`
+ File.unlink(binary_path + (FFI::Platform.windows? ? ".exe" : ""))
output.each_line do |line|
line =~ /^(\S+)\s(.*)$/
const = @constants[$1]