Commit Graph

127 Commits

Author SHA1 Message Date
Victor Stinner a858bbde03 Avoid fcntl() if possible in set_inheritable()
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).
2016-04-17 16:51:52 +02:00
Victor Stinner 8a1be61849 Add more checks on the GIL
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()
2016-03-14 22:07:55 +01:00
Martin Panter 6f9b010242 Fix a couple of typos in code comments 2015-12-17 10:18:28 +00:00
Victor Stinner bc5b80bac1 Close #24784: Fix compilation without thread support
Add "#ifdef WITH_THREAD" around cals to:

* PyGILState_Check()
* _PyImport_AcquireLock()
* _PyImport_ReleaseLock()
2015-10-11 09:54:42 +02:00
Steve Dower 8fc8980c96 Issue #23524: Replace _PyVerify_fd function with calls to _set_thread_local_invalid_parameter_handler. 2015-04-12 00:26:27 -04:00
Victor Stinner 6f4fae8a95 Issue #23836: Document functions releasing the GIL in fileutils.c 2015-04-01 18:34:32 +02:00
Victor Stinner 82c3e4599d Issue #23836: Add _Py_write_noraise() function
Helper to write() which retries write() if it is interrupted by a signal (fails
with EINTR).
2015-04-01 18:34:45 +02:00
Victor Stinner e134a7fe36 Issue #23752: _Py_fstat() is now responsible to raise the Python exception
Add _Py_fstat_noraise() function when a Python exception is not welcome.
2015-03-30 10:09:31 +02:00
Victor Stinner 91afbb6088 Issue #23753: Move _Py_wstat() from Python/fileutils.c to Modules/getpath.c
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.
2015-03-24 12:16:28 +01:00
Victor Stinner f329878e74 Issue #23753: Python doesn't support anymore platforms without stat() or
fstat(), these functions are always required.

