From 95522535295ea6dceaafe50c4375dbf445f4945e Mon Sep 17 00:00:00 2001 From: maierru Date: Tue, 4 Jan 2022 16:03:29 +0300 Subject: prevent usage same binary file simultaneously --- lib/ffi/tools/const_generator.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/ffi') 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] -- cgit v1.2.1