Message56611
| Author |
christian.heimes |
| Recipients |
brett.cannon, christian.heimes, gvanrossum |
| Date |
2007年10月20日.20:17:07 |
| SpamBayes Score |
0.07395481 |
| Marked as misclassified |
No |
| Message-id |
<471A6241.5090907@cheimes.de> |
| In-reply-to |
<ca471dc20710201259g6eb69e2ft68bab0a82694359b@mail.gmail.com> |
| Content |
Guido van Rossum wrote:
> I think find_module() should return a file descriptor (fd), not a
> FILE*, but most of the rest of the code should call fdopen() on that
> fd. Only call_find_module() should use the fd to turn it into a Python
> file object. Then the amount of change should be pretty minimal.
K, I understand.
> I recommend changing the name of the API used to turn a fd into file
> object while we're at it; that's one of the few guidelines we have for
> C API changes.
Is PyFile_FromFd and PyFile_FromFdEx fine with you or do you prefer a
different name like PyFile_FromFD and PyFile_FromFDEx or
PyFile_FromFileDescriptor?
I've another question. The os.tmpfile method is using tmpfile() which
returns a file pointer. Do I have to dup its file number and explictely
close the file pointer as shown below or is a simple fileno() enough? I
haven't found sample code how to use a file descriptor after the file
pointer is closed.
static PyObject *
posix_tmpfile(PyObject *self, PyObject *noargs)
{
FILE *fp;
int fd;
fp = tmpfile();
if (fp == NULL)
return posix_error();
fd = dup(fileno(fp));
if (fd == -1)
return posix_error();
fclose(fp);
return PyFile_FromFD(fd, "<tmpfile>", "w+b");
} |
|