Repository navigation
gh-155247: Use raw string content for the extensions cache key - #155249
serhiy-storchaka merged 5 commits into
Conversation
The key of the extensions cache was built with _PyUnicode_AsUTF8NoNUL(), so importing an extension module failed with UnicodeEncodeError if its path contained characters unencodable in UTF-8, e.g. surrogate escapes of an undecodable file name. The raw content of the strings is now used. The rejection of embedded null characters, which was a side effect of the UTF-8 encoding, is now explicit in the extension module loader. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A loaded extension module cannot be removed on Windows, so the temporary directory is now removed with ignore_errors. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The key is hashed and compared as raw bytes, so the uninitialized padding of the header made lookups miss at random. Import the extension module in a subprocess: it stays loaded, and on Windows its file cannot be removed, so the temporary directory leaked.
|
This PR is stale because it has been open for 90 days with no activity. |
…ensions-cache-key # Conflicts: # Lib/test/test_import/__init__.py # Python/importdl.c
|
@ericsnowcurrently, could you please review this? It changes the key of the extensions cache, which you added in gh-105699, so that extension modules can be imported from a path which is not encodable in UTF-8. I have just resolved conflicts with main. |
ericsnowcurrently
left a comment
There was a problem hiding this comment.
LGTM
Thanks for taking care of this.
|
Thank you for your review. |
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
GH-162686 is a backport of this pull request to the 3.15 branch. |
|
GH-162687 is a backport of this pull request to the 3.14 branch. |
…GH-155249) (GH-162686) The key of the extensions cache was built with _PyUnicode_AsUTF8NoNUL(), so importing an extension module failed with UnicodeEncodeError if its path contained characters unencodable in UTF-8, e.g. surrogate escapes of an undecodable file name. The raw content of the strings is now used. The rejection of embedded null characters, which was a side effect of the UTF-8 encoding, is now explicit in the extension module loader. (cherry picked from commit 6a18ae4) Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
…GH-155249) (GH-162687) The key of the extensions cache was built with _PyUnicode_AsUTF8NoNUL(), so importing an extension module failed with UnicodeEncodeError if its path contained characters unencodable in UTF-8, e.g. surrogate escapes of an undecodable file name. The raw content of the strings is now used. The rejection of embedded null characters, which was a side effect of the UTF-8 encoding, is now explicit in the extension module loader. (cherry picked from commit 6a18ae4) Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Importing an extension module failed with
UnicodeEncodeErrorif its path contained characters unencodable in UTF-8, e.g. surrogate escapes of a file name undecodable in the filesystem encoding. As a result, Python could not be built or run in a directory with such name.The key of the extensions cache was built with
_PyUnicode_AsUTF8NoNUL(). The raw content of the strings (UCS1, UCS2 or UCS4) is now used instead.The rejection of embedded null characters, which was a side effect of the UTF-8 encoding, is now explicit in the extension module loader.