Skip to content

Commit

Permalink
Issue #17 Fix failure to issue #line directive for first include …
Browse files Browse the repository at this point in the history
…file in a file. Thanks to Sei-Lisa for reporting this.
  • Loading branch information
ned14 committed Jan 7, 2019
1 parent 798fcf2 commit ceb574b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ v1.20 (7th January 2019):
PLY no longer works using pypi packaging, David wants people to include the source of
PLY directly. pcpp does this via a git submodule, and has setuptools bundle the submodule.
- Add a formal LICENSE.txt file, as requested by Sei-Lisa.
- Fix failure to issue ``#line`` directive for first include file in a file. Thanks to
Sei-Lisa for reporting this.

v1.1 (19th June 2018):
----------------------
Expand Down
2 changes: 2 additions & 0 deletions pcpp/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,8 @@ def write(self, oh=sys.stdout):
emitlinedirective = (blanklines > 6) and self.line_directive is not None
if hasattr(toks[0], 'source'):
if lastsource is None:
if toks[0].source is not None:
emitlinedirective = True
lastsource = toks[0].source
elif lastsource != toks[0].source:
emitlinedirective = True
Expand Down
1 change: 0 additions & 1 deletion tests/issue0017-ref.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#line 1 "tests/issue0017/issue0017.c"
#line 1 "inc.h"
inc1

Expand Down
23 changes: 23 additions & 0 deletions tests/issue0017.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import absolute_import, print_function
import unittest

class issue0017(unittest.TestCase):
def runTest(self):
from pcpp import Preprocessor
import os, sys

p = Preprocessor()
path = 'tests/issue0017/issue0017.c'
with open(path, 'rt') as ih:
p.parse(ih.read(), path)
with open('tests/issue0017.i', 'w') as oh:
p.write(oh)
with open('tests/issue0017.i', 'r') as ih:
was = ih.read()
with open('tests/issue0017-ref.i', 'r') as ih:
shouldbe = ih.read()
if was != shouldbe:
print("Should be:\n" + shouldbe, file = sys.stderr)
print("\n\nWas:\n" + was, file = sys.stderr)
self.assertEqual(p.return_code, 0)
self.assertEqual(was, shouldbe)

0 comments on commit ceb574b

Please sign in to comment.