@@ -433,8 +433,6 @@ typedef struct {
433
433
434
434
static int basicblock_next_instr (basicblock * );
435
435
436
- static int cfg_builder_addop_i (cfg_builder * g , int opcode , Py_ssize_t oparg , struct location loc );
437
-
438
436
static void compiler_free (struct compiler * );
439
437
static int compiler_error (struct compiler * , const char * , ...);
440
438
static int compiler_warn (struct compiler * , const char * , ...);
@@ -1269,6 +1267,17 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
1269
1267
(!HAS_TARGET (opcode ) && target == NO_TARGET ));
1270
1268
assert (!(oparg != NO_OPARG && target != NO_TARGET ));
1271
1269
1270
+ if (oparg != NO_OPARG ) {
1271
+ /* oparg value is unsigned, but a signed C int is usually used to store
1272
+ it in the C code (like Python/ceval.c).
1273
+
1274
+ Limit to 32-bit signed C int (rather than INT_MAX) for portability.
1275
+
1276
+ The argument of a concrete bytecode instruction is limited to 8-bit.
1277
+ EXTENDED_ARG is used for 16, 24, and 32-bit arguments. */
1278
+
1279
+ oparg = Py_SAFE_DOWNCAST (oparg , Py_ssize_t , int );
1280
+ }
1272
1281
int off = basicblock_next_instr (b );
1273
1282
if (off < 0 ) {
1274
1283
return 0 ;
@@ -1299,7 +1308,11 @@ cfg_builder_addop(cfg_builder *g, int opcode, int oparg, basicblock *target,
1299
1308
1300
1309
/* Add an instruction with no arg. Returns 0 on failure, 1 on success. */
1301
1310
#define CFG_BUILDER_ADDOP_NOARG (G , OP , LOC ) \
1302
- cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, LOC)
1311
+ cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, LOC)
1312
+
1313
+ /* Add an instruction with an integer arg. Returns 0 on failure, 1 on success. */
1314
+ #define CFG_BUILDER_ADDOP_I (G , OP , ARG , LOC ) \
1315
+ cfg_builder_addop(G, OP, ARG, NO_TARGET, LOC)
1303
1316
1304
1317
/* Add a jump instruction. Returns 0 on faiure, 1 on success. */
1305
1318
#define CFG_BUILDER_ADDOP_J (G , OP , T , LOC ) \
@@ -1462,7 +1475,7 @@ compiler_addop_load_const(struct compiler *c, PyObject *o)
1462
1475
Py_ssize_t arg = compiler_add_const (c , o );
1463
1476
if (arg < 0 )
1464
1477
return 0 ;
1465
- return cfg_builder_addop_i (CFG_BUILDER (c ), LOAD_CONST , arg , COMPILER_LOC (c ));
1478
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), LOAD_CONST , arg , COMPILER_LOC (c ));
1466
1479
}
1467
1480
1468
1481
static int
@@ -1472,7 +1485,8 @@ compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,
1472
1485
Py_ssize_t arg = dict_add_o (dict , o );
1473
1486
if (arg < 0 )
1474
1487
return 0 ;
1475
- return cfg_builder_addop_i (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1488
+ assert (HAS_ARG (opcode ));
1489
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1476
1490
}
1477
1491
1478
1492
static int
@@ -1496,28 +1510,9 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
1496
1510
arg <<= 1 ;
1497
1511
arg |= 1 ;
1498
1512
}
1499
- return cfg_builder_addop_i (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1513
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1500
1514
}
1501
1515
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 );
1518
- }
1519
-
1520
-
1521
1516
#define ADDOP (C , OP ) { \
1522
1517
if (!CFG_BUILDER_ADDOP_NOARG(CFG_BUILDER(C), (OP), COMPILER_LOC(C))) \
1523
1518
return 0; \
@@ -1568,12 +1563,14 @@ cfg_builder_addop_i(cfg_builder *g, int opcode, Py_ssize_t oparg, struct locatio
1568
1563
}
1569
1564
1570
1565
#define ADDOP_I (C , OP , O ) { \
1571
- if (!cfg_builder_addop_i(CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1566
+ assert(HAS_ARG(OP)); \
1567
+ if (!CFG_BUILDER_ADDOP_I(CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1572
1568
return 0; \
1573
1569
}
1574
1570
1575
1571
#define ADDOP_I_NOLINE (C , OP , O ) { \
1576
- if (!cfg_builder_addop_i(CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1572
+ assert(HAS_ARG(OP)); \
1573
+ if (!CFG_BUILDER_ADDOP_I(CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1577
1574
return 0; \
1578
1575
}
1579
1576
@@ -4236,7 +4233,8 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
4236
4233
if (op == LOAD_GLOBAL ) {
4237
4234
arg <<= 1 ;
4238
4235
}
4239
- return cfg_builder_addop_i (CFG_BUILDER (c ), op , arg , COMPILER_LOC (c ));
4236
+ assert (HAS_ARG (op ));
4237
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), op , arg , COMPILER_LOC (c ));
4240
4238
}
4241
4239
4242
4240
static int
@@ -6713,7 +6711,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)
6713
6711
pc -> fail_pop = NULL ;
6714
6712
pc -> fail_pop_size = 0 ;
6715
6713
pc -> on_top = 0 ;
6716
- if (!cfg_builder_addop_i (CFG_BUILDER (c ), COPY , 1 , COMPILER_LOC (c )) ||
6714
+ if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), COPY , 1 , COMPILER_LOC (c )) ||
6717
6715
!compiler_pattern (c , alt , pc )) {
6718
6716
goto error ;
6719
6717
}
0 commit comments