summaryrefslogtreecommitdiff
path: root/tool/leaked-globals
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-16 23:26:57 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-16 23:34:01 +0900
commit23751a2681abd50e9081bdbb00f818942570c872 (patch)
tree252ec32a1e204cba3479caf5268dc6c32c4ba460 /tool/leaked-globals
parente0f0ab959e9a0fa3db8dfdb2a493b057d6e7541b (diff)
leaked-globals: check if un-prefixed symbols leak externally
Diffstat (limited to 'tool/leaked-globals')
-rwxr-xr-xtool/leaked-globals40
1 files changed, 40 insertions, 0 deletions
diff --git a/tool/leaked-globals b/tool/leaked-globals
new file mode 100755
index 0000000000..48e8ec74c7
--- /dev/null
+++ b/tool/leaked-globals
@@ -0,0 +1,40 @@
+#!/usr/bin/ruby
+require_relative '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|st_|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