Update of /cvsroot/python/python/dist/src/Modules In directory usw-pr-cvs1:/tmp/cvs-serv6222a/Modules Modified Files: Tag: release22-maint _hotshot.c Log Message: The logreader object did not always refill the input buffer correctly and got confused by certain log files. Remove logreader_refill and the associated logic and replace with fgetc. Index: _hotshot.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/_hotshot.c,v retrieving revision 1.11.6.2 retrieving revision 1.11.6.3 diff -C2 -d -r1.11.6.2 -r1.11.6.3 *** _hotshot.c 8 Feb 2002 21:31:23 -0000 1.11.6.2 --- _hotshot.c 29 May 2002 18:44:30 -0000 1.11.6.3 *************** *** 81,89 **** PyObject *info; FILE *logfp; - int filled; - int index; int linetimings; int frametimings; - unsigned char buffer[BUFFERSIZE]; } LogReaderObject; --- 81,86 ---- *************** *** 270,292 **** unpack_packed_int(LogReaderObject *self, int *pvalue, int discard) { int accum = 0; int bits = 0; - int index = self->index; int cont; do { - if (index >= self->filled) - return ERR_EOF; /* read byte */ ! accum |= ((self->buffer[index] & 0x7F) >> discard) << bits; bits += (7 - discard); ! cont = self->buffer[index] & 0x80; ! /* move to next */ discard = 0; - index++; } while (cont); - /* save state */ - self->index = index; *pvalue = accum; --- 267,285 ---- unpack_packed_int(LogReaderObject *self, int *pvalue, int discard) { + int c; int accum = 0; int bits = 0; int cont; do { /* read byte */ ! if ((c = fgetc(self->logfp)) == EOF) ! return ERR_EOF; ! accum |= ((c & 0x7F) >> discard) << bits; bits += (7 - discard); ! cont = c & 0x80; discard = 0; } while (cont); *pvalue = accum; *************** *** 300,330 **** unpack_string(LogReaderObject *self, PyObject **pvalue) { int len; ! int oldindex = self->index; ! int err = unpack_packed_int(self, &len, 0); ! if (!err) { ! /* need at least len bytes in buffer */ ! if (len > (self->filled - self->index)) { ! self->index = oldindex; ! err = ERR_EOF; ! } ! else { ! *pvalue = PyString_FromStringAndSize((char *)self->buffer + self->index, ! len); ! if (*pvalue == NULL) { ! self->index = oldindex; ! err = ERR_EXCEPTION; ! } ! else ! self->index += len; } } ! return err; } static int ! unpack_add_info(LogReaderObject *self, int skip_opcode) { PyObject *key; --- 293,322 ---- unpack_string(LogReaderObject *self, PyObject **pvalue) { + int i; int len; ! int err; ! char *buf; ! ! if ((err = unpack_packed_int(self, &len, 0))) ! return err; ! buf = malloc(len); ! for (i=0; i < len; i++) { ! if ((buf[i] = fgetc(self->logfp)) == EOF) { ! free(buf); ! return ERR_EOF; } } ! *pvalue = PyString_FromStringAndSize(buf, len); ! free(buf); ! if (*pvalue == NULL) { ! return ERR_EXCEPTION; ! } ! return 0; } static int ! unpack_add_info(LogReaderObject *self) { PyObject *key; *************** *** 332,340 **** int err; - if (skip_opcode) { - if (self->buffer[self->index] != WHAT_ADD_INFO) - return ERR_BAD_RECTYPE; - self->index++; - } err = unpack_string(self, &key); if (!err) { --- 324,327 ---- *************** *** 367,389 **** static void - logreader_refill(LogReaderObject *self) - { - int needed; - size_t res; - - if (self->index) { - memmove(self->buffer, &self->buffer[self->index], - self->filled - self->index); - self->filled = self->filled - self->index; - self->index = 0; - } - needed = BUFFERSIZE - self->filled; - if (needed > 0) { - res = fread(&self->buffer[self->filled], 1, needed, self->logfp); - self->filled += res; - } - } - - static void eof_error(void) { --- 354,357 ---- *************** *** 395,399 **** logreader_tp_iternext(LogReaderObject *self) { ! int what, oldindex; int err = ERR_NONE; int lineno = -1; --- 363,368 ---- logreader_tp_iternext(LogReaderObject *self) { ! int c; ! int what; int err = ERR_NONE; int lineno = -1; *************** *** 411,430 **** return NULL; } - restart: - if ((self->filled - self->index) < MAXEVENTSIZE) - logreader_refill(self); ! /* end of input */ ! if (self->filled == 0) return NULL; ! oldindex = self->index; - /* decode the record type */ - what = self->buffer[self->index] & WHAT_OTHER; - if (what == WHAT_OTHER) { - what = self->buffer[self->index]; - self->index++; - } switch (what) { case WHAT_ENTER: --- 380,395 ---- return NULL; } ! restart: ! /* decode the record type */ ! if ((c = fgetc(self->logfp)) == EOF) return NULL; ! what = c & WHAT_OTHER; ! if (what == WHAT_OTHER) ! what = c; /* need all the bits for type */ ! else ! ungetc(c, self->logfp); /* type byte includes packed int */ switch (what) { case WHAT_ENTER: *************** *** 445,449 **** break; case WHAT_ADD_INFO: ! err = unpack_add_info(self, 0); break; case WHAT_DEFINE_FILE: --- 410,414 ---- break; case WHAT_ADD_INFO: ! err = unpack_add_info(self); break; case WHAT_DEFINE_FILE: *************** *** 466,497 **** break; case WHAT_LINE_TIMES: ! if (self->index >= self->filled) err = ERR_EOF; else { ! self->linetimings = self->buffer[self->index] ? 1 : 0; ! self->index++; ! goto restart; ! } break; case WHAT_FRAME_TIMES: ! if (self->index >= self->filled) err = ERR_EOF; else { ! self->frametimings = self->buffer[self->index] ? 1 : 0; ! self->index++; ! goto restart; ! } break; default: err = ERR_BAD_RECTYPE; } - if (err == ERR_EOF && oldindex != 0) { - /* It looks like we ran out of data before we had it all; this - * could easily happen with large packed integers or string - * data. Try forcing the buffer to be re-filled before failing. - */ - err = ERR_NONE; - logreader_refill(self); - } if (err == ERR_BAD_RECTYPE) { PyErr_SetString(PyExc_ValueError, --- 431,452 ---- break; case WHAT_LINE_TIMES: ! if ((c = fgetc(self->logfp)) == EOF) err = ERR_EOF; else { ! self->linetimings = c ? 1 : 0; ! goto restart; ! } break; case WHAT_FRAME_TIMES: ! if ((c = fgetc(self->logfp)) == EOF) err = ERR_EOF; else { ! self->frametimings = c ? 1 : 0; ! goto restart; ! } break; default: err = ERR_BAD_RECTYPE; } if (err == ERR_BAD_RECTYPE) { PyErr_SetString(PyExc_ValueError, *************** *** 499,503 **** } else if (err == ERR_EOF) { - /* Could not avoid end-of-buffer error. */ eof_error(); } --- 454,457 ---- *************** *** 1387,1396 **** LogReaderObject *self = NULL; char *filename; if (PyArg_ParseTuple(args, "s:logreader", &filename)) { self = PyObject_New(LogReaderObject, &LogReaderType); if (self != NULL) { - self->filled = 0; - self->index = 0; self->frametimings = 1; self->linetimings = 0; --- 1341,1350 ---- LogReaderObject *self = NULL; char *filename; + int c; + int err = 0; if (PyArg_ParseTuple(args, "s:logreader", &filename)) { self = PyObject_New(LogReaderObject, &LogReaderType); if (self != NULL) { self->frametimings = 1; self->linetimings = 0; *************** *** 1408,1419 **** goto finally; } ! /* Aggressively attempt to load all preliminary ADD_INFO ! * records from the log so the info records are available ! * from a fresh logreader object. ! */ ! logreader_refill(self); ! while (self->filled > self->index ! && self->buffer[self->index] == WHAT_ADD_INFO) { ! int err = unpack_add_info(self, 1); if (err) { if (err == ERR_EOF) --- 1362,1376 ---- goto finally; } ! /* read initial info */ ! for (;;) { ! if ((c = fgetc(self->logfp)) == EOF) { ! eof_error(); ! break; ! } ! if (c != WHAT_ADD_INFO) { ! ungetc(c, self->logfp); ! break; ! } ! err = unpack_add_info(self); if (err) { if (err == ERR_EOF) *************** *** 1424,1433 **** break; } - /* Refill agressively so we can avoid EOF during - * initialization unless there's a real EOF condition - * (the tp_iternext handler loops attempts to refill - * and try again). - */ - logreader_refill(self); } } --- 1381,1384 ----
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4