Skip to content
Merged
Prev Previous commit
Next Next commit
Refactor: replace query with parameter
Pass module state to iobase_unsupported()
  • Loading branch information
erlend-aasland committed May 9, 2023
commit 482f13404ff6a7d1e1b3c4f158de641939bf0b7c
24 changes: 14 additions & 10 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ PyDoc_STRVAR(iobase_doc,

/* Internal methods */
static PyObject *
iobase_unsupported(const char *message)
iobase_unsupported(_PyIO_State *state, const char *message)
{
_PyIO_State *state = IO_STATE();
if (state != NULL)
PyErr_SetString(state->unsupported_operation, message);
PyErr_SetString(state->unsupported_operation, message);
return NULL;
}

Expand All @@ -97,7 +95,8 @@ PyDoc_STRVAR(iobase_seek_doc,
static PyObject *
iobase_seek(PyObject *self, PyObject *args)
{
return iobase_unsupported("seek");
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "seek");
}

/*[clinic input]
Expand All @@ -122,7 +121,8 @@ PyDoc_STRVAR(iobase_truncate_doc,
static PyObject *
iobase_truncate(PyObject *self, PyObject *args)
{
return iobase_unsupported("truncate");
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "truncate");
}

static int
Expand Down Expand Up @@ -379,7 +379,8 @@ _PyIOBase_check_seekable(PyObject *self, PyObject *args)
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
iobase_unsupported("File or stream is not seekable.");
_PyIO_State *state = IO_STATE();
iobase_unsupported(state, "File or stream is not seekable.");
return NULL;
}
if (args == Py_True) {
Expand Down Expand Up @@ -412,7 +413,8 @@ _PyIOBase_check_readable(PyObject *self, PyObject *args)
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
iobase_unsupported("File or stream is not readable.");
_PyIO_State *state = IO_STATE();
iobase_unsupported(state, "File or stream is not readable.");
return NULL;
}
if (args == Py_True) {
Expand Down Expand Up @@ -445,7 +447,8 @@ _PyIOBase_check_writable(PyObject *self, PyObject *args)
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
iobase_unsupported("File or stream is not writable.");
_PyIO_State *state = IO_STATE();
iobase_unsupported(state, "File or stream is not writable.");
return NULL;
}
if (args == Py_True) {
Expand Down Expand Up @@ -487,7 +490,8 @@ static PyObject *
_io__IOBase_fileno_impl(PyObject *self)
/*[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/
{
return iobase_unsupported("fileno");
_PyIO_State *state = IO_STATE();
return iobase_unsupported(state, "fileno");
}

/*[clinic input]
Expand Down