Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
6d0a37b
Add tests
erlend-aasland Feb 12, 2023
bd19a20
StringIO type
erlend-aasland Feb 11, 2023
9af73fe
PyTextIOWrapper type
erlend-aasland Feb 11, 2023
4bd73bd
Move get_io_state() to main header
erlend-aasland Feb 11, 2023
8d96a7a
PyFileIO type
erlend-aasland Feb 11, 2023
97f382f
Buffered* types
erlend-aasland Feb 12, 2023
eeb5c48
PyBytesIO type
erlend-aasland Feb 12, 2023
4106c1b
PyTextIOBase type
erlend-aasland Feb 12, 2023
3eba873
PyBufferedIOBase type
erlend-aasland Feb 12, 2023
de3acf0
PyIncrementalNewlineDecoder type
erlend-aasland Feb 13, 2023
bc35218
PyBytesIOBuffer type
erlend-aasland Feb 15, 2023
62a91e9
PyWindowsConsoleIO type
erlend-aasland Feb 15, 2023
23b79eb
RawIOBase type
erlend-aasland Feb 15, 2023
be64029
IOBase type
erlend-aasland Feb 15, 2023
55234a2
Remove crud
erlend-aasland Feb 15, 2023
0328a34
Fixup module def init
erlend-aasland Feb 15, 2023
a83cf1f
WIP module state / multi-phase init
erlend-aasland Feb 16, 2023
e9b0a27
Pull in main
erlend-aasland Feb 20, 2023
4e64198
Fix state assignment
kumaraditya303 Feb 20, 2023
bda9b43
Merge branch 'main' into isolate-io/poc
hauntsaninja Feb 20, 2023
a51823a
Experimental: add explicit finalizers to all types
erlend-aasland Feb 20, 2023
0cdd1ea
Fix check readable/writable/seekable methods
erlend-aasland Feb 20, 2023
3a1ed0b
Fix _textiowrapper_decode
erlend-aasland Feb 20, 2023
039b757
Revert "Experimental: add explicit finalizers to all types"
erlend-aasland Feb 20, 2023
17eb640
Purge old exports
erlend-aasland Feb 20, 2023
00d5abb
Revert "Fix check readable/writable/seekable methods"
erlend-aasland Feb 21, 2023
916ae8c
Pull in main
erlend-aasland Feb 23, 2023
fe8c256
Pass state to _check* functions
erlend-aasland Feb 23, 2023
d0a0d54
Windows fix (first of many)
erlend-aasland Feb 23, 2023
741d66b
Merge branch 'main' into isolate-io/poc
kumaraditya303 Mar 6, 2023
ce131d4
Merge branch 'main' of https://github.com/python/cpython into isolate…
kumaraditya303 Mar 14, 2023
2e0d06d
Pull in Kumar's work
erlend-aasland Mar 14, 2023
d9806e5
Merge branch 'python:main' into isolate-io/poc
kumaraditya303 Mar 14, 2023
6a813b4
fix conflict
kumaraditya303 Mar 14, 2023
0689f21
remove duplicate declarations
kumaraditya303 Mar 14, 2023
5e19c48
add missing methods
kumaraditya303 Mar 14, 2023
6099d5b
fix pickling
kumaraditya303 Mar 14, 2023
18de912
Add NEWS
erlend-aasland Mar 14, 2023
c363eb8
fix windows console check
kumaraditya303 Mar 14, 2023
1099d1f
Merge branch 'isolate-io/poc' of github.com:erlend-aasland/cpython in…
kumaraditya303 Mar 14, 2023
73d581c
remove locale
kumaraditya303 Mar 14, 2023
eaf585e
fix all windows checks
kumaraditya303 Mar 15, 2023
5a5bd9a
Merge branch 'main' of https://github.com/python/cpython into isolate…
kumaraditya303 Mar 15, 2023
7a8c2be
Merge branch 'main' into isolate-io/poc
kumaraditya303 Mar 18, 2023
d836b95
Pull in main
erlend-aasland Mar 22, 2023
8d5b6a1
Fix merge
erlend-aasland Mar 22, 2023
be971d1
Pull in main again
erlend-aasland Mar 24, 2023
9083979
Merge branch 'main' into isolate-io/poc
kumaraditya303 Apr 1, 2023
e12eb85
use _PyType_GetModuleState
kumaraditya303 Apr 4, 2023
137fc32
Merge branch 'main' of https://github.com/python/cpython into isolate-io
kumaraditya303 Apr 4, 2023
30b746b
Pull in main
erlend-aasland Apr 8, 2023
f1efcb1
Pull in main
erlend-aasland Apr 13, 2023
53ddde7
Pull in main
erlend-aasland Apr 18, 2023
4c7ca15
Pull in main again
erlend-aasland Apr 19, 2023
408c3b2
WIP
erlend-aasland Apr 19, 2023
142ac7f
Pull in main
erlend-aasland Apr 26, 2023
b4a89e4
Pull in main
erlend-aasland Apr 27, 2023
22b73a1
Visit and clear bytesio buf
erlend-aasland Apr 28, 2023
b3ec63a
Pull in main
erlend-aasland May 6, 2023
21470e6
Update NEWS
erlend-aasland May 6, 2023
ce82d88
Minimise diff a little bit
erlend-aasland May 6, 2023
3a9f582
Add Py_mod_multiple_interpreters mod slot
erlend-aasland May 6, 2023
f287cd5
Pull in main
erlend-aasland May 6, 2023
13700b5
Fix pickling
erlend-aasland May 6, 2023
e8d0b57
Make cannot-pickle function less smelly
erlend-aasland May 6, 2023
c65fcac
Pull in main
erlend-aasland May 7, 2023
f1a5de0
Style nit
erlend-aasland May 7, 2023
7bfbad0
Pull in main
erlend-aasland May 7, 2023
314137f
Pull in main
erlend-aasland May 9, 2023
9ca079f
Pull in main
erlend-aasland May 10, 2023
1078857
Reduce diff
erlend-aasland May 10, 2023
3dad388
Remove duplicate ADD_TYPE(PyBytesIOBuffer_Type...)
erlend-aasland May 10, 2023
8edc6cf
Pull in main and reduce diff further
erlend-aasland May 10, 2023
8df2633
Remove unneeded stylic change
erlend-aasland May 10, 2023
1505872
Reduce diff further
erlend-aasland May 10, 2023
18e8c43
Pull in main
erlend-aasland May 10, 2023
626685c
Pull in main
erlend-aasland May 11, 2023
6d55da9
fixes by Victor
kumaraditya303 May 12, 2023
bd73ab1
Merge branch 'main' of https://github.com/python/cpython into isolate…
kumaraditya303 May 12, 2023
80af518
remove unused functions
kumaraditya303 May 12, 2023
02dbef7
use defining_class
kumaraditya303 May 12, 2023
8518ec5
remove rawiobase_dealloc
kumaraditya303 May 12, 2023
d4b6dcc
Merge branch 'main' of https://github.com/python/cpython into isolate…
kumaraditya303 May 12, 2023
c5a4305
fix merge
kumaraditya303 May 12, 2023
ab1baf4
fix merge
kumaraditya303 May 12, 2023
fe2db1b
Merge branch 'main' into isolate-io/poc
kumaraditya303 May 15, 2023
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
Next Next commit
PyFileIO type
  • Loading branch information
