Skip to content

Commit

Permalink
Windows fix: normalizes extra_incdir, universal_newlines on preproces…
Browse files Browse the repository at this point in the history
…sor output.

When input is a filename without directory, the dirname is empty, which inserts `-I `, instead of ` -I .`, which breaks the command.
Remedied with os.path.normpath

On Windows with MinGW gcc, preprocessor output has Windows newlines, which pycparser can't handle.
Remedied by universal_newlines=True for subprocess.
  • Loading branch information
Per Rosengren committed Sep 14, 2016
1 parent 064b143 commit 2e619ce
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions autopxd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ def lines(self):


def preprocess(code, extra_cpp_args=[]):
proc = subprocess.Popen([
'cpp', '-nostdinc', '-D__attribute__(x)=', '-I', BUILTIN_HEADERS_DIR,
] + extra_cpp_args + ['-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc = subprocess.Popen(
['cpp', '-nostdinc', '-D__attribute__(x)=',
'-I', BUILTIN_HEADERS_DIR] +
extra_cpp_args + ['-'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
result = []
result.append(proc.communicate(input=code.encode('utf-8'))[0])
while proc.poll() is None:
Expand All @@ -328,7 +330,7 @@ def parse(code, extra_cpp_args=[]):


def translate(code, hdrname, extra_cpp_args=[]):
extra_incdir = os.path.dirname(hdrname)
extra_incdir = os.path.normpath(os.path.dirname(hdrname))
p = AutoPxd(hdrname)
p.visit(parse(code, extra_cpp_args=['-I', extra_incdir]))
return str(p)
Expand Down

0 comments on commit 2e619ce

Please sign in to comment.