D4118: index: make node tree a Python object

Yuya Nishihara yuya at tcha.org
Tue Aug 7 10:02:58 EDT 2018


Can you bump the cext version as this patch introduces new API?

> +static int nt_init_py(nodetree *self, PyObject *args)
> +{
> +	PyObject *index;
> +	unsigned capacity;
> +	if (!PyArg_ParseTuple(args, "OI", &index, &capacity))
> +		return -1;

It leaves self->nodes uninitialized on error, and nt_dealloc() would fail if
self->nodes wasn't luckily 0. Strictly speaking, it's too late to initialize
pointers in tp_init because __init__() may be called more than once, but our
C types don't handle such cases.

> +	return nt_init(self, (indexObject*)index, capacity);

We'll probably need INCREF/DECREF business for the index object.

I didn't review the other refcounting thingy carefully. Since it's painful
to do refcounting right, an internal nodetree could be embedded in the
indexObject, and a thin PyObject wrapper could be added. Just an idea.

```
struct nodetree {
};

struct nodetreeObject {
    PyObject_HEAD
    nodetree nt;
};

struct indexObject {
    ...
    nodetree nt;
    ...
};
```


More information about the Mercurial-devel mailing list