mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
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...)
This commit is contained in:
parent
f70590f990
commit
2f09812efa
1 changed files with 16 additions and 15 deletions
|
@ -394,31 +394,32 @@ static char O_write__doc__[] =
|
||||||
static int
|
static int
|
||||||
O_cwrite(PyObject *self, char *c, int l) {
|
O_cwrite(PyObject *self, char *c, int l) {
|
||||||
int newl;
|
int newl;
|
||||||
|
Oobject *oself;
|
||||||
|
|
||||||
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
|
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
|
||||||
|
oself = (Oobject *)self;
|
||||||
|
|
||||||
newl=((Oobject*)self)->pos+l;
|
newl = oself->pos+l;
|
||||||
if (newl >= ((Oobject*)self)->buf_size) {
|
if (newl >= oself->buf_size) {
|
||||||
((Oobject*)self)->buf_size*=2;
|
oself->buf_size *= 2;
|
||||||
if (((Oobject*)self)->buf_size <= newl)
|
if (oself->buf_size <= newl)
|
||||||
((Oobject*)self)->buf_size=newl+1;
|
oself->buf_size = newl+1;
|
||||||
UNLESS (((Oobject*)self)->buf=
|
UNLESS (oself->buf =
|
||||||
(char*)realloc(
|
(char*)realloc(oself->buf,
|
||||||
((Oobject*)self)->buf,
|
(oself->buf_size) * sizeof(char))) {
|
||||||
(((Oobject*)self)->buf_size) *sizeof(char))) {
|
|
||||||
PyErr_SetString(PyExc_MemoryError,"out of memory");
|
PyErr_SetString(PyExc_MemoryError,"out of memory");
|
||||||
((Oobject*)self)->buf_size=((Oobject*)self)->pos=0;
|
oself->buf_size = oself->pos = 0;
|
||||||
return -1;
|
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) {
|
if (oself->string_size < oself->pos) {
|
||||||
((Oobject*)self)->string_size = ((Oobject*)self)->pos;
|
oself->string_size = oself->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue