Comments
Patch
@@ -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);
}