Browse Source

gen_ir.py: don't let python 'fix' line endings in input file

...otherwise the range values in the Clang ast-dump are off.
Andre Weissflog 8 tháng trước cách đây
mục cha
commit
68e9694f2f
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      bindgen/gen_ir.py

+ 5 - 1
bindgen/gen_ir.py

@@ -134,7 +134,11 @@ def gen(header_path, source_path, module, main_prefix, dep_prefixes, with_commen
     outp['prefix'] = main_prefix
     outp['prefix'] = main_prefix
     outp['dep_prefixes'] = dep_prefixes
     outp['dep_prefixes'] = dep_prefixes
     outp['decls'] = []
     outp['decls'] = []
-    with open(header_path, 'r') as f:
+    # load string with original line endings (otherwise Clang's output ranges
+    # for comments are off)
+    # NOTE: that same problem might exist for non-ASCII characters,
+    # so don't use those in header files!
+    with open(header_path, mode='r', newline='') as f:
         source = f.read()
         source = f.read()
         first_comment = re.search(r"/\*(.*?)\*/", source, re.S).group(1)
         first_comment = re.search(r"/\*(.*?)\*/", source, re.S).group(1)
         if first_comment and "Project URL" in first_comment:
         if first_comment and "Project URL" in first_comment: