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 vmurashev
Recipients paul.moore, steve.dower, tim.golden, vmurashev, zach.ware
Date 2015-07-03.17:47:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1435945665.32.0.485913142675.issue24561@psf.upfronthosting.co.za>
In-reply-to
Content
[Affects Windows only]
Brief description (after analysis in debugger):

Py_InitializeEx fails inside internal call:

1.
    if (initstdio() < 0)
        Py_FatalError(
            "Py_Initialize: can't initialize sys standard streams");

2. inside initstdio():

    if (!is_valid_fd(fd)) {
        std = Py_None;
        Py_INCREF(std);
    }
    else {
// ===> is_valid_fd() passed and we come here
        std = create_stdio(iomod, fd, 0, "<stdin>", encoding, errors);
        if (std == NULL)
            goto error; // ===> this goto leads to fatal error

3.
is_valid_fd(int fd)   /// => JFI: fd=0
{
    int dummy_fd;
    if (fd < 0 || !_PyVerify_fd(fd))
        return 0;
    dummy_fd = dup(fd); /// ==>> dup() WORKS well
    if (dummy_fd < 0)
        return 0;
    close(dummy_fd);
    return 1;
}

4.
Let's Look whats going in create_stdio():
Modules\_io\fileio.c

static int
fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
{ ...
    if (fd >= 0) {
        if (check_fd(fd))
            goto error;    /// => fail is here 

5. Let's have a look at check_fd():
static int
check_fd(int fd)
{
#if defined(HAVE_FSTAT) /// => yes, it is defined for Windows
    struct stat buf;
    if (!_PyVerify_fd(fd) || (fstat(fd, &buf) < 0 && errno == EBADF)) {
        PyObject *exc;
        char *msg = strerror(EBADF);
        exc = PyObject_CallFunction(PyExc_OSError, "(is)",
                                    EBADF, msg);
        PyErr_SetObject(PyExc_OSError, exc);
        Py_XDECREF(exc);
        return -1;
    }
#endif
    return 0;
}
History
Date User Action Args
2015-07-03 17:47:45vmurashevsetrecipients: + vmurashev, paul.moore, tim.golden, zach.ware, steve.dower
2015-07-03 17:47:45vmurashevsetmessageid: <1435945665.32.0.485913142675.issue24561@psf.upfronthosting.co.za>
2015-07-03 17:47:45vmurashevlinkissue24561 messages
2015-07-03 17:47:44vmurashevcreate