summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2023-05-12 07:30:26 (GMT)
committerGitHub <noreply@github.com>2023-05-12 07:30:26 (GMT)
commit15795b57d92ee6315b5c8263290944b16834b5f2 (patch)
tree63a3584fbe5fda12b64d28fa595248c8a980a145 /Modules
parent718b13277217e90232da5edf7ab3267e59189698 (diff)
downloadcpython-15795b57d92ee6315b5c8263290944b16834b5f2.zip
cpython-15795b57d92ee6315b5c8263290944b16834b5f2.tar.gz
cpython-15795b57d92ee6315b5c8263290944b16834b5f2.tar.bz2
gh-101819: Prepare _io._IOBase for module state (#104386)
- Add PyIOBase_Type to _io module state - Pass defining class to _io._IOBase.fileno
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/_iomodule.c3
-rw-r--r--Modules/_io/_iomodule.h1
-rw-r--r--Modules/_io/clinic/iobase.c.h18
-rw-r--r--Modules/_io/iobase.c10
4 files changed, 21 insertions, 11 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index ee4eca7..2457cb1 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -582,6 +582,7 @@ iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
return 0;
Py_VISIT(state->unsupported_operation);
+ Py_VISIT(state->PyIOBase_Type);
Py_VISIT(state->PyIncrementalNewlineDecoder_Type);
Py_VISIT(state->PyRawIOBase_Type);
Py_VISIT(state->PyBufferedIOBase_Type);
@@ -609,6 +610,7 @@ iomodule_clear(PyObject *mod) {
return 0;
Py_CLEAR(state->unsupported_operation);
+ Py_CLEAR(state->PyIOBase_Type);
Py_CLEAR(state->PyIncrementalNewlineDecoder_Type);
Py_CLEAR(state->PyRawIOBase_Type);
Py_CLEAR(state->PyBufferedIOBase_Type);
@@ -751,6 +753,7 @@ PyInit__io(void)
}
// Base classes
+ state->PyIOBase_Type = (PyTypeObject *)Py_NewRef(&PyIOBase_Type);
ADD_TYPE(m, state->PyIncrementalNewlineDecoder_Type, &nldecoder_spec, NULL);
ADD_TYPE(m, state->PyBytesIOBuffer_Type, &bytesiobuf_spec, NULL);
diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h
index 44d6513..ae06fec 100644
--- a/Modules/_io/_iomodule.h
+++ b/Modules/_io/_iomodule.h
@@ -149,6 +149,7 @@ struct _io_state {
PyObject *unsupported_operation;
/* Types */
+ PyTypeObject *PyIOBase_Type;
PyTypeObject *PyIncrementalNewlineDecoder_Type;
PyTypeObject *PyRawIOBase_Type;
PyTypeObject *PyBufferedIOBase_Type;
diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h
index 7273988..7e6b3b5 100644
--- a/Modules/_io/clinic/iobase.c.h
+++ b/Modules/_io/clinic/iobase.c.h
@@ -231,20 +231,24 @@ PyDoc_STRVAR(_io__IOBase_fileno__doc__,
"fileno($self, /)\n"
"--\n"
"\n"
-"Returns underlying file descriptor if one exists.\n"
+"Return underlying file descriptor if one exists.\n"
"\n"
-"OSError is raised if the IO object does not use a file descriptor.");
+"Raise OSError if the IO object does not use a file descriptor.");
#define _IO__IOBASE_FILENO_METHODDEF \
- {"fileno", (PyCFunction)_io__IOBase_fileno, METH_NOARGS, _io__IOBase_fileno__doc__},
+ {"fileno", _PyCFunction_CAST(_io__IOBase_fileno), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__IOBase_fileno__doc__},
static PyObject *
-_io__IOBase_fileno_impl(PyObject *self);
+_io__IOBase_fileno_impl(PyObject *self, PyTypeObject *cls);
static PyObject *
-_io__IOBase_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
+_io__IOBase_fileno(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
- return _io__IOBase_fileno_impl(self);
+ if (nargs) {
+ PyErr_SetString(PyExc_TypeError, "fileno() takes no arguments");
+ return NULL;
+ }
+ return _io__IOBase_fileno_impl(self, cls);
}
PyDoc_STRVAR(_io__IOBase_isatty__doc__,
@@ -416,4 +420,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__RawIOBase_readall_impl(self);
}
-/*[clinic end generated code: output=b6d4845254da1da2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=63bc25a5bfcecaf0 input=a9049054013a1b77]*/
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index a74e46c..26f2a31 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -511,15 +511,17 @@ iobase_exit(PyObject *self, PyObject *args)
/*[clinic input]
_io._IOBase.fileno
+ cls: defining_class
+ /
-Returns underlying file descriptor if one exists.
+Return underlying file descriptor if one exists.
-OSError is raised if the IO object does not use a file descriptor.
+Raise OSError if the IO object does not use a file descriptor.
[clinic start generated code]*/
static PyObject *
-_io__IOBase_fileno_impl(PyObject *self)
-/*[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/
+_io__IOBase_fileno_impl(PyObject *self, PyTypeObject *cls)
+/*[clinic end generated code: output=7caaa32a6f4ada3d input=1927c8bea5c85099]*/
{
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "fileno");