py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
authorYuya Nishihara <yuya@tcha.org>
Sat, 03 Mar 2018 06:18:47 -0500
changeset 36649 186c6df3a373
parent 36648 1f8c3fadbb8e
child 36650 4015b9248da0
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*() Perhaps we need this because 's' accepts a unicode string. https://docs.python.org/3/c-api/arg.html#strings-and-buffers Substituted using the following pattern with some manual fixes: '\b(PyArg_ParseTuple)\((\s*\w+,\s*)"([^"]+)"' '\b(PyArg_ParseTupleAndKeywords)\((\s*\w+,\s*\w+,\s*)"([^"]+)"'
mercurial/cext/base85.c
mercurial/cext/bdiff.c
mercurial/cext/charencode.c
mercurial/cext/mpatch.c
mercurial/cext/osutil.c
mercurial/cext/parsers.c
mercurial/cext/pathencode.c
mercurial/cext/revlog.c
--- a/mercurial/cext/base85.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/base85.c	Sat Mar 03 06:18:47 2018 -0500
@@ -37,7 +37,7 @@
 	unsigned int acc, val, ch;
 	int pad = 0;
 
-	if (!PyArg_ParseTuple(args, "s#|i", &text, &len, &pad))
+	if (!PyArg_ParseTuple(args, PY23("s#|i", "y#|i"), &text, &len, &pad))
 		return NULL;
 
 	if (pad)
@@ -84,7 +84,7 @@
 	int c;
 	unsigned int acc;
 
-	if (!PyArg_ParseTuple(args, "s#", &text, &len))
+	if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &text, &len))
 		return NULL;
 
 	olen = len / 5 * 4;
--- a/mercurial/cext/bdiff.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/bdiff.c	Sat Mar 03 06:18:47 2018 -0500
@@ -70,7 +70,8 @@
 
 	l.next = NULL;
 
-	if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb))
+	if (!PyArg_ParseTuple(args, PY23("s#s#:bdiff", "y#y#:bdiff"), &sa, &la,
+	                      &sb, &lb))
 		return NULL;
 
 	if (la > UINT_MAX || lb > UINT_MAX) {
@@ -196,7 +197,7 @@
 	Py_ssize_t nelts = 0, size, i, start = 0;
 	PyObject *result = NULL;
 
-	if (!PyArg_ParseTuple(args, "s#", &text, &size)) {
+	if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &text, &size)) {
 		goto abort;
 	}
 	if (!size) {
--- a/mercurial/cext/charencode.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/charencode.c	Sat Mar 03 06:18:47 2018 -0500
@@ -132,7 +132,8 @@
 {
 	const char *buf;
 	Py_ssize_t i, len;
-	if (!PyArg_ParseTuple(args, "s#:isasciistr", &buf, &len))
+	if (!PyArg_ParseTuple(args, PY23("s#:isasciistr", "y#:isasciistr"),
+	                      &buf, &len))
 		return NULL;
 	i = 0;
 	/* char array in PyStringObject should be at least 4-byte aligned */
--- a/mercurial/cext/mpatch.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/mpatch.c	Sat Mar 03 06:18:47 2018 -0500
@@ -134,7 +134,7 @@
 	Py_ssize_t patchlen;
 	char *bin;
 
-	if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen))
+	if (!PyArg_ParseTuple(args, PY23("ls#", "ly#"), &orig, &bin, &patchlen))
 		return NULL;
 
 	while (pos >= 0 && pos < patchlen) {
--- a/mercurial/cext/osutil.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/osutil.c	Sat Mar 03 06:18:47 2018 -0500
@@ -758,7 +758,7 @@
 static PyObject *setprocname(PyObject *self, PyObject *args)
 {
 	const char *name = NULL;
-	if (!PyArg_ParseTuple(args, "s", &name))
+	if (!PyArg_ParseTuple(args, PY23("s", "y"), &name))
 		return NULL;
 
 #if defined(SETPROCNAME_USE_SETPROCTITLE)
@@ -1105,7 +1105,7 @@
 	const char *path = NULL;
 	struct statfs buf;
 	int r;
-	if (!PyArg_ParseTuple(args, "s", &path))
+	if (!PyArg_ParseTuple(args, PY23("s", "y"), &path))
 		return NULL;
 
 	memset(&buf, 0, sizeof(buf));
@@ -1123,7 +1123,7 @@
 	const char *path = NULL;
 	struct statfs buf;
 	int r;
-	if (!PyArg_ParseTuple(args, "s", &path))
+	if (!PyArg_ParseTuple(args, PY23("s", "y"), &path))
 		return NULL;
 
 	memset(&buf, 0, sizeof(buf));
@@ -1164,7 +1164,8 @@
 
 	static char *kwlist[] = {"path", "stat", "skip", NULL};
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|OO:listdir",
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, PY23("s#|OO:listdir",
+							    "y#|OO:listdir"),
 			kwlist, &path, &plen, &statobj, &skipobj))
 		return NULL;
 
