Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit d3191f5

Browse files
author
Thomas Nagy
committed
handle empty defines when pasting tokens
1 parent afad85c commit d3191f5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/preproc/wscript

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ def build(bld):
142142
'e' : 'e a || b || c || d'
143143
}
144144

145+
146+
def test_pasting():
147+
main = bld.path.find_resource('src/pasting.c')
148+
defs = ['PREFIX_VAL=', 'SUFFIX_VAL=']
149+
bld.env['DEFINES'] = ["%s %s" %(x[0], trimquotes('='.join(x[1:]))) for x in [y.split('=') for y in defs]]
150+
gruik = c_preproc.c_parser([main.parent])
151+
gruik.start(main, bld.env)
152+
if len(gruik.nodes) == 1 and gruik.nodes[0].name == 'a.h':
153+
color = "GREEN"
154+
else:
155+
color = "RED"
156+
pprint(color, "token pasting -> %r (expected a.h)" % gruik.nodes)
157+
158+
test_pasting()
159+
145160
def test(x, result):
146161
toks = c_preproc.tokenize(x)
147162
c_preproc.reduce_tokens(toks, defs, [])
@@ -156,6 +171,7 @@ def build(bld):
156171
test('a&&b&&c&&d', 0)
157172
test('e', 1)
158173

174+
159175
return
160176
test("1?1,(0?5:9):3,4", 0) # <- invalid expression
161177

waflib/Tools/c_preproc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def reduce_tokens(lst, defs, ban=[]):
478478
if one_param: args.append(one_param)
479479
break
480480
elif v2 == ',':
481-
if not one_param: raise PreprocError("empty param in funcall %s" % p)
481+
if not one_param: raise PreprocError("empty param in funcall %s" % v)
482482
args.append(one_param)
483483
one_param = []
484484
else:
@@ -645,7 +645,11 @@ def extract_macro(txt):
645645
return (name, [params, t[i+1:]])
646646
else:
647647
(p, v) = t[0]
648-
return (v, [[], t[1:]])
648+
if len(t) > 1:
649+
return (v, [[], t[1:]])
650+
else:
651+
# empty define, assign an empty token
652+
return (v, [[], [('T','')]])
649653

650654
re_include = re.compile('^\s*(<(?P<a>.*)>|"(?P<b>.*)")')
651655
def extract_include(txt, defs):

0 commit comments

Comments
 (0)