summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2023-02-20 14:56:48 +0000
committerGitHub <noreply@github.com>2023-02-20 14:56:48 +0000
commita99eb5cd9947629a6745a4ad99cb07af1c287b5d (patch)
tree2d2b82cef5aa1c514eda32eaca115e2723fd7f1c /Objects
parentc00faf79438cc7f0d98af2679c695f747e4369a3 (diff)
downloadcpython-git-a99eb5cd9947629a6745a4ad99cb07af1c287b5d.tar.gz
gh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (GH-101912)
* gh-101907: Removes use of non-standard C++ extension from Include/cpython/code.h * Make cases_generator correct on Windows
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c20
-rw-r--r--Objects/frameobject.c24
-rw-r--r--Objects/genobject.c10
-rw-r--r--Objects/typeobject.c4
4 files changed, 29 insertions, 29 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index ab31b6582c..a03b14edea 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -413,7 +413,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
PyBytes_GET_SIZE(con->code));
int entry_point = 0;
while (entry_point < Py_SIZE(co) &&
- _Py_OPCODE(_PyCode_CODE(co)[entry_point]) != RESUME) {
+ _PyCode_CODE(co)[entry_point].op.code != RESUME) {
entry_point++;
}
co->_co_firsttraceable = entry_point;
@@ -1505,12 +1505,12 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
{
for (int i = 0; i < len; i++) {
_Py_CODEUNIT instruction = instructions[i];
- int opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
+ int opcode = _PyOpcode_Deopt[instruction.op.code];
int caches = _PyOpcode_Caches[opcode];
- instructions[i].opcode = opcode;
+ instructions[i].op.code = opcode;
while (caches--) {
- instructions[++i].opcode = CACHE;
- instructions[i].oparg = 0;
+ instructions[++i].op.code = CACHE;
+ instructions[i].op.arg = 0;
}
}
}
@@ -1763,13 +1763,13 @@ code_richcompare(PyObject *self, PyObject *other, int op)
for (int i = 0; i < Py_SIZE(co); i++) {
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
- co_instr.opcode = _PyOpcode_Deopt[_Py_OPCODE(co_instr)];
- cp_instr.opcode =_PyOpcode_Deopt[_Py_OPCODE(cp_instr)];
+ co_instr.op.code = _PyOpcode_Deopt[co_instr.op.code];
+ cp_instr.op.code = _PyOpcode_Deopt[cp_instr.op.code];
eq = co_instr.cache == cp_instr.cache;
if (!eq) {
goto unequal;
}
- i += _PyOpcode_Caches[_Py_OPCODE(co_instr)];
+ i += _PyOpcode_Caches[co_instr.op.code];
}
/* compare constants */
@@ -1848,9 +1848,9 @@ code_hash(PyCodeObject *co)
SCRAMBLE_IN(co->co_firstlineno);
SCRAMBLE_IN(Py_SIZE(co));
for (int i = 0; i < Py_SIZE(co); i++) {
- int deop = _PyOpcode_Deopt[_Py_OPCODE(_PyCode_CODE(co)[i])];
+ int deop = _PyOpcode_Deopt[_PyCode_CODE(co)[i].op.code];
SCRAMBLE_IN(deop);
- SCRAMBLE_IN(_Py_OPARG(_PyCode_CODE(co)[i]));
+ SCRAMBLE_IN(_PyCode_CODE(co)[i].op.arg);
i += _PyOpcode_Caches[deop];
}
if ((Py_hash_t)uhash == -1) {
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 581ed2d214..34143c9a40 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -111,13 +111,13 @@ static unsigned int
get_arg(const _Py_CODEUNIT *codestr, Py_ssize_t i)
{
_Py_CODEUNIT word;
- unsigned int oparg = _Py_OPARG(codestr[i]);
- if (i >= 1 && _Py_OPCODE(word = codestr[i-1]) == EXTENDED_ARG) {
- oparg |= _Py_OPARG(word) << 8;
- if (i >= 2 && _Py_OPCODE(word = codestr[i-2]) == EXTENDED_ARG) {
- oparg |= _Py_OPARG(word) << 16;
- if (i >= 3 && _Py_OPCODE(word = codestr[i-3]) == EXTENDED_ARG) {
- oparg |= _Py_OPARG(word) << 24;
+ unsigned int oparg = codestr[i].op.arg;
+ if (i >= 1 && (word = codestr[i-1]).op.code == EXTENDED_ARG) {
+ oparg |= word.op.arg << 8;
+ if (i >= 2 && (word = codestr[i-2]).op.code == EXTENDED_ARG) {
+ oparg |= word.op.arg << 16;
+ if (i >= 3 && (word = codestr[i-3]).op.code == EXTENDED_ARG) {
+ oparg |= word.op.arg << 24;
}
}
}
@@ -304,7 +304,7 @@ mark_stacks(PyCodeObject *code_obj, int len)
if (next_stack == UNINITIALIZED) {
continue;
}
- opcode = _Py_OPCODE(code[i]);
+ opcode = code[i].op.code;
switch (opcode) {
case JUMP_IF_FALSE_OR_POP:
case JUMP_IF_TRUE_OR_POP:
@@ -610,7 +610,7 @@ _PyFrame_GetState(PyFrameObject *frame)
if (_PyInterpreterFrame_LASTI(frame->f_frame) < 0) {
return FRAME_CREATED;
}
- switch (_Py_OPCODE(*frame->f_frame->prev_instr))
+ switch (frame->f_frame->prev_instr->op.code)
{
case COPY_FREE_VARS:
case MAKE_CELL:
@@ -1092,8 +1092,8 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg)
for (_Py_CODEUNIT *instruction = _PyCode_CODE(frame->f_code);
instruction < frame->prev_instr; instruction++)
{
- int check_opcode = _PyOpcode_Deopt[_Py_OPCODE(*instruction)];
- check_oparg |= _Py_OPARG(*instruction);
+ int check_opcode = _PyOpcode_Deopt[instruction->op.code];
+ check_oparg |= instruction->op.arg;
if (check_opcode == opcode && check_oparg == oparg) {
return 1;
}
@@ -1117,7 +1117,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame)
// here:
PyCodeObject *co = frame->f_code;
int lasti = _PyInterpreterFrame_LASTI(frame);
- if (!(lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS
+ if (!(lasti < 0 && _PyCode_CODE(co)->op.code == COPY_FREE_VARS
&& PyFunction_Check(frame->f_funcobj)))
{
/* Free vars are initialized */
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 35246653c4..aec64ca700 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -332,11 +332,11 @@ _PyGen_yf(PyGenObject *gen)
/* Return immediately if the frame didn't start yet. SEND
always come after LOAD_CONST: a code object should not start
with SEND */
- assert(_Py_OPCODE(_PyCode_CODE(gen->gi_code)[0]) != SEND);
+ assert(_PyCode_CODE(gen->gi_code)[0].op.code != SEND);
return NULL;
}
_Py_CODEUNIT next = frame->prev_instr[1];
- if (_Py_OPCODE(next) != RESUME || _Py_OPARG(next) < 2)
+ if (next.op.code != RESUME || next.op.arg < 2)
{
/* Not in a yield from */
return NULL;
@@ -371,9 +371,9 @@ gen_close(PyGenObject *gen, PyObject *args)
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe;
/* It is possible for the previous instruction to not be a
* YIELD_VALUE if the debugger has changed the lineno. */
- if (err == 0 && frame->prev_instr->opcode == YIELD_VALUE) {
- assert(frame->prev_instr[1].opcode == RESUME);
- int exception_handler_depth = frame->prev_instr->oparg;
+ if (err == 0 && frame->prev_instr[0].op.code == YIELD_VALUE) {
+ assert(frame->prev_instr[1].op.code == RESUME);
+ int exception_handler_depth = frame->prev_instr[0].op.code;
assert(exception_handler_depth > 0);
/* We can safely ignore the outermost try block
* as it automatically generated to handle
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index f2e8092aa3..2d1220a069 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -9507,8 +9507,8 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co,
if (_PyInterpreterFrame_LASTI(cframe) >= 0) {
// MAKE_CELL and COPY_FREE_VARS have no quickened forms, so no need
// to use _PyOpcode_Deopt here:
- assert(_Py_OPCODE(_PyCode_CODE(co)[0]) == MAKE_CELL ||
- _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS);
+ assert(_PyCode_CODE(co)[0].op.code == MAKE_CELL ||
+ _PyCode_CODE(co)[0].op.code == COPY_FREE_VARS);
assert(PyCell_Check(firstarg));
firstarg = PyCell_GET(firstarg);
}