Merged revisions 76805 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76805 | benjamin.peterson | 2009-12-13 13:19:07 -0600 (Sun, 13 Dec 2009) | 7 lines
accept None as the same as having passed no argument in file types #7349
This is for consistency with imitation file objects like StringIO and BytesIO.
This commit also adds a few tests, where they were lacking for concerned
methods.
........
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 02776f3..dfd66aa 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -561,6 +561,30 @@
return result;
}
+
+/* Basically the "n" format code with the ability to turn None into -1. */
+int
+_PyIO_ConvertSsize_t(PyObject *obj, void *result) {
+ Py_ssize_t limit;
+ if (obj == Py_None) {
+ limit = -1;
+ }
+ else if (PyNumber_Check(obj)) {
+ limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError);
+ if (limit == -1 && PyErr_Occurred())
+ return 0;
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "integer argument expected, got '%.200s'",
+ Py_TYPE(obj)->tp_name);
+ return 0;
+ }
+ *((Py_ssize_t *)result) = limit;
+ return 1;
+}
+
+
static int
iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
_PyIO_State *state = IO_MOD_STATE(mod);
@@ -574,6 +598,7 @@
return 0;
}
+
static int
iomodule_clear(PyObject *mod) {
_PyIO_State *state = IO_MOD_STATE(mod);
@@ -591,6 +616,7 @@
iomodule_clear(mod);
}
+
/*
* Module definition
*/