]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/Modules/cStringIO.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Modules / cStringIO.c
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Modules/cStringIO.c b/AppPkg/Applications/Python/Python-2.7.10/Modules/cStringIO.c
deleted file mode 100644 (file)
index 9710f33..0000000
+++ /dev/null
@@ -1,779 +0,0 @@
-\r
-#include "Python.h"\r
-#include "import.h"\r
-#include "cStringIO.h"\r
-#include "structmember.h"\r
-\r
-PyDoc_STRVAR(cStringIO_module_documentation,\r
-"A simple fast partial StringIO replacement.\n"\r
-"\n"\r
-"This module provides a simple useful replacement for\n"\r
-"the StringIO module that is written in C.  It does not provide the\n"\r
-"full generality of StringIO, but it provides enough for most\n"\r
-"applications and is especially useful in conjunction with the\n"\r
-"pickle module.\n"\r
-"\n"\r
-"Usage:\n"\r
-"\n"\r
-"  from cStringIO import StringIO\n"\r
-"\n"\r
-"  an_output_stream=StringIO()\n"\r
-"  an_output_stream.write(some_stuff)\n"\r
-"  ...\n"\r
-"  value=an_output_stream.getvalue()\n"\r
-"\n"\r
-"  an_input_stream=StringIO(a_string)\n"\r
-"  spam=an_input_stream.readline()\n"\r
-"  spam=an_input_stream.read(5)\n"\r
-"  an_input_stream.seek(0)           # OK, start over\n"\r
-"  spam=an_input_stream.read()       # and read it all\n"\r
-"  \n"\r
-"If someone else wants to provide a more complete implementation,\n"\r
-"go for it. :-)  \n"\r
-"\n"\r
-"cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp\n");\r
-\r
-/* Declaration for file-like objects that manage data as strings\r
-\r
-   The IOobject type should be though of as a common base type for\r
-   Iobjects, which provide input (read-only) StringIO objects and\r
-   Oobjects, which provide read-write objects.  Most of the methods\r
-   depend only on common data.\r
-*/\r
-\r
-typedef struct {\r
-  PyObject_HEAD\r
-  char *buf;\r
-  Py_ssize_t pos, string_size;\r
-} IOobject;\r
-\r
-#define IOOOBJECT(O) ((IOobject*)(O))\r
-\r
-/* Declarations for objects of type StringO */\r
-\r
-typedef struct { /* Subtype of IOobject */\r
-  PyObject_HEAD\r
-  char *buf;\r
-  Py_ssize_t pos, string_size;\r
-\r
-  Py_ssize_t buf_size;\r
-  int softspace;\r
-} Oobject;\r
-\r
-/* Declarations for objects of type StringI */\r
-\r
-typedef struct { /* Subtype of IOobject */\r
-  PyObject_HEAD\r
-  char *buf;\r
-  Py_ssize_t pos, string_size;\r
-    Py_buffer pbuf;\r
-} Iobject;\r
-\r
-/* IOobject (common) methods */\r
-\r
-PyDoc_STRVAR(IO_flush__doc__, "flush(): does nothing.");\r
-\r
-static int\r
-IO__opencheck(IOobject *self) {\r
-    if (!self->buf) {\r
-        PyErr_SetString(PyExc_ValueError,\r
-                        "I/O operation on closed file");\r
-        return 0;\r
-    }\r
-    return 1;\r
-}\r
-\r
-static PyObject *\r
-IO_get_closed(IOobject *self, void *closure)\r
-{\r
-    PyObject *result = Py_False;\r
-\r
-    if (self->buf == NULL)\r
-        result = Py_True;\r
-    Py_INCREF(result);\r
-    return result;\r
-}\r
-\r
-static PyGetSetDef file_getsetlist[] = {\r
-    {"closed", (getter)IO_get_closed, NULL, "True if the file is closed"},\r
-    {0},\r
-};\r
-\r
-static PyObject *\r
-IO_flush(IOobject *self, PyObject *unused) {\r
-\r
-    if (!IO__opencheck(self)) return NULL;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(IO_getval__doc__,\r
-"getvalue([use_pos]) -- Get the string value."\r
-"\n"\r
-"If use_pos is specified and is a true value, then the string returned\n"\r
-"will include only the text up to the current file position.\n");\r
-\r
-static PyObject *\r
-IO_cgetval(PyObject *self) {\r
-    if (!IO__opencheck(IOOOBJECT(self))) return NULL;\r
-    assert(IOOOBJECT(self)->pos >= 0);\r
-    return PyString_FromStringAndSize(((IOobject*)self)->buf,\r
-                                      ((IOobject*)self)->pos);\r
-}\r
-\r
-static PyObject *\r
-IO_getval(IOobject *self, PyObject *args) {\r
-    PyObject *use_pos=Py_None;\r
-    int b;\r
-    Py_ssize_t s;\r
-\r
-    if (!IO__opencheck(self)) return NULL;\r
-    if (!PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL;\r
-\r
-    b = PyObject_IsTrue(use_pos);\r
-    if (b < 0)\r
-        return NULL;\r
-    if (b) {\r
-              s=self->pos;\r
-              if (s > self->string_size) s=self->string_size;\r
-    }\r
-    else\r
-              s=self->string_size;\r
-    assert(self->pos >= 0);\r
-    return PyString_FromStringAndSize(self->buf, s);\r
-}\r
-\r
-PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0");\r
-\r
-static PyObject *\r
-IO_isatty(IOobject *self, PyObject *unused) {\r
-    if (!IO__opencheck(self)) return NULL;\r
-    Py_INCREF(Py_False);\r
-    return Py_False;\r
-}\r
-\r
-PyDoc_STRVAR(IO_read__doc__,\r
-"read([s]) -- Read s characters, or the rest of the string");\r
-\r
-static int\r
-IO_cread(PyObject *self, char **output, Py_ssize_t  n) {\r
-    Py_ssize_t l;\r
-\r
-    if (!IO__opencheck(IOOOBJECT(self))) return -1;\r
-    assert(IOOOBJECT(self)->pos >= 0);\r
-    assert(IOOOBJECT(self)->string_size >= 0);\r
-    l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos;\r
-    if (n < 0 || n > l) {\r
-        n = l;\r
-        if (n < 0) n=0;\r
-    }\r
-    if (n > INT_MAX) {\r
-        PyErr_SetString(PyExc_OverflowError,\r
-                        "length too large");\r
-        return -1;\r
-    }\r
-\r
-    *output=((IOobject*)self)->buf + ((IOobject*)self)->pos;\r
-    ((IOobject*)self)->pos += n;\r
-    return (int)n;\r
-}\r
-\r
-static PyObject *\r
-IO_read(IOobject *self, PyObject *args) {\r
-    Py_ssize_t n = -1;\r
-    char *output = NULL;\r
-\r
-    if (!PyArg_ParseTuple(args, "|n:read", &n)) return NULL;\r
-\r
-    if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL;\r
-\r
-    return PyString_FromStringAndSize(output, n);\r
-}\r
-\r
-PyDoc_STRVAR(IO_readline__doc__, "readline() -- Read one line");\r
-\r
-static int\r
-IO_creadline(PyObject *self, char **output) {\r
-    char *n, *start, *end;\r
-    Py_ssize_t len;\r
-\r
-    if (!IO__opencheck(IOOOBJECT(self))) return -1;\r
-\r
-    n = start = ((IOobject*)self)->buf + ((IOobject*)self)->pos;\r
-    end = ((IOobject*)self)->buf + ((IOobject*)self)->string_size;\r
-    while (n < end && *n != '\n')\r
-        n++;\r
-\r
-    if (n < end) n++;\r
-\r
-    len = n - start;\r
-    if (len > INT_MAX)\r
-        len = INT_MAX;\r
-\r
-    *output=start;\r
-\r
-    assert(IOOOBJECT(self)->pos <= PY_SSIZE_T_MAX - len);\r
-    assert(IOOOBJECT(self)->pos >= 0);\r
-    assert(IOOOBJECT(self)->string_size >= 0);\r
-\r
-    ((IOobject*)self)->pos += len;\r
-    return (int)len;\r
-}\r
-\r
-static PyObject *\r
-IO_readline(IOobject *self, PyObject *args) {\r
-    int n, m=-1;\r
-    char *output;\r
-\r
-    if (args)\r
-        if (!PyArg_ParseTuple(args, "|i:readline", &m)) return NULL;\r
-\r
-    if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL;\r
-    if (m >= 0 && m < n) {\r
-        m = n - m;\r
-        n -= m;\r
-        self->pos -= m;\r
-    }\r
-    assert(IOOOBJECT(self)->pos >= 0);\r
-    return PyString_FromStringAndSize(output, n);\r
-}\r
-\r
-PyDoc_STRVAR(IO_readlines__doc__, "readlines() -- Read all lines");\r
-\r
-static PyObject *\r
-IO_readlines(IOobject *self, PyObject *args) {\r
-    int n;\r
-    char *output;\r
-    PyObject *result, *line;\r
-    Py_ssize_t hint = 0, length = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "|n:readlines", &hint)) return NULL;\r
-\r
-    result = PyList_New(0);\r
-    if (!result)\r
-        return NULL;\r
-\r
-    while (1){\r
-        if ( (n = IO_creadline((PyObject*)self,&output)) < 0)\r
-            goto err;\r
-        if (n == 0)\r
-            break;\r
-        line = PyString_FromStringAndSize (output, n);\r
-        if (!line)\r
-            goto err;\r
-        if (PyList_Append (result, line) == -1) {\r
-            Py_DECREF (line);\r
-            goto err;\r
-        }\r
-        Py_DECREF (line);\r
-        length += n;\r
-        if (hint > 0 && length >= hint)\r
-            break;\r
-    }\r
-    return result;\r
- err:\r
-    Py_DECREF(result);\r
-    return NULL;\r
-}\r
-\r
-PyDoc_STRVAR(IO_reset__doc__,\r
-"reset() -- Reset the file position to the beginning");\r
-\r
-static PyObject *\r
-IO_reset(IOobject *self, PyObject *unused) {\r
-\r
-    if (!IO__opencheck(self)) return NULL;\r
-\r
-    self->pos = 0;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(IO_tell__doc__, "tell() -- get the current position.");\r
-\r
-static PyObject *\r
-IO_tell(IOobject *self, PyObject *unused) {\r
-\r
-    if (!IO__opencheck(self)) return NULL;\r
-\r
-    assert(self->pos >= 0);\r
-    return PyInt_FromSsize_t(self->pos);\r
-}\r
-\r
-PyDoc_STRVAR(IO_truncate__doc__,\r
-"truncate(): truncate the file at the current position.");\r
-\r
-static PyObject *\r
-IO_truncate(IOobject *self, PyObject *args) {\r
-    Py_ssize_t pos = -1;\r
-\r
-    if (!IO__opencheck(self)) return NULL;\r
-    if (!PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;\r
-\r
-    if (PyTuple_Size(args) == 0) {\r
-        /* No argument passed, truncate to current position */\r
-        pos = self->pos;\r
-    }\r
-\r
-    if (pos < 0) {\r
-        errno = EINVAL;\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-\r
-    if (self->string_size > pos) self->string_size = pos;\r
-    self->pos = self->string_size;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-static PyObject *\r
-IO_iternext(Iobject *self)\r
-{\r
-    PyObject *next;\r
-    next = IO_readline((IOobject *)self, NULL);\r
-    if (!next)\r
-        return NULL;\r
-    if (!PyString_GET_SIZE(next)) {\r
-        Py_DECREF(next);\r
-        PyErr_SetNone(PyExc_StopIteration);\r
-        return NULL;\r
-    }\r
-    return next;\r
-}\r
-\r
-\r
-\r
-\r
-/* Read-write object methods */\r
-\r
-PyDoc_STRVAR(IO_seek__doc__,\r
-"seek(position)       -- set the current position\n"\r
-"seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF");\r
-\r
-static PyObject *\r
-IO_seek(Iobject *self, PyObject *args) {\r
-    Py_ssize_t position;\r
-    int mode = 0;\r
-\r
-    if (!IO__opencheck(IOOOBJECT(self))) return NULL;\r
-    if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode))\r
-        return NULL;\r
-\r
-    if (mode == 2) {\r
-        position += self->string_size;\r
-    }\r
-    else if (mode == 1) {\r
-        position += self->pos;\r
-    }\r
-\r
-    if (position < 0) position=0;\r
-\r
-    self->pos=position;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(O_write__doc__,\r
-"write(s) -- Write a string to the file"\r
-"\n\nNote (hack:) writing None resets the buffer");\r
-\r
-\r
-static int\r
-O_cwrite(PyObject *self, const char *c, Py_ssize_t  len) {\r
-    Py_ssize_t newpos;\r
-    Oobject *oself;\r
-    char *newbuf;\r
-\r
-    if (!IO__opencheck(IOOOBJECT(self))) return -1;\r
-    oself = (Oobject *)self;\r
-\r
-    if (len > INT_MAX) {\r
-        PyErr_SetString(PyExc_OverflowError,\r
-                        "length too large");\r
-        return -1;\r
-    }\r
-    assert(len >= 0);\r
-    if (oself->pos >= PY_SSIZE_T_MAX - len) {\r
-        PyErr_SetString(PyExc_OverflowError,\r
-                        "new position too large");\r
-        return -1;\r
-    }\r
-    newpos = oself->pos + len;\r
-    if (newpos >= oself->buf_size) {\r
-        size_t newsize = oself->buf_size;\r
-        newsize *= 2;\r
-        if (newsize <= (size_t)newpos || newsize > PY_SSIZE_T_MAX) {\r
-            assert(newpos < PY_SSIZE_T_MAX - 1);\r
-            newsize = newpos + 1;\r
-        }\r
-        newbuf = (char*)realloc(oself->buf, newsize);\r
-        if (!newbuf) {\r
-            PyErr_SetString(PyExc_MemoryError,"out of memory");\r
-            return -1;\r
-        }\r
-        oself->buf_size = (Py_ssize_t)newsize;\r
-        oself->buf = newbuf;\r
-    }\r
-\r
-    if (oself->string_size < oself->pos) {\r
-        /* In case of overseek, pad with null bytes the buffer region between\r
-           the end of stream and the current position.\r
-\r
-          0   lo      string_size                           hi\r
-          |   |<---used--->|<----------available----------->|\r
-          |   |            <--to pad-->|<---to write--->    |\r
-          0   buf                   position\r
-        */\r
-        memset(oself->buf + oself->string_size, '\0',\r
-               (oself->pos - oself->string_size) * sizeof(char));\r
-    }\r
-\r
-    memcpy(oself->buf + oself->pos, c, len);\r
-\r
-    oself->pos = newpos;\r
-\r
-    if (oself->string_size < oself->pos) {\r
-        oself->string_size = oself->pos;\r
-    }\r
-\r
-    return (int)len;\r
-}\r
-\r
-static PyObject *\r
-O_write(Oobject *self, PyObject *args) {\r
-    Py_buffer buf;\r
-    int result;\r
-\r
-    if (!PyArg_ParseTuple(args, "s*:write", &buf)) return NULL;\r
-\r
-    result = O_cwrite((PyObject*)self, buf.buf, buf.len);\r
-    PyBuffer_Release(&buf);\r
-    if (result < 0) return NULL;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(O_close__doc__, "close(): explicitly release resources held.");\r
-\r
-static PyObject *\r
-O_close(Oobject *self, PyObject *unused) {\r
-    if (self->buf != NULL) free(self->buf);\r
-    self->buf = NULL;\r
-\r
-    self->pos = self->string_size = self->buf_size = 0;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(O_writelines__doc__,\r
-"writelines(sequence_of_strings) -> None.  Write the strings to the file.\n"\r
-"\n"\r
-"Note that newlines are not added.  The sequence can be any iterable object\n"\r
-"producing strings. This is equivalent to calling write() for each string.");\r
-static PyObject *\r
-O_writelines(Oobject *self, PyObject *args) {\r
-    PyObject *it, *s;\r
-\r
-    it = PyObject_GetIter(args);\r
-    if (it == NULL)\r
-        return NULL;\r
-    while ((s = PyIter_Next(it)) != NULL) {\r
-        Py_ssize_t n;\r
-        char *c;\r
-        if (PyString_AsStringAndSize(s, &c, &n) == -1) {\r
-            Py_DECREF(it);\r
-            Py_DECREF(s);\r
-            return NULL;\r
-        }\r
-        if (O_cwrite((PyObject *)self, c, n) == -1) {\r
-            Py_DECREF(it);\r
-            Py_DECREF(s);\r
-            return NULL;\r
-           }\r
-           Py_DECREF(s);\r
-       }\r
-\r
-       Py_DECREF(it);\r
-\r
-       /* See if PyIter_Next failed */\r
-       if (PyErr_Occurred())\r
-           return NULL;\r
-\r
-       Py_RETURN_NONE;\r
-}\r
-static struct PyMethodDef O_methods[] = {\r
-  /* Common methods: */\r
-  {"flush",     (PyCFunction)IO_flush,    METH_NOARGS,  IO_flush__doc__},\r
-  {"getvalue",  (PyCFunction)IO_getval,   METH_VARARGS, IO_getval__doc__},\r
-  {"isatty",    (PyCFunction)IO_isatty,   METH_NOARGS,  IO_isatty__doc__},\r
-  {"read",      (PyCFunction)IO_read,     METH_VARARGS, IO_read__doc__},\r
-  {"readline",  (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__},\r
-  {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__},\r
-  {"reset",     (PyCFunction)IO_reset,    METH_NOARGS,  IO_reset__doc__},\r
-  {"seek",      (PyCFunction)IO_seek,     METH_VARARGS, IO_seek__doc__},\r
-  {"tell",      (PyCFunction)IO_tell,     METH_NOARGS,  IO_tell__doc__},\r
-  {"truncate",  (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__},\r
-\r
-  /* Read-write StringIO specific  methods: */\r
-  {"close",      (PyCFunction)O_close,      METH_NOARGS,  O_close__doc__},\r
-  {"write",      (PyCFunction)O_write,      METH_VARARGS, O_write__doc__},\r
-  {"writelines", (PyCFunction)O_writelines, METH_O,       O_writelines__doc__},\r
-  {NULL,         NULL}          /* sentinel */\r
-};\r
-\r
-static PyMemberDef O_memberlist[] = {\r
-    {"softspace",       T_INT,  offsetof(Oobject, softspace),   0,\r
-     "flag indicating that a space needs to be printed; used by print"},\r
-     /* getattr(f, "closed") is implemented without this table */\r
-    {NULL} /* Sentinel */\r
-};\r
-\r
-static void\r
-O_dealloc(Oobject *self) {\r
-    if (self->buf != NULL)\r
-        free(self->buf);\r
-    PyObject_Del(self);\r
-}\r
-\r
-PyDoc_STRVAR(Otype__doc__, "Simple type for output to strings.");\r
-\r
-static PyTypeObject Otype = {\r
-  PyVarObject_HEAD_INIT(NULL, 0)\r
-  "cStringIO.StringO",          /*tp_name*/\r
-  sizeof(Oobject),              /*tp_basicsize*/\r
-  0,                            /*tp_itemsize*/\r
-  /* methods */\r
-  (destructor)O_dealloc,        /*tp_dealloc*/\r
-  0,                            /*tp_print*/\r
-  0,                            /*tp_getattr */\r
-  0,                            /*tp_setattr */\r
-  0,                            /*tp_compare*/\r
-  0,                            /*tp_repr*/\r
-  0,                            /*tp_as_number*/\r
-  0,                            /*tp_as_sequence*/\r
-  0,                            /*tp_as_mapping*/\r
-  0,                            /*tp_hash*/\r
-  0     ,                       /*tp_call*/\r
-  0,                            /*tp_str*/\r
-  0,                            /*tp_getattro */\r
-  0,                            /*tp_setattro */\r
-  0,                            /*tp_as_buffer */\r
-  Py_TPFLAGS_DEFAULT,           /*tp_flags*/\r
-  Otype__doc__,                 /*tp_doc */\r
-  0,                            /*tp_traverse */\r
-  0,                            /*tp_clear */\r
-  0,                            /*tp_richcompare */\r
-  0,                            /*tp_weaklistoffset */\r
-  PyObject_SelfIter,            /*tp_iter */\r
-  (iternextfunc)IO_iternext,    /*tp_iternext */\r
-  O_methods,                    /*tp_methods */\r
-  O_memberlist,                 /*tp_members */\r
-  file_getsetlist,              /*tp_getset */\r
-};\r
-\r
-static PyObject *\r
-newOobject(int  size) {\r
-    Oobject *self;\r
-\r
-    self = PyObject_New(Oobject, &Otype);\r
-    if (self == NULL)\r
-        return NULL;\r
-    self->pos=0;\r
-    self->string_size = 0;\r
-    self->softspace = 0;\r
-\r
-    self->buf = (char *)malloc(size);\r
-    if (!self->buf) {\r
-              PyErr_SetString(PyExc_MemoryError,"out of memory");\r
-              self->buf_size = 0;\r
-              Py_DECREF(self);\r
-              return NULL;\r
-      }\r
-\r
-    self->buf_size=size;\r
-    return (PyObject*)self;\r
-}\r
-\r
-/* End of code for StringO objects */\r
-/* -------------------------------------------------------- */\r
-\r
-static PyObject *\r
-I_close(Iobject *self, PyObject *unused) {\r
-    PyBuffer_Release(&self->pbuf);\r
-    self->buf = NULL;\r
-\r
-    self->pos = self->string_size = 0;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-static struct PyMethodDef I_methods[] = {\r
-  /* Common methods: */\r
-  {"flush",     (PyCFunction)IO_flush,    METH_NOARGS,  IO_flush__doc__},\r
-  {"getvalue",  (PyCFunction)IO_getval,   METH_VARARGS, IO_getval__doc__},\r
-  {"isatty",    (PyCFunction)IO_isatty,   METH_NOARGS,  IO_isatty__doc__},\r
-  {"read",      (PyCFunction)IO_read,     METH_VARARGS, IO_read__doc__},\r
-  {"readline",  (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__},\r
-  {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__},\r
-  {"reset",     (PyCFunction)IO_reset,    METH_NOARGS,  IO_reset__doc__},\r
-  {"seek",      (PyCFunction)IO_seek,     METH_VARARGS, IO_seek__doc__},\r
-  {"tell",      (PyCFunction)IO_tell,     METH_NOARGS,  IO_tell__doc__},\r
-  {"truncate",  (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__},\r
-\r
-  /* Read-only StringIO specific  methods: */\r
-  {"close",     (PyCFunction)I_close,    METH_NOARGS,  O_close__doc__},\r
-  {NULL,        NULL}\r
-};\r
-\r
-static void\r
-I_dealloc(Iobject *self) {\r
-  PyBuffer_Release(&self->pbuf);\r
-  PyObject_Del(self);\r
-}\r
-\r
-\r
-PyDoc_STRVAR(Itype__doc__,\r
-"Simple type for treating strings as input file streams");\r
-\r
-static PyTypeObject Itype = {\r
-  PyVarObject_HEAD_INIT(NULL, 0)\r
-  "cStringIO.StringI",                  /*tp_name*/\r
-  sizeof(Iobject),                      /*tp_basicsize*/\r
-  0,                                    /*tp_itemsize*/\r
-  /* methods */\r
-  (destructor)I_dealloc,                /*tp_dealloc*/\r
-  0,                                    /*tp_print*/\r
-  0,                                    /* tp_getattr */\r
-  0,                                    /*tp_setattr*/\r
-  0,                                    /*tp_compare*/\r
-  0,                                    /*tp_repr*/\r
-  0,                                    /*tp_as_number*/\r
-  0,                                    /*tp_as_sequence*/\r
-  0,                                    /*tp_as_mapping*/\r
-  0,                                    /*tp_hash*/\r
-  0,                                    /*tp_call*/\r
-  0,                                    /*tp_str*/\r
-  0,                                    /* tp_getattro */\r
-  0,                                    /* tp_setattro */\r
-  0,                                    /* tp_as_buffer */\r
-  Py_TPFLAGS_DEFAULT,                   /* tp_flags */\r
-  Itype__doc__,                         /* tp_doc */\r
-  0,                                    /* tp_traverse */\r
-  0,                                    /* tp_clear */\r
-  0,                                    /* tp_richcompare */\r
-  0,                                    /* tp_weaklistoffset */\r
-  PyObject_SelfIter,                    /* tp_iter */\r
-  (iternextfunc)IO_iternext,            /* tp_iternext */\r
-  I_methods,                            /* tp_methods */\r
-  0,                                    /* tp_members */\r
-  file_getsetlist,                      /* tp_getset */\r
-};\r
-\r
-static PyObject *\r
-newIobject(PyObject *s) {\r
-  Iobject *self;\r
-  Py_buffer buf;\r
-  PyObject *args;\r
-  int result;\r
-\r
-  args = Py_BuildValue("(O)", s);\r
-  if (args == NULL)\r
-      return NULL;\r
-  result = PyArg_ParseTuple(args, "s*:StringIO", &buf);\r
-  Py_DECREF(args);\r
-  if (!result)\r
-      return NULL;\r
-\r
-  self = PyObject_New(Iobject, &Itype);\r
-  if (!self) {\r
-      PyBuffer_Release(&buf);\r
-      return NULL;\r
-  }\r
-  self->buf=buf.buf;\r
-  self->string_size=buf.len;\r
-  self->pbuf=buf;\r
-  self->pos=0;\r
-\r
-  return (PyObject*)self;\r
-}\r
-\r
-/* End of code for StringI objects */\r
-/* -------------------------------------------------------- */\r
-\r
-\r
-PyDoc_STRVAR(IO_StringIO__doc__,\r
-"StringIO([s]) -- Return a StringIO-like stream for reading or writing");\r
-\r
-static PyObject *\r
-IO_StringIO(PyObject *self, PyObject *args) {\r
-  PyObject *s=0;\r
-\r
-  if (!PyArg_UnpackTuple(args, "StringIO", 0, 1, &s)) return NULL;\r
-\r
-  if (s) return newIobject(s);\r
-  return newOobject(128);\r
-}\r
-\r
-/* List of methods defined in the module */\r
-\r
-static struct PyMethodDef IO_methods[] = {\r
-  {"StringIO",  (PyCFunction)IO_StringIO,\r
-   METH_VARARGS,        IO_StringIO__doc__},\r
-  {NULL,                NULL}           /* sentinel */\r
-};\r
-\r
-\r
-/* Initialization function for the module (*must* be called initcStringIO) */\r
-\r
-static struct PycStringIO_CAPI CAPI = {\r
-  IO_cread,\r
-  IO_creadline,\r
-  O_cwrite,\r
-  IO_cgetval,\r
-  newOobject,\r
-  newIobject,\r
-  &Itype,\r
-  &Otype,\r
-};\r
-\r
-#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */\r
-#define PyMODINIT_FUNC void\r
-#endif\r
-PyMODINIT_FUNC\r
-initcStringIO(void) {\r
-  PyObject *m, *d, *v;\r
-\r
-\r
-  /* Create the module and add the functions */\r
-  m = Py_InitModule4("cStringIO", IO_methods,\r
-                     cStringIO_module_documentation,\r
-                     (PyObject*)NULL,PYTHON_API_VERSION);\r
-  if (m == NULL) return;\r
-\r
-  /* Add some symbolic constants to the module */\r
-  d = PyModule_GetDict(m);\r
-\r
-  /* Export C API */\r
-  Py_TYPE(&Itype)=&PyType_Type;\r
-  Py_TYPE(&Otype)=&PyType_Type;\r
-  if (PyType_Ready(&Otype) < 0) return;\r
-  if (PyType_Ready(&Itype) < 0) return;\r
-  v = PyCapsule_New(&CAPI, PycStringIO_CAPSULE_NAME, NULL);\r
-  PyDict_SetItemString(d,"cStringIO_CAPI", v);\r
-  Py_XDECREF(v);\r
-\r
-  /* Export Types */\r
-  PyDict_SetItemString(d,"InputType",  (PyObject*)&Itype);\r
-  PyDict_SetItemString(d,"OutputType", (PyObject*)&Otype);\r
-\r
-  /* Maybe make certain warnings go away */\r
-  if (0) PycString_IMPORT;\r
-}\r