Skip to content

Commit 3ecbf96

Browse files
committed
fix: fix build
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent dbc6979 commit 3ecbf96

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

deps/libffi/sanitize-asm.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
import re
54
from pathlib import Path
65

76

87
def normalize_path(value):
98
return str(value).strip().strip('"')
109

1110

12-
DIRECTIVE_PREFIX = re.compile(r'^\s*\ufeff?#')
11+
def decode_source(raw):
12+
for encoding in ('utf-8-sig', 'utf-16', 'latin-1'):
13+
try:
14+
return raw.decode(encoding)
15+
except UnicodeDecodeError:
16+
continue
17+
return raw.decode('latin-1', errors='replace')
1318

1419

1520
def sanitize_asm(input_path, output_path):
16-
source = Path(normalize_path(input_path)).read_text(encoding='utf-8')
21+
source = decode_source(Path(normalize_path(input_path)).read_bytes())
22+
source = source.replace('\x00', '')
23+
1724
lines = []
1825
for line in source.splitlines(keepends=True):
19-
if DIRECTIVE_PREFIX.match(line):
26+
if line.lstrip().startswith('#'):
2027
continue
2128
lines.append(line)
2229

23-
Path(normalize_path(output_path)).write_text(''.join(lines), encoding='utf-8')
30+
Path(normalize_path(output_path)).write_text(''.join(lines), encoding='utf-8', newline='')
2431

2532

2633
def main(argv=None):

0 commit comments

Comments
 (0)