1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#! /bin/sh
t=__wt.$$
trap 'rm -f $t' 0 1 2 3 13 15
cd ..
# Parse a C file, discarding functions that don't return an int, and formatting
# the remaining functions as a single line.
file_parse()
{
sed -n \
-e '/^int$/b loop' \
-e '/^static int$/b loop' \
-e '/^static inline int$/b loop' \
-e 'd' \
-e ': loop' \
-e 'H' \
-e 'n' \
-e '/^}$/!b loop' \
-e 'H' \
-e 'x' \
-e 's/\n/ /g' \
-e 'p' \
-e 's/.*//' \
-e 'x' \
-e 'd' $1
}
# Strip out a list of functions that will be flagged, but are OK.
func_ok()
{
sed \
-e '/int __bm_stat$/d' \
-e '/int __checkpoint_presync$/d' \
-e '/int __compact_uri_analyze$/d' \
-e '/int __config_parser_close$/d' \
-e '/int __curlog_reset$/d' \
-e '/int __cursor_fix_implicit$/d' \
-e '/int __handle_close_default$/d' \
-e '/int __handle_progress_default$/d' \
-e '/int __im_file_close$/d' \
-e '/int __im_file_lock$/d' \
-e '/int __im_file_size$/d' \
-e '/int __im_file_sync$/d' \
-e '/int __im_fs_directory_list_free$/d' \
-e '/int __im_fs_exist$/d' \
-e '/int __page_write_gen_wrapped_check$/d' \
-e '/int __posix_terminate$/d' \
-e '/int __rec_destroy_session$/d' \
-e '/int __tree_walk_skip_count_callback$/d' \
-e '/int __txn_rollback_to_stable_custom_skip$/d' \
-e '/int __win_terminate$/d' \
-e '/int __wt_block_compact_end$/d' \
-e '/int __wt_block_compact_start$/d' \
-e '/int __wt_block_manager_size$/d' \
-e '/int __wt_block_write_size$/d' \
-e '/int __wt_buf_catfmt$/d' \
-e '/int __wt_buf_fmt$/d' \
-e '/int __wt_count_birthmarks$/d' \
-e '/int __wt_curjoin_joined$/d' \
-e '/int __wt_cursor_noop$/d' \
-e '/int __wt_epoch$/d' \
-e '/int __wt_errno$/d' \
-e '/int __wt_get_vm_pagesize$/d' \
-e '/int __wt_lsm_manager_pop_entry$/d' \
-e '/int __wt_once$/d' \
-e '/int __wt_posix_directory_list_free$/d' \
-e '/int __wt_session_breakpoint$/d' \
-e '/int __wt_set_return_func$/d' \
-e '/int __wt_spin_init$/d' \
-e '/int __wt_spin_trylock$/d' \
-e '/int __wt_stat_connection_desc$/d' \
-e '/int __wt_stat_dsrc_desc$/d' \
-e '/int __wt_stat_join_desc$/d' \
-e '/int __wt_stat_session_desc/d' \
-e '/int __wt_txn_rollback_required$/d' \
-e '/int __wt_win_directory_list_free$/d' \
-e '/int bdb_compare_reverse$/d' \
-e '/int copyout_val$/d' \
-e '/int csv_error$/d' \
-e '/int csv_terminate$/d' \
-e '/int demo_file_close$/d' \
-e '/int demo_file_lock$/d' \
-e '/int demo_file_size$/d' \
-e '/int demo_file_sync$/d' \
-e '/int demo_fs_directory_list_free$/d' \
-e '/int demo_fs_exist$/d' \
-e '/int fail_file_lock$/d' \
-e '/int fail_file_sync$/d' \
-e '/int fail_fs_directory_list_free$/d' \
-e '/int fail_fs_exist$/d' \
-e '/int fail_fs_simulate_fail$/d' \
-e '/int fail_fs_terminate$/d' \
-e '/int handle_message$/d' \
-e '/int handle_progress$/d' \
-e '/int index_compare_S$/d' \
-e '/int index_compare_primary$/d' \
-e '/int index_compare_u$/d' \
-e '/int index_extractor_u$/d' \
-e '/int log_print_err$/d' \
-e '/int lz4_error$/d' \
-e '/int lz4_pre_size$/d' \
-e '/int lz4_terminate$/d' \
-e '/int main$/d' \
-e '/int nop_decompress$/d' \
-e '/int nop_decrypt$/d' \
-e '/int nop_error$/d' \
-e '/int nop_pre_size$/d' \
-e '/int nop_sizing$/d' \
-e '/int nop_terminate$/d' \
-e '/int os_errno$/d' \
-e '/int revint_terminate$/d' \
-e '/int rotn_error$/d' \
-e '/int rotn_sizing$/d' \
-e '/int rotn_terminate$/d' \
-e '/int snappy_pre_size$/d' \
-e '/int snappy_terminate$/d' \
-e '/int subtest_error_handler$/d' \
-e '/int test_las_workload$/d' \
-e '/int uri2name$/d' \
-e '/int usage$/d' \
-e '/int util_err$/d' \
-e '/int wiredtiger_extension_init$/d' \
-e '/int wiredtiger_extension_terminate$/d' \
-e '/int wiredtiger_pack_close$/d' \
-e '/int zlib_error$/d' \
-e '/int zlib_terminate$/d' \
-e '/int zstd_error$/d' \
-e '/int zstd_pre_size$/d' \
-e '/int zstd_terminate$/d'
}
for f in `find bench ext src test -name '*.[ci]'`; do
if expr "$f" : '.*/windows_shim.c' > /dev/null; then
continue
fi
# Complain about functions which return an "int" but which don't return
# except at the end of the function.
#
# Turn each function into a single line, then discard the function's
# final "return" call, then discard any function that still has some
# form of return assignment or call.
file_parse $f |
sed -e 's/return ([^)]*); }$//' \
-e '/[_A-Z]*_API_CALL[_A-Z]*(/d' \
-e '/WT_CURSOR_NEEDKEY(/d' \
-e '/WT_CURSOR_NEEDVALUE(/d' \
-e '/WT_ERR[A-Z_]*(/d' \
-e '/WT_PANIC[A-Z_]*(/d' \
-e '/WT_RET[A-Z_]*(/d' \
-e '/WT_SIZE_CHECK_PACK(/d' \
-e '/WT_SIZE_CHECK_UNPACK(/d' \
-e '/WT_SYSCALL(/d' \
-e '/WT_TRET(/d' \
-e '/[^a-z_]ret = /d' \
-e '/[^a-z_]return (/d' \
-e 's/^\([^(]*\).*/\1/' \
-e 's/^ *//' |
func_ok > $t
test -s $t && {
echo "=============================================="
echo "$f:"
cat $t | sed 's/^/ /'
echo "Function could return void instead of int."
echo "Add false positives to the list in dist/s_void."
echo "=============================================="
}
# Complain about functions which declare a "ret" value but never use it.
file_parse $f |
grep 'WT_DECL_RET' |
sed -e '/ret =/d' \
-e '/[_A-Z]*_API_CALL[_A-Z]*(/d' \
-e '/WT_CURSOR_NEEDKEY/d' \
-e '/WT_CURSOR_NEEDVALUE/d' \
-e '/WT_ERR/d' \
-e '/WT_SYSCALL.*ret/d' \
-e '/WT_TRET/d' \
-e 's/^\([^(]*\).*/\1/' \
-e 's/^ *//' > $t
test -s $t && {
echo "=============================================="
echo "$f:"
cat $t | sed 's/^/ /'
echo "Function declares ret without using it."
echo "Add false positives to the list in dist/s_void."
echo "=============================================="
}
done
exit 0
|