Skip to content

bpo-1635741: Fix refleaks of encodings module by removing the encodings._aliases #21896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/encodings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
_cache = {}
_unknown = '--unknown--'
_import_tail = ['*']
_aliases = aliases.aliases


class CodecRegistryError(LookupError, SystemError):
pass
Expand Down Expand Up @@ -69,6 +69,7 @@ def normalize_encoding(encoding):

def search_function(encoding):

_aliases = aliases.aliases
Copy link

@ghost ghost Aug 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand the problem.
This statement should be placed at below so that it does not affect the performance of the cache.

Copy link
Member Author

@shihai1991 shihai1991 Aug 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand the problem.

Thanks for your comment. It will affect the encodings module's refcount in C level and reduce the refleaks.

This statement should be placed at below so that it does not affect the performance of the cache.

MAYBE removing this line and using aliases.aliases to replace _aliases is fine too :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking this comment: #21896 (comment)

Copy link

@ghost ghost Aug 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking this comment: #21896 (comment)

The usage of aliases.aliasesis is very normal, maybe the root of the problem is not here.

# Cache lookup
entry = _cache.get(encoding, _unknown)
if entry is not _unknown:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix refleaks of `encodings.aliases` by Moving `encodings._aliases` to
:func:`encodings.search_function`.