diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c +++ b/mercurial/cext/revlog.c @@ -54,6 +54,7 @@ typedef struct { PyObject_HEAD /* Type-specific fields go here. */ + PyObject *nullentry; /* Represents an empty/unknown index value */ PyObject *data; /* raw bytes of index */ Py_buffer buf; /* buffer of data */ PyObject **cache; /* cached tuples */ @@ -81,7 +82,6 @@ return self->length + PyList_GET_SIZE(self->added); } -static PyObject *nullentry; static const char nullid[20]; static Py_ssize_t inline_scan(indexObject *self, const char **offsets); @@ -167,8 +167,8 @@ } if (pos == length - 1) { - Py_INCREF(nullentry); - return nullentry; + Py_INCREF(self->nullentry); + return self->nullentry; } if (pos >= self->length - 1) { @@ -1861,7 +1861,7 @@ PyObject *data_obj, *inlined_obj; Py_ssize_t size; - /* Initialize before argument-checking to avoid index_dealloc() crash. */ + self->nullentry = NULL; self->raw_length = 0; self->added = NULL; self->cache = NULL; @@ -1873,6 +1873,13 @@ self->nt = NULL; self->offsets = NULL; + /* Initialize before argument-checking to avoid index_dealloc() crash. */ + self->nullentry = Py_BuildValue("iiiiiiis#", 0, 0, 0, + -1, -1, -1, -1, nullid, 20); + if (!self->nullentry) { + return -1; + } + if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj)) return -1; if (!PyObject_CheckBuffer(data_obj)) { @@ -1930,6 +1937,7 @@ } Py_XDECREF(self->data); Py_XDECREF(self->added); + Py_XDECREF(self->nullentry); PyObject_Del(self); } @@ -2076,9 +2084,4 @@ return; Py_INCREF(&indexType); PyModule_AddObject(mod, "index", (PyObject *)&indexType); - - nullentry = Py_BuildValue("iiiiiiis#", 0, 0, 0, - -1, -1, -1, -1, nullid, 20); - if (nullentry) - PyObject_GC_UnTrack(nullentry); }