Remove HAVE_STAT and HAVE_FSTAT defines, and stop supporting DONT_HAVE_STAT and
DONT_HAVE_FSTAT.
2015-03-24 10:27:50 +01:00
Victor Stinner a3c0202eb5 Issue #23708: Save/restore errno in _Py_read() and _Py_write()
Save and then restore errno because PyErr_CheckSignals() and
PyErr_SetFromErrno() can modify it.
2015-03-20 11:58:18 +01:00
Victor Stinner 7f04d4d4b7 Issue #23708: Split assertion expression in two assertions in _Py_read() and
_Py_write() to know which test failed on the buildbot "AMD64 Snow Leop 3.x".
2015-03-20 11:21:41 +01:00
Victor Stinner c1cf4f7ef9 Issue #23708: Fix _Py_read() compilation error on Windows
Fix typo: self->fd => fd
2015-03-19 23:53:04 +01:00
Victor Stinner 66aab0c4b5 Issue #23708: Add _Py_read() and _Py_write() functions to factorize code handle
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.
2015-03-19 22:53:20 +01:00
Victor Stinner a47fc5c2dd Issue #23694: Handle EINTR in _Py_open() and _Py_fopen_obj()
Retry open()/fopen() if it fails with EINTR and the Python signal handler
doesn't raise an exception.
2015-03-18 09:52:54 +01:00
Victor Stinner e42ccd2bfd Issue #23694: Enhance _Py_fopen(), it now raises an exception on error
* If fopen() fails, OSError is raised with the original filename object.
* The GIL is now released while calling fopen()
2015-03-18 01:39:23 +01:00
Victor Stinner a555cfcb73 Issue #23694: Enhance _Py_open(), it now raises exceptions
* _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
2015-03-18 00:22:14 +01:00
Steve Dower 9aa31d5479 Fixes incorrect use of GetLastError where errno should be used. 2015-03-14 11:39:18 -07:00
Steve Dower 41e7244c06 Fixes incorrect use of GetLastError where errno should be used. 2015-03-14 11:38:27 -07:00
Steve Dower 8acde7dcce Issue #23524: Change back to using Windows errors for _Py_fstat instead of the errno shim. 2015-03-07 18:14:07 -08:00
Steve Dower d81431f587 Issue #23524: Replace _PyVerify_fd function with calling _set_thread_local_invalid_parameter_handler on every thread. 2015-03-06 14:47:02 -08:00
Steve Dower bf1f376b3e Issue #23152: Renames time_t_to_FILE_TIME to _Py_time_t_to_FILE_TIME, removes unused struct win32_stat and return value 2015-02-21 15:26:02 -08:00
Steve Dower a2af1a5a5a Issue #23152: Renames attribute_data_to_stat to _Py_attribute_data_to_stat 2015-02-21 10:04:10 -08:00
Steve Dower f2f373f593 Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on Windows.
fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer.
2015-02-21 08:44:05 -08:00
Benjamin Peterson f8693416b5 merge 3.4 (#23165) 2015-01-04 16:06:14 -06:00
Benjamin Peterson 10ecaa2416 merge 3.3 (closes #23165) 2015-01-04 16:05:39 -06:00
Benjamin Peterson 72c2a0f60a merge 3.2 (closes #23165) 2015-01-04 16:03:59 -06:00
Benjamin Peterson f18bf6fd2d add some overflow checks before multiplying (closes #23165) 2015-01-04 16:03:17 -06:00
Victor Stinner 282124b8c4 Closes #22258: Fix the the internal function set_inheritable() on Illumos.
This platform exposes the function ioctl(FIOCLEX), but calling it fails with
errno is ENOTTY: "Inappropriate ioctl for device". set_inheritable() now falls
back to the slower fcntl() (F_GETFD and then F_SETFD).
2014-09-02 11:41:04 +02:00
Victor Stinner 8257b6283e (Merge 3.4) Closes #22258: Fix the the internal function set_inheritable() on
Illumos.  This platform exposes the function ioctl(FIOCLEX), but calling it
fails with errno is ENOTTY: "Inappropriate ioctl for device". set_inheritable()
now falls back to the slower fcntl() (F_GETFD and then F_SETFD).
2014-09-02 11:49:48 +02:00
Victor Stinner f6a271ae98 Issue #18395: Rename ``_Py_char2wchar()`` to :c:func:`Py_DecodeLocale`, rename
``_Py_wchar2char()`` to :c:func:`Py_EncodeLocale`, and document these
functions.
2014-08-01 12:28:48 +02:00
Victor Stinner 1db9e7bb19 Issue #22054: Add os.get_blocking() and os.set_blocking() functions to get and
set the blocking mode of a file descriptor (False if the O_NONBLOCK flag is
set, True otherwise). These functions are not available on Windows.
2014-07-29 22:32:47 +02:00
Stefan Krah 34e4628453 Merge from 3.3. 2014-01-20 15:35:38 +01:00
Stefan Krah 6c01e38677 Issue #19036: Including locale.h should not depend on HAVE_LANGINFO_H. 2014-01-20 15:31:08 +01:00
Victor Stinner b11d6cb711 fileutils.c: use MAXPATHLEN instead of PATH_MAX
PATH_MAX is not declared on IRIX nor Windows.
2013-11-15 18:14:11 +01:00
Victor Stinner c31ebb60f9 (Merge 3.3) fileutils.c: use MAXPATHLEN instead of PATH_MAX
PATH_MAX is not declared on IRIX nor Windows.
2013-11-15 18:14:33 +01:00
Stefan Krah 49d0479357 Add unused third arg for the benefit of Valgrind. 2013-11-14 15:35:47 +01:00
Antoine Pitrou 409b53840b Don't export internal symbols ("make smelly") 2013-10-12 22:41:17 +02:00
Victor Stinner b034eee711 Close #18954: Fix some typo in fileutils.c comments
Patch written by Vajrasky Kok.
2013-09-07 10:36:04 +02:00
Victor Stinner daf455554b Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(),
os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
2013-08-28 00:53:59 +02:00
Victor Stinner 65bf9cf26f Issue #18203: Fix decode_ascii_surrogateescape(), use PyMem_RawMalloc() as _Py_char2wchar() 2013-07-07 16:35:54 +02:00
Victor Stinner 1a7425f67a Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
* Replace malloc() with PyMem_RawMalloc()
* Replace PyMem_Malloc() with PyMem_RawMalloc() where the GIL is not held.
* _Py_char2wchar() now returns a buffer allocated by PyMem_RawMalloc(), instead
  of PyMem_Malloc()
2013-07-07 16:25:15 +02:00
Victor Stinner 14b9b11098 If MS_WIN64 is defined, MS_WINDOWS is also defined: #ifdef can be simplified. 2013-06-25 00:37:25 +02:00
Victor Stinner 56785eab33 Issue #9566: Fix compiler warning on Windows 64-bit 2013-06-05 00:46:29 +02:00
Victor Stinner 313f10c722 Fix a compiler warning: in and out are unused in _Py_char2wchar() if
HAVE_MBRTOWC is not defined
2013-05-07 23:48:56 +02:00
Philip Jenvey 215c49a509 thinko 2013-01-15 13:24:12 -08:00
Victor Stinner 7ae320d667 (Merge 3.2) Issue #16455: On FreeBSD and Solaris, if the locale is C, the
ASCII/surrogateescape codec is now used, instead of the locale encoding, to
decode the command line arguments. This change fixes inconsistencies with
os.fsencode() and os.fsdecode() because these operating systems announces an
ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice.
2013-01-03 01:21:07 +01:00
Victor Stinner 20b654acb5 Issue #16455: On FreeBSD and Solaris, if the locale is C, the
ASCII/surrogateescape codec is now used, instead of the locale encoding, to
decode the command line arguments. This change fixes inconsistencies with
os.fsencode() and os.fsdecode() because these operating systems announces an
ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice.
2013-01-03 01:08:58 +01:00
Victor Stinner d45c7f8d74 Issue #16455: On FreeBSD and Solaris, if the locale is C, the
ASCII/surrogateescape codec is now used, instead of the locale encoding, to
decode the command line arguments. This change fixes inconsistencies with
os.fsencode() and os.fsdecode() because these operating systems announces an
ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice.
2012-12-04 01:34:47 +01:00
Victor Stinner 41a234a679 Issue #16416: Fix compilation error 2012-12-03 14:11:57 +01:00
Victor Stinner 2660e427d1 (Merge 3.2) Issue #16416: On Mac OS X, operating system data are now always
encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding
(which may be ASCII if no locale environment variable is set), to avoid
inconsistencies with os.fsencode() and os.fsdecode() functions which are
already using UTF-8/surrogateescape.
2012-12-03 12:48:53 +01:00
Victor Stinner 27b1ca29cc Issue #16416: On Mac OS X, operating system data are now always
encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding
(which may be ASCII if no locale environment variable is set), to avoid
inconsistencies with os.fsencode() and os.fsdecode() functions which are
already using UTF-8/surrogateescape.
2012-12-03 12:47:59 +01:00
Victor Stinner 0d92c4f667 Issue #16416: Fix error handling in _Py_wchar2char() _Py_char2wchar() functions 2012-11-12 23:32:21 +01:00
Victor Stinner e262377cab Issue #16416: OS data are now always encoded/decoded to/from
UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no
locale environment variable is set), to avoid inconsistencies with
os.fsencode() and os.fsdecode() functions which are already using
UTF-8/surrogateescape.
2012-11-12 23:04:02 +01:00
Stefan Krah abaca8cb06 Merge 3.3. 2012-11-12 20:24:09 +01:00
Stefan Krah 6df5cae49a Issue #15835: Define PATH_MAX on HP-UX. 2012-11-12 20:14:36 +01:00
Victor Stinner 76df43de30 Issue #16330: Use surrogate-related macros
Patch written by Serhiy Storchaka.
2012-10-30 01:42:39 +01:00
Brett Cannon efb00c0cc1 Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
the os module.
2012-02-29 18:31:31 -05:00
Antoine Pitrou 0e576f1f50 Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
SSLContext.load_dh_params() method and the ssl.OP_SINGLE_DH_USE option.
2011-12-22 10:03:38 +01:00
Antoine Pitrou 2b1cc89572 _Py_fopen now allows bytes filenames under non-Windows platforms. 2011-12-19 18:19:06 +01:00
Victor Stinner bd0850b857 import.c now catchs _Py_stat() exceptions
_Py_stat() now returns -2 if an exception was raised.
2011-12-18 20:47:30 +01:00
Victor Stinner af02e1c85a Add PyUnicode_DecodeLocaleAndSize() and PyUnicode_DecodeLocale()
* PyUnicode_DecodeLocaleAndSize() and PyUnicode_DecodeLocale() decode a string
   from the current locale encoding
 * _Py_char2wchar() writes an "error code" in the size argument to indicate
   if the function failed because of memory allocation failure or because of a
   decoding error. The function doesn't write the error message directly to
   stderr.
 * Fix time.strftime() (if wcsftime() is missing): decode strftime() result
   from the current locale encoding, not from the filesystem encoding.
2011-12-16 23:56:01 +01:00
Victor Stinner ee587eaa36 Catch PyUnicode_AS_UNICODE() errors in fileutils.c 2011-11-17 00:51:38 +01:00
Victor Stinner 19de4c3a8c _Py_char2wchar() frees the memory on conversion error
Explain in the documentation that conversion errors should never happen.
2010-11-08 23:30:46 +00:00
Victor Stinner 2f02a51135 PyUnicode_EncodeFS() raises an exception if _Py_wchar2char() fails
* Add error_pos optional argument to _Py_wchar2char()
 * PyUnicode_EncodeFS() raises a UnicodeEncodeError or MemoryError if
   _Py_wchar2char() fails
2010-11-08 22:43:46 +00:00
Victor Stinner 168e117e0a Add an optional size argument to _Py_char2wchar()
_Py_char2wchar() callers usually need the result size in characters. Since it's
trivial to compute it in _Py_char2wchar() (O(1) whereas wcslen() is O(n)), add
an option to get it.
2010-10-16 23:16:16 +00:00
Victor Stinner 0a1b8cba90 _Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
2010-10-16 22:55:47 +00:00
Victor Stinner 350147b5ca _Py_wreadlink(): catch _Py_char2wchar() failure 2010-10-16 22:52:09 +00:00
Victor Stinner 3f711f4a3e _Py_wreadlink() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
2010-10-16 22:47:37 +00:00
Victor Stinner 5d1e3438cd Mark _Py_char2wchar() input argument as constant 2010-10-15 11:15:54 +00:00
Victor Stinner f4061dac60 _Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates 2010-10-14 12:37:19 +00:00
Victor Stinner 6672d0c5bb fileutils.c: document which encodings are used 2010-10-07 22:53:43 +00:00
Victor Stinner 015f4d87ab _Py_wrealpath() requires the size of the output buffer 2010-10-07 22:29:53 +00:00
Victor Stinner a4a759515e _Py_stat() and _Py_fopen(): avoid PyUnicode_AsWideCharString() on Windows
On Windows, Py_UNICODE is wchar_t, so we can avoid the expensive Py_UNICODE*
=> wchar_t* conversion.
2010-10-07 22:23:10 +00:00
Victor Stinner b306d7594f Fix fileutils for Windows
* Don't define _Py_wstat() on Windows, Windows has its own _wstat() function
   with a different API (the stat buffer has another type)
 * Include windows.h
2010-10-07 22:09:40 +00:00
Victor Stinner e7c8083bf1 Ooops, fileutils.c contains twice the same code
I suppose that I reapplied my local patch creating Python/fileutils.c whereas
the file already existed.
2010-10-07 21:55:44 +00:00
Victor Stinner 4e31443c4d Create fileutils.c/.h
* _Py_fopen() and _Py_stat() come from Python/import.c
 * (_Py)_wrealpath() comes from Python/sysmodule.c
 * _Py_char2wchar(), _Py_wchar2char() and _Py_wfopen() come from Modules/main.c
 * (_Py)_wstat(), (_Py)_wgetcwd(), _Py_wreadlink() come from Modules/getpath.c
2010-10-07 21:45:39 +00:00