Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue with SConsCPPConditionalScanner misinterpreting ifdefs suffixed with L or UL #4624

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
- Added error handling when creating MS VC detection debug log file specified by
SCONS_MSCOMMON_DEBUG

From William Deegan:
- Fix SConsCPPConditionalScanner to properly handle #ifdefs with non number prefixing numbers followed by UL or L.
Previously it was removing the L or UL when that should only have been done when a only numbers preceded them.

From Alex James:
- On Darwin, PermissionErrors are now handled while trying to access
/etc/paths.d. This may occur if SCons is invoked in a sandboxed
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ FIXES
- Skip running a few validation tests if the user is root and the test is
not designed to work for the root user.

- Fix SConsCPPConditionalScanner to properly handle ifdefs with non number prefixing numbers followed by UL or L.
Previously it was removing the L or UL when that should only have been done when a only numbers preceded them.

IMPROVEMENTS
------------

Expand Down
2 changes: 1 addition & 1 deletion SCons/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def Cleanup_CPP_Expressions(ts):
[r'defined\s+(\w+)', '"\\1" in __dict__'],
[r'defined\s*\((\w+)\)', '"\\1" in __dict__'],
[r'(0x[0-9A-Fa-f]+)(?:L|UL)?', '\\1'],
[r'(\d+)(?:L|UL)?', '\\1'],
[r'^(\d+)(?:L|ULL|UL|U)?', '\\1'],
]

# Replace the string representations of the regular expressions in the
Expand Down
94 changes: 87 additions & 7 deletions SCons/cppTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,60 @@
#include <file30-no>
#endif

#if 123456789UL || 0x13L
#include <file301-yes>
#if 123456789UL
#include <file301ul-yes>
#else
#include <file301-no>
#include <file301ul-no>
#endif

#if 1234U
#include <file301u-yes>
#else
#include <file301u-no>
#endif

#if 1234L
#include <file301l-yes>
#else
#include <file301l-no>
#endif

#if 1234ULL
#include <file301ull-yes>
#else
#include <file301ull-no>
#endif

#define X1234UL 1
#if X1234UL
#include <file302-yes>
#else
#include <file302-no>
#endif

#define X1234U 1
#if X1234U
#include <file303-yes>
#else
#include <file303-no>
#endif

#define X1234L 1
#if X1234L
#include <file304-yes>
#else
#include <file304-no>
#endif

#define X1234ULL 1
#if X1234ULL
#include <file305-yes>
#else
#include <file305-no>
#endif



"""


Expand Down Expand Up @@ -480,7 +529,12 @@ def test_expression(self) -> None:
"""Test #if with arithmetic expressions"""
expect = self.expression_expect
result = self.cpp.process_contents(expression_input)
assert expect == result, (expect, result)
if expect != result:
for e,r in zip(expect, result):
if e != r:
print("XXXX->",end="")
print(f"{e}: {r}")
assert expect == result, f"\nexpect:{expect}\nresult:{result}"

def test_undef(self) -> None:
"""Test #undef handling"""
Expand Down Expand Up @@ -588,7 +642,17 @@ class PreProcessorTestCase(cppAllTestCase):
('include', '<', 'file28-yes'),
('include', '"', 'file29-yes'),
('include', '<', 'file30-yes'),
('include', '<', 'file301-yes'),

('include', '<', 'file301ul-yes'),
('include', '<', 'file301u-yes'),
('include', '<', 'file301l-yes'),
('include', '<', 'file301ull-yes'),

('include', '<', 'file302-yes'),
('include', '<', 'file303-yes'),
('include', '<', 'file304-yes'),
('include', '<', 'file305-yes'),

]

undef_expect = [
Expand Down Expand Up @@ -717,8 +781,24 @@ class DumbPreProcessorTestCase(cppAllTestCase):
('include', '"', 'file29-yes'),
('include', '<', 'file30-yes'),
('include', '<', 'file30-no'),
('include', '<', 'file301-yes'),
('include', '<', 'file301-no'),

('include', '<', 'file301ul-yes'),
('include', '<', 'file301ul-no'),
('include', '<', 'file301u-yes'),
('include', '<', 'file301u-no'),
('include', '<', 'file301l-yes'),
('include', '<', 'file301l-no'),
('include', '<', 'file301ull-yes'),
('include', '<', 'file301ull-no'),

('include', '<', 'file302-yes'),
('include', '<', 'file302-no'),
('include', '<', 'file303-yes'),
('include', '<', 'file303-no'),
('include', '<', 'file304-yes'),
('include', '<', 'file304-no'),
('include', '<', 'file305-yes'),
('include', '<', 'file305-no'),
]

undef_expect = [
Expand Down
Loading