Skip to content

Commit 5e06cad

Browse files
committed
basicblock_addop takes location by reference
1 parent 016ebbc commit 5e06cad

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Python/compile.c

Lines changed: 7 additions & 8 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
((struct location){(LNO), (END_LNO), (COL), (END_COL)})
161161

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

164164
struct instr {
165165
int i_opcode;
@@ -348,7 +348,6 @@ enum {
348348
COMPILER_SCOPE_COMPREHENSION,
349349
};
350350

351-
352351
/* The following items change on entry and exit of code blocks.
353352
They must be saved and restored when returning to a block.
354353
*/
@@ -1273,7 +1272,7 @@ compiler_use_new_implicit_block_if_needed(struct compiler *c)
12731272

12741273
static int
12751274
basicblock_addop(basicblock *b, int opcode, int oparg,
1276-
basicblock *target, struct location loc)
1275+
basicblock *target, const struct location *loc)
12771276
{
12781277
assert(IS_WITHIN_OPCODE_RANGE(opcode));
12791278
assert(!IS_ASSEMBLER_OPCODE(opcode));
@@ -1292,7 +1291,7 @@ basicblock_addop(basicblock *b, int opcode, int oparg,
12921291
i->i_opcode = opcode;
12931292
i->i_oparg = oparg;
12941293
i->i_target = target;
1295-
i->i_loc = loc;
1294+
i->i_loc = *loc;
12961295

12971296
return 1;
12981297
}
@@ -1305,7 +1304,7 @@ compiler_addop(struct compiler *c, int opcode, bool line)
13051304
return -1;
13061305
}
13071306

1308-
struct location loc = line ? c->u->u_loc : NO_LOCATION;
1307+
const struct location *loc = line ? &c->u->u_loc : &NO_LOCATION;
13091308
return basicblock_addop(c->u->u_curblock, opcode, 0, NULL, loc);
13101309
}
13111310

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

15141513
int oparg_ = Py_SAFE_DOWNCAST(oparg, Py_ssize_t, int);
15151514

1516-
struct location loc = line ? c->u->u_loc : NO_LOCATION;
1515+
const struct location *loc = line ? &c->u->u_loc : &NO_LOCATION;
15171516
return basicblock_addop(c->u->u_curblock, opcode, oparg_, NULL, loc);
15181517
}
15191518

@@ -1523,7 +1522,7 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *target, bool line)
15231522
if (compiler_use_new_implicit_block_if_needed(c) < 0) {
15241523
return -1;
15251524
}
1526-
struct location loc = line ? c->u->u_loc : NO_LOCATION;
1525+
const struct location *loc = line ? &c->u->u_loc : &NO_LOCATION;
15271526
assert(target != NULL);
15281527
assert(IS_JUMP_OPCODE(opcode) || IS_BLOCK_PUSH_OPCODE(opcode));
15291528
return basicblock_addop(c->u->u_curblock, opcode, 0, target, loc);
@@ -7387,7 +7386,7 @@ push_cold_blocks_to_end(struct compiler *c, basicblock *entry, int code_flags) {
73877386
if (explicit_jump == NULL) {
73887387
return -1;
73897388
}
7390-
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, NO_LOCATION);
7389+
basicblock_addop(explicit_jump, JUMP, 0, b->b_next, &NO_LOCATION);
73917390

73927391
explicit_jump->b_cold = 1;
73937392
explicit_jump->b_next = b->b_next;

0 commit comments

Comments
 (0)