move to a naming scheme with all lowercase and underscores

This commit is contained in:
Benjamin Peterson 2009-06-12 02:07:12 +00:00
parent 2c3ac6b875
commit 680bf1afe8
8 changed files with 656 additions and 661 deletions

View file

@ -94,7 +94,7 @@ PyDoc_STRVAR(module_doc,
*/ */
static int static int
BlockingIOError_init(PyBlockingIOErrorObject *self, PyObject *args, blockingioerror_init(PyBlockingIOErrorObject *self, PyObject *args,
PyObject *kwds) PyObject *kwds)
{ {
PyObject *myerrno = NULL, *strerror = NULL; PyObject *myerrno = NULL, *strerror = NULL;
@ -123,7 +123,7 @@ BlockingIOError_init(PyBlockingIOErrorObject *self, PyObject *args,
return 0; return 0;
} }
static PyMemberDef BlockingIOError_members[] = { static PyMemberDef blockingioerror_members[] = {
{"characters_written", T_PYSSIZET, offsetof(PyBlockingIOErrorObject, written), 0}, {"characters_written", T_PYSSIZET, offsetof(PyBlockingIOErrorObject, written), 0},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
@ -158,14 +158,14 @@ static PyTypeObject _PyExc_BlockingIOError = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
0, /* tp_methods */ 0, /* tp_methods */
BlockingIOError_members, /* tp_members */ blockingioerror_members, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)BlockingIOError_init, /* tp_init */ (initproc)blockingioerror_init, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
0, /* tp_new */ 0, /* tp_new */
}; };

View file

@ -23,10 +23,10 @@ extern PyTypeObject PyIncrementalNewlineDecoder_Type;
* with args=NULL, and return a new reference. * with args=NULL, and return a new reference.
* BUT when args=Py_True is passed, they return a borrowed reference. * BUT when args=Py_True is passed, they return a borrowed reference.
*/ */
extern PyObject* _PyIOBase_checkReadable(PyObject *self, PyObject *args); extern PyObject* _PyIOBase_check_readable(PyObject *self, PyObject *args);
extern PyObject* _PyIOBase_checkWritable(PyObject *self, PyObject *args); extern PyObject* _PyIOBase_check_writable(PyObject *self, PyObject *args);
extern PyObject* _PyIOBase_checkSeekable(PyObject *self, PyObject *args); extern PyObject* _PyIOBase_check_seekable(PyObject *self, PyObject *args);
extern PyObject* _PyIOBase_checkClosed(PyObject *self, PyObject *args); extern PyObject* _PyIOBase_check_closed(PyObject *self, PyObject *args);
/* Helper for finalization. /* Helper for finalization.
This function will revive an object ready to be deallocated and try to This function will revive an object ready to be deallocated and try to

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@ typedef struct {
size_t buf_size; size_t buf_size;
PyObject *dict; PyObject *dict;
PyObject *weakreflist; PyObject *weakreflist;
} BytesIOObject; } bytesio;
#define CHECK_CLOSED(self) \ #define CHECK_CLOSED(self) \
if ((self)->buf == NULL) { \ if ((self)->buf == NULL) { \
@ -23,7 +23,7 @@ typedef struct {
object. Returns the length between the current position to the object. Returns the length between the current position to the
next newline character. */ next newline character. */
static Py_ssize_t static Py_ssize_t
get_line(BytesIOObject *self, char **output) get_line(bytesio *self, char **output)
{ {
char *n; char *n;
const char *str_end; const char *str_end;
@ -56,7 +56,7 @@ get_line(BytesIOObject *self, char **output)
The caller should ensure that the 'size' argument is non-negative. Returns The caller should ensure that the 'size' argument is non-negative. Returns
0 on success, -1 otherwise. */ 0 on success, -1 otherwise. */
static int static int
resize_buffer(BytesIOObject *self, size_t size) resize_buffer(bytesio *self, size_t size)
{ {
/* Here, unsigned types are used to avoid dealing with signed integer /* Here, unsigned types are used to avoid dealing with signed integer
overflow, which is undefined in C. */ overflow, which is undefined in C. */
@ -108,7 +108,7 @@ resize_buffer(BytesIOObject *self, size_t size)
/* Internal routine for writing a string of bytes to the buffer of a BytesIO /* Internal routine for writing a string of bytes to the buffer of a BytesIO
object. Returns the number of bytes wrote, or -1 on error. */ object. Returns the number of bytes wrote, or -1 on error. */
static Py_ssize_t static Py_ssize_t
write_bytes(BytesIOObject *self, const char *bytes, Py_ssize_t len) write_bytes(bytesio *self, const char *bytes, Py_ssize_t len)
{ {
assert(self->buf != NULL); assert(self->buf != NULL);
assert(self->pos >= 0); assert(self->pos >= 0);
@ -146,7 +146,7 @@ write_bytes(BytesIOObject *self, const char *bytes, Py_ssize_t len)
} }
static PyObject * static PyObject *
bytesio_get_closed(BytesIOObject *self) bytesio_get_closed(bytesio *self)
{ {
if (self->buf == NULL) { if (self->buf == NULL) {
Py_RETURN_TRUE; Py_RETURN_TRUE;
@ -158,7 +158,7 @@ bytesio_get_closed(BytesIOObject *self)
/* Generic getter for the writable, readable and seekable properties */ /* Generic getter for the writable, readable and seekable properties */
static PyObject * static PyObject *
return_true(BytesIOObject *self) return_true(bytesio *self)
{ {
Py_RETURN_TRUE; Py_RETURN_TRUE;
} }
@ -167,7 +167,7 @@ PyDoc_STRVAR(flush_doc,
"flush() -> None. Does nothing."); "flush() -> None. Does nothing.");
static PyObject * static PyObject *
bytesio_flush(BytesIOObject *self) bytesio_flush(bytesio *self)
{ {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -178,7 +178,7 @@ PyDoc_STRVAR(getval_doc,
"Retrieve the entire contents of the BytesIO object."); "Retrieve the entire contents of the BytesIO object.");
static PyObject * static PyObject *
bytesio_getvalue(BytesIOObject *self) bytesio_getvalue(bytesio *self)
{ {
CHECK_CLOSED(self); CHECK_CLOSED(self);
return PyBytes_FromStringAndSize(self->buf, self->string_size); return PyBytes_FromStringAndSize(self->buf, self->string_size);
@ -191,7 +191,7 @@ PyDoc_STRVAR(isatty_doc,
"to a tty-like device."); "to a tty-like device.");
static PyObject * static PyObject *
bytesio_isatty(BytesIOObject *self) bytesio_isatty(bytesio *self)
{ {
CHECK_CLOSED(self); CHECK_CLOSED(self);
Py_RETURN_FALSE; Py_RETURN_FALSE;
@ -201,7 +201,7 @@ PyDoc_STRVAR(tell_doc,
"tell() -> current file position, an integer\n"); "tell() -> current file position, an integer\n");
static PyObject * static PyObject *
bytesio_tell(BytesIOObject *self) bytesio_tell(bytesio *self)
{ {
CHECK_CLOSED(self); CHECK_CLOSED(self);
return PyLong_FromSsize_t(self->pos); return PyLong_FromSsize_t(self->pos);
@ -214,7 +214,7 @@ PyDoc_STRVAR(read_doc,
"Return an empty string at EOF."); "Return an empty string at EOF.");
static PyObject * static PyObject *
bytesio_read(BytesIOObject *self, PyObject *args) bytesio_read(bytesio *self, PyObject *args)
{ {
Py_ssize_t size, n; Py_ssize_t size, n;
char *output; char *output;
@ -263,7 +263,7 @@ PyDoc_STRVAR(read1_doc,
"Return an empty string at EOF."); "Return an empty string at EOF.");
static PyObject * static PyObject *
bytesio_read1(BytesIOObject *self, PyObject *n) bytesio_read1(bytesio *self, PyObject *n)
{ {
PyObject *arg, *res; PyObject *arg, *res;
@ -283,7 +283,7 @@ PyDoc_STRVAR(readline_doc,
"Return an empty string at EOF.\n"); "Return an empty string at EOF.\n");
static PyObject * static PyObject *
bytesio_readline(BytesIOObject *self, PyObject *args) bytesio_readline(bytesio *self, PyObject *args)
{ {
Py_ssize_t size, n; Py_ssize_t size, n;
char *output; char *output;
@ -328,7 +328,7 @@ PyDoc_STRVAR(readlines_doc,
"total number of bytes in the lines returned.\n"); "total number of bytes in the lines returned.\n");
static PyObject * static PyObject *
bytesio_readlines(BytesIOObject *self, PyObject *args) bytesio_readlines(bytesio *self, PyObject *args)
{ {
Py_ssize_t maxsize, size, n; Py_ssize_t maxsize, size, n;
PyObject *result, *line; PyObject *result, *line;
@ -387,7 +387,7 @@ PyDoc_STRVAR(readinto_doc,
"is set not to block as has no data to read."); "is set not to block as has no data to read.");
static PyObject * static PyObject *
bytesio_readinto(BytesIOObject *self, PyObject *buffer) bytesio_readinto(bytesio *self, PyObject *buffer)
{ {
void *raw_buffer; void *raw_buffer;
Py_ssize_t len; Py_ssize_t len;
@ -415,7 +415,7 @@ PyDoc_STRVAR(truncate_doc,
"Returns the new size. Imply an absolute seek to the position size."); "Returns the new size. Imply an absolute seek to the position size.");
static PyObject * static PyObject *
bytesio_truncate(BytesIOObject *self, PyObject *args) bytesio_truncate(bytesio *self, PyObject *args)
{ {
Py_ssize_t size; Py_ssize_t size;
PyObject *arg = Py_None; PyObject *arg = Py_None;
@ -457,7 +457,7 @@ bytesio_truncate(BytesIOObject *self, PyObject *args)
} }
static PyObject * static PyObject *
bytesio_iternext(BytesIOObject *self) bytesio_iternext(bytesio *self)
{ {
char *next; char *next;
Py_ssize_t n; Py_ssize_t n;
@ -482,7 +482,7 @@ PyDoc_STRVAR(seek_doc,
"Returns the new absolute position."); "Returns the new absolute position.");
static PyObject * static PyObject *
bytesio_seek(BytesIOObject *self, PyObject *args) bytesio_seek(bytesio *self, PyObject *args)
{ {
Py_ssize_t pos; Py_ssize_t pos;
int mode = 0; int mode = 0;
@ -536,7 +536,7 @@ PyDoc_STRVAR(write_doc,
"Return the number of bytes written."); "Return the number of bytes written.");
static PyObject * static PyObject *
bytesio_write(BytesIOObject *self, PyObject *obj) bytesio_write(bytesio *self, PyObject *obj)
{ {
Py_ssize_t n = 0; Py_ssize_t n = 0;
Py_buffer buf; Py_buffer buf;
@ -564,7 +564,7 @@ PyDoc_STRVAR(writelines_doc,
"each string."); "each string.");
static PyObject * static PyObject *
bytesio_writelines(BytesIOObject *self, PyObject *v) bytesio_writelines(bytesio *self, PyObject *v)
{ {
PyObject *it, *item; PyObject *it, *item;
PyObject *ret; PyObject *ret;
@ -597,7 +597,7 @@ PyDoc_STRVAR(close_doc,
"close() -> None. Disable all I/O operations."); "close() -> None. Disable all I/O operations.");
static PyObject * static PyObject *
bytesio_close(BytesIOObject *self) bytesio_close(bytesio *self)
{ {
if (self->buf != NULL) { if (self->buf != NULL) {
PyMem_Free(self->buf); PyMem_Free(self->buf);
@ -607,7 +607,7 @@ bytesio_close(BytesIOObject *self)
} }
static void static void
bytesio_dealloc(BytesIOObject *self) bytesio_dealloc(bytesio *self)
{ {
if (self->buf != NULL) { if (self->buf != NULL) {
PyMem_Free(self->buf); PyMem_Free(self->buf);
@ -620,10 +620,10 @@ bytesio_dealloc(BytesIOObject *self)
static PyObject * static PyObject *
bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
BytesIOObject *self; bytesio *self;
assert(type != NULL && type->tp_alloc != NULL); assert(type != NULL && type->tp_alloc != NULL);
self = (BytesIOObject *)type->tp_alloc(type, 0); self = (bytesio *)type->tp_alloc(type, 0);
if (self == NULL) if (self == NULL)
return NULL; return NULL;
@ -640,7 +640,7 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
} }
static int static int
bytesio_init(BytesIOObject *self, PyObject *args, PyObject *kwds) bytesio_init(bytesio *self, PyObject *args, PyObject *kwds)
{ {
PyObject *initvalue = NULL; PyObject *initvalue = NULL;
@ -664,7 +664,7 @@ bytesio_init(BytesIOObject *self, PyObject *args, PyObject *kwds)
} }
static int static int
bytesio_traverse(BytesIOObject *self, visitproc visit, void *arg) bytesio_traverse(bytesio *self, visitproc visit, void *arg)
{ {
Py_VISIT(self->dict); Py_VISIT(self->dict);
Py_VISIT(self->weakreflist); Py_VISIT(self->weakreflist);
@ -672,7 +672,7 @@ bytesio_traverse(BytesIOObject *self, visitproc visit, void *arg)
} }
static int static int
bytesio_clear(BytesIOObject *self) bytesio_clear(bytesio *self)
{ {
Py_CLEAR(self->dict); Py_CLEAR(self->dict);
if (self->weakreflist != NULL) if (self->weakreflist != NULL)
@ -717,7 +717,7 @@ PyDoc_STRVAR(bytesio_doc,
PyTypeObject PyBytesIO_Type = { PyTypeObject PyBytesIO_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"_io.BytesIO", /*tp_name*/ "_io.BytesIO", /*tp_name*/
sizeof(BytesIOObject), /*tp_basicsize*/ sizeof(bytesio), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)bytesio_dealloc, /*tp_dealloc*/ (destructor)bytesio_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
@ -740,7 +740,7 @@ PyTypeObject PyBytesIO_Type = {
(traverseproc)bytesio_traverse, /*tp_traverse*/ (traverseproc)bytesio_traverse, /*tp_traverse*/
(inquiry)bytesio_clear, /*tp_clear*/ (inquiry)bytesio_clear, /*tp_clear*/
0, /*tp_richcompare*/ 0, /*tp_richcompare*/
offsetof(BytesIOObject, weakreflist), /*tp_weaklistoffset*/ offsetof(bytesio, weakreflist), /*tp_weaklistoffset*/
PyObject_SelfIter, /*tp_iter*/ PyObject_SelfIter, /*tp_iter*/
(iternextfunc)bytesio_iternext, /*tp_iternext*/ (iternextfunc)bytesio_iternext, /*tp_iternext*/
bytesio_methods, /*tp_methods*/ bytesio_methods, /*tp_methods*/
@ -750,7 +750,7 @@ PyTypeObject PyBytesIO_Type = {
0, /*tp_dict*/ 0, /*tp_dict*/
0, /*tp_descr_get*/ 0, /*tp_descr_get*/
0, /*tp_descr_set*/ 0, /*tp_descr_set*/
offsetof(BytesIOObject, dict), /*tp_dictoffset*/ offsetof(bytesio, dict), /*tp_dictoffset*/
(initproc)bytesio_init, /*tp_init*/ (initproc)bytesio_init, /*tp_init*/
0, /*tp_alloc*/ 0, /*tp_alloc*/
bytesio_new, /*tp_new*/ bytesio_new, /*tp_new*/

View file

@ -51,7 +51,7 @@ typedef struct {
int closefd : 1; int closefd : 1;
PyObject *weakreflist; PyObject *weakreflist;
PyObject *dict; PyObject *dict;
} PyFileIOObject; } fileio;
PyTypeObject PyFileIO_Type; PyTypeObject PyFileIO_Type;
@ -60,7 +60,7 @@ PyTypeObject PyFileIO_Type;
int int
_PyFileIO_closed(PyObject *self) _PyFileIO_closed(PyObject *self)
{ {
return ((PyFileIOObject *)self)->fd < 0; return ((fileio *)self)->fd < 0;
} }
static PyObject * static PyObject *
@ -70,7 +70,7 @@ static PyObject *portable_lseek(int fd, PyObject *posobj, int whence);
/* Returns 0 on success, -1 with exception set on failure. */ /* Returns 0 on success, -1 with exception set on failure. */
static int static int
internal_close(PyFileIOObject *self) internal_close(fileio *self)
{ {
int err = 0; int err = 0;
int save_errno = 0; int save_errno = 0;
@ -98,7 +98,7 @@ internal_close(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_close(PyFileIOObject *self) fileio_close(fileio *self)
{ {
if (!self->closefd) { if (!self->closefd) {
self->fd = -1; self->fd = -1;
@ -115,11 +115,11 @@ fileio_close(PyFileIOObject *self)
static PyObject * static PyObject *
fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PyFileIOObject *self; fileio *self;
assert(type != NULL && type->tp_alloc != NULL); assert(type != NULL && type->tp_alloc != NULL);
self = (PyFileIOObject *) type->tp_alloc(type, 0); self = (fileio *) type->tp_alloc(type, 0);
if (self != NULL) { if (self != NULL) {
self->fd = -1; self->fd = -1;
self->readable = 0; self->readable = 0;
@ -137,7 +137,7 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
directories, so we need a check. */ directories, so we need a check. */
static int static int
dircheck(PyFileIOObject* self, const char *name) dircheck(fileio* self, const char *name)
{ {
#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
struct stat buf; struct stat buf;
@ -181,7 +181,7 @@ check_fd(int fd)
static int static int
fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
{ {
PyFileIOObject *self = (PyFileIOObject *) oself; fileio *self = (fileio *) oself;
static char *kwlist[] = {"file", "mode", "closefd", NULL}; static char *kwlist[] = {"file", "mode", "closefd", NULL};
const char *name = NULL; const char *name = NULL;
PyObject *nameobj, *stringobj = NULL; PyObject *nameobj, *stringobj = NULL;
@ -380,21 +380,21 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
} }
static int static int
fileio_traverse(PyFileIOObject *self, visitproc visit, void *arg) fileio_traverse(fileio *self, visitproc visit, void *arg)
{ {
Py_VISIT(self->dict); Py_VISIT(self->dict);
return 0; return 0;
} }
static int static int
fileio_clear(PyFileIOObject *self) fileio_clear(fileio *self)
{ {
Py_CLEAR(self->dict); Py_CLEAR(self->dict);
return 0; return 0;
} }
static void static void
fileio_dealloc(PyFileIOObject *self) fileio_dealloc(fileio *self)
{ {
if (_PyIOBase_finalize((PyObject *) self) < 0) if (_PyIOBase_finalize((PyObject *) self) < 0)
return; return;
@ -420,7 +420,7 @@ err_mode(char *action)
} }
static PyObject * static PyObject *
fileio_fileno(PyFileIOObject *self) fileio_fileno(fileio *self)
{ {
if (self->fd < 0) if (self->fd < 0)
return err_closed(); return err_closed();
@ -428,7 +428,7 @@ fileio_fileno(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_readable(PyFileIOObject *self) fileio_readable(fileio *self)
{ {
if (self->fd < 0) if (self->fd < 0)
return err_closed(); return err_closed();
@ -436,7 +436,7 @@ fileio_readable(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_writable(PyFileIOObject *self) fileio_writable(fileio *self)
{ {
if (self->fd < 0) if (self->fd < 0)
return err_closed(); return err_closed();
@ -444,7 +444,7 @@ fileio_writable(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_seekable(PyFileIOObject *self) fileio_seekable(fileio *self)
{ {
if (self->fd < 0) if (self->fd < 0)
return err_closed(); return err_closed();
@ -462,7 +462,7 @@ fileio_seekable(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_readinto(PyFileIOObject *self, PyObject *args) fileio_readinto(fileio *self, PyObject *args)
{ {
Py_buffer pbuf; Py_buffer pbuf;
Py_ssize_t n; Py_ssize_t n;
@ -494,7 +494,7 @@ fileio_readinto(PyFileIOObject *self, PyObject *args)
} }
static size_t static size_t
new_buffersize(PyFileIOObject *self, size_t currentsize) new_buffersize(fileio *self, size_t currentsize)
{ {
#ifdef HAVE_FSTAT #ifdef HAVE_FSTAT
off_t pos, end; off_t pos, end;
@ -524,7 +524,7 @@ new_buffersize(PyFileIOObject *self, size_t currentsize)
} }
static PyObject * static PyObject *
fileio_readall(PyFileIOObject *self) fileio_readall(fileio *self)
{ {
PyObject *result; PyObject *result;
Py_ssize_t total = 0; Py_ssize_t total = 0;
@ -590,7 +590,7 @@ fileio_readall(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_read(PyFileIOObject *self, PyObject *args) fileio_read(fileio *self, PyObject *args)
{ {
char *ptr; char *ptr;
Py_ssize_t n; Py_ssize_t n;
@ -641,7 +641,7 @@ fileio_read(PyFileIOObject *self, PyObject *args)
} }
static PyObject * static PyObject *
fileio_write(PyFileIOObject *self, PyObject *args) fileio_write(fileio *self, PyObject *args)
{ {
Py_buffer pbuf; Py_buffer pbuf;
Py_ssize_t n; Py_ssize_t n;
@ -734,7 +734,7 @@ portable_lseek(int fd, PyObject *posobj, int whence)
} }
static PyObject * static PyObject *
fileio_seek(PyFileIOObject *self, PyObject *args) fileio_seek(fileio *self, PyObject *args)
{ {
PyObject *posobj; PyObject *posobj;
int whence = 0; int whence = 0;
@ -749,7 +749,7 @@ fileio_seek(PyFileIOObject *self, PyObject *args)
} }
static PyObject * static PyObject *
fileio_tell(PyFileIOObject *self, PyObject *args) fileio_tell(fileio *self, PyObject *args)
{ {
if (self->fd < 0) if (self->fd < 0)
return err_closed(); return err_closed();
@ -759,7 +759,7 @@ fileio_tell(PyFileIOObject *self, PyObject *args)
#ifdef HAVE_FTRUNCATE #ifdef HAVE_FTRUNCATE
static PyObject * static PyObject *
fileio_truncate(PyFileIOObject *self, PyObject *args) fileio_truncate(fileio *self, PyObject *args)
{ {
PyObject *posobj = NULL; PyObject *posobj = NULL;
Py_off_t pos; Py_off_t pos;
@ -831,7 +831,7 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
#endif #endif
static char * static char *
mode_string(PyFileIOObject *self) mode_string(fileio *self)
{ {
if (self->readable) { if (self->readable) {
if (self->writable) if (self->writable)
@ -844,7 +844,7 @@ mode_string(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_repr(PyFileIOObject *self) fileio_repr(fileio *self)
{ {
PyObject *nameobj, *res; PyObject *nameobj, *res;
@ -869,7 +869,7 @@ fileio_repr(PyFileIOObject *self)
} }
static PyObject * static PyObject *
fileio_isatty(PyFileIOObject *self) fileio_isatty(fileio *self)
{ {
long res; long res;
@ -980,19 +980,19 @@ static PyMethodDef fileio_methods[] = {
/* 'closed' and 'mode' are attributes for backwards compatibility reasons. */ /* 'closed' and 'mode' are attributes for backwards compatibility reasons. */
static PyObject * static PyObject *
get_closed(PyFileIOObject *self, void *closure) get_closed(fileio *self, void *closure)
{ {
return PyBool_FromLong((long)(self->fd < 0)); return PyBool_FromLong((long)(self->fd < 0));
} }
static PyObject * static PyObject *
get_closefd(PyFileIOObject *self, void *closure) get_closefd(fileio *self, void *closure)
{ {
return PyBool_FromLong((long)(self->closefd)); return PyBool_FromLong((long)(self->closefd));
} }
static PyObject * static PyObject *
get_mode(PyFileIOObject *self, void *closure) get_mode(fileio *self, void *closure)
{ {
return PyUnicode_FromString(mode_string(self)); return PyUnicode_FromString(mode_string(self));
} }
@ -1008,7 +1008,7 @@ static PyGetSetDef fileio_getsetlist[] = {
PyTypeObject PyFileIO_Type = { PyTypeObject PyFileIO_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"_io.FileIO", "_io.FileIO",
sizeof(PyFileIOObject), sizeof(fileio),
0, 0,
(destructor)fileio_dealloc, /* tp_dealloc */ (destructor)fileio_dealloc, /* tp_dealloc */
0, /* tp_print */ 0, /* tp_print */
@ -1031,7 +1031,7 @@ PyTypeObject PyFileIO_Type = {
(traverseproc)fileio_traverse, /* tp_traverse */ (traverseproc)fileio_traverse, /* tp_traverse */
(inquiry)fileio_clear, /* tp_clear */ (inquiry)fileio_clear, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
offsetof(PyFileIOObject, weakreflist), /* tp_weaklistoffset */ offsetof(fileio, weakreflist), /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
fileio_methods, /* tp_methods */ fileio_methods, /* tp_methods */
@ -1041,7 +1041,7 @@ PyTypeObject PyFileIO_Type = {
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
offsetof(PyFileIOObject, dict), /* tp_dictoffset */ offsetof(fileio, dict), /* tp_dictoffset */
fileio_init, /* tp_init */ fileio_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */ PyType_GenericAlloc, /* tp_alloc */
fileio_new, /* tp_new */ fileio_new, /* tp_new */

View file

@ -22,9 +22,9 @@ typedef struct {
PyObject *dict; PyObject *dict;
PyObject *weakreflist; PyObject *weakreflist;
} IOBaseObject; } iobase;
PyDoc_STRVAR(IOBase_doc, PyDoc_STRVAR(iobase_doc,
"The abstract base class for all I/O classes, acting on streams of\n" "The abstract base class for all I/O classes, acting on streams of\n"
"bytes. There is no public constructor.\n" "bytes. There is no public constructor.\n"
"\n" "\n"
@ -63,7 +63,7 @@ PyDoc_STRVAR(IOBase_doc,
/* Internal methods */ /* Internal methods */
static PyObject * static PyObject *
IOBase_unsupported(const char *message) iobase_unsupported(const char *message)
{ {
PyErr_SetString(IO_STATE->unsupported_operation, message); PyErr_SetString(IO_STATE->unsupported_operation, message);
return NULL; return NULL;
@ -71,7 +71,7 @@ IOBase_unsupported(const char *message)
/* Positionning */ /* Positionning */
PyDoc_STRVAR(IOBase_seek_doc, PyDoc_STRVAR(iobase_seek_doc,
"Change stream position.\n" "Change stream position.\n"
"\n" "\n"
"Change the stream position to byte offset offset. offset is\n" "Change the stream position to byte offset offset. offset is\n"
@ -85,41 +85,41 @@ PyDoc_STRVAR(IOBase_seek_doc,
"Return the new absolute position."); "Return the new absolute position.");
static PyObject * static PyObject *
IOBase_seek(PyObject *self, PyObject *args) iobase_seek(PyObject *self, PyObject *args)
{ {
return IOBase_unsupported("seek"); return iobase_unsupported("seek");
} }
PyDoc_STRVAR(IOBase_tell_doc, PyDoc_STRVAR(iobase_tell_doc,
"Return current stream position."); "Return current stream position.");
static PyObject * static PyObject *
IOBase_tell(PyObject *self, PyObject *args) iobase_tell(PyObject *self, PyObject *args)
{ {
return PyObject_CallMethod(self, "seek", "ii", 0, 1); return PyObject_CallMethod(self, "seek", "ii", 0, 1);
} }
PyDoc_STRVAR(IOBase_truncate_doc, PyDoc_STRVAR(iobase_truncate_doc,
"Truncate file to size bytes.\n" "Truncate file to size bytes.\n"
"\n" "\n"
"Size defaults to the current IO position as reported by tell(). Return\n" "Size defaults to the current IO position as reported by tell(). Return\n"
"the new size."); "the new size.");
static PyObject * static PyObject *
IOBase_truncate(PyObject *self, PyObject *args) iobase_truncate(PyObject *self, PyObject *args)
{ {
return IOBase_unsupported("truncate"); return iobase_unsupported("truncate");
} }
/* Flush and close methods */ /* Flush and close methods */
PyDoc_STRVAR(IOBase_flush_doc, PyDoc_STRVAR(iobase_flush_doc,
"Flush write buffers, if applicable.\n" "Flush write buffers, if applicable.\n"
"\n" "\n"
"This is not implemented for read-only and non-blocking streams.\n"); "This is not implemented for read-only and non-blocking streams.\n");
static PyObject * static PyObject *
IOBase_flush(PyObject *self, PyObject *args) iobase_flush(PyObject *self, PyObject *args)
{ {
/* XXX Should this return the number of bytes written??? */ /* XXX Should this return the number of bytes written??? */
if (IS_CLOSED(self)) { if (IS_CLOSED(self)) {
@ -129,13 +129,13 @@ IOBase_flush(PyObject *self, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
PyDoc_STRVAR(IOBase_close_doc, PyDoc_STRVAR(iobase_close_doc,
"Flush and close the IO object.\n" "Flush and close the IO object.\n"
"\n" "\n"
"This method has no effect if the file is already closed.\n"); "This method has no effect if the file is already closed.\n");
static int static int
IOBase_closed(PyObject *self) iobase_closed(PyObject *self)
{ {
PyObject *res; PyObject *res;
int closed; int closed;
@ -150,15 +150,15 @@ IOBase_closed(PyObject *self)
} }
static PyObject * static PyObject *
IOBase_closed_get(PyObject *self, void *context) iobase_closed_get(PyObject *self, void *context)
{ {
return PyBool_FromLong(IS_CLOSED(self)); return PyBool_FromLong(IS_CLOSED(self));
} }
PyObject * PyObject *
_PyIOBase_checkClosed(PyObject *self, PyObject *args) _PyIOBase_check_closed(PyObject *self, PyObject *args)
{ {
if (IOBase_closed(self)) { if (iobase_closed(self)) {
PyErr_SetString(PyExc_ValueError, "I/O operation on closed file."); PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
return NULL; return NULL;
} }
@ -173,7 +173,7 @@ _PyIOBase_checkClosed(PyObject *self, PyObject *args)
whatever behaviour a non-trivial derived class will implement. */ whatever behaviour a non-trivial derived class will implement. */
static PyObject * static PyObject *
IOBase_close(PyObject *self, PyObject *args) iobase_close(PyObject *self, PyObject *args)
{ {
PyObject *res; PyObject *res;
@ -260,14 +260,14 @@ _PyIOBase_finalize(PyObject *self)
} }
static int static int
IOBase_traverse(IOBaseObject *self, visitproc visit, void *arg) iobase_traverse(iobase *self, visitproc visit, void *arg)
{ {
Py_VISIT(self->dict); Py_VISIT(self->dict);
return 0; return 0;
} }
static int static int
IOBase_clear(IOBaseObject *self) iobase_clear(iobase *self)
{ {
if (_PyIOBase_finalize((PyObject *) self) < 0) if (_PyIOBase_finalize((PyObject *) self) < 0)
return -1; return -1;
@ -278,7 +278,7 @@ IOBase_clear(IOBaseObject *self)
/* Destructor */ /* Destructor */
static void static void
IOBase_dealloc(IOBaseObject *self) iobase_dealloc(iobase *self)
{ {
/* NOTE: since IOBaseObject has its own dict, Python-defined attributes /* NOTE: since IOBaseObject has its own dict, Python-defined attributes
are still available here for close() to use. are still available here for close() to use.
@ -301,20 +301,20 @@ IOBase_dealloc(IOBaseObject *self)
/* Inquiry methods */ /* Inquiry methods */
PyDoc_STRVAR(IOBase_seekable_doc, PyDoc_STRVAR(iobase_seekable_doc,
"Return whether object supports random access.\n" "Return whether object supports random access.\n"
"\n" "\n"
"If False, seek(), tell() and truncate() will raise IOError.\n" "If False, seek(), tell() and truncate() will raise IOError.\n"
"This method may need to do a test seek()."); "This method may need to do a test seek().");
static PyObject * static PyObject *
IOBase_seekable(PyObject *self, PyObject *args) iobase_seekable(PyObject *self, PyObject *args)
{ {
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
PyObject * PyObject *
_PyIOBase_checkSeekable(PyObject *self, PyObject *args) _PyIOBase_check_seekable(PyObject *self, PyObject *args)
{ {
PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_seekable, NULL); PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_seekable, NULL);
if (res == NULL) if (res == NULL)
@ -330,20 +330,20 @@ _PyIOBase_checkSeekable(PyObject *self, PyObject *args)
return res; return res;
} }
PyDoc_STRVAR(IOBase_readable_doc, PyDoc_STRVAR(iobase_readable_doc,
"Return whether object was opened for reading.\n" "Return whether object was opened for reading.\n"
"\n" "\n"
"If False, read() will raise IOError."); "If False, read() will raise IOError.");
static PyObject * static PyObject *
IOBase_readable(PyObject *self, PyObject *args) iobase_readable(PyObject *self, PyObject *args)
{ {
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
/* May be called with any object */ /* May be called with any object */
PyObject * PyObject *
_PyIOBase_checkReadable(PyObject *self, PyObject *args) _PyIOBase_check_readable(PyObject *self, PyObject *args)
{ {
PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_readable, NULL); PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_readable, NULL);
if (res == NULL) if (res == NULL)
@ -359,20 +359,20 @@ _PyIOBase_checkReadable(PyObject *self, PyObject *args)
return res; return res;
} }
PyDoc_STRVAR(IOBase_writable_doc, PyDoc_STRVAR(iobase_writable_doc,
"Return whether object was opened for writing.\n" "Return whether object was opened for writing.\n"
"\n" "\n"
"If False, read() will raise IOError."); "If False, read() will raise IOError.");
static PyObject * static PyObject *
IOBase_writable(PyObject *self, PyObject *args) iobase_writable(PyObject *self, PyObject *args)
{ {
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
/* May be called with any object */ /* May be called with any object */
PyObject * PyObject *
_PyIOBase_checkWritable(PyObject *self, PyObject *args) _PyIOBase_check_writable(PyObject *self, PyObject *args)
{ {
PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_writable, NULL); PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_writable, NULL);
if (res == NULL) if (res == NULL)
@ -391,9 +391,9 @@ _PyIOBase_checkWritable(PyObject *self, PyObject *args)
/* Context manager */ /* Context manager */
static PyObject * static PyObject *
IOBase_enter(PyObject *self, PyObject *args) iobase_enter(PyObject *self, PyObject *args)
{ {
if (_PyIOBase_checkClosed(self, Py_True) == NULL) if (_PyIOBase_check_closed(self, Py_True) == NULL)
return NULL; return NULL;
Py_INCREF(self); Py_INCREF(self);
@ -401,7 +401,7 @@ IOBase_enter(PyObject *self, PyObject *args)
} }
static PyObject * static PyObject *
IOBase_exit(PyObject *self, PyObject *args) iobase_exit(PyObject *self, PyObject *args)
{ {
return PyObject_CallMethodObjArgs(self, _PyIO_str_close, NULL); return PyObject_CallMethodObjArgs(self, _PyIO_str_close, NULL);
} }
@ -410,33 +410,33 @@ IOBase_exit(PyObject *self, PyObject *args)
/* XXX Should these be present even if unimplemented? */ /* XXX Should these be present even if unimplemented? */
PyDoc_STRVAR(IOBase_fileno_doc, PyDoc_STRVAR(iobase_fileno_doc,
"Returns underlying file descriptor if one exists.\n" "Returns underlying file descriptor if one exists.\n"
"\n" "\n"
"An IOError is raised if the IO object does not use a file descriptor.\n"); "An IOError is raised if the IO object does not use a file descriptor.\n");
static PyObject * static PyObject *
IOBase_fileno(PyObject *self, PyObject *args) iobase_fileno(PyObject *self, PyObject *args)
{ {
return IOBase_unsupported("fileno"); return iobase_unsupported("fileno");
} }
PyDoc_STRVAR(IOBase_isatty_doc, PyDoc_STRVAR(iobase_isatty_doc,
"Return whether this is an 'interactive' stream.\n" "Return whether this is an 'interactive' stream.\n"
"\n" "\n"
"Return False if it can't be determined.\n"); "Return False if it can't be determined.\n");
static PyObject * static PyObject *
IOBase_isatty(PyObject *self, PyObject *args) iobase_isatty(PyObject *self, PyObject *args)
{ {
if (_PyIOBase_checkClosed(self, Py_True) == NULL) if (_PyIOBase_check_closed(self, Py_True) == NULL)
return NULL; return NULL;
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
/* Readline(s) and writelines */ /* Readline(s) and writelines */
PyDoc_STRVAR(IOBase_readline_doc, PyDoc_STRVAR(iobase_readline_doc,
"Read and return a line from the stream.\n" "Read and return a line from the stream.\n"
"\n" "\n"
"If limit is specified, at most limit bytes will be read.\n" "If limit is specified, at most limit bytes will be read.\n"
@ -446,7 +446,7 @@ PyDoc_STRVAR(IOBase_readline_doc,
"terminator(s) recognized.\n"); "terminator(s) recognized.\n");
static PyObject * static PyObject *
IOBase_readline(PyObject *self, PyObject *args) iobase_readline(PyObject *self, PyObject *args)
{ {
/* For backwards compatibility, a (slowish) readline(). */ /* For backwards compatibility, a (slowish) readline(). */
@ -541,9 +541,9 @@ IOBase_readline(PyObject *self, PyObject *args)
} }
static PyObject * static PyObject *
IOBase_iter(PyObject *self) iobase_iter(PyObject *self)
{ {
if (_PyIOBase_checkClosed(self, Py_True) == NULL) if (_PyIOBase_check_closed(self, Py_True) == NULL)
return NULL; return NULL;
Py_INCREF(self); Py_INCREF(self);
@ -551,7 +551,7 @@ IOBase_iter(PyObject *self)
} }
static PyObject * static PyObject *
IOBase_iternext(PyObject *self) iobase_iternext(PyObject *self)
{ {
PyObject *line = PyObject_CallMethodObjArgs(self, _PyIO_str_readline, NULL); PyObject *line = PyObject_CallMethodObjArgs(self, _PyIO_str_readline, NULL);
@ -566,7 +566,7 @@ IOBase_iternext(PyObject *self)
return line; return line;
} }
PyDoc_STRVAR(IOBase_readlines_doc, PyDoc_STRVAR(iobase_readlines_doc,
"Return a list of lines from the stream.\n" "Return a list of lines from the stream.\n"
"\n" "\n"
"hint can be specified to control the number of lines read: no more\n" "hint can be specified to control the number of lines read: no more\n"
@ -574,7 +574,7 @@ PyDoc_STRVAR(IOBase_readlines_doc,
"lines so far exceeds hint."); "lines so far exceeds hint.");
static PyObject * static PyObject *
IOBase_readlines(PyObject *self, PyObject *args) iobase_readlines(PyObject *self, PyObject *args)
{ {
Py_ssize_t hint = -1, length = 0; Py_ssize_t hint = -1, length = 0;
PyObject *hintobj = Py_None, *result; PyObject *hintobj = Py_None, *result;
@ -631,7 +631,7 @@ IOBase_readlines(PyObject *self, PyObject *args)
} }
static PyObject * static PyObject *
IOBase_writelines(PyObject *self, PyObject *args) iobase_writelines(PyObject *self, PyObject *args)
{ {
PyObject *lines, *iter, *res; PyObject *lines, *iter, *res;
@ -639,7 +639,7 @@ IOBase_writelines(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
if (_PyIOBase_checkClosed(self, Py_True) == NULL) if (_PyIOBase_check_closed(self, Py_True) == NULL)
return NULL; return NULL;
iter = PyObject_GetIter(lines); iter = PyObject_GetIter(lines);
@ -669,37 +669,37 @@ IOBase_writelines(PyObject *self, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyMethodDef IOBase_methods[] = { static PyMethodDef iobase_methods[] = {
{"seek", IOBase_seek, METH_VARARGS, IOBase_seek_doc}, {"seek", iobase_seek, METH_VARARGS, iobase_seek_doc},
{"tell", IOBase_tell, METH_NOARGS, IOBase_tell_doc}, {"tell", iobase_tell, METH_NOARGS, iobase_tell_doc},
{"truncate", IOBase_truncate, METH_VARARGS, IOBase_truncate_doc}, {"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc},
{"flush", IOBase_flush, METH_NOARGS, IOBase_flush_doc}, {"flush", iobase_flush, METH_NOARGS, iobase_flush_doc},
{"close", IOBase_close, METH_NOARGS, IOBase_close_doc}, {"close", iobase_close, METH_NOARGS, iobase_close_doc},
{"seekable", IOBase_seekable, METH_NOARGS, IOBase_seekable_doc}, {"seekable", iobase_seekable, METH_NOARGS, iobase_seekable_doc},
{"readable", IOBase_readable, METH_NOARGS, IOBase_readable_doc}, {"readable", iobase_readable, METH_NOARGS, iobase_readable_doc},
{"writable", IOBase_writable, METH_NOARGS, IOBase_writable_doc}, {"writable", iobase_writable, METH_NOARGS, iobase_writable_doc},
{"_checkClosed", _PyIOBase_checkClosed, METH_NOARGS}, {"_checkClosed", _PyIOBase_check_closed, METH_NOARGS},
{"_checkSeekable", _PyIOBase_checkSeekable, METH_NOARGS}, {"_checkSeekable", _PyIOBase_check_seekable, METH_NOARGS},
{"_checkReadable", _PyIOBase_checkReadable, METH_NOARGS}, {"_checkReadable", _PyIOBase_check_readable, METH_NOARGS},
{"_checkWritable", _PyIOBase_checkWritable, METH_NOARGS}, {"_checkWritable", _PyIOBase_check_writable, METH_NOARGS},
{"fileno", IOBase_fileno, METH_NOARGS, IOBase_fileno_doc}, {"fileno", iobase_fileno, METH_NOARGS, iobase_fileno_doc},
{"isatty", IOBase_isatty, METH_NOARGS, IOBase_isatty_doc}, {"isatty", iobase_isatty, METH_NOARGS, iobase_isatty_doc},
{"__enter__", IOBase_enter, METH_NOARGS}, {"__enter__", iobase_enter, METH_NOARGS},
{"__exit__", IOBase_exit, METH_VARARGS}, {"__exit__", iobase_exit, METH_VARARGS},
{"readline", IOBase_readline, METH_VARARGS, IOBase_readline_doc}, {"readline", iobase_readline, METH_VARARGS, iobase_readline_doc},
{"readlines", IOBase_readlines, METH_VARARGS, IOBase_readlines_doc}, {"readlines", iobase_readlines, METH_VARARGS, iobase_readlines_doc},
{"writelines", IOBase_writelines, METH_VARARGS}, {"writelines", iobase_writelines, METH_VARARGS},
{NULL, NULL} {NULL, NULL}
}; };
static PyGetSetDef IOBase_getset[] = { static PyGetSetDef iobase_getset[] = {
{"closed", (getter)IOBase_closed_get, NULL, NULL}, {"closed", (getter)iobase_closed_get, NULL, NULL},
{NULL} {NULL}
}; };
@ -707,9 +707,9 @@ static PyGetSetDef IOBase_getset[] = {
PyTypeObject PyIOBase_Type = { PyTypeObject PyIOBase_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"_io._IOBase", /*tp_name*/ "_io._IOBase", /*tp_name*/
sizeof(IOBaseObject), /*tp_basicsize*/ sizeof(iobase), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)IOBase_dealloc, /*tp_dealloc*/ (destructor)iobase_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -726,21 +726,21 @@ PyTypeObject PyIOBase_Type = {
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC, /*tp_flags*/ | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
IOBase_doc, /* tp_doc */ iobase_doc, /* tp_doc */
(traverseproc)IOBase_traverse, /* tp_traverse */ (traverseproc)iobase_traverse, /* tp_traverse */
(inquiry)IOBase_clear, /* tp_clear */ (inquiry)iobase_clear, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
offsetof(IOBaseObject, weakreflist), /* tp_weaklistoffset */ offsetof(iobase, weakreflist), /* tp_weaklistoffset */
IOBase_iter, /* tp_iter */ iobase_iter, /* tp_iter */
IOBase_iternext, /* tp_iternext */ iobase_iternext, /* tp_iternext */
IOBase_methods, /* tp_methods */ iobase_methods, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
IOBase_getset, /* tp_getset */ iobase_getset, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
offsetof(IOBaseObject, dict), /* tp_dictoffset */ offsetof(iobase, dict), /* tp_dictoffset */
0, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PyType_GenericNew, /* tp_new */ PyType_GenericNew, /* tp_new */
@ -750,7 +750,7 @@ PyTypeObject PyIOBase_Type = {
/* /*
* RawIOBase class, Inherits from IOBase. * RawIOBase class, Inherits from IOBase.
*/ */
PyDoc_STRVAR(RawIOBase_doc, PyDoc_STRVAR(rawiobase_doc,
"Base class for raw binary I/O."); "Base class for raw binary I/O.");
/* /*
@ -766,7 +766,7 @@ PyDoc_STRVAR(RawIOBase_doc,
*/ */
static PyObject * static PyObject *
RawIOBase_read(PyObject *self, PyObject *args) rawiobase_read(PyObject *self, PyObject *args)
{ {
Py_ssize_t n = -1; Py_ssize_t n = -1;
PyObject *b, *res; PyObject *b, *res;
@ -803,11 +803,11 @@ RawIOBase_read(PyObject *self, PyObject *args)
} }
PyDoc_STRVAR(RawIOBase_readall_doc, PyDoc_STRVAR(rawiobase_readall_doc,
"Read until EOF, using multiple read() call."); "Read until EOF, using multiple read() call.");
static PyObject * static PyObject *
RawIOBase_readall(PyObject *self, PyObject *args) rawiobase_readall(PyObject *self, PyObject *args)
{ {
int r; int r;
PyObject *chunks = PyList_New(0); PyObject *chunks = PyList_New(0);
@ -846,9 +846,9 @@ RawIOBase_readall(PyObject *self, PyObject *args)
return result; return result;
} }
static PyMethodDef RawIOBase_methods[] = { static PyMethodDef rawiobase_methods[] = {
{"read", RawIOBase_read, METH_VARARGS}, {"read", rawiobase_read, METH_VARARGS},
{"readall", RawIOBase_readall, METH_NOARGS, RawIOBase_readall_doc}, {"readall", rawiobase_readall, METH_NOARGS, rawiobase_readall_doc},
{NULL, NULL} {NULL, NULL}
}; };
@ -873,14 +873,14 @@ PyTypeObject PyRawIOBase_Type = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
RawIOBase_doc, /* tp_doc */ rawiobase_doc, /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
RawIOBase_methods, /* tp_methods */ rawiobase_methods, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PyIOBase_Type, /* tp_base */ &PyIOBase_Type, /* tp_base */

View file

@ -24,7 +24,7 @@ typedef struct {
PyObject *dict; PyObject *dict;
PyObject *weakreflist; PyObject *weakreflist;
} StringIOObject; } stringio;
#define CHECK_INITIALIZED(self) \ #define CHECK_INITIALIZED(self) \
if (self->ok <= 0) { \ if (self->ok <= 0) { \
@ -51,7 +51,7 @@ PyDoc_STRVAR(stringio_doc,
buffer of StringIO objects. The caller should ensure that the 'size' buffer of StringIO objects. The caller should ensure that the 'size'
argument is non-negative. Returns 0 on success, -1 otherwise. */ argument is non-negative. Returns 0 on success, -1 otherwise. */
static int static int
resize_buffer(StringIOObject *self, size_t size) resize_buffer(stringio *self, size_t size)
{ {
/* Here, unsigned types are used to avoid dealing with signed integer /* Here, unsigned types are used to avoid dealing with signed integer
overflow, which is undefined in C. */ overflow, which is undefined in C. */
@ -106,7 +106,7 @@ resize_buffer(StringIOObject *self, size_t size)
/* Internal routine for writing a whole PyUnicode object to the buffer of a /* Internal routine for writing a whole PyUnicode object to the buffer of a
StringIO object. Returns 0 on success, or -1 on error. */ StringIO object. Returns 0 on success, or -1 on error. */
static Py_ssize_t static Py_ssize_t
write_str(StringIOObject *self, PyObject *obj) write_str(stringio *self, PyObject *obj)
{ {
Py_UNICODE *str; Py_UNICODE *str;
Py_ssize_t len; Py_ssize_t len;
@ -186,7 +186,7 @@ PyDoc_STRVAR(stringio_getvalue_doc,
"Retrieve the entire contents of the object."); "Retrieve the entire contents of the object.");
static PyObject * static PyObject *
stringio_getvalue(StringIOObject *self) stringio_getvalue(stringio *self)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
CHECK_CLOSED(self); CHECK_CLOSED(self);
@ -197,7 +197,7 @@ PyDoc_STRVAR(stringio_tell_doc,
"Tell the current file position."); "Tell the current file position.");
static PyObject * static PyObject *
stringio_tell(StringIOObject *self) stringio_tell(stringio *self)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
CHECK_CLOSED(self); CHECK_CLOSED(self);
@ -211,7 +211,7 @@ PyDoc_STRVAR(stringio_read_doc,
"is reached. Return an empty string at EOF.\n"); "is reached. Return an empty string at EOF.\n");
static PyObject * static PyObject *
stringio_read(StringIOObject *self, PyObject *args) stringio_read(stringio *self, PyObject *args)
{ {
Py_ssize_t size, n; Py_ssize_t size, n;
Py_UNICODE *output; Py_UNICODE *output;
@ -252,7 +252,7 @@ stringio_read(StringIOObject *self, PyObject *args)
/* Internal helper, used by stringio_readline and stringio_iternext */ /* Internal helper, used by stringio_readline and stringio_iternext */
static PyObject * static PyObject *
_stringio_readline(StringIOObject *self, Py_ssize_t limit) _stringio_readline(stringio *self, Py_ssize_t limit)
{ {
Py_UNICODE *start, *end, old_char; Py_UNICODE *start, *end, old_char;
Py_ssize_t len, consumed; Py_ssize_t len, consumed;
@ -286,7 +286,7 @@ PyDoc_STRVAR(stringio_readline_doc,
"Returns an empty string if EOF is hit immediately.\n"); "Returns an empty string if EOF is hit immediately.\n");
static PyObject * static PyObject *
stringio_readline(StringIOObject *self, PyObject *args) stringio_readline(stringio *self, PyObject *args)
{ {
PyObject *arg = Py_None; PyObject *arg = Py_None;
Py_ssize_t limit = -1; Py_ssize_t limit = -1;
@ -310,7 +310,7 @@ stringio_readline(StringIOObject *self, PyObject *args)
} }
static PyObject * static PyObject *
stringio_iternext(StringIOObject *self) stringio_iternext(stringio *self)
{ {
PyObject *line; PyObject *line;
@ -354,7 +354,7 @@ PyDoc_STRVAR(stringio_truncate_doc,
"Returns the new absolute position.\n"); "Returns the new absolute position.\n");
static PyObject * static PyObject *
stringio_truncate(StringIOObject *self, PyObject *args) stringio_truncate(stringio *self, PyObject *args)
{ {
Py_ssize_t size; Py_ssize_t size;
PyObject *arg = Py_None; PyObject *arg = Py_None;
@ -405,7 +405,7 @@ PyDoc_STRVAR(stringio_seek_doc,
"Returns the new absolute position.\n"); "Returns the new absolute position.\n");
static PyObject * static PyObject *
stringio_seek(StringIOObject *self, PyObject *args) stringio_seek(stringio *self, PyObject *args)
{ {
Py_ssize_t pos; Py_ssize_t pos;
int mode = 0; int mode = 0;
@ -453,7 +453,7 @@ PyDoc_STRVAR(stringio_write_doc,
"the length of the string.\n"); "the length of the string.\n");
static PyObject * static PyObject *
stringio_write(StringIOObject *self, PyObject *obj) stringio_write(stringio *self, PyObject *obj)
{ {
Py_ssize_t size; Py_ssize_t size;
@ -479,7 +479,7 @@ PyDoc_STRVAR(stringio_close_doc,
"This method has no effect if the file is already closed.\n"); "This method has no effect if the file is already closed.\n");
static PyObject * static PyObject *
stringio_close(StringIOObject *self) stringio_close(stringio *self)
{ {
self->closed = 1; self->closed = 1;
/* Free up some memory */ /* Free up some memory */
@ -492,21 +492,21 @@ stringio_close(StringIOObject *self)
} }
static int static int
stringio_traverse(StringIOObject *self, visitproc visit, void *arg) stringio_traverse(stringio *self, visitproc visit, void *arg)
{ {
Py_VISIT(self->dict); Py_VISIT(self->dict);
return 0; return 0;
} }
static int static int
stringio_clear(StringIOObject *self) stringio_clear(stringio *self)
{ {
Py_CLEAR(self->dict); Py_CLEAR(self->dict);
return 0; return 0;
} }
static void static void
stringio_dealloc(StringIOObject *self) stringio_dealloc(stringio *self)
{ {
_PyObject_GC_UNTRACK(self); _PyObject_GC_UNTRACK(self);
Py_CLEAR(self->readnl); Py_CLEAR(self->readnl);
@ -522,10 +522,10 @@ stringio_dealloc(StringIOObject *self)
static PyObject * static PyObject *
stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
StringIOObject *self; stringio *self;
assert(type != NULL && type->tp_alloc != NULL); assert(type != NULL && type->tp_alloc != NULL);
self = (StringIOObject *)type->tp_alloc(type, 0); self = (stringio *)type->tp_alloc(type, 0);
if (self == NULL) if (self == NULL)
return NULL; return NULL;
@ -542,7 +542,7 @@ stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
} }
static int static int
stringio_init(StringIOObject *self, PyObject *args, PyObject *kwds) stringio_init(stringio *self, PyObject *args, PyObject *kwds)
{ {
char *kwlist[] = {"initial_value", "newline", NULL}; char *kwlist[] = {"initial_value", "newline", NULL};
PyObject *value = NULL; PyObject *value = NULL;
@ -625,28 +625,28 @@ stringio_init(StringIOObject *self, PyObject *args, PyObject *kwds)
/* Properties and pseudo-properties */ /* Properties and pseudo-properties */
static PyObject * static PyObject *
stringio_seekable(StringIOObject *self, PyObject *args) stringio_seekable(stringio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
Py_RETURN_TRUE; Py_RETURN_TRUE;
} }
static PyObject * static PyObject *
stringio_readable(StringIOObject *self, PyObject *args) stringio_readable(stringio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
Py_RETURN_TRUE; Py_RETURN_TRUE;
} }
static PyObject * static PyObject *
stringio_writable(StringIOObject *self, PyObject *args) stringio_writable(stringio *self, PyObject *args)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
Py_RETURN_TRUE; Py_RETURN_TRUE;
} }
static PyObject * static PyObject *
stringio_buffer(StringIOObject *self, void *context) stringio_buffer(stringio *self, void *context)
{ {
PyErr_SetString(IO_STATE->unsupported_operation, PyErr_SetString(IO_STATE->unsupported_operation,
"buffer attribute is unsupported on type StringIO"); "buffer attribute is unsupported on type StringIO");
@ -654,14 +654,14 @@ stringio_buffer(StringIOObject *self, void *context)
} }
static PyObject * static PyObject *
stringio_closed(StringIOObject *self, void *context) stringio_closed(stringio *self, void *context)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
return PyBool_FromLong(self->closed); return PyBool_FromLong(self->closed);
} }
static PyObject * static PyObject *
stringio_line_buffering(StringIOObject *self, void *context) stringio_line_buffering(stringio *self, void *context)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
CHECK_CLOSED(self); CHECK_CLOSED(self);
@ -669,7 +669,7 @@ stringio_line_buffering(StringIOObject *self, void *context)
} }
static PyObject * static PyObject *
stringio_newlines(StringIOObject *self, void *context) stringio_newlines(stringio *self, void *context)
{ {
CHECK_INITIALIZED(self); CHECK_INITIALIZED(self);
CHECK_CLOSED(self); CHECK_CLOSED(self);
@ -711,7 +711,7 @@ static PyGetSetDef stringio_getset[] = {
PyTypeObject PyStringIO_Type = { PyTypeObject PyStringIO_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"_io.StringIO", /*tp_name*/ "_io.StringIO", /*tp_name*/
sizeof(StringIOObject), /*tp_basicsize*/ sizeof(stringio), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)stringio_dealloc, /*tp_dealloc*/ (destructor)stringio_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
@ -734,7 +734,7 @@ PyTypeObject PyStringIO_Type = {
(traverseproc)stringio_traverse, /*tp_traverse*/ (traverseproc)stringio_traverse, /*tp_traverse*/
(inquiry)stringio_clear, /*tp_clear*/ (inquiry)stringio_clear, /*tp_clear*/
0, /*tp_richcompare*/ 0, /*tp_richcompare*/
offsetof(StringIOObject, weakreflist), /*tp_weaklistoffset*/ offsetof(stringio, weakreflist), /*tp_weaklistoffset*/
0, /*tp_iter*/ 0, /*tp_iter*/
(iternextfunc)stringio_iternext, /*tp_iternext*/ (iternextfunc)stringio_iternext, /*tp_iternext*/
stringio_methods, /*tp_methods*/ stringio_methods, /*tp_methods*/
@ -744,7 +744,7 @@ PyTypeObject PyStringIO_Type = {
0, /*tp_dict*/ 0, /*tp_dict*/
0, /*tp_descr_get*/ 0, /*tp_descr_get*/
0, /*tp_descr_set*/ 0, /*tp_descr_set*/
offsetof(StringIOObject, dict), /*tp_dictoffset*/ offsetof(stringio, dict), /*tp_dictoffset*/
(initproc)stringio_init, /*tp_init*/ (initproc)stringio_init, /*tp_init*/
0, /*tp_alloc*/ 0, /*tp_alloc*/
stringio_new, /*tp_new*/ stringio_new, /*tp_new*/

File diff suppressed because it is too large Load diff