Rip out the file object's implementation.

Fixed test_import.py while I was at it.

However, there's still a problem in import.c -- get_file() can leak a
FILE struct (not a file descriptor though).  I'm not sure how to fix
this; closing the FILE* closes the file descriptor, and that's the
wrong thing to do when there's still a Python file object keeping the
file descriptor open.  I also would rather not mess with dup(), as it
won't port to Windows.
This commit is contained in:
Guido van Rossum 2007-06-12 23:30:11 +00:00
parent 2d5c219fe0
commit da5b8f2d28
14 changed files with 106 additions and 2537 deletions

View file

@ -1075,6 +1075,7 @@ BZ2File_seek(BZ2FileObject *self, PyObject *args)
offset -= self->pos;
} else {
/* we cannot move back, so rewind the stream */
FILE *fp = NULL; /* XXX temporary!!! */
BZ2_bzReadClose(&bzerror, self->fp);
if (bzerror != BZ_OK) {
Util_CatchBZ2Error(bzerror);
@ -1086,7 +1087,7 @@ BZ2File_seek(BZ2FileObject *self, PyObject *args)
Py_DECREF(ret);
ret = NULL;
self->pos = 0;
self->fp = BZ2_bzReadOpen(&bzerror, PyFile_AsFile(self->file),
self->fp = BZ2_bzReadOpen(&bzerror, fp,
0, 0, NULL, 0);
if (bzerror != BZ_OK) {
Util_CatchBZ2Error(bzerror);
@ -1286,6 +1287,7 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "mode", "buffering",
"compresslevel", 0};
FILE *fp = NULL; /* XXX temporary!!! */
PyObject *name;
char *mode = "r";
int buffering = -1;
@ -1347,8 +1349,8 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
mode = (mode_char == 'r') ? "rb" : "wb";
self->file = PyObject_CallFunction((PyObject*)&PyFile_Type, "(Osi)",
name, mode, buffering);
self->file = NULL; /* XXX io.open(name, mode, buffering); */
PyErr_SetString(PyExc_RuntimeError, "can't open bz2 files yet");
if (self->file == NULL)
return -1;
@ -1365,11 +1367,11 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
if (mode_char == 'r')
self->fp = BZ2_bzReadOpen(&bzerror,
PyFile_AsFile(self->file),
fp,
0, 0, NULL, 0);
else
self->fp = BZ2_bzWriteOpen(&bzerror,
PyFile_AsFile(self->file),
fp,
compresslevel, 0, 0);
if (bzerror != BZ_OK) {