cext: backout e9ca736f5b52 "remove Python 2 file handling code"
authorYuya Nishihara <yuya@tcha.org>
Thu, 03 Mar 2022 09:43:10 +0900
changeset 48840 499733de460f
parent 48839 7b068abe4aa2
child 48841 2ef3b7d30cc1
cext: backout e9ca736f5b52 "remove Python 2 file handling code" It's if"n"def.
mercurial/cext/osutil.c
--- a/mercurial/cext/osutil.c	Wed Mar 02 10:32:36 2022 -0500
+++ b/mercurial/cext/osutil.c	Thu Mar 03 09:43:10 2022 +0900
@@ -1176,7 +1176,9 @@
 	char fpmode[4];
 	int fppos = 0;
 	int plus;
+#ifndef IS_PY3K
 	FILE *fp;
+#endif
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|yi:posixfile",
 					 kwlist,
@@ -1248,6 +1250,7 @@
 		PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
 		goto bail;
 	}
+#ifndef IS_PY3K
 	fp = _fdopen(fd, fpmode);
 	if (fp == NULL) {
 		_close(fd);
@@ -1262,6 +1265,11 @@
 	}
 
 	PyFile_SetBufSize(file_obj, bufsize);
+#else
+	file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1);
+	if (file_obj == NULL)
+		goto bail;
+#endif
 bail:
 	PyMem_Free(name);
 	return file_obj;