D4372: index: embed nodetree in index object to avoid reference cycle

Yuya Nishihara yuya at tcha.org
Sat Aug 25 05:33:59 EDT 2018


> -static int nt_init_py(nodetree *self, PyObject *args)
> +static int ntobj_init(nodetreeObject *self, PyObject *args)
>  {
>  	PyObject *index;
>  	unsigned capacity;
> +	int ret;
>  	if (!PyArg_ParseTuple(args, "O!I", &indexType, &index, &capacity))
>  		return -1;
> -	return nt_init(self, (indexObject*)index, capacity);
> +	ret = nt_init(&self->nt, (indexObject*)index, capacity);
> +	if (ret == 0) {
> +	  Py_INCREF(index);
> +	}

Perhaps index should be increfed no matter if nt_init() succeeds or not,
since the self is ntobj_dealloc()-ed anyway.


More information about the Mercurial-devel mailing list