Revert the fix for #1548891, it broke backwards compatibility with arbitrary read buffers.
Fixes #1730114.
(backport from rev. 56830)
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 06bc6cb..2d8a6ab 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -665,8 +665,11 @@
char *buf;
Py_ssize_t size;
- if (PyObject_AsCharBuffer(s, (const char **)&buf, &size) != 0)
- return NULL;
+ if (PyObject_AsReadBuffer(s, (const char **)&buf, &size)) {
+ PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found",
+ s->ob_type->tp_name);
+ return NULL;
+ }
self = PyObject_New(Iobject, &Itype);
if (!self) return NULL;