summaryrefslogtreecommitdiffstats
path: root/Modules
Commit message (Collapse)AuthorAgeFilesLines
* bpo-42208: Add _Py_GetLocaleEncoding() (GH-23050)Victor Stinner2020-10-313-48/+4
| | | | | | | | _io.TextIOWrapper no longer calls getpreferredencoding(False) of _bootlocale to get the locale encoding, but calls _Py_GetLocaleEncoding() instead. Add config_get_fs_encoding() sub-function. Reorganize also config_get_locale_encoding() code.
* bpo-42208: Call GC collect earlier in PyInterpreterState_Clear() (GH-23044)Victor Stinner2020-10-301-4/+6
| | | | | | | | The last GC collection is now done before clearing builtins and sys dictionaries. Add also assertions to ensure that gc.collect() is no longer called after _PyGC_Fini(). Pass also the tstate to PyInterpreterState_Clear() to pass the correct tstate to _PyGC_CollectNoFail() and _PyGC_Fini().
* bpo-42208: Pass tstate to _PyGC_CollectNoFail() (GH-23038)Victor Stinner2020-10-301-25/+18
| | | | | | | | | | | | Move private _PyGC_CollectNoFail() to the internal C API. Remove the private _PyGC_CollectIfEnabled() which was just an alias to the public PyGC_Collect() function since Python 3.8. Rename functions: * collect() => gc_collect_main() * collect_with_callback() => gc_collect_with_callback() * collect_generations() => gc_collect_generations()
* bpo-42029: Remove IRIX code (GH-23023)Victor Stinner2020-10-292-9/+5
| | | | IRIX code was slowy removed in Python 2.4 (--with-sgi-dl), Python 3.3 (Irix threads), and Python 3.7.
* bpo-42161: Micro-optimize _collections._count_elements() (GH-23008)Victor Stinner2020-10-271-4/+5
| | | Move the _PyLong_GetOne() call outside the fast-path loop.
* bpo-42161: Modules/ uses _PyLong_GetZero() and _PyLong_GetOne() (GH-22998)Victor Stinner2020-10-2713-35/+53
| | | | | | Use _PyLong_GetZero() and _PyLong_GetOne() in Modules/ directory. _cursesmodule.c and zoneinfo.c are now built with Py_BUILD_CORE_MODULE macro defined.
* bpo-42157: Rename unicodedata.ucnhash_CAPI (GH-22994)Victor Stinner2020-10-271-2/+2
| | | | | | | Removed the unicodedata.ucnhash_CAPI attribute which was an internal PyCapsule object. The related private _PyUnicode_Name_CAPI structure was moved to the internal C API. Rename unicodedata.ucnhash_CAPI as unicodedata._ucnhash_CAPI.
* bpo-42157: Convert unicodedata.UCD to heap type (GH-22991)Victor Stinner2020-10-262-84/+52
| | | | | | | Convert the unicodedata extension module to the multiphase initialization API (PEP 489) and convert the unicodedata.UCD static type to a heap type. Co-Authored-By: Mohamed Koubaa <koubaa.m@gmail.com>
* bpo-42157: unicodedata avoids references to UCD_Type (GH-22990)Victor Stinner2020-10-261-105/+111
| | | | | | | | | | * UCD_Check() uses PyModule_Check() * Simplify the internal _PyUnicode_Name_CAPI structure: * Remove size and state members * Remove state and self parameters of getcode() and getname() functions * Remove global_module_state
* bpo-1635741: _PyUnicode_Name_CAPI moves to internal C API (GH-22713)Victor Stinner2020-10-262-14/+16
| | | | | | | | | | The private _PyUnicode_Name_CAPI structure of the PyCapsule API unicodedata.ucnhash_CAPI moves to the internal C API. Moreover, the structure gets a new state member which must be passed to the getcode() and getname() functions. * Move Include/ucnhash.h to Include/internal/pycore_ucnhash.h * unicodedata module is now built with Py_BUILD_CORE_MODULE. * unicodedata: move hashAPI variable into unicodedata_module_state.
* bpo-42152: Use PyDict_Contains and PyDict_SetDefault if appropriate. (GH-22986)Serhiy Storchaka2020-10-266-45/+33
| | | | | | | If PyDict_GetItemWithError is only used to check whether the key is in dict, it is better to use PyDict_Contains instead. And if it is used in combination with PyDict_SetItem, PyDict_SetDefault can replace the combination.
* bpo-42006: Stop using PyDict_GetItem, PyDict_GetItemString and ↵Serhiy Storchaka2020-10-265-45/+60
| | | | | | | | | | | _PyDict_GetItemId. (GH-22648) These functions are considered not safe because they suppress all internal errors and can return wrong result. PyDict_GetItemString and _PyDict_GetItemId can also silence current exception in rare cases. Remove no longer used _PyDict_GetItemId. Add _PyDict_ContainsId and rename _PyDict_Contains into _PyDict_Contains_KnownHash.
* bpo-42146: Fix memory leak in subprocess.Popen() in case of uid/gid overflow ↵Alexey Izbyshev2020-10-261-2/+2
| | | | | | | | | | | (GH-22966) Fix memory leak in subprocess.Popen() in case of uid/gid overflow Also add a test that would catch this leak with `--huntrleaks`. Alas, the test for `extra_groups` also exposes an inconsistency in our error reporting: we use a custom ValueError for `extra_groups`, but propagate OverflowError for `user` and `group`.
* bpo-42144: Add a missing "goto error;" in the _ssl module (GH-22959)Zackery Spytz2020-10-251-0/+1
|
* bpo-35823: Allow setsid() after vfork() on Linux. (GH-22945)Gregory P. Smith2020-10-241-2/+3
| | | | | | | | | | | It should just be a syscall updating a couple of fields in the kernel side process info. Confirming, in glibc is appears to be a shim for the setsid syscall (based on not finding any code implementing anything special for it) and in uclibc (*much* easier to read) it is clearly just a setsid syscall shim. A breadcrumb _suggesting_ that it is not allowed on Darwin/macOS comes from a commit in emacs: https://lists.gnu.org/archive/html/bug-gnu-emacs/2017-04/msg00297.html but I don't have a way to verify if that is true or not. As we are not supporting vfork on macOS today I just left a note in a comment.
* bpo-41052: Fix pickling heap types implemented in C with protocols 0 and 1 ↵Serhiy Storchaka2020-10-246-167/+3
| | | | (GH-22870)
* bpo-35823: subprocess: Fix handling of pthread_sigmask() errors (GH-22944)Alexey Izbyshev2020-10-241-4/+15
| | | | | | | | Using POSIX_CALL() is incorrect since pthread_sigmask() returns the error number instead of setting errno. Also handle failure of the first call to pthread_sigmask() in the parent process, and explain why we don't handle failure of the second call in a comment.
* bpo-35823: subprocess: Use vfork() instead of fork() on Linux when safe ↵Alexey Izbyshev2020-10-241-27/+197
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-11671) * bpo-35823: subprocess: Use vfork() instead of fork() on Linux when safe When used to run a new executable image, fork() is not a good choice for process creation, especially if the parent has a large working set: fork() needs to copy page tables, which is slow, and may fail on systems where overcommit is disabled, despite that the child is not going to touch most of its address space. Currently, subprocess is capable of using posix_spawn() instead, which normally provides much better performance. However, posix_spawn() does not support many of child setup operations exposed by subprocess.Popen(). Most notably, it's not possible to express `close_fds=True`, which happens to be the default, via posix_spawn(). As a result, most users can't benefit from faster process creation, at least not without changing their code. However, Linux provides vfork() system call, which creates a new process without copying the address space of the parent, and which is actually used by C libraries to efficiently implement posix_spawn(). Due to sharing of the address space and even the stack with the parent, extreme care is required to use vfork(). At least the following restrictions must hold: * No signal handlers must execute in the child process. Otherwise, they might clobber memory shared with the parent, potentially confusing it. * Any library function called after vfork() in the child must be async-signal-safe (as for fork()), but it must also not interact with any library state in a way that might break due to address space sharing and/or lack of any preparations performed by libraries on normal fork(). POSIX.1 permits to call only execve() and _exit(), and later revisions remove vfork() specification entirely. In practice, however, almost all operations needed by subprocess.Popen() can be safely implemented on Linux. * Due to sharing of the stack with the parent, the child must be careful not to clobber local variables that are alive across vfork() call. Compilers are normally aware of this and take extra care with vfork() (and setjmp(), which has a similar problem). * In case the parent is privileged, special attention must be paid to vfork() use, because sharing an address space across different privilege domains is insecure[1]. This patch adds support for using vfork() instead of fork() on Linux when it's possible to do safely given the above. In particular: * vfork() is not used if credential switch is requested. The reverse case (simple subprocess.Popen() but another application thread switches credentials concurrently) is not possible for pure-Python apps because subprocess.Popen() and functions like os.setuid() are mutually excluded via GIL. We might also consider to add a way to opt-out of vfork() (and posix_spawn() on platforms where it might be implemented via vfork()) in a future PR. * vfork() is not used if `preexec_fn != None`. With this change, subprocess will still use posix_spawn() if possible, but will fallback to vfork() on Linux in most cases, and, failing that, to fork(). [1] https://ewontfix.com/7 Co-authored-by: Gregory P. Smith [Google LLC] <gps@google.com>
* bpo-1635741: Fix NULL ptr deref in multiprocessing (GH-22880)Christian Heimes2020-10-221-1/+0
| | | | | | Commit 1d541c25c8019f7a0b80b3e1b437abe171e40b65 introduced a NULL pointer dereference in error path. Signed-off-by: Christian Heimes <christian@python.org>
* _testmultiphase: Fix possible ref leak (GH-22881)Dong-hee Na2020-10-221-0/+4
| | | | | | This is just test code, but sometimes external contributors reference the code snippets from test code. `PyModule_AddObject` should be handled in the proper way. https://docs.python.org/3/c-api/module.html#c.PyModule_AddObject
* Delete TaskWakeupMethWrapper_Type and use PyCFunction instead (#22875)Vladimir Matveev2020-10-221-94/+8
|
* bpo-38324: Fix test__locale.py Windows failures (GH-20529)TIGirardi2020-10-201-3/+22
| | | | Use wide-char _W_* fields of lconv structure on Windows Remove "ps_AF" from test__locale.known_numerics on Windows
* md5module: Fix doc strings variable names (GH-22722)Jakub Jelen2020-10-201-3/+3
|
* bpo-4356: Add key function support to the bisect module (GH-20556)Raymond Hettinger2020-10-202-45/+137
|
* bpo-41586: Add pipesize parameter to subprocess & F_GETPIPE_SZ and ↵Ruben Vorderman2020-10-191-0/+8
| | | | | | | | | | | | | | | | | F_SETPIPE_SZ to fcntl. (GH-21921) * Add F_SETPIPE_SZ and F_GETPIPE_SZ to fcntl module * Add pipesize parameter for subprocess.Popen class This will allow the user to control the size of the pipes. On linux the default is 64K. When a pipe is full it blocks for writing. When a pipe is empty it blocks for reading. On processes that are very fast this can lead to a lot of wasted CPU cycles. On a typical Linux system the max pipe size is 1024K which is much better. For high performance-oriented libraries such as xopen it is nice to be able to set the pipe size. The workaround without this feature is to use my_popen_process.stdout.fileno() in conjuction with fcntl and 1031 (value of F_SETPIPE_SZ) to acquire this behavior.
* bpo-16396: Allow wintypes to be imported on non-Windows systems. (GH-21394)Jason R. Coombs2020-10-191-3/+6
| | | Co-authored-by: Christian Heimes <christian@python.org>
* bpo-20184: Convert termios to Argument Clinic. (GH-22693)Serhiy Storchaka2020-10-182-99/+328
|
* bpo-41919, test_codecs: Move codecs.register calls to setUp() (GH-22513)Hai Shi2020-10-162-58/+1
| | | | * Move the codecs' (un)register operation to testcases. * Remove _codecs._forget_codec() and _PyCodec_Forget()
* bpo-1635741: Add a global module state to unicodedata (GH-22712)Victor Stinner2020-10-151-54/+107
| | | | | | Prepare unicodedata to add a state per module: start with a global "module" state, pass it to subfunctions which access &UCD_Type. This change also prepares the conversion of the UCD_Type static type to a heap type.
* bpo-42021: Fix possible ref leaks during _sqlite3 module init (GH-22673)Erlend Egeberg Aasland2020-10-153-129/+92
|
* bpo-41984: GC track all user classes (GH-22701)Brandt Bucher2020-10-151-0/+20
|
* bpo-40422: Move _Py_closerange to fileutils.c (GH-22680)Kyle Evans2020-10-134-79/+3
| | | | | | | This API is relatively lightweight and organizationally, given that it's used by multiple modules, it makes sense to move it to fileutils. Requires making sure that _posixsubprocess is compiled with the appropriate Py_BUIILD_CORE_BUILTIN macro.
* bpo-41995: Fix null ptr deref in tracemalloc_copy_trace() (GH-22660)Yunlongs2020-10-131-1/+1
| | | | Fix a null pointer dereference in tracemalloc_copy_trace() of _tracemalloc.
* bpo-40422: Move _Py_*_SUPPRESS_IPH bits into _Py_closerange (GH-22672)Kyle Evans2020-10-121-2/+2
| | | | | | This suppression is no longer needed in os_closerange_impl, as it just invokes the internal _Py_closerange implementation. On the other hand, consumers of _Py_closerange may not have any other reason to suppress invalid parameter issues, so narrow the scope to here.
* bpo-40423: Optimization: use close_range(2) if available (GH-22651)Kyle Evans2020-10-111-3/+14
| | | | | | | close_range(2) should be preferred at all times if it's available, otherwise we'll use closefrom(2) if available with a fallback to fdwalk(3) or plain old loop over fd range in order of most efficient to least. [note that this version does check for ENOSYS, but currently ignores all other errors] Automerge-Triggered-By: @pablogsal
* bpo-40422: create a common _Py_closerange API (GH-19754)Kyle Evans2020-10-113-37/+50
| | | | | | | Such an API can be used both for os.closerange and subprocess. For the latter, this yields potential improvement for platforms that have fdwalk but wouldn't have used it there. This will prove even more beneficial later for platforms that have close_range(2), as the new API will prefer that over all else if it's available. The new API is structured to look more like close_range(2), closing from [start, end] rather than the [low, high) of os.closerange(). Automerge-Triggered-By: @gpshead
* bpo-41756: Add PyIter_Send function (#22443)Vladimir Matveev2020-10-102-9/+3
|
* bpo-41985: Add _PyLong_FileDescriptor_Converter and AC converter for ↵Serhiy Storchaka2020-10-097-94/+35
| | | | "fildes". (GH-22620)
* Revert "bpo-26680: Incorporate is_integer in all built-in and standard ↵Raymond Hettinger2020-10-072-14/+5
| | | | | library numeric types (GH-6121)" (GH-22584) This reverts commit 58a7da9e125422323f79c4ee95ac5549989d8162.
* bpo-41867: List options for timespec in docstrings of isoformat methods ↵Ram Rachum2020-10-031-4/+8
| | | | (GH-22418)
* Update link to supporting references (GH-22488)Raymond Hettinger2020-10-021-1/+1
|
* bpo-26680: Incorporate is_integer in all built-in and standard library ↵Robert Smallshire2020-10-012-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | numeric types (GH-6121) * bpo-26680: Adds support for int.is_integer() for compatibility with float.is_integer(). The int.is_integer() method always returns True. * bpo-26680: Adds a test to ensure that False.is_integer() and True.is_integer() are always True. * bpo-26680: Adds Real.is_integer() with a trivial implementation using conversion to int. This default implementation is intended to reduce the workload for subclass implementers. It is not robust in the presence of infinities or NaNs and may have suboptimal performance for other types. * bpo-26680: Adds Rational.is_integer which returns True if the denominator is one. This implementation assumes the Rational is represented in it's lowest form, as required by the class docstring. * bpo-26680: Adds Integral.is_integer which always returns True. * bpo-26680: Adds tests for Fraction.is_integer called as an instance method. The tests for the Rational abstract base class use an unbound method to sidestep the inability to directly instantiate Rational. These tests check that everything works correct as an instance method. * bpo-26680: Updates documentation for Real.is_integer and built-ins int and float. The call x.is_integer() is now listed in the table of operations which apply to all numeric types except complex, with a reference to the full documentation for Real.is_integer(). Mention of is_integer() has been removed from the section 'Additional Methods on Float'. The documentation for Real.is_integer() describes its purpose, and mentions that it should be overridden for performance reasons, or to handle special values like NaN. * bpo-26680: Adds Decimal.is_integer to the Python and C implementations. The C implementation of Decimal already implements and uses mpd_isinteger internally, we just expose the existing function to Python. The Python implementation uses internal conversion to integer using to_integral_value(). In both cases, the corresponding context methods are also implemented. Tests and documentation are included. * bpo-26680: Updates the ACKS file. * bpo-26680: NEWS entries for int, the numeric ABCs and Decimal. Co-authored-by: Robert Smallshire <rob@sixty-north.com>
* bpo-41861: Convert _sqlite3 CursorType and ConnectionType to heap types ↵Erlend Egeberg Aasland2020-10-016-102/+74
| | | | (GH-22478)
* bpo-41861: Convert _sqlite3 RowType and StatementType to heap types (GH-22444)Erlend Egeberg Aasland2020-10-019-118/+71
|
* bpo-41861: Convert _sqlite3 PrepareProtocolType to heap type (GH-22428)Erlend Egeberg Aasland2020-09-285-54/+33
|
* bpo-41842: Add codecs.unregister() function (GH-22360)Hai Shi2020-09-282-1/+34
| | | | Add codecs.unregister() and PyCodec_Unregister() functions to unregister a codec search function.
* bpo-41861: Convert _sqlite3 cache and node static types to heap types (GH-22417)Erlend Egeberg Aasland2020-09-274-99/+48
|
* bpo-1635741: Port _bisect module to multi-phase init (GH-22415)Dong-hee Na2020-09-261-9/+5
|
* bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633)Zackery Spytz2020-09-233-13/+8
| | | | Add PyDateTime_DATE_GET_TZINFO() and PyDateTime_TIME_GET_TZINFO() macros.
* bpo-40170: Use inline _PyType_HasFeature() function (GH-22375)Victor Stinner2020-09-231-1/+2
| | | | | Use _PyType_HasFeature() in the _io module and in structseq implementation. Replace PyType_HasFeature() opaque function call with _PyType_HasFeature() inlined function.