erlend-aasland committed Feb 15, 2023
commit 8d96a7aabd29f2ef8b643898ff5a969e941d6d67
8 changes: 5 additions & 3 deletions Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,

/* Create the Raw file stream */
{
PyObject *RawIO_class = (PyObject *)&PyFileIO_Type;
_PyIO_State *state = get_io_state(module);
PyObject *RawIO_class = (PyObject *)state->PyFileIO_Type;
#ifdef MS_WINDOWS
const PyConfig *config = _Py_GetConfig();
if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') {
Expand Down Expand Up @@ -646,7 +647,6 @@ static PyTypeObject* static_types[] = {
&PyBufferedRandom_Type,

// PyRawIOBase_Type(PyIOBase_Type) subclasses
&PyFileIO_Type,
&_PyBytesIOBuffer_Type,
#ifdef MS_WINDOWS
&PyWindowsConsoleIO_Type,
Expand Down Expand Up @@ -706,7 +706,6 @@ PyInit__io(void)
}

// Set type base classes
PyFileIO_Type.tp_base = &PyRawIOBase_Type;
PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type;
#ifdef MS_WINDOWS
PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type;
Expand All @@ -724,6 +723,9 @@ PyInit__io(void)
}
}

// PyRawIOBase_Type(PyIOBase_Type) subclasses
ADD_TYPE(m, state->PyFileIO_Type, &fileio_spec, &PyRawIOBase_Type);

