From 5c77e5655d85211139e03ba4ef2642c66827c273 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 21 Jul 2024 10:45:34 +0300 Subject: [PATCH 1/4] gh-122081: fixed crash in decimal.IEEEContext() Now $ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \ ./python -m test test_decimal - PASS --- .../Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst | 1 + Modules/_decimal/_decimal.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst diff --git a/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst b/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst new file mode 100644 index 00000000000000..1431f220084f9b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst @@ -0,0 +1 @@ +Fixed crash in optional :func:`!decimal.IEEEContext()` function. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 94a2cc2c8e5f8a..083d54fd334d14 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1519,7 +1519,7 @@ init_extended_context(PyObject *v) #ifdef EXTRA_FUNCTIONALITY /* Factory function for creating IEEE interchange format contexts */ static PyObject * -ieee_context(PyObject *dummy UNUSED, PyObject *v) +ieee_context(PyObject *self, PyObject *v) { PyObject *context; mpd_ssize_t bits; @@ -1536,7 +1536,7 @@ ieee_context(PyObject *dummy UNUSED, PyObject *v) goto error; } - decimal_state *state = get_module_state_by_def(Py_TYPE(v)); + decimal_state *state = get_module_state(self); context = PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL); if (context == NULL) { return NULL; From 1b1df411faeac082711588bbe92aca3db8337df1 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 18 Aug 2024 11:44:18 +0300 Subject: [PATCH 2/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst b/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst index 1431f220084f9b..53a88c8bf65259 100644 --- a/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst +++ b/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst @@ -1 +1,2 @@ -Fixed crash in optional :func:`!decimal.IEEEContext()` function. +Fix a crash in the :func:`!decimal.IEEEContext()` optional function +available via the ``EXTRA_FUNCTIONALITY`` configuration flag. From 02113030e13539f6051a60a50e628d8c80f4829c Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Mon, 19 Aug 2024 12:50:16 +0530 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst --- .../next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst b/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst index 53a88c8bf65259..4c988b16168047 100644 --- a/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst +++ b/Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst @@ -1,2 +1,2 @@ -Fix a crash in the :func:`!decimal.IEEEContext()` optional function +Fix a crash in the :func:`!decimal.IEEEContext` optional function available via the ``EXTRA_FUNCTIONALITY`` configuration flag. From 3ff29735b13e43e9cdb446a577aee45836c043b5 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Mon, 19 Aug 2024 12:56:30 +0530 Subject: [PATCH 4/4] Apply suggestions from code review --- Modules/_decimal/_decimal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 083d54fd334d14..15855e2cf1bb32 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1519,7 +1519,7 @@ init_extended_context(PyObject *v) #ifdef EXTRA_FUNCTIONALITY /* Factory function for creating IEEE interchange format contexts */ static PyObject * -ieee_context(PyObject *self, PyObject *v) +ieee_context(PyObject *module, PyObject *v) { PyObject *context; mpd_ssize_t bits; @@ -1536,7 +1536,7 @@ ieee_context(PyObject *self, PyObject *v) goto error; } - decimal_state *state = get_module_state(self); + decimal_state *state = get_module_state(module); context = PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL); if (context == NULL) { return NULL;