How to resolve circular reference in python C extension?

Stefan Behnel stefan_ml at behnel.de
Mon Apr 9 03:26:54 EDT 2012


罗勇刚(Yonggang Luo) , 09.04.2012 04:28:
> static PyObject *
> Repository_get_index(Repository *self, void *closure)
> {
>     int err;
>     git_index *index;
>     Index *py_index;
> 
>     assert(self->repo);
> 
>     if (self->index == NULL) {
>         err = git_repository_index(&index, self->repo);
>         if (err < 0)
>             return Error_set(err);
> 
>         py_index = PyObject_GC_New(Index, &IndexType);
>         if (!py_index) {
>             git_index_free(index);
>             return NULL;
>         }
> 
>         Py_INCREF(self);
>         py_index->repo = self;
>         py_index->index = index;
>         PyObject_GC_Track(py_index);
>         self->index = (PyObject*)py_index;
>     }
> 
>     Py_INCREF(self->index);
>     return self->index;
> }

It would have been nice if you had added some explanatory text to this code
dump.

What do you mean by "resolve"?

Stefan




More information about the Python-list mailing list