// PyTextIOBase_Type(PyIOBase_Type) subclasses
ADD_TYPE(m, state->PyStringIO_Type, &stringio_spec, &PyTextIOBase_Type);
ADD_TYPE(m, state->PyTextIOWrapper_Type, &textiowrapper_spec,
Expand Down
3 changes: 2 additions & 1 deletion Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern PyTypeObject PyBufferedIOBase_Type;
extern PyTypeObject PyTextIOBase_Type;

/* Concrete classes */
extern PyTypeObject PyFileIO_Type;
extern PyTypeObject PyBytesIO_Type;
extern PyTypeObject PyBufferedReader_Type;
extern PyTypeObject PyBufferedWriter_Type;
Expand All @@ -23,6 +22,7 @@ extern PyTypeObject PyBufferedRandom_Type;
extern PyTypeObject PyIncrementalNewlineDecoder_Type;

/* Type specs */
extern PyType_Spec fileio_spec;
extern PyType_Spec stringio_spec;
extern PyType_Spec textiowrapper_spec;

Expand Down Expand Up @@ -147,6 +147,7 @@ typedef struct {
PyObject *unsupported_operation;

/* Types */
PyTypeObject *PyFileIO_Type;
PyTypeObject *PyStringIO_Type;
PyTypeObject *PyTextIOWrapper_Type;
} _PyIO_State;
Expand Down
9 changes: 6 additions & 3 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,9 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
return -1;
_bufferedreader_reset_buf(self);

_PyIO_State *state = IO_STATE();
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedReader_Type) &&
Py_IS_TYPE(raw, &PyFileIO_Type));
Py_IS_TYPE(raw, state->PyFileIO_Type));

self->ok = 1;
return 0;
Expand Down Expand Up @@ -1783,8 +1784,9 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
_bufferedwriter_reset_buf(self);
self->pos = 0;

_PyIO_State *state = IO_STATE();
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedWriter_Type) &&
Py_IS_TYPE(raw, &PyFileIO_Type));
Py_IS_TYPE(raw, state->PyFileIO_Type));

self->ok = 1;
return 0;
Expand Down Expand Up @@ -2295,8 +2297,9 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
_bufferedwriter_reset_buf(self);
self->pos = 0;

_PyIO_State *state = IO_STATE();
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedRandom_Type) &&
Py_IS_TYPE(raw, &PyFileIO_Type));
Py_IS_TYPE(raw, state->PyFileIO_Type));

self->ok = 1;
return 0;
Expand Down
86 changes: 30 additions & 56 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

/*[clinic input]
module _io
class _io.FileIO "fileio *" "&PyFileIO_Type"
class _io.FileIO "fileio *" "clinic_state()->PyFileIO_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=1c77708b41fda70c]*/

Expand All @@ -70,9 +70,7 @@ typedef struct {
PyObject *dict;
} fileio;

PyTypeObject PyFileIO_Type;

#define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type))
#define PyFileIO_Check(state, op) (PyObject_TypeCheck((op), state->PyFileIO_Type))

/* Forward declarations */
static PyObject* portable_lseek(fileio *self, PyObject *posobj, int whence, bool suppress_pipe_error);
Expand Down Expand Up @@ -242,7 +240,8 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
int fstat_result;
int async_err = 0;

