summaryrefslogtreecommitdiff
path: root/Include/cpython
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 /Include/cpython
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 'Include/cpython')
-rw-r--r--Include/cpython/code.h28
1 files changed, 21 insertions, 7 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h
index 0cf49f06c8..fba9296aed 100644
--- a/Include/cpython/code.h
+++ b/Include/cpython/code.h
@@ -19,21 +19,35 @@ extern "C" {
typedef union {
uint16_t cache;
struct {
- uint8_t opcode;
- uint8_t oparg;
- };
+ uint8_t code;
+ uint8_t arg;
+ } op;
} _Py_CODEUNIT;
-#define _Py_OPCODE(word) ((word).opcode)
-#define _Py_OPARG(word) ((word).oparg)
+
+/* These macros only remain defined for compatibility. */
+#define _Py_OPCODE(word) ((word).op.code)
+#define _Py_OPARG(word) ((word).op.arg)
+
+static inline _Py_CODEUNIT
+_py_make_codeunit(uint8_t opcode, uint8_t oparg)
+{
+ // No designated initialisers because of C++ compat
+ _Py_CODEUNIT word;
+ word.op.code = opcode;
+ word.op.arg = oparg;
+ return word;
+}
static inline void
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
{
- word->opcode = opcode;
+ word->op.code = opcode;
}
-#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode)
+#define _Py_MAKE_CODEUNIT(opcode, oparg) _py_make_codeunit((opcode), (oparg))
+#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), (opcode))
+
typedef struct {
PyObject *_co_code;