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 maxdeliso
Recipients maxdeliso, vstinner
Date 2013-06-16.05:25:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1371360358.04.0.850804601232.issue18197@psf.upfronthosting.co.za>
In-reply-to
Content
ok I checked in to this more deeply and I was wrong about a few things. first, my patch is worthless - there are several more instances where the retval of fileno is passed directly to fstat and that is totally valid (provided the file* points to a valid file).

looking deeper in the call stack, this call stack is originating from a PyCFunction_Call from mercurial's native extension, osutil.

 # Call Site
00 MSVCR90!fstat64i32+0xe8
01 python27!dircheck+0x29
02 python27!fill_file_fields+0x18e
03 python27!PyFile_FromFile+0x89
04 osutil+0x176f
05 python27!PyCFunction_Call+0x76

Here's the code in osutil.c (which is part of mercurial)

(osutil.c:554)
#ifndef IS_PY3K
	fp = _fdopen(fd, fpmode);
	if (fp == NULL) {
		_close(fd);
		PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
		goto bail;
	}

	file_obj = PyFile_FromFile(fp, name, mode, fclose); //this is the call that is the parent
	if (file_obj == NULL) {
		fclose(fp);
		goto bail;
	}

	PyFile_SetBufSize(file_obj, bufsize);
#else

fileno() is actually 'succeeding' and returning a value of 3.
fstat is then throwing the invalid parameter exception, presumably because 3 is not a valid file descriptor.
the way fileno() is implemented in M$CRT is really simple: it just copies a value at a fixed offset from the pointer passed to it without checking to see if the FILE* is valid.

this is why in the docs for _fileno they say "The result is undefined if stream does not specify an open file."

anyways, I don't think this is a bug in python, but rather in the mercurial extension.
it's a little tricky to debug on windows because the osutil module gets delay-loaded.
I'm taking another pass at it now.
History
Date User Action Args
2013-06-16 05:25:58maxdelisosetrecipients: + maxdeliso, vstinner
2013-06-16 05:25:58maxdelisosetmessageid: <1371360358.04.0.850804601232.issue18197@psf.upfronthosting.co.za>
2013-06-16 05:25:58maxdelisolinkissue18197 messages
2013-06-16 05:25:57maxdelisocreate