Patchwork D1767: cext: make nullentry a member of index types

login
register
mail settings
Submitter phabricator
Date Jan. 6, 2018, 8:26 a.m.
Message ID <c5f4ad2d1e5c850d089c1aa49bfbac27@localhost.localdomain>
Download mbox | patch
Permalink /patch/26584/
State Not Applicable
Headers show

Comments

phabricator - Jan. 6, 2018, 8:26 a.m.
indygreg updated this revision to Diff 4736.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1767?vs=4628&id=4736

REVISION DETAIL
  https://phab.mercurial-scm.org/D1767

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: indygreg, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

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) {
@@ -1862,6 +1862,7 @@ 
 	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 +1874,12 @@ 
 	self->nt = NULL;
 	self->offsets = NULL;
 
+	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);
 }