This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients brett.cannon, christian.heimes, gvanrossum
Date 2007-10-16.05:27:01
SpamBayes Score 0.00013932661
Marked as misclassified No
Message-id <47144BA0.90702@cheimes.de>
In-reply-to <ca471dc20710152047m5083194fjdaf96d959f8977a8@mail.gmail.com>
Content
Guido van Rossum wrote:
> Don't call open() with keyword arg for newline="\r"; open() takes
> positional args too. This is done specifically to simplify life for C
> code calling it. :-) Perhaps one of the PyFunction_Call(..) variants
> makes it easier to call it without having to explicitly construct the
> tuple for the argument list. (All this because you're leaking the
> value of PyString_FromString("\n"). :-)

I need a way to open a file with a specific encoding for
imp.find_module(), too. I found PyFile_FromFile(). It uses io.open but
it doesn't accept the additional arguments. I like to add another
function PyFile_FromFileEx() to the API.

PyObject *
PyFile_FromFileEx(FILE *fp, char *name, char *mode, int (*close)(FILE
*), int buffering, char *encoding, char *newline)

Some people may also miss the PyFile_FromString() function but that's a
different story. With the my new function I can create sys.stdin with:

PyFile_FromFileEx(stdin, "<stdin>", "r", fclose, -1, NULL, "\n")

I kinda like it :)

> I would change the error handling to avoid the 'finally' label, like this:
> 
>         if (0) {
>   error:
>                 status = -1;
>                 Py_XDECREF(args);
>         }

Wow, that's tricky. :)

> I would add a comment "see initstdio() in pythonrun.c" to the
> OpenWrapper class, which otherwise looks a bit mysterious (as it's not
> used anywhere in the Python code).

That sounds like a good idea!

The code for const char *PyTokenizer_FindEncoding(FILE *fp) and
imp.find_module() is also finished and works.

Christian
History
Date User Action Args
2007-10-16 05:27:03christian.heimessetspambayes_score: 0.000139327 -> 0.00013932661
recipients: + christian.heimes, gvanrossum, brett.cannon
2007-10-16 05:27:02christian.heimeslinkissue1267 messages
2007-10-16 05:27:01christian.heimescreate