Commit 5df2e614 authored by Martin v. Löwis's avatar Martin v. Löwis

Remove UNLESS.

parent 7087f78d
...@@ -33,9 +33,6 @@ PyDoc_STRVAR(cStringIO_module_documentation, ...@@ -33,9 +33,6 @@ PyDoc_STRVAR(cStringIO_module_documentation,
"\n" "\n"
"cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp\n"); "cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp\n");
#define UNLESS(E) if (!(E))
/* Declaration for file-like objects that manage data as strings /* Declaration for file-like objects that manage data as strings
The IOobject type should be though of as a common base type for The IOobject type should be though of as a common base type for
...@@ -80,7 +77,7 @@ PyDoc_STRVAR(IO_flush__doc__, "flush(): does nothing."); ...@@ -80,7 +77,7 @@ PyDoc_STRVAR(IO_flush__doc__, "flush(): does nothing.");
static int static int
IO__opencheck(IOobject *self) { IO__opencheck(IOobject *self) {
UNLESS (self->buf) { if (!self->buf) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"I/O operation on closed file"); "I/O operation on closed file");
return 0; return 0;
...@@ -107,7 +104,7 @@ static PyGetSetDef file_getsetlist[] = { ...@@ -107,7 +104,7 @@ static PyGetSetDef file_getsetlist[] = {
static PyObject * static PyObject *
IO_flush(IOobject *self, PyObject *unused) { IO_flush(IOobject *self, PyObject *unused) {
UNLESS (IO__opencheck(self)) return NULL; if (!IO__opencheck(self)) return NULL;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
...@@ -121,7 +118,7 @@ PyDoc_STRVAR(IO_getval__doc__, ...@@ -121,7 +118,7 @@ PyDoc_STRVAR(IO_getval__doc__,
static PyObject * static PyObject *
IO_cgetval(PyObject *self) { IO_cgetval(PyObject *self) {
UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; if (!IO__opencheck(IOOOBJECT(self))) return NULL;
return PyString_FromStringAndSize(((IOobject*)self)->buf, return PyString_FromStringAndSize(((IOobject*)self)->buf,
((IOobject*)self)->pos); ((IOobject*)self)->pos);
} }
...@@ -131,8 +128,8 @@ IO_getval(IOobject *self, PyObject *args) { ...@@ -131,8 +128,8 @@ IO_getval(IOobject *self, PyObject *args) {
PyObject *use_pos=Py_None; PyObject *use_pos=Py_None;
Py_ssize_t s; Py_ssize_t s;
UNLESS (IO__opencheck(self)) return NULL; if (!IO__opencheck(self)) return NULL;
UNLESS (PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL; if (!PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL;
if (PyObject_IsTrue(use_pos)) { if (PyObject_IsTrue(use_pos)) {
s=self->pos; s=self->pos;
...@@ -158,7 +155,7 @@ static int ...@@ -158,7 +155,7 @@ static int
IO_cread(PyObject *self, char **output, Py_ssize_t n) { IO_cread(PyObject *self, char **output, Py_ssize_t n) {
Py_ssize_t l; Py_ssize_t l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; if (!IO__opencheck(IOOOBJECT(self))) return -1;
l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos; l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos;
if (n < 0 || n > l) { if (n < 0 || n > l) {
n = l; n = l;
...@@ -175,7 +172,7 @@ IO_read(IOobject *self, PyObject *args) { ...@@ -175,7 +172,7 @@ IO_read(IOobject *self, PyObject *args) {
Py_ssize_t n = -1; Py_ssize_t n = -1;
char *output = NULL; char *output = NULL;
UNLESS (PyArg_ParseTuple(args, "|n:read", &n)) return NULL; if (!PyArg_ParseTuple(args, "|n:read", &n)) return NULL;
if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL; if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL;
...@@ -189,7 +186,7 @@ IO_creadline(PyObject *self, char **output) { ...@@ -189,7 +186,7 @@ IO_creadline(PyObject *self, char **output) {
char *n, *s; char *n, *s;
Py_ssize_t l; Py_ssize_t l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; if (!IO__opencheck(IOOOBJECT(self))) return -1;
for (n = ((IOobject*)self)->buf + ((IOobject*)self)->pos, for (n = ((IOobject*)self)->buf + ((IOobject*)self)->pos,
s = ((IOobject*)self)->buf + ((IOobject*)self)->string_size; s = ((IOobject*)self)->buf + ((IOobject*)self)->string_size;
...@@ -209,7 +206,7 @@ IO_readline(IOobject *self, PyObject *args) { ...@@ -209,7 +206,7 @@ IO_readline(IOobject *self, PyObject *args) {
char *output; char *output;
if (args) if (args)
UNLESS (PyArg_ParseTuple(args, "|i:readline", &m)) return NULL; if (!PyArg_ParseTuple(args, "|i:readline", &m)) return NULL;
if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL; if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL;
if (m >= 0 && m < n) { if (m >= 0 && m < n) {
...@@ -229,7 +226,7 @@ IO_readlines(IOobject *self, PyObject *args) { ...@@ -229,7 +226,7 @@ IO_readlines(IOobject *self, PyObject *args) {
PyObject *result, *line; PyObject *result, *line;
int hint = 0, length = 0; int hint = 0, length = 0;
UNLESS (PyArg_ParseTuple(args, "|i:readlines", &hint)) return NULL; if (!PyArg_ParseTuple(args, "|i:readlines", &hint)) return NULL;
result = PyList_New(0); result = PyList_New(0);
if (!result) if (!result)
...@@ -264,7 +261,7 @@ PyDoc_STRVAR(IO_reset__doc__, ...@@ -264,7 +261,7 @@ PyDoc_STRVAR(IO_reset__doc__,
static PyObject * static PyObject *
IO_reset(IOobject *self, PyObject *unused) { IO_reset(IOobject *self, PyObject *unused) {
UNLESS (IO__opencheck(self)) return NULL; if (!IO__opencheck(self)) return NULL;
self->pos = 0; self->pos = 0;
...@@ -277,7 +274,7 @@ PyDoc_STRVAR(IO_tell__doc__, "tell() -- get the current position."); ...@@ -277,7 +274,7 @@ PyDoc_STRVAR(IO_tell__doc__, "tell() -- get the current position.");
static PyObject * static PyObject *
IO_tell(IOobject *self, PyObject *unused) { IO_tell(IOobject *self, PyObject *unused) {
UNLESS (IO__opencheck(self)) return NULL; if (!IO__opencheck(self)) return NULL;
return PyInt_FromSsize_t(self->pos); return PyInt_FromSsize_t(self->pos);
} }
...@@ -289,8 +286,8 @@ static PyObject * ...@@ -289,8 +286,8 @@ static PyObject *
IO_truncate(IOobject *self, PyObject *args) { IO_truncate(IOobject *self, PyObject *args) {
Py_ssize_t pos = -1; Py_ssize_t pos = -1;
UNLESS (IO__opencheck(self)) return NULL; if (!IO__opencheck(self)) return NULL;
UNLESS (PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL; if (!PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;
if (pos < 0) pos = self->pos; if (pos < 0) pos = self->pos;
if (self->string_size > pos) self->string_size = pos; if (self->string_size > pos) self->string_size = pos;
...@@ -329,8 +326,8 @@ O_seek(Oobject *self, PyObject *args) { ...@@ -329,8 +326,8 @@ O_seek(Oobject *self, PyObject *args) {
Py_ssize_t position; Py_ssize_t position;
int mode = 0; int mode = 0;
UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; if (!IO__opencheck(IOOOBJECT(self))) return NULL;
UNLESS (PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode))
return NULL; return NULL;
if (mode == 2) { if (mode == 2) {
...@@ -343,8 +340,8 @@ O_seek(Oobject *self, PyObject *args) { ...@@ -343,8 +340,8 @@ O_seek(Oobject *self, PyObject *args) {
if (position > self->buf_size) { if (position > self->buf_size) {
self->buf_size*=2; self->buf_size*=2;
if (self->buf_size <= position) self->buf_size=position+1; if (self->buf_size <= position) self->buf_size=position+1;
UNLESS (self->buf = (char*) self->buf = (char*) realloc(self->buf,self->buf_size);
realloc(self->buf,self->buf_size)) { if (!self->buf) {
self->buf_size=self->pos=0; self->buf_size=self->pos=0;
return PyErr_NoMemory(); return PyErr_NoMemory();
} }
...@@ -369,7 +366,7 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) { ...@@ -369,7 +366,7 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
Py_ssize_t newl; Py_ssize_t newl;
Oobject *oself; Oobject *oself;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; if (!IO__opencheck(IOOOBJECT(self))) return -1;
oself = (Oobject *)self; oself = (Oobject *)self;
newl = oself->pos+l; newl = oself->pos+l;
...@@ -379,8 +376,8 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) { ...@@ -379,8 +376,8 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
assert(newl + 1 < INT_MAX); assert(newl + 1 < INT_MAX);
oself->buf_size = (int)(newl+1); oself->buf_size = (int)(newl+1);
} }
UNLESS (oself->buf = oself->buf = (char*)realloc(oself->buf, oself->buf_size);
(char*)realloc(oself->buf, oself->buf_size)) { if (!oself->buf) {
PyErr_SetString(PyExc_MemoryError,"out of memory"); PyErr_SetString(PyExc_MemoryError,"out of memory");
oself->buf_size = oself->pos = 0; oself->buf_size = oself->pos = 0;
return -1; return -1;
...@@ -404,7 +401,7 @@ O_write(Oobject *self, PyObject *args) { ...@@ -404,7 +401,7 @@ O_write(Oobject *self, PyObject *args) {
char *c; char *c;
int l; int l;
UNLESS (PyArg_ParseTuple(args, "t#:write", &c, &l)) return NULL; if (!PyArg_ParseTuple(args, "t#:write", &c, &l)) return NULL;
if (O_cwrite((PyObject*)self,c,l) < 0) return NULL; if (O_cwrite((PyObject*)self,c,l) < 0) return NULL;
...@@ -543,7 +540,8 @@ newOobject(int size) { ...@@ -543,7 +540,8 @@ newOobject(int size) {
self->string_size = 0; self->string_size = 0;
self->softspace = 0; self->softspace = 0;
UNLESS (self->buf = (char *)malloc(size)) { self->buf = (char *)malloc(size);
if (!self->buf) {
PyErr_SetString(PyExc_MemoryError,"out of memory"); PyErr_SetString(PyExc_MemoryError,"out of memory");
self->buf_size = 0; self->buf_size = 0;
return NULL; return NULL;
...@@ -573,8 +571,8 @@ I_seek(Iobject *self, PyObject *args) { ...@@ -573,8 +571,8 @@ I_seek(Iobject *self, PyObject *args) {
Py_ssize_t position; Py_ssize_t position;
int mode = 0; int mode = 0;
UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; if (!IO__opencheck(IOOOBJECT(self))) return NULL;
UNLESS (PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode))
return NULL; return NULL;
if (mode == 2) position += self->string_size; if (mode == 2) position += self->string_size;
...@@ -662,7 +660,8 @@ newIobject(PyObject *s) { ...@@ -662,7 +660,8 @@ newIobject(PyObject *s) {
s->ob_type->tp_name); s->ob_type->tp_name);
return NULL; return NULL;
} }
UNLESS (self = PyObject_New(Iobject, &Itype)) return NULL; self = PyObject_New(Iobject, &Itype);
if (!self) return NULL;
Py_INCREF(s); Py_INCREF(s);
self->buf=buf; self->buf=buf;
self->string_size=size; self->string_size=size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment