123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- #include "python_ioin.h"
- /**@file python_ioin.c
- * @ingroup lib_ioin
- */
-
- /**@brief If given object io_stream is NULL set error indicator
- * @param self The IoIn instance
- * @return 0 if no error else -1 or -2
- */
- static int _check_nullin(PyObject *self);
-
- /**@brief Request a new buffer size.
- *
- * @param self The IoIn instance
- * @param nreq number of bytes required in buffer
- * @return 0 on error else buffer size
- */
- static int pyfcgi_io__reqbuf(PyObject *self, int nreq);
-
- /**@brief Concat two bytes/unicode given IoIn configuration flag
- */
- static PyObject* IoIn__Concat(PyObject *self, PyObject *left, PyObject *right);
-
- PyObject* pyfcgi_io_true(PyObject *self, PyObject **argv, Py_ssize_t argc);
- PyObject* pyfcgi_io_false(PyObject *self, PyObject **argv, Py_ssize_t argc);
-
- PyMethodDef IoIn_methods[] = {
- {"close", (PyCFunction)pyfcgi_io_close, METH_FASTCALL, NULL},
- {"fileno", (PyCFunction)pyfcgi_io_fileno, METH_FASTCALL, NULL},
- {"flush", (PyCFunction)pyfcgi_io_flush, METH_FASTCALL, NULL},
- {"isatty", (PyCFunction)pyfcgi_io_isatty, METH_FASTCALL, NULL},
- {"readable", (PyCFunction)pyfcgi_ioin_readable, METH_FASTCALL, NULL},
- {"readline", (PyCFunction)pyfcgi_ioin_readline, METH_FASTCALL, NULL},
- {"readlines", (PyCFunction)pyfcgi_ioin_readlines, METH_FASTCALL, NULL},
- {"seek", (PyCFunction)pyfcgi_io_seek, METH_FASTCALL, NULL},
- {"seekable", (PyCFunction)pyfcgi_io_seekable, METH_FASTCALL, NULL},
- {"tell", (PyCFunction)pyfcgi_io_tell, METH_FASTCALL, NULL},
- {"truncate", (PyCFunction)pyfcgi_io_truncate, METH_FASTCALL, NULL},
- {"writable", (PyCFunction)pyfcgi_ioin_writable, METH_FASTCALL, NULL},
- {"writelines", (PyCFunction)pyfcgi_ioin_writelines, METH_FASTCALL, NULL},
- {"read", (PyCFunction)pyfcgi_ioin_read, METH_FASTCALL, NULL},
- {"readall", (PyCFunction)pyfcgi_ioin_readall, METH_FASTCALL, NULL},
- {"readinto", (PyCFunction)pyfcgi_ioin_readinto, METH_FASTCALL, NULL},
- {"write", (PyCFunction)pyfcgi_ioin_write, METH_FASTCALL, NULL},
- {NULL} //Sentinel
- };
-
- PyMemberDef IoIn_members[] = {
- {"closed", T_OBJECT, offsetof(PyIO_t, closed), READONLY, "True if the stream is closed"},
- {NULL}
- };
-
- PyTypeObject IoInType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "libpyfcgi.IoIn", /* tp_name */
- sizeof(PyIO_t), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)pyfcgi_io_del, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_reserved */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
- "RawIo interface to FCGI input stream", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- IoIn_methods, /* tp_methods */
- IoIn_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- pyfcgi_ioin_init, /* tp_init */
- 0, /* tp_alloc */
- 0, /* tp_new */
- };
-
- PyMethodDef IoOut_methods[] = {
- {"close", (PyCFunction)pyfcgi_io_close, METH_FASTCALL, NULL},
- {"fileno", (PyCFunction)pyfcgi_io_fileno, METH_FASTCALL, NULL},
- {"flush", (PyCFunction)pyfcgi_io_flush, METH_FASTCALL, NULL},
- {"isatty", (PyCFunction)pyfcgi_io_isatty, METH_FASTCALL, NULL},
- {"readable", (PyCFunction)pyfcgi_ioout_readable, METH_FASTCALL, NULL},
- {"readline", (PyCFunction)pyfcgi_ioout_readline, METH_FASTCALL, NULL},
- {"readlines", (PyCFunction)pyfcgi_ioout_readlines, METH_FASTCALL, NULL},
- {"seek", (PyCFunction)pyfcgi_io_seek, METH_FASTCALL, NULL},
- {"seekable", (PyCFunction)pyfcgi_io_seekable, METH_FASTCALL, NULL},
- {"tell", (PyCFunction)pyfcgi_io_tell, METH_FASTCALL, NULL},
- {"truncate", (PyCFunction)pyfcgi_io_truncate, METH_FASTCALL, NULL},
- {"writable", (PyCFunction)pyfcgi_ioout_writable, METH_FASTCALL, NULL},
- {"writelines", (PyCFunction)pyfcgi_ioout_writelines, METH_FASTCALL, NULL},
- {"read", (PyCFunction)pyfcgi_ioout_read, METH_FASTCALL, NULL},
- {"readall", (PyCFunction)pyfcgi_ioout_readall, METH_FASTCALL, NULL},
- {"readinto", (PyCFunction)pyfcgi_ioout_readinto, METH_FASTCALL, NULL},
- {"write", (PyCFunction)pyfcgi_ioout_write, METH_FASTCALL, NULL},
- {NULL} //Sentinel
- };
-
- PyMemberDef IoOut_members[] = {
- {"closed", T_OBJECT, offsetof(PyIO_t, closed), READONLY, "True if the stream is closed"},
- {NULL}
- };
-
- PyTypeObject IoOutType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "libpyfcgi.IoOut", /* tp_name */
- sizeof(PyIO_t), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)pyfcgi_io_del, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_reserved */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
- "RawIo interface to FCGI input stream", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- IoOut_methods, /* tp_methods */
- IoOut_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- pyfcgi_ioout_init, /* tp_init */
- 0, /* tp_alloc */
- 0, /* tp_new */
- };
-
-
-
- int pyfcgi_io_init(PyObject *self)
- {
- PyIO_t *ioin = (void*)self;
- ioin->io_stream = NULL;
- ioin->buff = NULL;
- ioin->buff_sz = 0;
- ioin->eof=0;
- ioin->bin=1;
- ioin->write = NULL;
- return 0;
- }
-
- int pyfcgi_ioin_init(PyObject *self, PyObject *args, PyObject *kwds)
- {
- pyfcgi_io_init(self);
- return 0;
- }
-
- int pyfcgi_ioout_init(PyObject *self, PyObject *args, PyObject *kwds)
- {
- pyfcgi_io_init(self);
- return 0;
- }
-
- void pyfcgi_io_del(PyIO_t *self)
- {
- PyIO_t *ioin = self;
- if(ioin->buff) { free(ioin->buff); }
- Py_TYPE(self)->tp_free((PyObject*)self);
- }
-
- PyObject* pyfcgi_io_close(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.close() not expecting any argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- if(FCGX_FClose(*((PyIO_t*)self)->io_stream) < 0)
- {
- PyErr_Format(PyExc_OSError,
- "%A unable to close", self);
- }
- ((PyIO_t*)self)->closed = Py_True;
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_io_fileno(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyErr_SetString(PyExc_OSError, "libpyfcgi.IoIn has no fileno");
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_io_flush(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.close() not expecting any argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- if(FCGX_FFlush(*((PyIO_t*)self)->io_stream) < 0)
- {
- PyErr_Format(PyExc_OSError,
- "%A unable to flush", self);
- }
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_ioin_readline(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- int read_n;
- long arg;
- char *ret;
-
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc > 1)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.close() expecting 0 or 1 argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- if(!argc || !argv[0])
- {
- read_n = pyfcgi_io__reqbuf(self, 0);
- }
- else
- {
- arg = PyLong_AsLong(argv[0]);
- if(PyErr_Occurred())
- {
- Py_RETURN_NONE;
- }
- read_n = pyfcgi_io__reqbuf(self, (arg>INT_MAX)?INT_MAX:arg);
- }
-
- ret = ((PyIO_t*)self)->buff;
- if(!FCGX_GetLine(ret, read_n, *((PyIO_t*)self)->io_stream))
- {
- ((PyIO_t*)self)->eof = 1;
- ret = "";
- }
- //dprintf(2, "readline : '%s'\n", ret);
- return IoIn__FromString(self, ret);
- }
-
- PyObject* pyfcgi_ioin_readlines(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- size_t hint, left;
- int read_n, toread;
- size_t sz;
- PyObject *res, *cur_str, *read_str, *tmp;
- char *buff;
-
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc > 1)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.close() expecting 0 or 1 argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- if(!argc || !argv[0])
- {
- hint = 0;
- left = 0;
- }
- else
- {
- hint = PyLong_AsSize_t(argv[0]);
- if(PyErr_Occurred())
- {
- Py_RETURN_NONE;
- }
- left = hint;
- }
-
- res = PyList_New(0);
- if(!res)
- {
- Py_RETURN_NONE;
- }
- Py_INCREF(res);
-
- read_n = pyfcgi_io__reqbuf(self, 0);
- buff = ((PyIO_t*)self)->buff;
- cur_str = NULL;
-
- while((hint && left) || !hint)
- {
- toread = (hint&&((size_t)read_n > left))?(int)left:read_n;
- if(!FCGX_GetLine(buff, toread,
- *((PyIO_t*)self)->io_stream))
- {
- ((PyIO_t*)self)->eof = 1;
- break;
- }
- sz = strlen(buff);
- left -= sz;
- read_str = IoIn__FromBuff(self);
- if(!read_str)
- {
- Py_RETURN_NONE;
- }
- Py_INCREF(read_str);
- if(cur_str)
- {
- tmp = IoIn__Concat(self, cur_str, read_str);
- Py_INCREF(tmp);
- cur_str = tmp;
- }
- else
- {
- cur_str = read_str;
- }
-
- if(buff[sz-1] == '\n')
- {
- //dprintf(2, "readlines : '%s'\n", PyUnicode_AsUTF8(cur_str));
- if(PyList_Append(res, cur_str))
- {
- Py_DECREF(cur_str);
- Py_RETURN_NONE;
- }
- Py_DECREF(cur_str);
- cur_str = NULL;
- }
- }
- if(cur_str)
- {
- //dprintf(2, "readlines(post) : '%s'\n", PyUnicode_AsUTF8(cur_str));
- if(PyList_Append(res, cur_str))
- {
- Py_DECREF(cur_str);
- Py_RETURN_NONE;
- }
- Py_DECREF(cur_str);
- }
- Py_DECREF(res);
- return res;
- }
-
- PyObject* pyfcgi_ioin_read(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- size_t left, max;
- long l;
- int read_n, toread, sz;
- PyObject *res, *read_str;
- char *buff;
-
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc > 1)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.read() expecting at most 1 argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
-
- if(((PyIO_t*)self)->eof)
- {
- return IoIn__FromString(self, "");
- }
- max = 0;
- if(argc)
- {
- l = PyLong_AsLong(argv[0]);
- if(PyErr_Occurred() || l > 0)
- {
- PyErr_Clear();
- max = PyLong_AsSize_t(argv[0]);
- if(PyErr_Occurred())
- {
- Py_RETURN_NONE;
- }
- }
- }
- left = max;
- read_n = pyfcgi_io__reqbuf(self, 0);
- buff = ((PyIO_t*)self)->buff;
- if(!(res = IoIn__FromString(self, "")))
- {
- Py_RETURN_NONE;
- }
- Py_INCREF(res);
- while((max && left) || !max)
- {
- toread = (max&&((size_t)read_n > left))?(int)left:read_n;
- sz = FCGX_GetStr(buff, toread, *((PyIO_t*)self)->io_stream);
- if(sz)
- {
- if(sz == toread) { buff[sz] = '\0'; }
- left -= sz;
- if(!(read_str = IoIn__FromBuff(self)))
- {
- Py_RETURN_NONE;
- }
- Py_INCREF(read_str);
- if(!(res = IoIn__Concat(self, res, read_str)))
- {
- Py_RETURN_NONE;
- }
- Py_INCREF(res);
- }
-
- if( sz < toread)
- {
- ((PyIO_t*)self)->eof = 1;
- break;
- }
- }
- //dprintf(2, "read : %s\n", PyBytes_AsString(res));
- Py_DECREF(res);
- return res;
- }
-
- PyObject* pyfcgi_ioin_readall(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.readall() not expecting any argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- dprintf(2, "readall calling read : ");
- return pyfcgi_ioin_read(self, NULL, 0);
- }
-
- PyObject* pyfcgi_ioin_readinto(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyObject *b;
- Py_ssize_t max, left, read_n;
- char *buff, *buff_ptr;
- int toread, ret;
-
- if(_check_nullin(self)) { Py_RETURN_NONE; }
- if(argc != 1)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.readinto() expecting 1 argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- b = argv[0];
- if(!PyByteArray_Check(b))
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoIn.readinto() expected bytearray as argument but %A given",
- b);
- Py_RETURN_NONE;
- }
- left = max = PyByteArray_Size(b);
- buff = PyByteArray_AsString(b);
- buff_ptr = buff;
- read_n = pyfcgi_io__reqbuf(self, 0);
- while(left)
- {
- toread = left>read_n?read_n:left;
- if((ret = FCGX_GetStr(buff_ptr, toread,
- *((PyIO_t*)self)->io_stream)) < toread)
- {
- ((PyIO_t*)self)->eof = 1;
- break;
- }
- buff_ptr += ret;
- left -= ret;
-
- }
- //dprintf(2, "readinto chr buff : '%s'\n", buff);
- //dprintf(2, "readinto bytes repr : '%s'\n", PyByteArray_AsString(b));
- return b;
- }
-
- PyObject* pyfcgi_ioout_writelines(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyObject *lines, *iter, *line;
- const char *bytes;
- Py_ssize_t bytes_len, lineno;
- if( ! *((PyIO_t*)self)->write)
- {
- PyErr_Format(PyExc_RuntimeError, "%A write function not set",
- self);
- Py_RETURN_NONE;
- }
- if(argc != 1)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoOut.writelines() expected 1 argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- lines = argv[0];
- iter = PyObject_GetIter(lines);
- if(!iter)
- {
- // should drop exception raised by GetIter ??
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoOut.writelines() first argument does not support iterator protocol : %A",
- lines);
- Py_RETURN_NONE;
- }
- lineno = 0;
- Py_INCREF(iter);
- while( (line = PyIter_Next(lines)) )
- {
- lineno++;
- Py_INCREF(line);
- if(PyUnicode_Check(line))
- {
- bytes = PyUnicode_AsUTF8AndSize(line, &bytes_len);
- if(!bytes) { Py_RETURN_NONE; } //forward error
- }
- else if(PyBytes_Check(line))
- {
- if(PyBytes_AsStringAndSize(line, (char**)&bytes, &bytes_len) == -1)
- {
- Py_RETURN_NONE; //forward error
- }
- }
- else
- {
- PyErr_Format(PyExc_TypeError,
- "libpyfcgi.IoOut.writelines() expected argument to be\
- str or bytes but %A given on line %zd",
- line, lineno);
- Py_RETURN_NONE;
- }
- if( ((PyIO_t*)self)->write(bytes, bytes_len) == -1)
- {
- PyErr_Format(PyExc_EOFError,
- "libpyfcgi.IoOut.writelines() EOF error when writing line %zd",
- lineno);
- Py_RETURN_NONE;
- }
- Py_DECREF(line);
- }
- Py_DECREF(iter);
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_ioout_write(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyObject *b;
- const char *bytes;
- Py_ssize_t bytes_len;
- if( ! *((PyIO_t*)self)->write)
- {
- PyErr_Format(PyExc_RuntimeError, "%A write function not set",
- self);
- Py_RETURN_NONE;
- }
- if(argc != 1)
- {
- PyErr_Format(PyExc_ValueError,
- "libpyfcgi.IoOut.writelines() expected 1 argument but %zd given",
- argc);
- Py_RETURN_NONE;
- }
- b = argv[0];
- if(PyBytes_Check(b))
- {
- if(PyBytes_AsStringAndSize(b, (char**)&bytes, &bytes_len) == -1)
- {
- Py_RETURN_NONE; //forward error
- }
- }
- else if(PyUnicode_Check(b))
- {
- bytes = PyUnicode_AsUTF8AndSize(b, &bytes_len);
- if(!bytes) { Py_RETURN_NONE; } //forward error
- }
- else
- {
- PyErr_Format(PyExc_TypeError,
- "libpyfcgi.IoOut.write() expected argument to be bytes\
- or str but %A given on line %zd",
- b);
- Py_RETURN_NONE;
- }
- if( ((PyIO_t*)self)->write(bytes, bytes_len) == -1)
- {
- PyErr_Format(PyExc_EOFError,
- "libpyfcgi.IoOut.writelines() EOF error when calling write");
- Py_RETURN_NONE;
- }
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_io_false(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- return Py_False;
- }
-
- PyObject* pyfcgi_io_true(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- return Py_True;
- }
-
- PyObject* pyfcgi_io_truncate(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyErr_SetString(PyExc_OSError, "libpyfcgi.Io cannot be truncated");
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_io_SeekError(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyErr_SetString(PyExc_OSError, "libpyfcgi.Io is not seekable");
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_io_WriteError(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyErr_SetString(PyExc_OSError, "libpyfcgi.IoIn is not writable");
- Py_RETURN_NONE;
- }
-
- PyObject* pyfcgi_io_ReadError(PyObject *self, PyObject **argv, Py_ssize_t argc)
- {
- PyErr_SetString(PyExc_OSError, "libpyfcgi.IoOut is not readable");
- Py_RETURN_NONE;
- }
-
- static int _check_nullin(PyObject *self)
- {
- if(!((PyIO_t*)self)->io_stream)
- {
- PyErr_SetString(PyExc_RuntimeError,
- "pyfcgi.IoIn called in wrong context : FGCI input not set");
- return -1;
- }
- else if(!(*(((PyIO_t*)self)->io_stream)))
- {
- PyErr_SetString(PyExc_RuntimeError,
- "pyfcgi.IoIn called in wrong context : FGCI input is NULL");
- return -2;
- }
- return 0;
- }
-
- static int pyfcgi_io__reqbuf(PyObject *self, int nreq)
- {
- PyIO_t *ioin;
- void *tmp;
- int err;
-
- ioin = (PyIO_t*)self;
-
- if(ioin->buff_sz > nreq && ioin->buff)
- {
- return ioin->buff_sz;
- }
-
- ioin->buff_sz = ((nreq>>12)+1)<<12;
- if(ioin->buff_sz < nreq) { ioin->buff_sz = nreq; }
-
- if(!(tmp = realloc(ioin->buff, ioin->buff_sz)))
- {
- err = errno;
- PyErr_Format(PyExc_OSError,
- "%A error reallocating internal buffer : %s",
- self, strerror(err));
- errno = err;
- return 0;
- }
- ioin->buff = tmp;
- return ioin->buff_sz;
- }
-
- /**@brief Concat two bytes/unicode given IoIn configuration flag
- * @warning Py_DECREF both arguments
- */
- static PyObject* IoIn__Concat(PyObject *self, PyObject *left, PyObject *right)
- {
- if(((PyIO_t*)self)->bin)
- {
- PyBytes_Concat(&left, right);
- Py_DECREF(right);
- return left;
- }
- PyObject *res;
- res = PyUnicode_Concat(left, right);
- Py_DECREF(left);
- Py_DECREF(right);
- return res;
- }
-
-
|