bpo-32030: Add _Py_EncodeLocaleRaw() by vstinner · Pull Request #4961 · python/cpython
Conversation
Replace Py_EncodeLocale() with _Py_EncodeLocaleRaw() in:
- _Py_wfopen()
- _Py_wreadlink()
- _Py_wrealpath()
- _Py_wstat()
- pymain_open_filename()
These functions are called early during Python intialization, only
the RAW memory allocator must be used.
Replace Py_EncodeLocale() with _Py_EncodeLocaleRaw() in: * _Py_wfopen() * _Py_wreadlink() * _Py_wrealpath() * _Py_wstat() * pymain_open_filename() These functions are called early during Python intialization, only the RAW memory allocator must be used.
| len = wcslen(text); | ||
|
|
||
| result = PyMem_Malloc(len + 1); /* +1 for NUL byte */ | ||
| /* +1 for NUL byte */ |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to your change but should it be "NULL byte" ?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I only saw your review after I merged my PR. Anyway, I fixed this typo in my following PR: PR #4963.
| if (converted == (size_t)-1) { | ||
| if (result != NULL) | ||
| PyMem_Free(result); | ||
| if (result != NULL) { |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, not quite related to your change but if PyMem_RawFree and PyMem_Free behave like free, it should be valid to pass a NULL argument and the test is not needed.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, fixed in PR #4963.