1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/leaked-globals
Yusuke Endoh 5f35b8ca30
st.c: Use rb_st_* prefix instead of st_* (#2479)
The original st.c was public domain hash table implementation, but
Ruby's st.c is highly modified, and its data structure is not
compatiblie with the original one.

Therefore, when creating an extension library to wrap C code that uses
the original st.c, the symbols conflict, which leads to segfault.

This changes the prefix `st_*` of st.c functions to `rb_st_*` for
reflecting that they are specific to Ruby's, and avoid symbol conflicts.
2019-09-22 22:12:18 +09:00

40 lines
955 B
Ruby
Executable file

#!/usr/bin/ruby
require_relative 'lib/colorize'
until ARGV.empty?
case ARGV[0]
when /\ASYMBOL_PREFIX=(.*)/
SYMBOL_PREFIX = $1
when /\ANM=(.*)/ # may be multiple words
NM = $1
else
break
end
ARGV.shift
end
config = ARGV.shift
count = 0
col = Colorize.new
REPLACE = File.read(config).scan(/\bAC_(?:REPLACE|CHECK)_FUNCS?\(\K\w+/)
print "Checking leaked global symbols..."
STDOUT.flush
IO.foreach("|#{NM} -Pgp #{ARGV.join(' ')}") do |line|
n, t, = line.split
next unless /[BDT]/ =~ t
next unless n.sub!(/^#{SYMBOL_PREFIX}/o, "")
next if n.include?(".")
next if /\A(?:Init_|InitVM_|ruby_|rb_|[Oo]nig|dln_|mjit_|coroutine_|nu(?:comp|rat)_)/ =~ n
next if REPLACE.include?(n)
puts col.fail("leaked") if count.zero?
count += 1
puts " #{n}"
end
case count
when 0
puts col.pass("none")
when 1
abort col.fail("1 un-prefixed symbol leaked")
else
abort col.fail("#{count} un-prefixed symbols leaked")
end