Patchwork [1,of,2] cext: backout e9ca736f5b52 "remove Python 2 file handling code"

login
register
mail settings
Submitter Yuya Nishihara
Date March 3, 2022, 2:37 a.m.
Message ID <499733de460faf0d8cee.1646275044@lemosa>
Download mbox | patch
Permalink /patch/50655/
State New
Headers show

Comments

Yuya Nishihara - March 3, 2022, 2:37 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1646268190 -32400
#      Thu Mar 03 09:43:10 2022 +0900
# Node ID 499733de460faf0d8cee6ea5e22bd05cec2fc93c
# Parent  7b068abe4aa2d1848cf91c2c203b68aa59feaaf7
cext: backout e9ca736f5b52 "remove Python 2 file handling code"

It's if"n"def.
Gregory Szorc - March 3, 2022, 3:14 a.m.
*facepalm*

Queued, thanks.

On Wed, Mar 2, 2022 at 7:42 PM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1646268190 -32400
> #      Thu Mar 03 09:43:10 2022 +0900
> # Node ID 499733de460faf0d8cee6ea5e22bd05cec2fc93c
> # Parent  7b068abe4aa2d1848cf91c2c203b68aa59feaaf7
> cext: backout e9ca736f5b52 "remove Python 2 file handling code"
>
> It's if"n"def.
>
> diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c
> --- a/mercurial/cext/osutil.c
> +++ b/mercurial/cext/osutil.c
> @@ -1176,7 +1176,9 @@ static PyObject *posixfile(PyObject *sel
>         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 @@ static PyObject *posixfile(PyObject *sel
>                 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
>                 goto bail;
>         }
> +#ifndef IS_PY3K
>         fp = _fdopen(fd, fpmode);
>         if (fp == NULL) {
>                 _close(fd);
> @@ -1262,6 +1265,11 @@ static PyObject *posixfile(PyObject *sel
>         }
>
>         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;
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c
--- a/mercurial/cext/osutil.c
+++ b/mercurial/cext/osutil.c
@@ -1176,7 +1176,9 @@  static PyObject *posixfile(PyObject *sel
 	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 @@  static PyObject *posixfile(PyObject *sel
 		PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
 		goto bail;
 	}
+#ifndef IS_PY3K
 	fp = _fdopen(fd, fpmode);
 	if (fp == NULL) {
 		_close(fd);
@@ -1262,6 +1265,11 @@  static PyObject *posixfile(PyObject *sel
 	}
 
 	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;