[PATCH] parsers: fix typing and sign issues
Henrik Stuart
hg at hstuart.dk
Sat Sep 6 15:25:37 CDT 2014
# HG changeset patch
# User Henrik Stuart <hg at hstuart.dk>
# Date 1410029932 -7200
# Sat Sep 06 20:58:52 2014 +0200
# Node ID 41abcba2e5d08ac00abf2df5f6cbe2fe3a7e2e6e
# Parent c5df4af17110838b713d6c9ec3b824fb0b6c1b33
parsers: fix typing and sign issues
Normalized the use of types in the parser to avoid signed/unsigned mismatches
and normalized const-ness call to free to omit warnings with both gcc and
Microsoft Visual C++.
All the fixes were based on warnings from Microsoft Visual C++ 2008.
diff -r c5df4af17110838b713d6c9ec3b824fb0b6c1b33 -r 41abcba2e5d08ac00abf2df5f6cbe2fe3a7e2e6e mercurial/parsers.c
--- a/mercurial/parsers.c Thu Sep 04 09:59:23 2014 -0400
+++ b/mercurial/parsers.c Sat Sep 06 20:58:52 2014 +0200
@@ -275,15 +275,20 @@
PyObject *fname = NULL, *cname = NULL, *entry = NULL;
char state, *cur, *str, *cpos;
int mode, size, mtime;
- unsigned int flen;
- int len, pos = 40;
+ unsigned int flen, len, pos = 40;
+ int readlen;
if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate",
&PyDict_Type, &dmap,
&PyDict_Type, &cmap,
- &str, &len))
+ &str, &readlen))
goto quit;
+ if (readlen < 0)
+ goto quit;
+
+ len = readlen;
+
/* read parents */
if (len < 40)
goto quit;
@@ -524,7 +529,7 @@
static PyObject *nullentry;
static const char nullid[20];
-static long inline_scan(indexObject *self, const char **offsets);
+static Py_ssize_t inline_scan(indexObject *self, const char **offsets);
#if LONG_MAX == 0x7fffffffL
static char *tuple_format = "Kiiiiiis#";
@@ -681,10 +686,10 @@
{
PyObject *obj;
char *node;
- long offset;
+ Py_ssize_t offset;
Py_ssize_t len, nodelen;
- if (!PyArg_ParseTuple(args, "lO", &offset, &obj))
+ if (!PyArg_ParseTuple(args, "nO", &offset, &obj))
return NULL;
if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) {
@@ -739,7 +744,7 @@
self->cache = NULL;
}
if (self->offsets) {
- free(self->offsets);
+ free((char**)self->offsets);
self->offsets = NULL;
}
if (self->nt) {
@@ -881,7 +886,7 @@
if (nothead[i])
continue;
- head = PyInt_FromLong(i);
+ head = PyInt_FromSsize_t(i);
if (head == NULL || PyList_Append(heads, head) == -1) {
Py_XDECREF(head);
goto bail;
@@ -1304,7 +1309,7 @@
PyObject *gca = PyList_New(0);
int i, v, interesting;
int maxrev = -1;
- long sp;
+ bitmask sp;
bitmask *seen;
if (gca == NULL)
@@ -1327,7 +1332,7 @@
interesting = revcount;
for (v = maxrev; v >= 0 && interesting; v--) {
- long sv = seen[v];
+ bitmask sv = seen[v];
int parents[2];
if (!sv)
@@ -1853,7 +1858,7 @@
* Find all RevlogNG entries in an index that has inline data. Update
* the optional "offsets" table with those entries.
*/
-static long inline_scan(indexObject *self, const char **offsets)
+static Py_ssize_t inline_scan(indexObject *self, const char **offsets)
{
const char *data = PyString_AS_STRING(self->data);
Py_ssize_t pos = 0;
@@ -1913,7 +1918,7 @@
Py_INCREF(self->data);
if (self->inlined) {
- long len = inline_scan(self, NULL);
+ Py_ssize_t len = inline_scan(self, NULL);
if (len == -1)
goto bail;
self->raw_length = len;
More information about the Mercurial-devel
mailing list