Remove some more C++-isms

This commit is contained in:
Fabian Boehm 2024-03-23 11:54:23 +01:00
parent d99a5bae88
commit b3ce8eee60
4 changed files with 0 additions and 367 deletions

View File

@ -1,109 +0,0 @@
#!/usr/bin/env fish
# Finds global variables by parsing the output of 'nm'
# for object files in this directory.
# This was written for macOS nm.
set -l FISH_SOURCE_DIR $argv[1]
if not test -d "$FISH_SOURCE_DIR"
echo "FISH_SOURCE_DIR not given"
exit 1
end
set -g whitelist \
# unclear what this is \
l_constinit \
# hacks to work around missing ncurses strings on mac \
sitm_esc ritm_esc dim_esc
# In our nm regex, we are interested in data (dD) and bss (bB) segments.
set -g nm_regex '^([^ ]+) ([dDbB])'
set -l total_globals 0
set -l boring_files \
fish_key_reader.cpp.o \
fish_indent.cpp.o
# return if we should ignore the given symbol name
function should_ignore
set -l symname $argv[1]
string match -q '*guard variable for*' $symname
and return 0
contains $symname $whitelist
and return 0
return 1
end
# echo a cleaned-up symbol name, e.g. replacing template gunk
function cleanup_syname
set -l symname $argv[1]
set symname (string replace --all 'std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >' 'wcstring' $symname)
set symname (string replace --all 'std::__1::vector<wcstring, std::__1::allocator<wcstring > >' 'std::vector<wcstring>' $symname)
echo $symname
end
# Output the declaration for a symbol name in a given file.
function print_decl -a FISH_SOURCE_DIR objfile symname
set -l varname (string split '::' $symname)[-1]
set -l srcfile (basename $objfile .o)
set -l srcpath $FISH_SOURCE_DIR/src/$srcfile
# A leading underscore indicates a global, strip it.
set varname (string replace --regex '^_' '' $varname)
if not test -f "$srcpath"
echo "Could not find $srcpath"
end
# Guess the variable as the first usage of the name.
# Strip everything after the first =.
set -l vardecl (egrep -m 1 " $varname\\b" $srcpath | cut -f -1 -d '=' | string trim)
if test -z "$vardecl"
echo "COULD_NOT_FIND_$varname"
return 1
end
echo $vardecl
return 0
end
# Return if a variable declaration is "thread safe".
function decl_is_threadsafe
set -l vardecl $argv[1]
# decls starting with 'const ' or containing ' const ' are assumed safe.
string match -q --regex '(^|\\*| )const ' $vardecl
and return 0
# Ordinary types indicating a safe variable.
set -l safes relaxed_atomic_bool_t std::mutex std::condition_variable std::once_flag sig_atomic_t
for safe in $safes
string match -q "*$safe*" $vardecl
and return 0
end
# Template types indicate a safe variable.
set safes owning_lock mainthread_t std::atomic relaxed_atomic_t latch_t
for safe in $safes
string match -q "*$safe<*" $vardecl
and return 0
end
end
for file in ./**.o
set -l filename (basename $file)
# Skip boring files.
contains $filename $boring_files
and continue
for line in (nm -p -P -U $file | egrep $nm_regex)
set -l matches (string match --regex $nm_regex -- $line)
or continue
set -l symname (cleanup_syname (echo $matches[2] | c++filt))
should_ignore $symname
and continue
set -l vardecl (print_decl $FISH_SOURCE_DIR $filename $symname)
decl_is_threadsafe $vardecl
and continue
echo $filename $symname $matches[3] ":" $vardecl
set total_globals (math $total_globals + 1)
end
end
echo "Total: $total_globals"

View File

@ -1,63 +0,0 @@
#!/usr/bin/env python3
# Finds potential ODR violations due to weak symbols.
# For example, if you have two different structs with the same name in different files,
# their inline constructors may collide.
# This works only on Linux. It is designed to be run from the cmake build directory.
# clang seems more willing to emit non-inlined ctors. Of course perform a Debug build.
import re
import subprocess
output = subprocess.check_output(
"nm --radix=d -g --demangle -l --print-size CMakeFiles/fishlib.dir/src/*.o",
shell=True,
universal_newlines=True,
)
files_by_name = {} # Symbol to set of paths
sizes_by_name = {} # Symbol to set of int sizes
for line in output.split("\n"):
# Keep only weak symbols with default values (e.g. emitted inline functions).
# Example line: "0000000000000000 0000000000000107 W symbol_name"
# First number is offset, second is size.
# Note this is decimal because of radix=d.
m = re.match(r"\d+ (\d+) W (.*)\t(.*)", line)
if not m:
continue
size, name, filename = m.groups()
files_by_name.setdefault(name, set()).add(filename)
sizes_by_name.setdefault(name, set()).add(int(size))
odr_violations = 0
for name, sizes in sizes_by_name.items():
if len(sizes) == 1:
continue
files = files_by_name[name]
# Ignore symbols that only appear in one file.
# These are typically headers - unclear why they get different sizes but it appears benign.
if len(files) == 1:
continue
# Multiple sizes for this symbol name.
odr_violations += 1
print("Multiple sizes for symbol: " + name)
print("\t%s" % ", ".join([str(x) for x in sizes]))
print("\tFound in files:")
for filename in files:
print("\t\t%s" % filename)
if odr_violations == 0:
print("No ODR violations found, hooray\n")
# Show potential weak symbols.
suspicious_odrs = 0
for (name, files) in files_by_name.items():
if len(files) != 1:
continue
(filename,) = files
if ".cpp" in filename:
if suspicious_odrs == 0:
print("Some suspicious singles:")
suspicious_odrs += 1
print("\t%s" % name)
print("\t\tIn file %s" % filename)

View File

@ -1,28 +0,0 @@
# Map file for the include-what-you-use tool on Linux.
[
{ include: ["<bits/fcntl-linux.h>", "private", "<fcntl.h>", "public"] },
{ include: ["<bits/mman-linux.h>", "private", "<sys/mman.h>", "public"] },
{ include: ["<bits/socket-linux.h>", "private", "<sys/socket.h>", "public"] },
{ include: ["<bits/socket_type.h>", "private", "<sys/socket.h>", "public"] },
{ include: ["<bits/local_lim.h>", "private", "<limits.h>", "public"] },
{ include: ["<tr1/memory>", "public", "<memory>", "public"] },
{ include: ["<features.h>", "public", "<stdio.h>", "public"] },
{ include: ["<features.h>", "public", "<stddef.h>", "public"] },
{ include: ["<features.h>", "public", "<unistd.h>", "public"] },
{ symbol: ["size_t", "private", "<unistd.h>", "public"] },
{ symbol: ["size_t", "private", "<stddef.h>", "public"] },
{ symbol: ["size_t", "private", "<stdlib.h>", "public"] },
{ symbol: ["intmax_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["intmax_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uint32_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["uint32_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uint64_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["uint64_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uintmax_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["uintmax_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["clock_gettime", "private", "<sys/time.h>", "public"] },
{ symbol: ["timespec", "private", "<sys/time.h>", "public"] },
{ symbol: ["memset", "private", "<string.h>", "public"] },
{ symbol: ["strerror", "private", "<string.h>", "public"] },
]

View File

@ -1,167 +0,0 @@
# Map file for the include-what-you-use tool on OS X. For some reason
# the version installed by HomeBrew doesn't have useful mappings for the
# system provided headers. This also has mappings for FreeBSD.
[
{ include: ["<__functional_base>", private, "<functional>", public ] },
{ include: ["<__mutex_base>", private, "<mutex>", public ] },
{ include: ["@<__algorithm/.*>", "private", "<algorithm>", "public"] },
{ include: ["@<__iterator/.*>", "private", "<iterator>", "public"] },
{ include: ["@<__functional/.*>", "private", "<functional>", "public"] },
{ include: ["@<__memory/.*>", "private", "<memory>", "public"] },
{ include: ["@<__utility/.*>", "private", "<utility>", "public"] },
{ include: ["@<__chrono/.*>", "private", "<chrono>", "public"] },
{ include: ["@<__numeric/.*>", "private", "<numeric>", "public"] },
{ include: ["@<__random/.*>", "private", "<random>", "public"] },
{ include: ["@<__locale/.*>", "private", "<locale>", "public"] },
{ include: ["@<xlocale/.*>", "private", "<xlocale.h>", "public"] },
# ratio false positive. See https://groups.google.com/g/include-what-you-use/c/OKVkkWUlx44
{ include: ["<ratio>", "public", "<chrono>", "public"] },
{ include: ["<__locale>", "private", "<locale>", "public"] },
{ include: ["<_ctype.h>", "private", "<ctype.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_once_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_mutex_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_rwlock_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_mutexattr_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_attr_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_cond_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_key_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthreadtypes.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_types/_posix_vdisable.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_types/_time_t.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/_types/_suseconds_t.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/_types/_suseconds_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/errno.h>", "private", "<errno.h>", "public"] },
{ include: ["<sys/unistd.h>", "private", "<unistd.h>", "public"] },
{ include: ["<_wctype.h>", "private", "<wctype.h>", "public"] },
{ include: ["<sys/fcntl.h>", "private", "<fcntl.h>", "public"] },
{ include: ["<sys/_types/_seek_set.h>", "private", "<fcntl.h>", "public"] },
{ include: ["<sys/_types/_mbstate_t.h>", "private", "<wchar.h>", "public"] },
{ include: ["<iosfwd>", "public", "<string>", "public"] },
{ include: ["<sys/_stdint.h>", "private", "<stdint.h>", "public"] },
{ include: ["<sys/_types/_s_ifmt.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_size_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_size_t.h>", "private", "<stdlib.h>", "public"] },
{ include: ["<sys/_types/_mode_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_pid_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_def.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_isset.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_set.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_zero.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_timeval.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_uid_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_intmax_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_uintmax_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_uint8_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_int32_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_uint64_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_uintptr_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_dev_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_ino_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_va_list.h>", "private", "<stdio.h>", "public"] },
{ include: ["<__functional_base>", "private", "<memory>", "public"] },
{ include: ["<__functional_base>", "private", "<vector>", "public"] },
{ include: ["<__functional_base>", "private", "<string>", "public"] },
{ include: ["<__tree>", "private", "<map>", "public"] },
{ include: ["<__tree>", "private", "<set>", "public"] },
{ include: ["<_types/_uint32_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_va_list.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_sigset_t.h>", "private", "<signal.h>", "public"] },
{ include: ["<sys/signal.h>", "private", "<signal.h>", "public"] },
{ include: ["<sys/termios.h>", "private", "<termios.h>", "public"] },
{ include: ["<sys/_termios.h>", "private", "<termios.h>", "public"] },
{ include: ["<sys/ttycom.h>", "private", "<termios.h>", "public"] },
{ include: ["<sys/syslimits.h>", "private", "<limits.h>", "public"] },
{ include: ["<i386/limits.h>", "private", "<limits.h>", "public"] },
{ include: ["<sys/limits.h>", "private", "<limits.h>", "public"] },
{ include: ["<sys/_types/_wint_t.h>", "private", "<stddef.h>", "public"] },
{ include: ["<sys/_select.h>", "private", "<select.h>", "public"] },
{ include: ["<sys/cdefs.h>", "private", "<unistd.h>", "public"] },
{ include: ["<istream>", "public", "<iostream>", "public"] },
{ include: ["<sys/_endian.h>", "private", "<netinet/in.h>", "public"] },
{ include: ["<sys/_types/_timespec.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/_timespec.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/spawn.h>", "private", "<spawn.h>", "public"] },
{ include: ["<sys/dirent.h>", "private", "<dirent.h>", "public"] },
{ include: ["<__mutex_base>", "private", "<mutex>", "public"] },
{ include: ["<__hash_table>", "private", "<unordered_map>", "public"] },
{ include: ["<__hash_table>", "private", "<unordered_set>", "public"] },
{ include: ['"../common.h"', "public", '"common.h"', "public"] },
# We provide our own assert. including assert.h/cassert spoils it and redefines the macro
{ symbol: ["assert", "private", '"common.h"', "public"] },
{ symbol: ["assert", "private", '"../common.h"', "public"] },
{ symbol: ["wcstring", "private", '"common.h"', "public"] },
{ symbol: ["wcstring", "private", '"../common.h"', "public"] },
{ symbol: ["wcstring", "private", '"flog.h"', "public"] },
{ symbol: ["size_t", "private", "<cstddef>", "public"] },
{ symbol: ["mutex", "private", "<mutex>", "public"] },
{ symbol: ["sig_atomic_t", "private", "<csignal>", "public"] },
{ symbol: ["va_end", "private", "<stdarg.h>", "public"] },
{ symbol: ["va_list", "private", "<stdarg.h>", "public"] },
{ symbol: ["va_start", "private", "<stdarg.h>", "public"] },
{ symbol: ["NULL", "private", "<cstddef>", "public"] },
{ symbol: ["NULL", "private", "<stdlib.h>", "public"] },
{ symbol: ["NULL", "private", "<stdio.h>", "public"] },
{ symbol: ["NULL", "private", "<unistd.h>", "public"] },
{ symbol: ["off_t", "private", "<unistd.h>", "public"] },
{ symbol: ["off_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["size_t", "private", "<cstddef>", "public"] },
{ symbol: ["ssize_t", "private", "<cstddef>", "public"] },
{ symbol: ["intptr_t", "private", "<unistd.h>", "public"] },
{ symbol: ["gid_t", "private", "<unistd.h>", "public"] },
{ symbol: ["uid_t", "private", "<unistd.h>", "public"] },
{ symbol: ["pid_t", "private", "<unistd.h>", "public"] },
{ symbol: ["pid_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uid_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["gid_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["timeval", "private", "<sys/time.h>", "public"] },
{ symbol: ["__uint32_t", "private", "<cstdint>", "public"] },
{ symbol: ["uint32_t", "private", "<cstdint>", "public"] },
{ symbol: ["intptr_t", "private", "<cstdint>", "public"] },
{ symbol: ["select", "private", "<sys/select.h>", "public"] },
{ symbol: ["_LIBCPP_VERSION", "private", "<cstddef>", "public"] },
{ symbol: ["_LIBCPP_VERSION", "private", "<unistd.h>", "public"] },
{ symbol: ["MB_CUR_MAX", "private", "<cstdlib>", "public"] },
{ symbol: ["MB_LEN_MAX", "private", "<cstdlib>", "public"] },
{ symbol: ["WEOF", "private", "<cwctype>", "public"] },
{ symbol: [ "std::declval", private, "<utility>", public ] },
{ symbol: [ "std::forward", private, "<utility>", public ] },
{ symbol: [ "std::move", private, "<utility>", public ] },
{ symbol: [ "std::nullptr_t", private, "<cstddef>", public ] },
{ symbol: [ "std::string", private, "<string>", public ] },
{ symbol: [ "std::isalnum", private, "<locale>", public ] },
{ symbol: [ "std::toupper", private, "<locale>", public ] },
{ symbol: [ "sem_t", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_post", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_wait", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_init", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_destroy", private, "<semaphore.h>", public ] },
{ symbol: [ "FD_SETSIZE", private, "<sys/select.h>", public ] },
{ symbol: [ "locale_t", private, "<locale>", public ] },
{ include: [ "<assert.h>", public, "<cassert>", public ] },
{ include: [ "<complex.h>", public, "<ccomplex>", public ] },
{ include: [ "<ctype.h>", public, "<cctype>", public ] },
{ include: [ "<errno.h>", public, "<cerrno>", public ] },
{ include: [ "<fenv.h>", public, "<cfenv>", public ] },
{ include: [ "<float.h>", public, "<cfloat>", public ] },
{ include: [ "<inttypes.h>", public, "<cinttypes>", public ] },
{ include: [ "<iso646.h>", public, "<ciso646>", public ] },
{ include: [ "<limits.h>", public, "<climits>", public ] },
{ include: [ "<locale.h>", public, "<clocale>", public ] },
{ include: [ "<math.h>", public, "<cmath>", public ] },
{ include: [ "<setjmp.h>", public, "<csetjmp>", public ] },
{ include: [ "<signal.h>", public, "<csignal>", public ] },
{ include: [ "<stdalign.h>", public, "<cstdalign>", public ] },
{ include: [ "<stdarg.h>", public, "<cstdarg>", public ] },
{ include: [ "<stdbool.h>", public, "<cstdbool>", public ] },
{ include: [ "<stddef.h>", public, "<cstddef>", public ] },
{ include: [ "<stdlib.h>", public, "<cstdlib>", public ] },
{ include: [ "<string.h>", public, "<cstring>", public ] },
{ include: [ "<tgmath.h>", public, "<ctgmath>", public ] },
{ include: [ "<time.h>", public, "<ctime>", public ] },
{ include: [ "<uchar.h>", public, "<cuchar>", public ] },
{ include: [ "<wchar.h>", public, "<cwchar>", public ] },
{ include: [ "<wctype.h>", public, "<cwctype>", public ] },
{ include: [ "<_xlocale.h>", private, "<xlocale.h>", public ] },
]