Skip to content

Commit fc74555

Browse files
committed
define static no_location in function scope
1 parent c23e2cf commit fc74555

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Python/compile.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct location {
159159
#define LOCATION(LNO, END_LNO, COL, END_COL) \
160160
((const struct location){(LNO), (END_LNO), (COL), (END_COL)})
161161

162-
static struct location NO_LOCATION = (LOCATION(-1, -1, -1, -1));
162+
#define NO_LOCATION (LOCATION(-1, -1, -1, -1))
163163

164164
struct instr {
165165
int i_opcode;
@@ -1283,6 +1283,8 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
12831283
IS_BLOCK_PUSH_OPCODE(opcode));
12841284
assert(oparg == 0 || target == NULL);
12851285

1286+
static struct location no_location = NO_LOCATION;
1287+
12861288
int off = basicblock_next_instr(b);
12871289
if (off < 0) {
12881290
return 0;
@@ -1291,7 +1293,7 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
12911293
i->i_opcode = opcode;
12921294
i->i_oparg = oparg;
12931295
i->i_target = target;
1294-
i->i_loc = *loc;
1296+
i->i_loc = loc ? *loc : no_location;
12951297

12961298
return 1;
12971299
}
@@ -1304,7 +1306,7 @@ compiler_addop(struct compiler *c, int opcode, bool line)
13041306
return -1;
13051307
}
13061308

1307-
const struct location *loc = line ? &c->u->u_loc : &NO_LOCATION;
1309+
const struct location *loc = line ? &c->u->u_loc : NULL;
13081310
return basicblock_addop(c->u->u_curblock, opcode, 0, NULL, loc);
13091311
}
13101312

@@ -1512,7 +1514,7 @@ compiler_addop_i(struct compiler *c, int opcode, Py_ssize_t oparg, bool line)
15121514

15131515
int oparg_ = Py_SAFE_DOWNCAST(oparg, Py_ssize_t, int);
15141516

1515-
const struct location *loc = line ? &c->u->u_loc : &NO_LOCATION;
1517+
const struct location *loc = line ? &c->u->u_loc : NULL;
15161518
return basicblock_addop(c->u->u_curblock, opcode, oparg_, NULL, loc);
15171519
}
15181520

@@ -1522,7 +1524,7 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *target, bool line)
15221524
if (compiler_use_new_implicit_block_if_needed(c) < 0) {
15231525
return -1;
15241526
}
1525-
const struct location *loc = line ? &c->u->u_loc : &NO_LOCATION;
1527+
const struct location *loc = line ? &c->u->u_loc : NULL;
15261528
assert(target != NULL);
15271529
assert(IS_JUMP_OPCODE(opcode) || IS_BLOCK_PUSH_OPCODE(opcode));
15281530
return basicblock_addop(c->u->u_curblock, opcode, 0, target, loc);
@@ -7386,7 +7388,8 @@ push_cold_blocks_to_end(struct compiler *c, basicblock *entry, int code_flags) {
73867388
if (explicit_jump == NULL) {
73877389
return -1;
73887390
}
7389-
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &NO_LOCATION);
7391+
static struct location no_location = NO_LOCATION;
7392+
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &no_location);
73907393

73917394
explicit_jump->b_cold = 1;
73927395
explicit_jump->b_next = b->b_next;
@@ -8289,9 +8292,10 @@ static int
82898292
insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
82908293
int *fixed, int nfreevars, int code_flags)
82918294
{
8292-
82938295
assert(c->u->u_firstlineno > 0);
82948296

8297+
static struct location no_location = NO_LOCATION;
8298+
82958299
/* Add the generator prefix instructions. */
82968300
if (code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
82978301
struct instr make_gen = {
@@ -8306,7 +8310,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
83068310
struct instr pop_top = {
83078311
.i_opcode = POP_TOP,
83088312
.i_oparg = 0,
8309-
.i_loc = NO_LOCATION,
8313+
.i_loc = no_location,
83108314
.i_target = NULL,
83118315
};
83128316
if (insert_instruction(entryblock, 1, &pop_top) < 0) {
@@ -8338,7 +8342,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
83388342
.i_opcode = MAKE_CELL,
83398343
// This will get fixed in offset_derefs().
83408344
.i_oparg = oldindex,
8341-
.i_loc = NO_LOCATION,
8345+
.i_loc = no_location,
83428346
.i_target = NULL,
83438347
};
83448348
if (insert_instruction(entryblock, ncellsused, &make_cell) < 0) {
@@ -8353,7 +8357,7 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
83538357
struct instr copy_frees = {
83548358
.i_opcode = COPY_FREE_VARS,
83558359
.i_oparg = nfreevars,
8356-
.i_loc = NO_LOCATION,
8360+
.i_loc = no_location,
83578361
.i_target = NULL,
83588362
};
83598363
if (insert_instruction(entryblock, 0, &copy_frees) < 0) {
@@ -9359,7 +9363,8 @@ propagate_line_numbers(struct assembler *a) {
93599363
continue;
93609364
}
93619365

9362-
struct location prev_location = NO_LOCATION;
9366+
static struct location no_location = NO_LOCATION;
9367+
struct location prev_location = no_location;
93639368
for (int i = 0; i < b->b_iused; i++) {
93649369
if (b->b_instr[i].i_loc.lineno < 0) {
93659370
b->b_instr[i].i_loc = prev_location;

0 commit comments

Comments
 (0)