Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Do Do not use _ + capital letter in cast macros as it is also UB.
  • Loading branch information
picnixz committed Feb 8, 2025
commit 2340cae3030ee80583c302880c3ee87ecde929b9
24 changes: 12 additions & 12 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ typedef struct {
} fileio;

#define PyFileIO_Check(state, op) (PyObject_TypeCheck((op), state->PyFileIO_Type))
#define _PyFileIO_CAST(op) _Py_CAST(fileio*, (op))
#define PyFileIO_CAST(op) ((fileio *)(op))

/* Forward declarations */
static PyObject* portable_lseek(fileio *self, PyObject *posobj, int whence, bool suppress_pipe_error);

int
_PyFileIO_closed(PyObject *self)
{
return (_PyFileIO_CAST(self)->fd < 0);
return (PyFileIO_CAST(self)->fd < 0);
}

/* Because this can call arbitrary code, it shouldn't be called when
Expand All @@ -100,7 +100,7 @@ _PyFileIO_closed(PyObject *self)
static PyObject *
fileio_dealloc_warn(PyObject *op, PyObject *source)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
if (self->fd >= 0 && self->closefd) {
PyObject *exc = PyErr_GetRaisedException();
if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
Expand Down Expand Up @@ -542,7 +542,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
static int
fileio_traverse(PyObject *op, visitproc visit, void *arg)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->dict);
return 0;
Expand All @@ -551,15 +551,15 @@ fileio_traverse(PyObject *op, visitproc visit, void *arg)
static int
fileio_clear(PyObject *op)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
Py_CLEAR(self->dict);
return 0;
}

static void
fileio_dealloc(PyObject *op)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
self->finalizing = 1;
if (_PyIOBase_finalize(op) < 0) {
return;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ mode_string(fileio *self)
static PyObject *
fileio_repr(PyObject *op)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
const char *type_name = Py_TYPE(self)->tp_name;

if (self->fd < 0) {
Expand Down Expand Up @@ -1229,7 +1229,7 @@ _io_FileIO_isatty_impl(fileio *self)
static PyObject *
_io_FileIO_isatty_open_only(PyObject *op, PyObject *Py_UNUSED(dummy))
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
if (self->stat_atopen != NULL && !S_ISCHR(self->stat_atopen->st_mode)) {
Py_RETURN_FALSE;
}
Expand Down Expand Up @@ -1264,28 +1264,28 @@ static PyMethodDef fileio_methods[] = {
static PyObject *
fileio_get_closed(PyObject *op, void *closure)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
return PyBool_FromLong((long)(self->fd < 0));
}

static PyObject *
fileio_get_closefd(PyObject *op, void *closure)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
return PyBool_FromLong((long)(self->closefd));
}

static PyObject *
fileio_get_mode(PyObject *op, void *closure)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
return PyUnicode_FromString(mode_string(self));
}

static PyObject *
fileio_get_blksize(PyObject *op, void *closure)
{
fileio *self = _PyFileIO_CAST(op);
fileio *self = PyFileIO_CAST(op);
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
if (self->stat_atopen != NULL && self->stat_atopen->st_blksize > 1) {
return PyLong_FromLong(self->stat_atopen->st_blksize);
Expand Down