From 87d2e7c85e2c990f550c9f789af881fbe36fd36f Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Mon, 21 Feb 2022 12:36:12 +0900 Subject: [PATCH 1/3] Take a log with diagnoses before the fix --- PCbuild/pythoncore.vcxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index c39ba3e1a9f412..48e167adad3ae3 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -100,6 +100,7 @@ /Zm200 %(AdditionalOptions) + /d2inlinelogfull:FrameDefault %(AdditionalOptions) $(PySourcePath)Python;%(AdditionalIncludeDirectories) $(zlibDir);%(AdditionalIncludeDirectories) _USRDLL;Py_BUILD_CORE;Py_BUILD_CORE_BUILTIN;Py_ENABLE_SHARED;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions) From 2d3cb284fe05d89ed5ce95a1a0c2289736edbbb8 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Mon, 21 Feb 2022 14:00:34 +0900 Subject: [PATCH 2/3] Make switch-case smaller _Py_NO_INLINE: MSVC inlines unknown_opcode_error() with no performance down, which is too uncommon to be inlined. --- Python/ceval.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index ab10b4166d6d21..5b1ae377ec33b0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -94,6 +94,7 @@ static PyObject * special_lookup(PyThreadState *, PyObject *, _Py_Identifier *); static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg); static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs); static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int); +static void unknown_opcode_error(PyThreadState *, PyFrameObject *, int); #define NAME_ERROR_MSG \ "name '%.200s' is not defined" @@ -4418,11 +4419,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) _unknown_opcode: #endif default: - fprintf(stderr, - "XXX lineno: %d, opcode: %d\n", - PyFrame_GetLineNumber(f), - opcode); - _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); + unknown_opcode_error(tstate, f, opcode); goto error; } /* switch */ @@ -6310,6 +6307,16 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop } } +_Py_NO_INLINE static void +unknown_opcode_error(PyThreadState *tstate, PyFrameObject *f, int opcode) +{ + fprintf(stderr, + "XXX lineno: %d, opcode: %d\n", + PyFrame_GetLineNumber(f), + opcode); + _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); +} + static PyObject * unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, PyFrameObject *f, const _Py_CODEUNIT *next_instr) From c2333fd4090a4971424eee85d9c807bd76554e04 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Mon, 21 Feb 2022 14:25:00 +0900 Subject: [PATCH 3/3] Disable diagnostic option --- PCbuild/pythoncore.vcxproj | 1 - 1 file changed, 1 deletion(-) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 48e167adad3ae3..c39ba3e1a9f412 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -100,7 +100,6 @@ /Zm200 %(AdditionalOptions) - /d2inlinelogfull:FrameDefault %(AdditionalOptions) $(PySourcePath)Python;%(AdditionalIncludeDirectories) $(zlibDir);%(AdditionalIncludeDirectories) _USRDLL;Py_BUILD_CORE;Py_BUILD_CORE_BUILTIN;Py_ENABLE_SHARED;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)