forked from ned14/pcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent errors due to infinite recursion in self-referential macros
Fixes: ned14#72 Patch based on work of @MatthewShao Test created by stripping down the reproducing example in above issue.
- Loading branch information
Showing
4 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#line 5 "tests/issue0072.h" | ||
FOO(42); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#define MODIFY(x) x | ||
#define FOO MODIFY(FOO) | ||
#define DO_FOO FOO(42); | ||
|
||
DO_FOO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import absolute_import, print_function | ||
import unittest | ||
|
||
class issue0072(unittest.TestCase): | ||
def runTest(self): | ||
from pcpp import Preprocessor | ||
import os, sys | ||
|
||
p = Preprocessor() | ||
path = 'tests/issue0072.h' | ||
with open(path, 'rt') as ih: | ||
p.parse(ih.read(), path) | ||
with open('tests/issue0072.i', 'w') as oh: | ||
p.write(oh) | ||
with open('tests/issue0072.i', 'r') as ih: | ||
was = ih.read() | ||
with open('tests/issue0072-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) |