cext: remove PY23()
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Feb 2022 16:09:02 -0700
changeset 48821 b0dd39b91e7a
parent 48820 acf9f778e048
child 48822 3aa1b7ded52c
cext: remove PY23() Since we always run on Python 3 now, we no longer need this macro to support Python 2. We refactor all users to just use the 2nd argument. Differential Revision: https://phab.mercurial-scm.org/D12232
mercurial/cext/base85.c
mercurial/cext/bdiff.c
mercurial/cext/charencode.c
mercurial/cext/manifest.c
mercurial/cext/mpatch.c
mercurial/cext/osutil.c
mercurial/cext/parsers.c
mercurial/cext/pathencode.c
mercurial/cext/revlog.c
mercurial/cext/util.h
--- a/mercurial/cext/base85.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/base85.c	Sun Feb 20 16:09:02 2022 -0700
@@ -38,7 +38,7 @@
 	unsigned int acc, val, ch;
 	int pad = 0;
 
-	if (!PyArg_ParseTuple(args, PY23("s#|i", "y#|i"), &text, &len, &pad)) {
+	if (!PyArg_ParseTuple(args, "y#|i", &text, &len, &pad)) {
 		return NULL;
 	}
 
@@ -90,7 +90,7 @@
 	int c;
 	unsigned int acc;
 
-	if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &text, &len)) {
+	if (!PyArg_ParseTuple(args, "y#", &text, &len)) {
 		return NULL;
 	}
 
--- a/mercurial/cext/bdiff.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/bdiff.c	Sun Feb 20 16:09:02 2022 -0700
@@ -76,8 +76,7 @@
 
 	l.next = NULL;
 
-	if (!PyArg_ParseTuple(args, PY23("s*s*:bdiff", "y*y*:bdiff"), &ba,
-	                      &bb)) {
+	if (!PyArg_ParseTuple(args, "y*y*:bdiff", &ba, &bb)) {
 		return NULL;
 	}
 
@@ -233,7 +232,7 @@
 	Py_ssize_t nelts = 0, size, i, start = 0;
 	PyObject *result = NULL;
 
-	if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &text, &size)) {
+	if (!PyArg_ParseTuple(args, "y#", &text, &size)) {
 		goto abort;
 	}
 	if (!size) {
@@ -299,8 +298,7 @@
 	    NULL, /* priv */
 	};
 
-	if (!PyArg_ParseTuple(args, PY23("s#s#", "y#y#"), &a.ptr, &la, &b.ptr,
-	                      &lb)) {
+	if (!PyArg_ParseTuple(args, "y#y#", &a.ptr, &la, &b.ptr, &lb)) {
 		return NULL;
 	}
 
--- a/mercurial/cext/charencode.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/charencode.c	Sun Feb 20 16:09:02 2022 -0700
@@ -125,8 +125,7 @@
 {
 	const char *buf;
 	Py_ssize_t i, len;
-	if (!PyArg_ParseTuple(args, PY23("s#:isasciistr", "y#:isasciistr"),
-	                      &buf, &len)) {
+	if (!PyArg_ParseTuple(args, "y#:isasciistr", &buf, &len)) {
 		return NULL;
 	}
 	i = 0;
--- a/mercurial/cext/manifest.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/manifest.c	Sun Feb 20 16:09:02 2022 -0700
@@ -780,7 +780,7 @@
 	Py_INCREF(copy->pydata);
 	for (i = 0; i < self->numlines; i++) {
 		PyObject *arglist = NULL, *result = NULL;
-		arglist = Py_BuildValue(PY23("(s)", "(y)"),
+		arglist = Py_BuildValue("(y)",
 					self->lines[i].start);
 		if (!arglist) {
 			goto bail;
--- a/mercurial/cext/mpatch.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/mpatch.c	Sun Feb 20 16:09:02 2022 -0700
@@ -144,8 +144,7 @@
 	Py_ssize_t patchlen;
 	char *bin;
 
-	if (!PyArg_ParseTuple(args, PY23("ls#", "ly#"), &orig, &bin,
-	                      &patchlen)) {
+	if (!PyArg_ParseTuple(args, "ly#", &orig, &bin, &patchlen)) {
 		return NULL;
 	}
 
--- a/mercurial/cext/osutil.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/osutil.c	Sun Feb 20 16:09:02 2022 -0700
@@ -198,7 +198,7 @@
 		? _S_IFDIR : _S_IFREG;
 
 	if (!wantstat)
-		return Py_BuildValue(PY23("si", "yi"), fd->cFileName, kind);
+		return Py_BuildValue("yi", fd->cFileName, kind);
 
 	py_st = PyObject_CallObject((PyObject *)&listdir_stat_type, NULL);
 	if (!py_st)
@@ -216,7 +216,7 @@
 	if (kind == _S_IFREG)
 		stp->st_size = ((__int64)fd->nFileSizeHigh << 32)
 				+ fd->nFileSizeLow;
-	return Py_BuildValue(PY23("siN", "yiN"), fd->cFileName,
+	return Py_BuildValue("yiN", fd->cFileName,
 		kind, py_st);
 }
 
@@ -404,10 +404,10 @@
 			PyObject *stat = makestat(&st);
 			if (!stat)
 				goto error;
-			elem = Py_BuildValue(PY23("siN", "yiN"), ent->d_name,
+			elem = Py_BuildValue("yiN", ent->d_name,
 					     kind, stat);
 		} else
-			elem = Py_BuildValue(PY23("si", "yi"), ent->d_name,
+			elem = Py_BuildValue("yi", ent->d_name,
 					     kind);
 		if (!elem)
 			goto error;
@@ -585,10 +585,10 @@
 				stat = makestat(&st);
 				if (!stat)
 					goto error;
-				elem = Py_BuildValue(PY23("siN", "yiN"),
+				elem = Py_BuildValue("yiN",
 						     filename, kind, stat);
 			} else
-				elem = Py_BuildValue(PY23("si", "yi"),
+				elem = Py_BuildValue("yi",
 						     filename, kind);
 			if (!elem)
 				goto error;
@@ -772,7 +772,7 @@
 static PyObject *setprocname(PyObject *self, PyObject *args)
 {
 	const char *name = NULL;
-	if (!PyArg_ParseTuple(args, PY23("s", "y"), &name))
+	if (!PyArg_ParseTuple(args, "y", &name))
 		return NULL;
 
 #if defined(SETPROCNAME_USE_SETPROCTITLE)
@@ -1127,14 +1127,14 @@
 	const char *path = NULL;
 	struct statfs buf;
 	int r;
-	if (!PyArg_ParseTuple(args, PY23("s", "y"), &path))
+	if (!PyArg_ParseTuple(args, "y", &path))
 		return NULL;
 
 	memset(&buf, 0, sizeof(buf));
 	r = statfs(path, &buf);
 	if (r != 0)
 		return PyErr_SetFromErrno(PyExc_OSError);
-	return Py_BuildValue(PY23("s", "y"), describefstype(&buf));
+	return Py_BuildValue("y", describefstype(&buf));
 }
 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
 
@@ -1145,14 +1145,14 @@
 	const char *path = NULL;
 	struct statfs buf;
 	int r;
-	if (!PyArg_ParseTuple(args, PY23("s", "y"), &path))
+	if (!PyArg_ParseTuple(args, "y", &path))
 		return NULL;
 
 	memset(&buf, 0, sizeof(buf));
 	r = statfs(path, &buf);
 	if (r != 0)
 		return PyErr_SetFromErrno(PyExc_OSError);
-	return Py_BuildValue(PY23("s", "y"), buf.f_mntonname);
+	return Py_BuildValue("y", buf.f_mntonname);
 }
 #endif /* defined(HAVE_BSD_STATFS) */
 
@@ -1187,8 +1187,7 @@
 
 	static char *kwlist[] = {"path", "stat", "skip", NULL};
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, PY23("s#|OO:listdir",
-							    "y#|OO:listdir"),
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|OO:listdir",
 			kwlist, &path, &plen, &statobj, &skipobj))
 		return NULL;
 
@@ -1221,8 +1220,7 @@
 	int plus;
 	FILE *fp;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, PY23("et|si:posixfile",
-							  "et|yi:posixfile"),
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|yi:posixfile",
 					 kwlist,
 					 Py_FileSystemDefaultEncoding,
 					 &name, &mode, &bufsize))
--- a/mercurial/cext/parsers.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/parsers.c	Sun Feb 20 16:09:02 2022 -0700
@@ -813,9 +813,8 @@
 	Py_ssize_t len = 40;
 	Py_ssize_t readlen;
 
-	if (!PyArg_ParseTuple(
-	        args, PY23("O!O!s#:parse_dirstate", "O!O!y#:parse_dirstate"),
-	        &PyDict_Type, &dmap, &PyDict_Type, &cmap, &str, &readlen)) {
+	if (!PyArg_ParseTuple(args, "O!O!y#:parse_dirstate", &PyDict_Type,
+	                      &dmap, &PyDict_Type, &cmap, &str, &readlen)) {
 		goto quit;
 	}
 
@@ -828,8 +827,8 @@
 		goto quit;
 	}
 
-	parents = Py_BuildValue(PY23("s#s#", "y#y#"), str, (Py_ssize_t)20,
-	                        str + 20, (Py_ssize_t)20);
+	parents = Py_BuildValue("y#y#", str, (Py_ssize_t)20, str + 20,
+	                        (Py_ssize_t)20);
 	if (!parents) {
 		goto quit;
 	}
@@ -1158,8 +1157,7 @@
 	Py_ssize_t datalen, offset, stop;
 	PyObject *markers = NULL;
 
-	if (!PyArg_ParseTuple(args, PY23("s#nn", "y#nn"), &data, &datalen,
-	                      &offset, &stop)) {
+	if (!PyArg_ParseTuple(args, "y#nn", &data, &datalen, &offset, &stop)) {
 		return NULL;
 	}
 	if (offset < 0) {
--- a/mercurial/cext/pathencode.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/pathencode.c	Sun Feb 20 16:09:02 2022 -0700
@@ -535,8 +535,7 @@
 	Py_ssize_t len, newlen;
 	PyObject *ret;
 
-	if (!PyArg_ParseTuple(args, PY23("s#:lowerencode", "y#:lowerencode"),
-	                      &path, &len)) {
+	if (!PyArg_ParseTuple(args, "y#:lowerencode", &path, &len)) {
 		return NULL;
 	}
 
@@ -711,7 +710,7 @@
 		}
 	}
 
-	shaobj = PyObject_CallFunction(shafunc, PY23("s#", "y#"), str, len);
+	shaobj = PyObject_CallFunction(shafunc, "y#", str, len);
 
 	if (shaobj == NULL) {
 		return -1;
--- a/mercurial/cext/revlog.c	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/revlog.c	Sun Feb 20 16:09:02 2022 -0700
@@ -109,11 +109,9 @@
 static int index_find_node(indexObject *self, const char *node);
 
 #if LONG_MAX == 0x7fffffffL
-static const char *const tuple_format =
-    PY23("Kiiiiiis#KiBBi", "Kiiiiiiy#KiBBi");
+static const char *const tuple_format = "Kiiiiiiy#KiBBi";
 #else
-static const char *const tuple_format =
-    PY23("kiiiiiis#kiBBi", "kiiiiiiy#kiBBi");
+static const char *const tuple_format = "kiiiiiiy#kiBBi";
 #endif
 
 /* A RevlogNG v1 index entry is 64 bytes long. */
@@ -720,9 +718,9 @@
 	char comp_mode;
 	char *data;
 #if LONG_MAX == 0x7fffffffL
-	const char *const sidedata_format = PY23("nKiKB", "nKiKB");
+	const char *const sidedata_format = "nKiKB";
 #else
-	const char *const sidedata_format = PY23("nkikB", "nkikB");
+	const char *const sidedata_format = "nkikB";
 #endif
 
 	if (self->entry_size == v1_entry_size || self->inlined) {
@@ -2301,7 +2299,7 @@
 	char *node;
 	int rev, i;
 
-	if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &node, &nodelen))
+	if (!PyArg_ParseTuple(args, "y#", &node, &nodelen))
 		return NULL;
 
 	if (nodelen < 1) {
@@ -3012,10 +3010,9 @@
 		self->entry_size = cl2_entry_size;
 	}
 
-	self->nullentry =
-	    Py_BuildValue(PY23("iiiiiiis#iiBBi", "iiiiiiiy#iiBBi"), 0, 0, 0, -1,
-	                  -1, -1, -1, nullid, self->nodelen, 0, 0,
-	                  comp_mode_inline, comp_mode_inline, rank_unknown);
+	self->nullentry = Py_BuildValue(
+	    "iiiiiiiy#iiBBi", 0, 0, 0, -1, -1, -1, -1, nullid, self->nodelen, 0,
+	    0, comp_mode_inline, comp_mode_inline, rank_unknown);
 
 	if (!self->nullentry)
 		return -1;
--- a/mercurial/cext/util.h	Sun Feb 20 16:13:57 2022 -0700
+++ b/mercurial/cext/util.h	Sun Feb 20 16:09:02 2022 -0700
@@ -14,13 +14,6 @@
 #define IS_PY3K
 #endif
 
-/* helper to switch things like string literal depending on Python version */
-#ifdef IS_PY3K
-#define PY23(py2, py3) py3
-#else
-#define PY23(py2, py3) py2
-#endif
-
 /* clang-format off */
 typedef struct {
 	PyObject_HEAD