diff options
author | Guido van Rossum <guido@python.org> | 2007-06-12 23:30:11 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-06-12 23:30:11 (GMT) |
commit | da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e (patch) | |
tree | f3b0ab1f90be8ba18b1cefdb660cebd95c0f70d9 /Python/sysmodule.c | |
parent | 2d5c219fe09eacf81c139e5af9114fbbdd093d85 (diff) | |
download | cpython-da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e.zip cpython-da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e.tar.gz cpython-da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e.tar.bz2 |
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1b7674b..71a455a 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -55,18 +55,6 @@ PySys_GetObject(char *name) return PyDict_GetItemString(sd, name); } -FILE * -PySys_GetFile(char *name, FILE *def) -{ - FILE *fp = NULL; - PyObject *v = PySys_GetObject(name); - if (v != NULL && PyFile_Check(v)) - fp = PyFile_AsFile(v); - if (fp == NULL) - fp = def; - return fp; -} - int PySys_SetObject(char *name, PyObject *v) { @@ -1353,25 +1341,21 @@ mywrite(char *name, FILE *fp, const char *format, va_list va) { PyObject *file; PyObject *error_type, *error_value, *error_traceback; + char buffer[1001]; + int written; PyErr_Fetch(&error_type, &error_value, &error_traceback); file = PySys_GetObject(name); - if (file == NULL || PyFile_AsFile(file) == fp) - vfprintf(fp, format, va); - else { - char buffer[1001]; - const int written = PyOS_vsnprintf(buffer, sizeof(buffer), - format, va); - if (PyFile_WriteString(buffer, file) != 0) { + written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va); + if (PyFile_WriteString(buffer, file) != 0) { + PyErr_Clear(); + fputs(buffer, fp); + } + if (written < 0 || (size_t)written >= sizeof(buffer)) { + const char *truncated = "... truncated"; + if (PyFile_WriteString(truncated, file) != 0) { PyErr_Clear(); - fputs(buffer, fp); - } - if (written < 0 || (size_t)written >= sizeof(buffer)) { - const char *truncated = "... truncated"; - if (PyFile_WriteString(truncated, file) != 0) { - PyErr_Clear(); - fputs(truncated, fp); - } + fputs(truncated, fp); } } PyErr_Restore(error_type, error_value, error_traceback); |