#!/usr/bin/env python# Script checking that all symbols exported by libpython start with Py or _Pyimport subprocessimport sysimport sysconfigdef get_exported_symbols():LIBRARY = sysconfig.get_config_var('LIBRARY')if not LIBRARY:raise Exception("failed to get LIBRARY")args = ('nm', '-p', LIBRARY)print("+ %s" % ' '.join(args))proc = subprocess.run(args, stdout=subprocess.PIPE, universal_newlines=True)if proc.returncode:sys.stdout.write(proc.stdout)sys.exit(proc.returncode)stdout = proc.stdout.rstrip()if not stdout:raise Exception("command output is empty")return stdoutdef get_smelly_symbols(stdout):symbols = []ignored_symtypes = set()for line in stdout.splitlines():# Split line '0000000000001b80 D PyTextIOWrapper_Type'if not line:continueparts = line.split(maxsplit=2)if len(parts) < 3:continuesymtype = parts[1].strip()# Ignore private symbols.## If lowercase, the symbol is usually local; if uppercase, the symbol# is global (external). There are however a few lowercase symbols that# are shown for special global symbols ("u", "v" and "w").if symtype.islower() and symtype not in "uvw":ignored_symtypes.add(symtype)continuesymbol = parts[-1]if symbol.startswith(('Py', '_Py')):continuesymbol = '%s (type: %s)' % (symbol, symtype)symbols.append(symbol)if ignored_symtypes:print("Ignored symbol types: %s" % ', '.join(sorted(ignored_symtypes)))print()return symbolsdef main():nm_output = get_exported_symbols()symbols = get_smelly_symbols(nm_output)if not symbols:print("OK: no smelly symbol found")sys.exit(0)symbols.sort()for symbol in symbols:print("Smelly symbol: %s" % symbol)print()print("ERROR: Found %s smelly symbols!" % len(symbols))sys.exit(1)if __name__ == "__main__":main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。