assert(PyFileIO_Check(self));
_PyIO_State *state = IO_STATE();
assert(PyFileIO_Check(state, self));
if (self->fd >= 0) {
if (self->closefd) {
/* Have to close the existing file first. */
Expand Down Expand Up @@ -503,6 +502,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
static int
fileio_traverse(fileio *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->dict);
return 0;
}
Expand All @@ -517,14 +517,16 @@ fileio_clear(fileio *self)
static void
fileio_dealloc(fileio *self)
{
PyTypeObject *tp = Py_TYPE(self);
self->finalizing = 1;
if (_PyIOBase_finalize((PyObject *) self) < 0)
return;
_PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
Py_CLEAR(self->dict);
Py_TYPE(self)->tp_free((PyObject *)self);
tp->tp_free((PyObject *)self);
Py_DECREF(tp);
}

static PyObject *
Expand Down Expand Up @@ -1177,57 +1179,29 @@ static PyGetSetDef fileio_getsetlist[] = {
static PyMemberDef fileio_members[] = {
{"_blksize", T_UINT, offsetof(fileio, blksize), 0},
{"_finalizing", T_BOOL, offsetof(fileio, finalizing), 0},
{"__weaklistoffset__", T_PYSSIZET, offsetof(fileio, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET, offsetof(fileio, dict), READONLY},
{NULL}
};

PyTypeObject PyFileIO_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_io.FileIO",
sizeof(fileio),
0,
(destructor)fileio_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
(reprfunc)fileio_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC, /* tp_flags */
_io_FileIO___init____doc__, /* tp_doc */
(traverseproc)fileio_traverse, /* tp_traverse */
(inquiry)fileio_clear, /* tp_clear */
0, /* tp_richcompare */
offsetof(fileio, weakreflist), /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
fileio_methods, /* tp_methods */
fileio_members, /* tp_members */
fileio_getsetlist, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
offsetof(fileio, dict), /* tp_dictoffset */
_io_FileIO___init__, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
fileio_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
0, /* tp_version_tag */
0, /* tp_finalize */
static PyType_Slot fileio_slots[] = {
{Py_tp_dealloc, fileio_dealloc},
{Py_tp_repr, fileio_repr},
{Py_tp_doc, (void *)_io_FileIO___init____doc__},
{Py_tp_traverse, fileio_traverse},
{Py_tp_clear, fileio_clear},
{Py_tp_methods, fileio_methods},
{Py_tp_members, fileio_members},
{Py_tp_getset, fileio_getsetlist},
{Py_tp_init, _io_FileIO___init__},
{Py_tp_new, fileio_new},
{0, NULL},
};

PyType_Spec fileio_spec = {
.name = "_io.FileIO",
.basicsize = sizeof(fileio),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = fileio_slots,
};
5 changes: 3 additions & 2 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
/* Finished sorting out the codec details */
Py_CLEAR(codec_info);

_PyIO_State *state = IO_STATE();
if (Py_IS_TYPE(buffer, &PyBufferedReader_Type) ||
Py_IS_TYPE(buffer, &PyBufferedWriter_Type) ||
Py_IS_TYPE(buffer, &PyBufferedRandom_Type))
Expand All @@ -1185,7 +1186,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error;
/* Cache the raw FileIO object to speed up 'closed' checks */
if (raw != NULL) {
if (Py_IS_TYPE(raw, &PyFileIO_Type))
if (Py_IS_TYPE(raw, state->PyFileIO_Type))
self->raw = raw;
else
Py_DECREF(raw);
Expand Down Expand Up @@ -1213,7 +1214,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error;
}

self->state = IO_STATE();
self->state = state;
self->ok = 1;
return 0;

Expand Down
1 change: 0 additions & 1 deletion Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ Modules/_io/bufferedio.c - PyBufferedReader_Type -
Modules/_io/bufferedio.c - PyBufferedWriter_Type -
Modules/_io/bytesio.c - PyBytesIO_Type -
Modules/_io/bytesio.c - _PyBytesIOBuffer_Type -
Modules/_io/fileio.c - PyFileIO_Type -
Modules/_io/iobase.c - PyIOBase_Type -
Modules/_io/iobase.c - PyRawIOBase_Type -
Modules/_io/textio.c - PyIncrementalNewlineDecoder_Type -
Expand Down