Make the Ruby DSL use a unique filename for each implicit file.

pull/8854/head
Joshua Haberman 3 years ago
parent c5960fdcf5
commit 3d51eb5d9f
  1. 21
      ruby/lib/google/protobuf/descriptor_dsl.rb

@ -7,7 +7,24 @@ require 'google/protobuf/descriptor_pb'
module Google module Google
module Protobuf module Protobuf
module Internal module Internal
class AtomicCounter
def initialize
@n = 0
@mu = Mutex.new
end
def get_and_increment
n = @n
@mu.synchronize {
@n += 1
}
return n
end
end
class Builder class Builder
@@file_number = AtomicCounter.new
def initialize(pool) def initialize(pool)
@pool = pool @pool = pool
@default_file = nil # Constructed lazily @default_file = nil # Constructed lazily
@ -42,7 +59,9 @@ module Google
end end
private def internal_default_file private def internal_default_file
@default_file ||= FileBuilder.new(@pool, "ruby_default_file.proto") number = @@file_number.get_and_increment
filename = "ruby_default_file#{number}.proto"
@default_file ||= FileBuilder.new(@pool, filename)
end end
end end

Loading…
Cancel
Save