Skip to content

Commit 1df5a9e

Browse files
authored
bpo-40334: Fix build errors and warnings in test_peg_generator (GH-19672)
1 parent ee40e4b commit 1df5a9e

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Parser/pegen/pegen.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,16 @@ _PyPegen_is_memoized(Parser *p, int type, void *pres)
640640
return 0;
641641
}
642642

643+
644+
int
645+
_PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p)
646+
{
647+
int mark = p->mark;
648+
void *res = func(p);
649+
p->mark = mark;
650+
return (res != NULL) == positive;
651+
}
652+
643653
int
644654
_PyPegen_lookahead_with_string(int positive, void *(func)(Parser *, const char *), Parser *p,
645655
const char *arg)
@@ -663,7 +673,7 @@ int
663673
_PyPegen_lookahead(int positive, void *(func)(Parser *), Parser *p)
664674
{
665675
int mark = p->mark;
666-
void *res = func(p);
676+
void *res = (void*)func(p);
667677
p->mark = mark;
668678
return (res != NULL) == positive;
669679
}

Parser/pegen/pegen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int _PyPegen_insert_memo(Parser *p, int mark, int type, void *node);
8585
int _PyPegen_update_memo(Parser *p, int mark, int type, void *node);
8686
int _PyPegen_is_memoized(Parser *p, int type, void *pres);
8787

88+
int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *);
8889
int _PyPegen_lookahead_with_string(int, void *(func)(Parser *, const char *), Parser *, const char *);
8990
int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int);
9091
int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *);

Tools/peg_generator/pegen/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from distutils.core import Distribution, Extension
1010
from distutils.command.clean import clean # type: ignore
1111
from distutils.command.build_ext import build_ext # type: ignore
12+
from distutils.tests.support import fixup_build_ext
1213

1314
from pegen.c_generator import CParserGenerator
1415
from pegen.grammar import Grammar
@@ -69,6 +70,7 @@ def compile_c_extension(
6970
]
7071
dist = Distribution({"name": extension_name, "ext_modules": extension})
7172
cmd = build_ext(dist)
73+
fixup_build_ext(cmd)
7274
cmd.inplace = True
7375
if build_dir:
7476
cmd.build_temp = build_dir

Tools/peg_generator/pegen/c_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def lookahead_call_helper(self, node: Lookahead, positive: int) -> Tuple[None, s
9393
func, args = call.split("(", 1)
9494
assert args[-1] == ")"
9595
args = args[:-1]
96-
if not args.startswith("p,"):
96+
if "name_token" in call:
97+
return None, f"_PyPegen_lookahead_with_name({positive}, {func}, {args})"
98+
elif not args.startswith("p,"):
9799
return None, f"_PyPegen_lookahead({positive}, {func}, {args})"
98100
elif args[2:].strip().isalnum():
99101
return None, f"_PyPegen_lookahead_with_int({positive}, {func}, {args})"

0 commit comments

Comments
 (0)