Skip to content

Commit 8d9a06f

Browse files
committed
Revert "turn cfg_builder_addop_i into a macro"
This reverts commit d347ba7.
1 parent 6f7d1b4 commit 8d9a06f

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

Diff for: Python/compile.c

+29-20
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct location {
134134
int end_col_offset;
135135
};
136136

137+
137138
#define LOCATION(LNO, END_LNO, COL, END_COL) \
138139
((const struct location){(LNO), (END_LNO), (COL), (END_COL)})
139140

@@ -432,6 +433,8 @@ typedef struct {
432433

433434
static int basicblock_next_instr(basicblock *);
434435

436+
static int cfg_builder_addop_i(cfg_builder *g, int opcode, Py_ssize_t oparg, struct location loc);
437+
435438
static void compiler_free(struct compiler *);
436439
static int compiler_error(struct compiler *, const char *, ...);
437440
static int compiler_warn(struct compiler *, const char *, ...);
@@ -1296,19 +1299,7 @@ cfg_builder_addop(cfg_builder *g, int opcode, int oparg, basicblock *target,
12961299

12971300
/* Add an instruction with no arg. Returns 0 on failure, 1 on success. */
12981301
#define CFG_BUILDER_ADDOP_NOARG(G, OP, LOC) \
1299-
cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, LOC)
1300-
1301-
/* Add an instructon with integer arg. Returns 0 on failure and 1 on success.
1302-
* oparg value is unsigned, but a signed C int is usually used to store
1303-
* it in the C code (like Python/ceval.c).
1304-
*
1305-
* Limit to 32-bit signed C int (rather than INT_MAX) for portability.
1306-
*
1307-
* The argument of a concrete bytecode instruction is limited to 8-bit.
1308-
* EXTENDED_ARG is used for 16, 24, and 32-bit arguments.
1309-
*/
1310-
#define CFG_BUILDER_ADDOP_I(G, OP, ARG, LOC) \
1311-
cfg_builder_addop(G, OP, Py_SAFE_DOWNCAST(ARG, Py_ssize_t, int), NULL, LOC)
1302+
cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, LOC)
13121303

13131304
/* Add a jump instruction. Returns 0 on faiure, 1 on success. */
13141305
#define CFG_BUILDER_ADDOP_J(G, OP, T, LOC) \
@@ -1471,7 +1462,7 @@ compiler_addop_load_const(struct compiler *c, PyObject *o)
14711462
Py_ssize_t arg = compiler_add_const(c, o);
14721463
if (arg < 0)
14731464
return 0;
1474-
return CFG_BUILDER_ADDOP_I(CFG_BUILDER(c), LOAD_CONST, arg, COMPILER_LOC(c));
1465+
return cfg_builder_addop_i(CFG_BUILDER(c), LOAD_CONST, arg, COMPILER_LOC(c));
14751466
}
14761467

14771468
static int
@@ -1481,7 +1472,7 @@ compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,
14811472
Py_ssize_t arg = dict_add_o(dict, o);
14821473
if (arg < 0)
14831474
return 0;
1484-
return CFG_BUILDER_ADDOP_I(CFG_BUILDER(c), opcode, arg, COMPILER_LOC(c));
1475+
return cfg_builder_addop_i(CFG_BUILDER(c), opcode, arg, COMPILER_LOC(c));
14851476
}
14861477

14871478
static int
@@ -1505,7 +1496,25 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
15051496
arg <<= 1;
15061497
arg |= 1;
15071498
}
1508-
return CFG_BUILDER_ADDOP_I(CFG_BUILDER(c), opcode, arg, COMPILER_LOC(c));
1499+
return cfg_builder_addop_i(CFG_BUILDER(c), opcode, arg, COMPILER_LOC(c));
1500+
}
1501+
1502+
/* Add an opcode with an integer argument.
1503+
Returns 0 on failure, 1 on success.
1504+
*/
1505+
static int
1506+
cfg_builder_addop_i(cfg_builder *g, int opcode, Py_ssize_t oparg, struct location loc)
1507+
{
1508+
/* oparg value is unsigned, but a signed C int is usually used to store
1509+
it in the C code (like Python/ceval.c).
1510+
1511+
Limit to 32-bit signed C int (rather than INT_MAX) for portability.
1512+
1513+
The argument of a concrete bytecode instruction is limited to 8-bit.
1514+
EXTENDED_ARG is used for 16, 24, and 32-bit arguments. */
1515+
1516+
int oparg_ = Py_SAFE_DOWNCAST(oparg, Py_ssize_t, int);
1517+
return cfg_builder_addop(g, opcode, oparg_, NULL, loc);
15091518
}
15101519

15111520

@@ -1559,12 +1568,12 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
15591568
}
15601569

15611570
#define ADDOP_I(C, OP, O) { \
1562-
if (!CFG_BUILDER_ADDOP_I(CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1571+
if (!cfg_builder_addop_i(CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
15631572
return 0; \
15641573
}
15651574

15661575
#define ADDOP_I_NOLINE(C, OP, O) { \
1567-
if (!CFG_BUILDER_ADDOP_I(CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1576+
if (!cfg_builder_addop_i(CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
15681577
return 0; \
15691578
}
15701579

@@ -4227,7 +4236,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
42274236
if (op == LOAD_GLOBAL) {
42284237
arg <<= 1;
42294238
}
4230-
return CFG_BUILDER_ADDOP_I(CFG_BUILDER(c), op, arg, COMPILER_LOC(c));
4239+
return cfg_builder_addop_i(CFG_BUILDER(c), op, arg, COMPILER_LOC(c));
42314240
}
42324241

42334242
static int
@@ -6704,7 +6713,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)
67046713
pc->fail_pop = NULL;
67056714
pc->fail_pop_size = 0;
67066715
pc->on_top = 0;
6707-
if (!CFG_BUILDER_ADDOP_I(CFG_BUILDER(c), COPY, 1, COMPILER_LOC(c)) ||
6716+
if (!cfg_builder_addop_i(CFG_BUILDER(c), COPY, 1, COMPILER_LOC(c)) ||
67086717
!compiler_pattern(c, alt, pc)) {
67096718
goto error;
67106719
}

0 commit comments

Comments
 (0)