Message56611
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");
} |
|
Date |
User |
Action |
Args |
2007-10-20 20:17:08 | christian.heimes | set | spambayes_score: 0.0739548 -> 0.07395481 recipients:
+ christian.heimes, gvanrossum, brett.cannon |
2007-10-20 20:17:08 | christian.heimes | link | issue1267 messages |
2007-10-20 20:17:07 | christian.heimes | create | |
|