From dd28b6e65fd16825626dedb6af71eb0f745c19eb Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa <koubaa.m@gmail.com> Date: Mon, 10 Aug 2020 19:14:26 -0500 Subject: [PATCH 1/5] port _opcode to multi-phase --- Modules/_opcode.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Modules/_opcode.c b/Modules/_opcode.c index 42a8732694afef..83e2c0471559bd 100644 --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -67,30 +67,34 @@ _opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg, return effect; } - - - static PyMethodDef opcode_functions[] = { _OPCODE_STACK_EFFECT_METHODDEF {NULL, NULL, 0, NULL} }; +static int +_opcode_exec(PyObject *m) +{ + return 0; +} + +static PyModuleDef_Slot opcode_slots[] = { + {Py_mod_exec, _opcode_exec}, + {0, NULL} +}; static struct PyModuleDef opcodemodule = { PyModuleDef_HEAD_INIT, - "_opcode", - "Opcode support module.", - -1, - opcode_functions, - NULL, - NULL, - NULL, - NULL + .m_name = "_opcode", + .m_doc = "Opcode support module.", + .m_size = 0, + .m_methods = opcode_functions, + .m_slots = opcode_slots }; PyMODINIT_FUNC PyInit__opcode(void) { - return PyModule_Create(&opcodemodule); + return PyModuleDef_Init(&opcodemodule); } From 6e44b6b8cd63816ddf8d0823762293dc07913d83 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa <koubaa.m@gmail.com> Date: Tue, 1 Sep 2020 17:06:09 -0500 Subject: [PATCH 2/5] opcode blurb --- .../2020-09-01-17-06-02.bpo-1635741.5jZymK.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-09-01-17-06-02.bpo-1635741.5jZymK.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-09-01-17-06-02.bpo-1635741.5jZymK.rst b/Misc/NEWS.d/next/Core and Builtins/2020-09-01-17-06-02.bpo-1635741.5jZymK.rst new file mode 100644 index 00000000000000..c3bc9a78a2e054 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-09-01-17-06-02.bpo-1635741.5jZymK.rst @@ -0,0 +1,2 @@ +Port the :mod:`_opcode` extension module to multi-phase initialization +(:pep:`489`). From 893e69203ec38762cf6600f6adbe7f9f4bb9fcc2 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa <koubaa.m@gmail.com> Date: Wed, 2 Sep 2020 18:35:41 -0500 Subject: [PATCH 3/5] add brace --- Modules/_opcode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_opcode.c b/Modules/_opcode.c index 83e2c0471559bd..3f4b6180d444fe 100644 --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -36,8 +36,9 @@ _opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg, return -1; } oparg_int = (int)PyLong_AsLong(oparg); - if ((oparg_int == -1) && PyErr_Occurred()) + if ((oparg_int == -1) && PyErr_Occurred()) { return -1; + } } else if (oparg != Py_None) { PyErr_SetString(PyExc_ValueError, From 7ff4a938bbf052bee49facc54240340dce98e673 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa <koubaa.m@gmail.com> Date: Thu, 3 Sep 2020 21:40:06 -0500 Subject: [PATCH 4/5] remove unneeded exec --- Modules/_opcode.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Modules/_opcode.c b/Modules/_opcode.c index 3f4b6180d444fe..f433d0366844fc 100644 --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -74,14 +74,7 @@ opcode_functions[] = { {NULL, NULL, 0, NULL} }; -static int -_opcode_exec(PyObject *m) -{ - return 0; -} - static PyModuleDef_Slot opcode_slots[] = { - {Py_mod_exec, _opcode_exec}, {0, NULL} }; From 500342f1c28f32fce7105b81fd2d2c26c1b1e1f4 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa <koubaa.m@gmail.com> Date: Sun, 6 Sep 2020 16:55:09 -0500 Subject: [PATCH 5/5] remove unneeded function --- Modules/_opcode.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Modules/_opcode.c b/Modules/_opcode.c index f433d0366844fc..d8de0762e765af 100644 --- a/Modules/_opcode.c +++ b/Modules/_opcode.c @@ -74,17 +74,12 @@ opcode_functions[] = { {NULL, NULL, 0, NULL} }; -static PyModuleDef_Slot opcode_slots[] = { - {0, NULL} -}; - static struct PyModuleDef opcodemodule = { PyModuleDef_HEAD_INIT, .m_name = "_opcode", .m_doc = "Opcode support module.", .m_size = 0, - .m_methods = opcode_functions, - .m_slots = opcode_slots + .m_methods = opcode_functions }; PyMODINIT_FUNC