Mercurial > hg
comparison mercurial/parsers.c @ 22604:5e0d1478db8e
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.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 01 Oct 2014 14:44:24 -0500 |
parents | 9a860ac8c216 |
children | 80f2b63dd83a |
comparison
equal
deleted
inserted
replaced
22597:58ec36686f0e | 22604:5e0d1478db8e |
---|---|
685 | 685 |
686 static PyObject *index_insert(indexObject *self, PyObject *args) | 686 static PyObject *index_insert(indexObject *self, PyObject *args) |
687 { | 687 { |
688 PyObject *obj; | 688 PyObject *obj; |
689 char *node; | 689 char *node; |
690 Py_ssize_t offset, len, nodelen; | 690 int index; |
691 | 691 Py_ssize_t len, nodelen; |
692 if (!PyArg_ParseTuple(args, "nO", &offset, &obj)) | 692 |
693 if (!PyArg_ParseTuple(args, "iO", &index, &obj)) | |
693 return NULL; | 694 return NULL; |
694 | 695 |
695 if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) { | 696 if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) { |
696 PyErr_SetString(PyExc_TypeError, "8-tuple required"); | 697 PyErr_SetString(PyExc_TypeError, "8-tuple required"); |
697 return NULL; | 698 return NULL; |
700 if (node_check(PyTuple_GET_ITEM(obj, 7), &node, &nodelen) == -1) | 701 if (node_check(PyTuple_GET_ITEM(obj, 7), &node, &nodelen) == -1) |
701 return NULL; | 702 return NULL; |
702 | 703 |
703 len = index_length(self); | 704 len = index_length(self); |
704 | 705 |
705 if (offset < 0) | 706 if (index < 0) |
706 offset += len; | 707 index += len; |
707 | 708 |
708 if (offset != len - 1) { | 709 if (index != len - 1) { |
709 PyErr_SetString(PyExc_IndexError, | 710 PyErr_SetString(PyExc_IndexError, |
710 "insert only supported at index -1"); | 711 "insert only supported at index -1"); |
711 return NULL; | |
712 } | |
713 | |
714 if (offset > INT_MAX) { | |
715 PyErr_SetString(PyExc_ValueError, | |
716 "currently only 2**31 revs supported"); | |
717 return NULL; | 712 return NULL; |
718 } | 713 } |
719 | 714 |
720 if (self->added == NULL) { | 715 if (self->added == NULL) { |
721 self->added = PyList_New(0); | 716 self->added = PyList_New(0); |
725 | 720 |
726 if (PyList_Append(self->added, obj) == -1) | 721 if (PyList_Append(self->added, obj) == -1) |
727 return NULL; | 722 return NULL; |
728 | 723 |
729 if (self->nt) | 724 if (self->nt) |
730 nt_insert(self, node, (int)offset); | 725 nt_insert(self, node, index); |
731 | 726 |
732 Py_CLEAR(self->headrevs); | 727 Py_CLEAR(self->headrevs); |
733 Py_RETURN_NONE; | 728 Py_RETURN_NONE; |
734 } | 729 } |
735 | 730 |