Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Jan 8, 2021

Convert _multibytecodec.MultibyteCodec type to a GC type and adds a
traverse function.

https://bugs.python.org/issue42866

Convert _multibytecodec.MultibyteCodec type to a GC type and adds a
traverse function.
@vstinner
Copy link
Member Author

vstinner commented Jan 8, 2021

Example:

import _codecs_jp
import gc
codec = _codecs_jp.getcodec('cp932')
print(gc.get_referents(codec))

Output:

[<class '_multibytecodec.MultibyteCodec'>]

@vstinner
Copy link
Member Author

vstinner commented Jan 8, 2021

I updated the PR to track/untrack an instance in the GC.

Example:

import _codecs_jp
import gc
codec = _codecs_jp.getcodec('cp932')
# instance -> type
print(gc.get_referents(codec) == [type(codec)])
# type -> instance
print(any(ref is codec for ref in gc.get_referrers(type(codec))))

Output with the PR:

True
True

@vstinner vstinner merged commit 11ef53a into python:master Jan 8, 2021
@vstinner vstinner deleted the mbc_traverse branch January 8, 2021 14:44
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…nGH-24166)

Convert _multibytecodec.MultibyteCodec type to a GC type and adds a
traverse function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants