parsers: fix Py2.4 argument parsing issue
Since
fa53d66b45a8, we were getting this strange message with Py2.4:
TypeError: argument 1 must be impossible<bad format char>, not int
..because we were using the 'n' type specifier introduced in 2.5.
It turns out that offset is actually a revision number index, which
ought to be an int anyway. So we store it in an int, use the 'i'
specifier, rely on Py_ParseTuple for range checking, and rename it to
avoid type confusion.
--- a/mercurial/parsers.c Sun Sep 14 20:32:34 2014 -0400
+++ b/mercurial/parsers.c Wed Oct 01 14:44:24 2014 -0500
@@ -687,9 +687,10 @@
{
PyObject *obj;
char *node;
- Py_ssize_t offset, len, nodelen;
+ int index;
+ Py_ssize_t len, nodelen;
- if (!PyArg_ParseTuple(args, "nO", &offset, &obj))
+ if (!PyArg_ParseTuple(args, "iO", &index, &obj))
return NULL;
if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) {
@@ -702,21 +703,15 @@
len = index_length(self);
- if (offset < 0)
- offset += len;
+ if (index < 0)
+ index += len;
- if (offset != len - 1) {
+ if (index != len - 1) {
PyErr_SetString(PyExc_IndexError,
"insert only supported at index -1");
return NULL;
}
- if (offset > INT_MAX) {
- PyErr_SetString(PyExc_ValueError,
- "currently only 2**31 revs supported");
- return NULL;
- }
-
if (self->added == NULL) {
self->added = PyList_New(0);
if (self->added == NULL)
@@ -727,7 +722,7 @@
return NULL;
if (self->nt)
- nt_insert(self, node, (int)offset);
+ nt_insert(self, node, index);
Py_CLEAR(self->headrevs);
Py_RETURN_NONE;