Skip to content

Commit 1f5d7cb

Browse files
committed
pythongh-101907: Removes use of non-standard C++ extension from Include/cpython/code.h
1 parent 81e3aa8 commit 1f5d7cb

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

Include/cpython/code.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ typedef union {
2121
struct {
2222
uint8_t opcode;
2323
uint8_t oparg;
24-
};
24+
} _op;
2525
} _Py_CODEUNIT;
2626

27-
#define _Py_OPCODE(word) ((word).opcode)
28-
#define _Py_OPARG(word) ((word).oparg)
27+
#define _Py_OPCODE(word) ((word)._op.opcode)
28+
#define _Py_OPARG(word) ((word)._op.oparg)
2929

3030
static inline void
3131
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
3232
{
33-
word->opcode = opcode;
33+
word->_op.opcode = opcode;
3434
}
3535

3636
#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removes use of non-standard C++ extension in public header files.

Objects/codeobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,10 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
15071507
_Py_CODEUNIT instruction = instructions[i];
15081508
int opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
15091509
int caches = _PyOpcode_Caches[opcode];
1510-
instructions[i].opcode = opcode;
1510+
_Py_OPCODE(instructions[i]) = opcode;
15111511
while (caches--) {
1512-
instructions[++i].opcode = CACHE;
1513-
instructions[i].oparg = 0;
1512+
_Py_OPCODE(instructions[++i]) = CACHE;
1513+
_Py_OPARG(instructions[i]) = 0;
15141514
}
15151515
}
15161516
}
@@ -1763,8 +1763,8 @@ code_richcompare(PyObject *self, PyObject *other, int op)
17631763
for (int i = 0; i < Py_SIZE(co); i++) {
17641764
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
17651765
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
1766-
co_instr.opcode = _PyOpcode_Deopt[_Py_OPCODE(co_instr)];
1767-
cp_instr.opcode =_PyOpcode_Deopt[_Py_OPCODE(cp_instr)];
1766+
_Py_OPCODE(co_instr) = _PyOpcode_Deopt[_Py_OPCODE(co_instr)];
1767+
_Py_OPCODE(cp_instr) =_PyOpcode_Deopt[_Py_OPCODE(cp_instr)];
17681768
eq = co_instr.cache == cp_instr.cache;
17691769
if (!eq) {
17701770
goto unequal;

Objects/genobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ gen_close(PyGenObject *gen, PyObject *args)
371371
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe;
372372
/* It is possible for the previous instruction to not be a
373373
* YIELD_VALUE if the debugger has changed the lineno. */
374-
if (err == 0 && frame->prev_instr->opcode == YIELD_VALUE) {
375-
assert(frame->prev_instr[1].opcode == RESUME);
376-
int exception_handler_depth = frame->prev_instr->oparg;
374+
if (err == 0 && _Py_OPCODE(frame->prev_instr[0]) == YIELD_VALUE) {
375+
assert(_Py_OPCODE(frame->prev_instr[1]) == RESUME);
376+
int exception_handler_depth = _Py_OPCODE(frame->prev_instr[0]);
377377
assert(exception_handler_depth > 0);
378378
/* We can safely ignore the outermost try block
379379
* as it automatically generated to handle

Python/compile.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,31 +274,31 @@ write_instr(_Py_CODEUNIT *codestr, struct instr *instruction, int ilen)
274274
int caches = _PyOpcode_Caches[opcode];
275275
switch (ilen - caches) {
276276
case 4:
277-
codestr->opcode = EXTENDED_ARG;
278-
codestr->oparg = (oparg >> 24) & 0xFF;
277+
_Py_OPCODE(*codestr) = EXTENDED_ARG;
278+
_Py_OPARG(*codestr) = (oparg >> 24) & 0xFF;
279279
codestr++;
280280
/* fall through */
281281
case 3:
282-
codestr->opcode = EXTENDED_ARG;
283-
codestr->oparg = (oparg >> 16) & 0xFF;
282+
_Py_OPCODE(*codestr) = EXTENDED_ARG;
283+
_Py_OPARG(*codestr) = (oparg >> 16) & 0xFF;
284284
codestr++;
285285
/* fall through */
286286
case 2:
287-
codestr->opcode = EXTENDED_ARG;
288-
codestr->oparg = (oparg >> 8) & 0xFF;
287+
_Py_OPCODE(*codestr) = EXTENDED_ARG;
288+
_Py_OPARG(*codestr) = (oparg >> 8) & 0xFF;
289289
codestr++;
290290
/* fall through */
291291
case 1:
292-
codestr->opcode = opcode;
293-
codestr->oparg = oparg & 0xFF;
292+
_Py_OPCODE(*codestr) = opcode;
293+
_Py_OPARG(*codestr) = oparg & 0xFF;
294294
codestr++;
295295
break;
296296
default:
297297
Py_UNREACHABLE();
298298
}
299299
while (caches--) {
300-
codestr->opcode = CACHE;
301-
codestr->oparg = 0;
300+
_Py_OPCODE(*codestr) = CACHE;
301+
_Py_OPARG(*codestr) = 0;
302302
codestr++;
303303
}
304304
}

Python/specialize.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,31 +291,31 @@ _PyCode_Quicken(PyCodeObject *code)
291291
}
292292
switch (previous_opcode << 8 | opcode) {
293293
case LOAD_CONST << 8 | LOAD_FAST:
294-
instructions[i - 1].opcode = LOAD_CONST__LOAD_FAST;
294+
_Py_OPCODE(instructions[i - 1]) = LOAD_CONST__LOAD_FAST;
295295
break;
296296
case LOAD_FAST << 8 | LOAD_CONST:
297-
instructions[i - 1].opcode = LOAD_FAST__LOAD_CONST;
297+
_Py_OPCODE(instructions[i - 1]) = LOAD_FAST__LOAD_CONST;
298298
break;
299299
case LOAD_FAST << 8 | LOAD_FAST:
300-
instructions[i - 1].opcode = LOAD_FAST__LOAD_FAST;
300+
_Py_OPCODE(instructions[i - 1]) = LOAD_FAST__LOAD_FAST;
301301
break;
302302
case STORE_FAST << 8 | LOAD_FAST:
303-
instructions[i - 1].opcode = STORE_FAST__LOAD_FAST;
303+
_Py_OPCODE(instructions[i - 1]) = STORE_FAST__LOAD_FAST;
304304
break;
305305
case STORE_FAST << 8 | STORE_FAST:
306-
instructions[i - 1].opcode = STORE_FAST__STORE_FAST;
306+
_Py_OPCODE(instructions[i - 1]) = STORE_FAST__STORE_FAST;
307307
break;
308308
case COMPARE_OP << 8 | POP_JUMP_IF_TRUE:
309309
case COMPARE_OP << 8 | POP_JUMP_IF_FALSE:
310310
{
311-
int oparg = instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP].oparg;
311+
int oparg = _Py_OPARG(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP]);
312312
assert((oparg >> 4) <= Py_GE);
313313
int mask = compare_masks[oparg >> 4];
314314
if (opcode == POP_JUMP_IF_FALSE) {
315315
mask = mask ^ 0xf;
316316
}
317-
instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP].opcode = COMPARE_AND_BRANCH;
318-
instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP].oparg = (oparg & 0xf0) | mask;
317+
_Py_OPCODE(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP]) = COMPARE_AND_BRANCH;
318+
_Py_OPARG(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP]) = (oparg & 0xf0) | mask;
319319
break;
320320
}
321321
}

0 commit comments

Comments
 (0)