How to resolve circular reference in python C extension?
罗勇刚(Yonggang Luo)
luoyonggang at gmail.com
Mon Apr 9 07:34:06 EDT 2012
I means remove the circular references without hurt the code, that is,
these two object will be destroyed at the same time. Even there
creation time is differ
2012/4/9, Stefan Behnel <stefan_ml at behnel.de>:
> 罗勇刚(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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
从我的移动设备发送
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
More information about the Python-list
mailing list