diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-12-21 16:49:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-21 16:49:13 +0100 |
commit | 9bee329130aae5a13050c08dab9d349b76e66835 (patch) | |
tree | 828e5eba0807b15d60bb7f5162685d0dc993fc42 /Python/fileutils.c | |
parent | bpo-32030: Add _Py_EncodeLocaleRaw() (#4961) (diff) | |
download | cpython-9bee329130aae5a13050c08dab9d349b76e66835.tar.gz cpython-9bee329130aae5a13050c08dab9d349b76e66835.tar.bz2 cpython-9bee329130aae5a13050c08dab9d349b76e66835.zip |
bpo-32030: Add _Py_FindEnvConfigValue() (#4963)
Add a new _Py_FindEnvConfigValue() function: code shared between
Windows and Unix implementations of _PyPathConfig_Calculate() to read
the pyenv.cfg file.
_Py_FindEnvConfigValue() now uses _Py_DecodeUTF8_surrogateescape()
instead of using a Python Unicode string, the Python API must not be
used early during Python initialization. Same change in Unix
search_for_exec_prefix(): use _Py_DecodeUTF8_surrogateescape().
Cleanup also encode_current_locale(): PyMem_RawFree/PyMem_Free can be
called with NULL.
Fix also "NUL byte" => "NULL byte" typo.
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r-- | Python/fileutils.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index 1ccd4baa6d2..645a1793664 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -20,8 +20,6 @@ extern int winerror_to_errno(int); #include <fcntl.h> #endif /* HAVE_FCNTL_H */ -extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size, - size_t *p_wlen); extern char* _Py_EncodeUTF8_surrogateescape(const wchar_t *text, size_t *error_pos, int raw_malloc); @@ -194,7 +192,7 @@ encode_ascii_surrogateescape(const wchar_t *text, size_t *error_pos, int raw_mal len = wcslen(text); - /* +1 for NUL byte */ + /* +1 for NULL byte */ if (raw_malloc) { result = PyMem_RawMalloc(len + 1); } @@ -467,13 +465,11 @@ encode_current_locale(const wchar_t *text, size_t *error_pos, int raw_malloc) else converted = wcstombs(NULL, buf, 0); if (converted == (size_t)-1) { - if (result != NULL) { - if (raw_malloc) { - PyMem_RawFree(result); - } - else { - PyMem_Free(result); - } + if (raw_malloc) { + PyMem_RawFree(result); + } + else { + PyMem_Free(result); } if (error_pos != NULL) *error_pos = i; |