summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-12-07 20:20:28 (GMT)
committerGuido van Rossum <guido@python.org>2001-12-07 20:20:28 (GMT)
commit2f09812efa0701721825b17086de3631462039a6 (patch)
tree05e237921f7f3208908b447724d3439e74534d8a /Modules
parentf70590f990e6b91c36c3aadd7da6fa6c0a9a5beb (diff)
downloadcpython-2f09812efa0701721825b17086de3631462039a6.zip
cpython-2f09812efa0701721825b17086de3631462039a6.tar.gz
cpython-2f09812efa0701721825b17086de3631462039a6.tar.bz2
O_cwrite(): rewrote for clarity, replacing all the (Oobject *)self
casts with a variable oself that has the proper type. A smart compiler may put this thing into a register. (I'm not sure what good this does except satisfy my desire to understand this function; I got a report about an uninitialized read from Insure++ about this function and it hurt my eyes to even look at it. I gotta run away or I'll get tempted to reformat the entire file...)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/cStringIO.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 49007e2..094804c 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -394,31 +394,32 @@ static char O_write__doc__[] =
static int
O_cwrite(PyObject *self, char *c, int l) {
int newl;
+ Oobject *oself;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
-
- newl=((Oobject*)self)->pos+l;
- if (newl >= ((Oobject*)self)->buf_size) {
- ((Oobject*)self)->buf_size*=2;
- if (((Oobject*)self)->buf_size <= newl)
- ((Oobject*)self)->buf_size=newl+1;
- UNLESS (((Oobject*)self)->buf=
- (char*)realloc(
- ((Oobject*)self)->buf,
- (((Oobject*)self)->buf_size) *sizeof(char))) {
+ oself = (Oobject *)self;
+
+ newl = oself->pos+l;
+ if (newl >= oself->buf_size) {
+ oself->buf_size *= 2;
+ if (oself->buf_size <= newl)
+ oself->buf_size = newl+1;
+ UNLESS (oself->buf =
+ (char*)realloc(oself->buf,
+ (oself->buf_size) * sizeof(char))) {
PyErr_SetString(PyExc_MemoryError,"out of memory");
- ((Oobject*)self)->buf_size=((Oobject*)self)->pos=0;
+ oself->buf_size = oself->pos = 0;
return -1;
}
}
- memcpy(((Oobject*)((Oobject*)self))->buf+((Oobject*)self)->pos,c,l);
+ memcpy(oself->buf+oself->pos,c,l);
- ((Oobject*)self)->pos += l;
+ oself->pos += l;
- if (((Oobject*)self)->string_size < ((Oobject*)self)->pos) {
- ((Oobject*)self)->string_size = ((Oobject*)self)->pos;
- }
+ if (oself->string_size < oself->pos) {
+ oself->string_size = oself->pos;
+ }
return l;
}