Skip to content

Commit

Permalink
Merge pull request #1195 from floooh/issue1194_genbindings_comments_w…
Browse files Browse the repository at this point in the history
…indows

gen_ir.py: comment generation fixes
  • Loading branch information
floooh authored Jan 21, 2025
2 parents cb11cc4 + 4daf0a2 commit d652051
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bindgen/gen_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def strip_comments(items):
return [i for i in items if i['kind'] != 'FullComment']

def extract_comment(comment, source):
return source[comment['range']['begin']['offset']:comment['range']['end']['offset']]
return source[comment['range']['begin']['offset']:comment['range']['end']['offset']+1].rstrip()

def is_dep_decl(decl, dep_prefixes):
for prefix in dep_prefixes:
Expand Down Expand Up @@ -134,7 +134,11 @@ def gen(header_path, source_path, module, main_prefix, dep_prefixes, with_commen
outp['prefix'] = main_prefix
outp['dep_prefixes'] = dep_prefixes
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()
first_comment = re.search(r"/\*(.*?)\*/", source, re.S).group(1)
if first_comment and "Project URL" in first_comment:
Expand Down

0 comments on commit d652051

Please sign in to comment.