@@ -1197,7 +1198,9 @@
 	int plus;
 	FILE *fp;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|si:posixfile", kwlist,
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, PY23("et|si:posixfile",
+							  "et|yi:posixfile"),
+					 kwlist,
 					 Py_FileSystemDefaultEncoding,
 					 &name, &mode, &bufsize))
 		return NULL;
--- a/mercurial/cext/parsers.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/parsers.c	Sat Mar 03 06:18:47 2018 -0500
@@ -48,8 +48,9 @@
 	char *str, *start, *end;
 	int len;
 
-	if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest", &PyDict_Type,
-	                      &mfdict, &PyDict_Type, &fdict, &str, &len))
+	if (!PyArg_ParseTuple(
+	        args, PY23("O!O!s#:parse_manifest", "O!O!y#:parse_manifest"),
+	        &PyDict_Type, &mfdict, &PyDict_Type, &fdict, &str, &len))
 		goto quit;
 
 	start = str;
@@ -241,8 +242,9 @@
 	unsigned int flen, len, pos = 40;
 	int readlen;
 
-	if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", &PyDict_Type,
-	                      &dmap, &PyDict_Type, &cmap, &str, &readlen))
+	if (!PyArg_ParseTuple(
+	        args, PY23("O!O!s#:parse_dirstate", "O!O!y#:parse_dirstate"),
+	        &PyDict_Type, &dmap, &PyDict_Type, &cmap, &str, &readlen))
 		goto quit;
 
 	len = readlen;
@@ -645,7 +647,8 @@
 	Py_ssize_t offset, stop;
 	PyObject *markers = NULL;
 
-	if (!PyArg_ParseTuple(args, "s#nn", &data, &datalen, &offset, &stop)) {
+	if (!PyArg_ParseTuple(args, PY23("s#nn", "y#nn"), &data, &datalen,
+	                      &offset, &stop)) {
 		return NULL;
 	}
 	dataend = data + datalen;
--- a/mercurial/cext/pathencode.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/pathencode.c	Sat Mar 03 06:18:47 2018 -0500
@@ -512,7 +512,8 @@
 	Py_ssize_t len, newlen;
 	PyObject *ret;
 
-	if (!PyArg_ParseTuple(args, "s#:lowerencode", &path, &len))
+	if (!PyArg_ParseTuple(args, PY23("s#:lowerencode", "y#:lowerencode"),
+	                      &path, &len))
 		return NULL;
 
 	newlen = _lowerencode(NULL, 0, path, len);
--- a/mercurial/cext/revlog.c	Sat Mar 03 06:08:22 2018 -0500
+++ b/mercurial/cext/revlog.c	Sat Mar 03 06:18:47 2018 -0500
@@ -1243,7 +1243,7 @@
 	char *node;
 	int rev, i;
 
-	if (!PyArg_ParseTuple(args, "s#", &node, &nodelen))
+	if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &node, &nodelen))
 		return NULL;
 
 	if (nodelen < 4) {