Skip to content

Commit 0b7829e

Browse files
authored
Compile extensions in test_peg_generator with C99 (GH-19668)
1 parent 1def775 commit 0b7829e

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

Parser/pegen/parse_string.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ static inline void shift_arg(expr_ty parent, arg_ty n, int line, int col) {
275275
}
276276

277277
static void fstring_shift_seq_locations(expr_ty parent, asdl_seq *seq, int lineno, int col_offset) {
278-
Py_ssize_t i;
279-
for (i = 0; i < asdl_seq_LEN(seq); i++) {
278+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) {
280279
expr_ty expr = asdl_seq_GET(seq, i);
281280
if (expr == NULL){
282281
continue;
@@ -323,13 +322,12 @@ static void fstring_shift_argument(expr_ty parent, arg_ty arg, int lineno, int c
323322
}
324323

325324
static void fstring_shift_arguments(expr_ty parent, arguments_ty args, int lineno, int col_offset) {
326-
Py_ssize_t i;
327-
for (i = 0; i < asdl_seq_LEN(args->posonlyargs); i++) {
325+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->posonlyargs); i < l; i++) {
328326
arg_ty arg = asdl_seq_GET(args->posonlyargs, i);
329327
shift_arg(parent, arg, lineno, col_offset);
330328
}
331329

332-
for (i = 0; i < asdl_seq_LEN(args->args); i++) {
330+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->args); i < l; i++) {
333331
arg_ty arg = asdl_seq_GET(args->args, i);
334332
shift_arg(parent, arg, lineno, col_offset);
335333
}
@@ -338,7 +336,7 @@ static void fstring_shift_arguments(expr_ty parent, arguments_ty args, int linen
338336
shift_arg(parent, args->vararg, lineno, col_offset);
339337
}
340338

341-
for (i = 0; i < asdl_seq_LEN(args->kwonlyargs); i++) {
339+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->kwonlyargs); i < l; i++) {
342340
arg_ty arg = asdl_seq_GET(args->kwonlyargs, i);
343341
shift_arg(parent, arg, lineno, col_offset);
344342
}
@@ -353,7 +351,6 @@ static void fstring_shift_arguments(expr_ty parent, arguments_ty args, int linen
353351
}
354352

355353
static void fstring_shift_children_locations(expr_ty n, int lineno, int col_offset) {
356-
Py_ssize_t i;
357354
switch (n->kind) {
358355
case BoolOp_kind:
359356
fstring_shift_seq_locations(n, n->v.BoolOp.values, lineno, col_offset);
@@ -387,29 +384,29 @@ static void fstring_shift_children_locations(expr_ty n, int lineno, int col_offs
387384
break;
388385
case ListComp_kind:
389386
shift_expr(n, n->v.ListComp.elt, lineno, col_offset);
390-
for (i = 0; i < asdl_seq_LEN(n->v.ListComp.generators); i++) {
387+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.ListComp.generators); i < l; i++) {
391388
comprehension_ty comp = asdl_seq_GET(n->v.ListComp.generators, i);
392389
fstring_shift_comprehension(n, comp, lineno, col_offset);
393390
}
394391
break;
395392
case SetComp_kind:
396393
shift_expr(n, n->v.SetComp.elt, lineno, col_offset);
397-
for (i = 0; i < asdl_seq_LEN(n->v.SetComp.generators); i++) {
394+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.SetComp.generators); i < l; i++) {
398395
comprehension_ty comp = asdl_seq_GET(n->v.SetComp.generators, i);
399396
fstring_shift_comprehension(n, comp, lineno, col_offset);
400397
}
401398
break;
402399
case DictComp_kind:
403400
shift_expr(n, n->v.DictComp.key, lineno, col_offset);
404401
shift_expr(n, n->v.DictComp.value, lineno, col_offset);
405-
for (i = 0; i < asdl_seq_LEN(n->v.DictComp.generators); i++) {
402+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.DictComp.generators); i < l; i++) {
406403
comprehension_ty comp = asdl_seq_GET(n->v.DictComp.generators, i);
407404
fstring_shift_comprehension(n, comp, lineno, col_offset);
408405
}
409406
break;
410407
case GeneratorExp_kind:
411408
shift_expr(n, n->v.GeneratorExp.elt, lineno, col_offset);
412-
for (i = 0; i < asdl_seq_LEN(n->v.GeneratorExp.generators); i++) {
409+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.GeneratorExp.generators); i < l; i++) {
413410
comprehension_ty comp = asdl_seq_GET(n->v.GeneratorExp.generators, i);
414411
fstring_shift_comprehension(n, comp, lineno, col_offset);
415412
}
@@ -430,7 +427,7 @@ static void fstring_shift_children_locations(expr_ty n, int lineno, int col_offs
430427
case Call_kind:
431428
shift_expr(n, n->v.Call.func, lineno, col_offset);
432429
fstring_shift_seq_locations(n, n->v.Call.args, lineno, col_offset);
433-
for (i = 0; i < asdl_seq_LEN(n->v.Call.keywords); i++) {
430+
for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.Call.keywords); i < l; i++) {
434431
keyword_ty keyword = asdl_seq_GET(n->v.Call.keywords, i);
435432
shift_expr(n, keyword->value, lineno, col_offset);
436433
}
@@ -521,8 +518,7 @@ fstring_fix_expr_location(Token *parent, expr_ty n, char *expr_str)
521518
}
522519
/* adjust the start based on the number of newlines encountered
523520
before the f-string expression */
524-
char *p;
525-
for (p = parent_str; p < substr; p++) {
521+
for (char* p = parent_str; p < substr; p++) {
526522
if (*p == '\n') {
527523
lines++;
528524
}

Tools/peg_generator/pegen/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pathlib
22
import shutil
33
import tokenize
4+
import sys
45

56
from typing import Optional, Tuple
67

@@ -42,6 +43,8 @@ def compile_c_extension(
4243
source_file_path = pathlib.Path(generated_source_path)
4344
extension_name = source_file_path.stem
4445
extra_compile_args = []
46+
if not sys.platform.startswith('win'):
47+
extra_compile_args.append("-std=c99")
4548
if keep_asserts:
4649
extra_compile_args.append("-UNDEBUG")
4750
extension = [

0 commit comments

Comments
 (0)