forked from MRtrix3/mrtrix3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_memalign
executable file
·116 lines (100 loc) · 3.38 KB
/
check_memalign
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
#!/bin/bash
LOG=memalign.log
echo -n "Checking memory alignment for Eigen 3.3 compatibility... "
echo "Checking memory alignment for Eigen 3.3 compatibility..." > $LOG
echo "" >> $LOG
retval=0
for f in $(find cmd core src -type f -name '*.h' -o -name '*.cpp' | grep -v '_moc.cpp'); do
# files to ignore:
[[ "$f" -ef "src/gui/shview/icons.h" ||
"$f" -ef "src/gui/shview/icons.cpp" ||
"$f" -ef "src/gui/mrview/icons.h" ||
"$f" -ef "src/gui/mrview/icons.cpp" ||
"$f" -ef "core/file/mgh.h" ||
"$f" -ef "core/file/json.h" ||
"$f" -ef "core/file/nifti2.h" ||
"$f" -ef "core/signal_handler.h" ||
"$f" -ef "core/signal_handler.cpp" ]] && continue
# detect classes not declared MEMALIGN or NOMEMALIGN:
res=$( \
cat $f | \
# remove C preprocessor macros:
grep -v '^#' | \
# remove C++ single-line comments:
perl -pe 's|//.*$||' | \
# remove all newlines to make file one long line:
tr '\n' ' ' | \
# remove any duplicate spaces:
perl -pe 's|\s+| |g' | \
# remove C-style comments:
perl -pe 's|/\*.*?\*/||g' | \
# remove quoted strings:
perl -pe 's/(")(\\"|.)*?"//g' | \
# remove any text within a template declaration (i.e. within <>):
perl -pe 's|<[^{};<]*?>||g' | \
# and do it multiple times to handle nested declarations:
perl -pe 's|<[^{};<]*?>||g' | \
perl -pe 's|<[^{};<]*?>||g' | \
perl -pe 's|<[^{};<]*?>||g' | \
# match for the parts we're interested in and output just the bits that match:
grep -Eo '(enum\s*)?\b(class|struct)\b[^;{]*?{(\s*(MEMALIGN\s*\([^\)]*\)|NOMEMALIGN))?' | \
# remove matches that correspond to an enum class declaration:
grep -Ev '\benum\s*class\b' | \
# remove matches that are properly specified:
grep -Ev '\b(class|struct)\b[^;{]*?{(\s*(MEMALIGN\s*\([^\)]*\)|NOMEMALIGN))'
)
# detect any instances of std::vector:
res="$res"$( \
cat $f | \
# remove C preprocessor macros:
grep -v '^#' | \
# remove C++ single-line comments:
perl -pe 's|//.*$||' | \
# remove all newlines to make file one long line:
tr '\n' ' ' | \
# remove any duplicate spaces:
perl -pe 's|\s+| |g' | \
# remove C-style comments:
perl -pe 's|/\*.*?\*/||g' | \
# remove quoted strings:
perl -pe 's/(")(\\"|.)*?"//g' | \
# match for the parts we're interested in and output just the bits that match:
grep -Po '(?<!::)std::vector\b'
)
# detect any instances of std::make_shared:
res="$res"$( \
cat $f | \
# remove C preprocessor macros:
grep -v '^#' | \
# remove C++ single-line comments:
perl -pe 's|//.*$||' | \
# remove all newlines to make file one long line:
tr '\n' ' ' | \
# remove any duplicate spaces:
perl -pe 's|\s+| |g' | \
# remove C-style comments:
perl -pe 's|/\*.*?\*/||g' | \
# remove quoted strings:
perl -pe 's/(")(\\"|.)*?"//g' | \
# match for the parts we're interested in and output just the bits that match:
grep -Po '(?<!::)std::make_shared\b'
)
# if anything is left after that, show it:
if [[ ! -z $res ]]; then
echo "################################### $f" >> $LOG
echo "$res" >> $LOG
retval=1
fi
done
# set exit code:
if [[ $retval == 0 ]]; then
echo "OK"
echo "no issues detected" >> $LOG
else
echo "FAIL"
echo "" >> $LOG
echo "Please add MEMALIGN() macro to the class declarations identified above,
replace all occurrences of std::vector with MR::vector,
and avoid use of std::make_shared" >> $LOG
exit 1
fi