summaryrefslogtreecommitdiffstats
path: root/Python/fileutils.c
Commit message (Collapse)AuthorAgeFilesLines
* Spelling fixes to docs, docstrings, and comments (GH-6374)Ville Skyttä2018-04-201-1/+1
|
* bpo-32869: Fix incorrect dst buffer size for MultiByteToWideChar (#5739)Alexey Izbyshev2018-02-181-1/+2
| | | | This function expects the destination buffer size to be given in wide characters, not bytes.
* bpo-32777: Fix _Py_set_inheritable async-safety in subprocess (GH-5560)Alexey Izbyshev2018-02-061-3/+16
| | | | | | | Fix a rare but potential pre-exec child process deadlock in subprocess on POSIX systems when marking file descriptors inheritable on exec in the child process. This bug appears to have been introduced in 3.4 with the inheritable file descriptors support. This also changes Python/fileutils.c `set_inheritable` to use the "slow" two `fcntl` syscall path instead of the "fast" single `ioctl` syscall path when asked to be async signal safe (by way of being asked not to raise exceptions). `ioctl` is not a POSIX async-signal-safe approved function. ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html
* bpo-29240: PyUnicode_DecodeLocale() uses UTF-8 on Android (#5272)Victor Stinner2018-01-221-0/+10
| | | | | | | | PyUnicode_DecodeLocaleAndSize(), PyUnicode_DecodeLocale() and PyUnicode_EncodeLocale() now use always use the UTF-8 encoding on Android, instead of the current locale encoding. On Android API 19, mbstowcs() and wcstombs() are broken and cannot be used.
* bpo-31900: Fix localeconv() encoding for LC_NUMERIC (#4174)Victor Stinner2018-01-151-0/+77
| | | | | | | | * Add _Py_GetLocaleconvNumeric() function: decode decimal_point and thousands_sep fields of localeconv() from the LC_NUMERIC encoding, rather than decoding from the LC_CTYPE encoding. * Modify locale.localeconv() and "n" formatter of str.format() (for int, float and complex to use _Py_GetLocaleconvNumeric() internally.
* bpo-29240: Fix locale encodings in UTF-8 Mode (#5170)Victor Stinner2018-01-151-139/+246
| | | | | | | | | | | | | | | | | | | | | | | | | | | Modify locale.localeconv(), time.tzname, os.strerror() and other functions to ignore the UTF-8 Mode: always use the current locale encoding. Changes: * Add _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx(). On decoding or encoding error, they return the position of the error and an error message which are used to raise Unicode errors in PyUnicode_DecodeLocale() and PyUnicode_EncodeLocale(). * Replace _Py_DecodeCurrentLocale() with _Py_DecodeLocaleEx(). * PyUnicode_DecodeLocale() now uses _Py_DecodeLocaleEx() for all cases, especially for the strict error handler. * Add _Py_DecodeUTF8Ex(): return more information on decoding error and supports the strict error handler. * Rename _Py_EncodeUTF8_surrogateescape() to _Py_EncodeUTF8Ex(). * Replace _Py_EncodeCurrentLocale() with _Py_EncodeLocaleEx(). * Ignore the UTF-8 mode to encode/decode localeconv(), strerror() and time zone name. * Remove PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize() and PyUnicode_EncodeLocale() now ignore the UTF-8 mode: always use the "current" locale. * Remove _PyUnicode_DecodeCurrentLocale(), _PyUnicode_DecodeCurrentLocaleAndSize() and _PyUnicode_EncodeCurrentLocale().
* bpo-29240: readline now ignores the UTF-8 Mode (#5145)Victor Stinner2018-01-101-28/+52
| | | | | | | | | | | | Add new fuctions ignoring the UTF-8 mode: * _Py_DecodeCurrentLocale() * _Py_EncodeCurrentLocale() * _PyUnicode_DecodeCurrentLocaleAndSize() * _PyUnicode_EncodeCurrentLocale() Modify the readline module to use these functions. Re-enable test_readline.test_nonascii().
* bpo-32030: Add _Py_FindEnvConfigValue() (#4963)Victor Stinner2017-12-211-10/+6
| | | | | | | | | | | | | | | 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.
* bpo-32030: Add _Py_EncodeLocaleRaw() (#4961)Victor Stinner2017-12-211-32/+72
| | | | | | | | | | | | 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.
* bpo-32030: Add _Py_EncodeUTF8_surrogateescape() (#4960)Victor Stinner2017-12-211-38/+4
| | | | | Py_EncodeLocale() now uses _Py_EncodeUTF8_surrogateescape(), instead of using temporary unicode and bytes objects. So Py_EncodeLocale() doesn't use the Python C API anymore.
* bpo-29240, bpo-32030: Py_Main() re-reads config if encoding changes (#4899)Victor Stinner2017-12-161-2/+2
| | | | | | | | | | | | | | | | | | bpo-29240, bpo-32030: If the encoding change (C locale coerced or UTF-8 Mode changed), Py_Main() now reads again the configuration with the new encoding. Changes: * Add _Py_UnixMain() called by main(). * Rename pymain_free_pymain() to pymain_clear_pymain(), it can now be called multipled times. * Rename pymain_parse_cmdline_envvars() to pymain_read_conf(). * Py_Main() now clears orig_argc and orig_argv at exit. * Remove argv_copy2, Py_Main() doesn't modify argv anymore. There is no need anymore to get two copies of the wchar_t** argv. * _PyCoreConfig: add coerce_c_locale and coerce_c_locale_warn. * Py_UTF8Mode is now initialized to -1. * Locale coercion (PEP 538) now respects -I and -E options.
* bpo-29240: Don't define decode_locale() on macOS (#4895)Victor Stinner2017-12-151-0/+4
| | | Don't define decode_locale() nor encode_locale() on macOS or Android.
* bpo-29240: PEP 540: Add a new UTF-8 Mode (#855)Victor Stinner2017-12-131-74/+100
| | | | | | | | | | | | | | | | | | | | | | * Add -X utf8 command line option, PYTHONUTF8 environment variable and a new sys.flags.utf8_mode flag. * If the LC_CTYPE locale is "C" at startup: enable automatically the UTF-8 mode. * Add _winapi.GetACP(). encodings._alias_mbcs() now calls _winapi.GetACP() to get the ANSI code page * locale.getpreferredencoding() now returns 'UTF-8' in the UTF-8 mode. As a side effect, open() now uses the UTF-8 encoding by default in this mode. * Py_DecodeLocale() and Py_EncodeLocale() now use the UTF-8 encoding in the UTF-8 Mode. * Update subprocess._args_from_interpreter_flags() to handle -X utf8 * Skip some tests relying on the current locale if the UTF-8 mode is enabled. * Add test_utf8mode.py. * _Py_DecodeUTF8_surrogateescape() gets a new optional parameter to return also the length (number of wide characters). * pymain_get_global_config() and pymain_set_global_config() now always copy flag values, rather than only copying if the new value is greater than the old value.
* Replace KB unit with KiB (#4293)Victor Stinner2017-11-081-4/+4
| | | | | | | | | | | kB (*kilo* byte) unit means 1000 bytes, whereas KiB ("kibibyte") means 1024 bytes. KB was misused: replace kB or KB with KiB when appropriate. Same change for MB and GB which become MiB and GiB. Change the output of Tools/iobench/iobench.py. Round also the size of the documentation from 5.5 MB to 5 MiB.
* bpo-31370: Remove support for threads-less builds (#3385)Antoine Pitrou2017-09-071-14/+0
| | | | | | * Remove Setup.config * Always define WITH_THREAD for compatibility.
* [security] bpo-13617: Reject embedded null characters in wchar* strings. (#2302)Serhiy Storchaka2017-06-281-6/+17
| | | | | | | Based on patch by Victor Stinner. Add private C API function _PyUnicode_AsUnicode() which is similar to PyUnicode_AsUnicode(), but checks for null characters.
* bpo-29619: Convert st_ino using unsigned integer (#557)Victor Stinner2017-03-091-2/+2
| | | | bpo-29619: os.stat() and os.DirEntry.inodeo() now convert inode (st_ino) using unsigned integers.
* Issue #26919: On Android, operating system data is now always encoded/decodedXavier de Gaye2016-12-151-5/+5
| | | | | to/from UTF-8, instead of the locale encoding to avoid inconsistencies with os.fsencode() and os.fsdecode() which are already using UTF-8.
* Issue #28746: Fix the set_inheritable() file descriptor method on platformsXavier de Gaye2016-11-191-1/+1
| | | | that do not have the ioctl FIOCLEX and FIONCLEX commands
* Fix check_force_ascii()Victor Stinner2016-09-101-8/+9
| | | | | Issue #27938: Normalize aliases of the ASCII encoding, because _Py_normalize_encoding() now correctly normalize encoding names.
* Issue #23524: Finish removing _PyVerify_fd from sourcesSteve Dower2016-09-081-124/+4
|
* Issue #27076: Merge spelling from 3.5Martin Panter2016-05-261-1/+1
|\
| * Issue #27076: Doc, comment and tests spelling fixesMartin Panter2016-05-261-1/+1
| | | | | | | | Most fixes to Doc/ and Lib/ directories by Ville Skyttä.
* | Merge 3.5 (issue #27057)Victor Stinner2016-05-191-2/+7
|\ \ | |/
| * Fix os.set_inheritable() on AndroidVictor Stinner2016-05-191-2/+7
| | | | | | | | | | | | | | Issue #27057: Fix os.set_inheritable() on Android, ioctl() is blocked by SELinux and fails with EACCESS. The function now falls back to fcntl(). Patch written by Michał Bednarski.
* | Avoid fcntl() if possible in set_inheritable()Victor Stinner2016-04-171-5/+13
| | | | | | | | | | | | Issue #26770: set_inheritable() avoids calling fcntl() twice if the FD_CLOEXEC is already set/cleared. This change only impacts platforms using the fcntl() implementation of set_inheritable() (not Linux nor Windows).
* | Add more checks on the GILVictor Stinner2016-03-141-0/+16
|/ | | | | | | | | | | | Issue #10915, #15751, #26558: * PyGILState_Check() now returns 1 (success) before the creation of the GIL and after the destruction of the GIL. It allows to use the function early in Python initialization and late in Python finalization. * Add a flag to disable PyGILState_Check(). Disable PyGILState_Check() when Py_NewInterpreter() is called * Add assert(PyGILState_Check()) to: _Py_dup(), _Py_fstat(), _Py_read() and _Py_write()
* Fix a couple of typos in code commentsMartin Panter2015-12-171-2/+2
|
* Close #24784: Fix compilation without thread supportVictor Stinner2015-10-111-0/+6
| | | | | | | | Add "#ifdef WITH_THREAD" around cals to: * PyGILState_Check() * _PyImport_AcquireLock() * _PyImport_ReleaseLock()
* Issue #23524: Replace _PyVerify_fd function with calls to ↵Steve Dower2015-04-121-39/+56
| | | | _set_thread_local_invalid_parameter_handler.
* Issue #23836: Document functions releasing the GIL in fileutils.cVictor Stinner2015-04-011-3/+5
|
* Issue #23836: Add _Py_write_noraise() functionVictor Stinner2015-04-011-48/+83
| | | | | Helper to write() which retries write() if it is interrupted by a signal (fails with EINTR).
* Issue #23752: _Py_fstat() is now responsible to raise the Python exceptionVictor Stinner2015-03-301-11/+47
| | | | Add _Py_fstat_noraise() function when a Python exception is not welcome.
* Issue #23753: Move _Py_wstat() from Python/fileutils.c to Modules/getpath.cVictor Stinner2015-03-241-17/+0
| | | | | | | I expected more users of _Py_wstat(), but in practice it's only used by Modules/getpath.c. Move the function because it's not needed on Windows. Windows uses PC/getpathp.c which uses the Win32 API (ex: GetFileAttributesW()) not the POSIX API.
* Issue #23753: Python doesn't support anymore platforms without stat() orVictor Stinner2015-03-241-16/+0
| | | | | | | fstat(), these functions are always required. Remove HAVE_STAT and HAVE_FSTAT defines, and stop supporting DONT_HAVE_STAT and DONT_HAVE_FSTAT.
* Issue #23708: Save/restore errno in _Py_read() and _Py_write()Victor Stinner2015-03-201-15/+21
| | | | | Save and then restore errno because PyErr_CheckSignals() and PyErr_SetFromErrno() can modify it.
* Issue #23708: Split assertion expression in two assertions in _Py_read() andVictor Stinner2015-03-201-2/+4
| | | | _Py_write() to know which test failed on the buildbot "AMD64 Snow Leop 3.x".
* Issue #23708: Fix _Py_read() compilation error on WindowsVictor Stinner2015-03-191-1/+1
| | | | Fix typo: self->fd => fd
* Issue #23708: Add _Py_read() and _Py_write() functions to factorize code handleVictor Stinner2015-03-191-0/+149
| | | | | | | | EINTR error and special cases for Windows. These functions now truncate the length to PY_SSIZE_T_MAX to have a portable and reliable behaviour. For example, read() result is undefined if counter is greater than PY_SSIZE_T_MAX on Linux.
* Issue #23694: Handle EINTR in _Py_open() and _Py_fopen_obj()Victor Stinner2015-03-181-13/+40
| | | | | Retry open()/fopen() if it fails with EINTR and the Python signal handler doesn't raise an exception.
* Issue #23694: Enhance _Py_fopen(), it now raises an exception on errorVictor Stinner2015-03-181-12/+36
| | | | | * If fopen() fails, OSError is raised with the original filename object. * The GIL is now released while calling fopen()
* Issue #23694: Enhance _Py_open(), it now raises exceptionsVictor Stinner2015-03-171-17/+55
| | | | | | | | * _Py_open() now raises exceptions on error. If open() fails, it raises an OSError with the filename. * _Py_open() now releases the GIL while calling open() * Add _Py_open_noraise() when _Py_open() cannot be used because the GIL is not held
* Fixes incorrect use of GetLastError where errno should be used.Steve Dower2015-03-141-6/+6
|\
| * Fixes incorrect use of GetLastError where errno should be used.Steve Dower2015-03-141-6/+6
| |
* | Issue #23524: Change back to using Windows errors for _Py_fstat instead of ↵Steve Dower2015-03-081-3/+5
| | | | | | | | the errno shim.
* | Issue #23524: Replace _PyVerify_fd function with calling ↵Steve Dower2015-03-061-5/+103
| | | | | | | | _set_thread_local_invalid_parameter_handler on every thread.
* | Issue #23152: Renames time_t_to_FILE_TIME to _Py_time_t_to_FILE_TIME, ↵Steve Dower2015-02-211-4/+2
| | | | | | | | removes unused struct win32_stat and return value
* | Issue #23152: Renames attribute_data_to_stat to _Py_attribute_data_to_statSteve Dower2015-02-211-2/+2
| |
* | Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on ↵Steve Dower2015-02-211-2/+140
| | | | | | | | | | | | Windows. fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer.
* | merge 3.4 (#23165)Benjamin Peterson2015-01-041-3/+13
|\ \ | |/