Patchwork parsers: fix two cases of unsigned long instead of Py_ssize_t

login
register
mail settings
Submitter Augie Fackler
Date Aug. 26, 2015, 2:21 p.m.
Message ID <f7c929553d447dec9aa3.1440598910@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/10294/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 26, 2015, 2:21 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1440598807 14400
#      Wed Aug 26 10:20:07 2015 -0400
# Node ID f7c929553d447dec9aa3df923c6e90faf9b9fd57
# Parent  05e7f57c74ac5b556b49870af86f61aa0c54babb
parsers: fix two cases of unsigned long instead of Py_ssize_t

We had to do this before because Python 2.4 didn't understand the n
format specifier in Py_BuildValue and friends. We no longer have that
problem.
Matt Mackall - Aug. 31, 2015, 10:07 p.m.
On Wed, 2015-08-26 at 10:21 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1440598807 14400
> #      Wed Aug 26 10:20:07 2015 -0400
> # Node ID f7c929553d447dec9aa3df923c6e90faf9b9fd57
> # Parent  05e7f57c74ac5b556b49870af86f61aa0c54babb
> parsers: fix two cases of unsigned long instead of Py_ssize_t

Queued for default, thanks.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1046,13 +1046,12 @@  static PyObject *list_copy(PyObject *lis
 	return newlist;
 }
 
-/* arg should be Py_ssize_t but Python 2.4 do not support the n format */
-static int check_filter(PyObject *filter, unsigned long arg) {
+static int check_filter(PyObject *filter, Py_ssize_t arg) {
 	if (filter) {
 		PyObject *arglist, *result;
 		int isfiltered;
 
-		arglist = Py_BuildValue("(k)", arg);
+		arglist = Py_BuildValue("(n)", arg);
 		if (!arglist) {
 			return -1;
 		}
@@ -2666,12 +2665,10 @@  bail:
 static PyObject *fm1readmarkers(PyObject *self, PyObject *args) {
 	const char *data;
 	Py_ssize_t datalen;
-	/* only unsigned long because python 2.4, should be Py_ssize_t */
-	unsigned long offset, stop;
+	Py_ssize_t offset, stop;
 	PyObject *markers = NULL;
 
-	/* replace kk with nn when we drop Python 2.4 */
-	if (!PyArg_ParseTuple(args, "s#kk", &data, &datalen, &offset, &stop)) {
+	if (!PyArg_ParseTuple(args, "s#nn", &data, &datalen, &offset, &stop)) {
 		return NULL;
 	}
 	data += offset;