Skip to content

Commit fa28c5d

Browse files
committed
Improve packaging/var-checker.
Make var-checker compare the variable type of the extern vars to ensure that they are all consistent. Fix the remaining issues.
1 parent 62bb9bb commit fa28c5d

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern int protect_args;
6666
extern int relative_paths;
6767
extern int sanitize_paths;
6868
extern int curr_dir_depth;
69-
extern int curr_dir_len;
69+
extern unsigned int curr_dir_len;
7070
extern int module_id;
7171
extern int rsync_port;
7272
extern int whole_file;

packaging/var-checker

+37-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import os, sys, re, argparse, glob
88

9-
VARS_RE = re.compile(r'^(?!(?:extern|enum)\s)([a-zA-Z]\S*\s+.*);', re.M)
9+
VARS_RE = re.compile(r'^(?!(?:extern|enum)\s)([a-zA-Z][^ \n\t:]*\s+.*);', re.M)
1010
EXTERNS_RE = re.compile(r'^extern\s+(.*);', re.M)
1111

12+
types = { }
1213
sizes = { }
1314

1415
def main():
@@ -68,19 +69,46 @@ def parse_vars(fn, lines):
6869
for line in lines:
6970
line = re.sub(r'\s*\{.*\}', '', line)
7071
line = re.sub(r'\s*\(.*\)', '', line)
71-
for item in re.split(r'\s*,\s*', line):
72-
item = re.sub(r'\s*=.*', '', item)
73-
m = re.search(r'(?P<var>\w+)(?P<sz>\[.*?\])?$', item)
72+
line = re.sub(r'\s*=\s*[^,]*', '', line)
73+
m = re.search(r'^(?:(?:static|extern)\s+)?(?P<type>[^\[,]+?)(?P<vars>\w+([\[,].+)?)$', line)
74+
if not m:
75+
print(f"Bogus match? ({line})")
76+
continue
77+
items = m['vars']
78+
main_type = m['type'].strip()
79+
mt_len = len(main_type)
80+
main_type = main_type.rstrip('*')
81+
first_stars = '*' * (mt_len - len(main_type))
82+
if first_stars:
83+
main_type = main_type.rstrip()
84+
items = first_stars + items
85+
for item in re.split(r'\s*,\s*', items):
86+
m = re.search(r'(?P<stars>\*+\s*)?(?P<var>\w+)(?P<sz>\[.*?\])?$', item)
7487
if not m:
7588
print(f"Bogus match? ({item})")
7689
continue
77-
if m['sz']:
78-
if m['var'] in sizes:
79-
if sizes[m['var']] != m['sz']:
90+
typ = main_type
91+
if m['stars']:
92+
typ = typ + m['stars'].strip()
93+
chk = [
94+
'type', typ, types,
95+
'size', m['sz'], sizes,
96+
]
97+
while chk:
98+
label = chk.pop(0)
99+
new = chk.pop(0)
100+
lst = chk.pop(0)
101+
if not new:
102+
continue
103+
if label == 'type':
104+
new = ' '.join(new.split()).replace(' *', '*')
105+
if m['var'] in lst:
106+
old = lst[m['var']]
107+
if new != old:
80108
var = m['var']
81-
print(fn, f'has inconsistent size for "{var}":', m['sz'], 'vs', sizes[var])
109+
print(fn, f'has inconsistent {label} for "{var}":', new, 'vs', old)
82110
else:
83-
sizes[m['var']] = m['sz']
111+
lst[m['var']] = new
84112
ret.append(m['var'])
85113
return ret
86114

t_stub.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int preallocate_files = 0;
2828
int protect_args = 0;
2929
int module_id = -1;
3030
int relative_paths = 0;
31-
int module_dirlen = 0;
31+
unsigned int module_dirlen = 0;
3232
int preserve_xattrs = 0;
3333
int preserve_perms = 0;
3434
int preserve_executability = 0;

0 commit comments

Comments
 (0)