Merge change 54982 from the trunk. This fixes the test_subprocess test in the testsuite for VisualStudio2005 builds, by "sanitizing" the "mode" that is used in the posixmodule's fdopen(). In particular the non-standard "U" mode character is removed.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 158b12e..b984c30 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6170,16 +6170,23 @@
posix_fdopen(PyObject *self, PyObject *args)
{
int fd;
- char *mode = "r";
+ char *orgmode = "r";
int bufsize = -1;
FILE *fp;
PyObject *f;
- if (!PyArg_ParseTuple(args, "i|si", &fd, &mode, &bufsize))
+ char *mode;
+ if (!PyArg_ParseTuple(args, "i|si", &fd, &orgmode, &bufsize))
return NULL;
- if (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a') {
- PyErr_Format(PyExc_ValueError,
- "invalid file mode '%s'", mode);
+ /* Sanitize mode. See fileobject.c */
+ mode = PyMem_MALLOC(strlen(orgmode)+3);
+ if (!mode) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ strcpy(mode, orgmode);
+ if (_PyFile_SanitizeMode(mode)) {
+ PyMem_FREE(mode);
return NULL;
}
Py_BEGIN_ALLOW_THREADS
@@ -6200,10 +6207,11 @@
#else
fp = fdopen(fd, mode);
#endif
+ PyMem_FREE(mode);
Py_END_ALLOW_THREADS
if (fp == NULL)
return posix_error();
- f = PyFile_FromFile(fp, "<fdopen>", mode, fclose);
+ f = PyFile_FromFile(fp, "<fdopen>", orgmode, fclose);
if (f != NULL)
PyFile_SetBufSize(f, bufsize);
return f;