summaryrefslogtreecommitdiffstats
path: root/Modules/_cursesmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-01-21 02:30:20 (GMT)
committerGitHub <noreply@github.com>2022-01-21 02:30:20 (GMT)
commit1781d55eb34f94029e50970232635fc5082378cb (patch)
tree613d5c847480facfe411345b4a61ee3239950e53 /Modules/_cursesmodule.c
parent17f268a4ae6190b2659c89c6f32ad2d006e0e3c8 (diff)
downloadcpython-1781d55eb34f94029e50970232635fc5082378cb.zip
cpython-1781d55eb34f94029e50970232635fc5082378cb.tar.gz
cpython-1781d55eb34f94029e50970232635fc5082378cb.tar.bz2
bpo-46417: _curses uses PyStructSequence_NewType() (GH-30736)
The _curses module now creates its ncurses_version type as a heap type using PyStructSequence_NewType(), rather than using a static type. * Move _PyStructSequence_FiniType() definition to pycore_structseq.h. * test.pythoninfo: log curses.ncurses_version.
Diffstat (limited to 'Modules/_cursesmodule.c')
-rw-r--r--Modules/_cursesmodule.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index bf742da..423b042 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -108,7 +108,7 @@ static const char PyCursesVersion[] = "2.2";
#include "Python.h"
#include "pycore_long.h" // _PyLong_GetZero()
-#include "pycore_structseq.h" // PyStructSequence_InitType()
+#include "pycore_structseq.h" // _PyStructSequence_NewType()
#ifdef __hpux
#define STRICT_SYSV_CURSES
@@ -4569,8 +4569,6 @@ PyDoc_STRVAR(ncurses_version__doc__,
\n\
Ncurses version information as a named tuple.");
-static PyTypeObject NcursesVersionType;
-
static PyStructSequence_Field ncurses_version_fields[] = {
{"major", "Major release number"},
{"minor", "Minor release number"},
@@ -4586,12 +4584,12 @@ static PyStructSequence_Desc ncurses_version_desc = {
};
static PyObject *
-make_ncurses_version(void)
+make_ncurses_version(PyTypeObject *type)
{
PyObject *ncurses_version;
int pos = 0;
- ncurses_version = PyStructSequence_New(&NcursesVersionType);
+ ncurses_version = PyStructSequence_New(type);
if (ncurses_version == NULL) {
return NULL;
}
@@ -4796,14 +4794,14 @@ PyInit__curses(void)
#ifdef NCURSES_VERSION
/* ncurses_version */
- if (NcursesVersionType.tp_name == NULL) {
- if (_PyStructSequence_InitType(&NcursesVersionType,
- &ncurses_version_desc,
- Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) {
- return NULL;
- }
+ PyTypeObject *version_type;
+ version_type = _PyStructSequence_NewType(&ncurses_version_desc,
+ Py_TPFLAGS_DISALLOW_INSTANTIATION);
+ if (version_type == NULL) {
+ return NULL;
}
- v = make_ncurses_version();
+ v = make_ncurses_version(version_type);
+ Py_DECREF(version_type);
if (v == NULL) {
return NULL;
}