Commit Graph

6837 Commits

Author SHA1 Message Date
kj 33b3fedd43
[3.9] bpo-42195: Ensure consistency of Callable's __args__ in collections.abc and typing (GH-23765)
Backport of GH-23060.
2020-12-14 08:30:45 -08:00
Brandt Bucher 60463e8e4f
bpo-42536: GC track recycled tuples (GH-23623) (GH-23651)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector:

- collections.OrderedDict.items
- dict.items
- enumerate
- functools.reduce
- itertools.combinations
- itertools.combinations_with_replacement
- itertools.permutations
- itertools.product
- itertools.zip_longest
- zip

Previously, they could have become untracked by a prior garbage collection.
(cherry picked from commit 226a012d1c)
2020-12-07 20:07:48 +00:00
Miss Islington (bot) d5c029b1a9
bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656)
Use `_PyArg_NoKeywords` instead of `_PyArg_NoKwnames` when checking the `kwds` tuple when creating `GenericAlias`. This fixes an interpreter crash when passing in keyword arguments to `GenericAlias`'s constructor.

Needs backport to 3.9.

Automerge-Triggered-By: GH:gvanrossum
(cherry picked from commit 804d6893b8)

Co-authored-by: kj <28750310+Fidget-Spinner@users.noreply.github.com>
2020-12-05 08:24:38 -08:00
Miss Islington (bot) d153eb8a1e
bpo-42412: Fix possible leaks and check arguments in PyType_FromModuleAndSpec() (GH-23410)
* There were leaks if Py_tp_bases is used more than once or if some call is
  failed before setting tp_bases.
* There was a crash if the bases argument or the Py_tp_bases slot is not a tuple.
* The documentation was not accurate.
(cherry picked from commit 1db76394ea)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2020-11-21 03:09:40 -08:00
Miss Islington (bot) 994c68f586
bpo-40998: Address compiler warnings found by ubsan (GH-20929)
Signed-off-by: Christian Heimes <christian@python.org>

Automerge-Triggered-By: GH:tiran
(cherry picked from commit 07f2adedf0)

Co-authored-by: Christian Heimes <christian@python.org>
2020-11-18 08:01:48 -08:00
kj 71ba5f52d2
[3.9] bpo-42332: Add weakref slot to types.GenericAlias (GH-23250) (GH-23309)
(cherry picked from commit 384b7a4bd9)
2020-11-17 14:45:08 -08:00
Miss Islington (bot) 2a86ade9e3
Fix typo in unicodeobject.c (GH-23180)
exeeds -> exceeds

Automerge-Triggered-By: GH:Mariatta
(cherry picked from commit 38811d68ca)

Co-authored-by: Ikko Ashimine <eltociear@gmail.com>
2020-11-09 22:18:34 -08:00
Miss Skeleton (bot) 60324d26b5
bpo-42143: Ensure PyFunction_NewWithQualName() can't fail after creating the func object (GH-22953) (GH-23021)
func_dealloc() does not handle partially-created objects. Best not to give it any.
(cherry picked from commit 350526105f)

Co-authored-by: Yonatan Goldschmidt <yon.goldschmidt@gmail.com>
2020-10-29 13:02:50 +02:00
Miss Skeleton (bot) 6a2aa4994e
bpo-42065: Fix incorrectly formatted _codecs.charmap_decode error message (GH-19940)
(cherry picked from commit 3635388f52)

Co-authored-by: Max Bernstein <tekknolagi@users.noreply.github.com>
2020-10-18 09:00:18 +03:00
Miss Skeleton (bot) d197b2bb3e
bpo-41984: GC track all user classes (GH-22701/GH-22702)
(cherry picked from commit c13b847a6f)
2020-10-14 20:38:25 -07:00
Miss Skeleton (bot) 8a12503b45
bpo-42015: Reorder dereferencing calls in meth_dealloc, to make sure m_self is kept alive long enough (GH-22670)
(cherry picked from commit 04b8631d84)

Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net>
2020-10-12 14:29:01 -07:00
Miss Skeleton (bot) 3da210b69f
Fix the attribute names in the docstring of GenericAlias (GH-22594)
(cherry picked from commit 77f0a23e7a)

Co-authored-by: Mikhail Golubev <qsolo825@gmail.com>
2020-10-08 15:02:26 -07:00
Serhiy Storchaka 7aa22ba923
[3.9] bpo-41909: Enable previously disabled recursion checks. (GH-22536) (GH-22550)
Enable recursion checks which were disabled when get __bases__ of
non-type objects in issubclass() and isinstance() and when intern
strings. It fixes a stack overflow when getting __bases__ leads
to infinite recursion.

Originally recursion checks was disabled for PyDict_GetItem() which
silences all errors including the one raised in case of detected
recursion and can return incorrect result. But now the code uses
PyDict_GetItemWithError() and PyDict_SetDefault() instead.
(cherry picked from commit 9ece9cd65c)
2020-10-05 01:27:38 +03:00
Miss Islington (bot) 49917d576a
bpo-41780: Fix __dir__ of types.GenericAlias (GH-22262)
Automerge-Triggered-By: @gvanrossum
(cherry picked from commit 2e87774df1)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
2020-09-15 16:37:13 -07:00
Miss Islington (bot) e92219d8f8
bpo-29590: fix stack trace for gen.throw() with yield from (GH-19896)
* Add failing test.

* bpo-29590: fix stack trace for gen.throw() with yield from (GH-NNNN)

When gen.throw() is called on a generator after a "yield from", the
intermediate stack trace entries are lost.  This commit fixes that.
(cherry picked from commit 8b33961e4b)

Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
2020-09-04 16:07:18 -07:00
Pablo Galindo d14775ddbb
[3.9] bpo-41654: Fix deallocator of MemoryError to account for subclasses (GH-22020) (GH-22045)
When allocating MemoryError classes, there is some logic to use
pre-allocated instances in a freelist only if the type that is being
allocated is not a subclass of MemoryError. Unfortunately in the
destructor this logic is not present so the freelist is altered even
with subclasses of MemoryError..
(cherry picked from commit 9b648a95cc)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2020-09-01 21:40:57 +01:00
Miss Islington (bot) 01ab963460
bpo-41295: Reimplement the Carlo Verre "hackcheck" (GH-21528)
Walk down the MRO backwards to find the type that originally defined the final `tp_setattro`, then make sure we are not jumping over intermediate C-level bases with the Python-level call.

Automerge-Triggered-By: @gvanrossum
(cherry picked from commit c53b310e59)

Co-authored-by: scoder <stefan_ml@behnel.de>
2020-07-18 14:39:02 -07:00
Miss Islington (bot) 51b36ed96d
bpo-41175: Guard against a NULL pointer dereference within bytearrayobject (GH-21240)
The issue is triggered by the bytearray() + bytearray() operation.

Detected by GCC 10 static analysis tool.
(cherry picked from commit 61fc23ca10)

Co-authored-by: stratakis <cstratak@redhat.com>
2020-07-10 03:18:45 -07:00
Miss Islington (bot) bfec674254
bpo-39960: Allow heap types in the "Carlo Verre" hack check that override "tp_setattro()" (GH-21092)
Automerge-Triggered-By: @gvanrossum
(cherry picked from commit 148f329135)

Co-authored-by: scoder <stefan_ml@behnel.de>
2020-07-02 17:28:41 -07:00
Miss Islington (bot) 353c4bab7d
bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537)
Unexpected errors in calling the __iter__ method are no longer
masked by TypeError in the "in" operator and functions
operator.contains(), operator.indexOf() and operator.countOf().
(cherry picked from commit cafe1b6e9d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2020-06-22 01:20:56 -07:00
Inada Naoki 610a60c601
bpo-36346: Add Py_DEPRECATED to deprecated unicode APIs (GH-20878)
Co-authored-by: Kyle Stanley <aeros167@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 2c4928d37e)
2020-06-18 17:30:53 +09:00
Miss Islington (bot) 9419158a3e
bpo-40703: Let PyType_FromSpec() set "type.__module__" only if it is not set yet. (GH-20273) (GH-20782)
(cherry picked from commit 24b8bad6d3)
2020-06-10 18:43:10 +02:00
Miss Islington (bot) 1e4fa91104
bpo-40724: Support setting buffer slots from type specs (GH-20648) (GH-20683)
This is not part of the limited API but makes the buffer slots available for type specs.
(cherry picked from commit f7c4e23642)
2020-06-07 09:06:40 +02:00
Miss Islington (bot) bcbe5c59dd
bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType_FromSpec types (reverts GH-19414) (GH-20264)
Heap types now always visit the type in tp_traverse. See added docs for details.

This reverts commit 0169d3003b.

Automerge-Triggered-By: @encukou
(cherry picked from commit 1cf15af9a6)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2020-05-28 08:12:23 -07:00
Miss Islington (bot) a3c3e8920a
Remove spurious NULL in descrobject.c (GH-20344)
Co-authored-by: hai shi <shihai1991@126.com>
(cherry picked from commit 3f5f61409e)

Co-authored-by: Hai Shi <shihai1992@gmail.com>
2020-05-23 22:24:56 -07:00
Miss Islington (bot) 7f77ac463c
bpo-40696: Fix a hang that can arise after gen.throw() (GH-20287)
This updates _PyErr_ChainStackItem() to use _PyErr_SetObject()
instead of _PyErr_ChainExceptions(). This prevents a hang in
certain circumstances because _PyErr_SetObject() performs checks
to prevent cycles in the exception context chain while
_PyErr_ChainExceptions() doesn't.
(cherry picked from commit 7c30d12bd5)

Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
2020-05-22 14:35:22 -07:00
Victor Stinner 9512ad74b0
[3.9] bpo-40514: Remove --with-experimental-isolated-subinterpreters in 3.9 (GH-20228)
Remove --with-experimental-isolated-subinterpreters configure option
in Python 3.9: the experiment continues in the master branch, but
it's no longer needed in 3.9.
2020-05-20 00:27:46 +02:00
Miss Islington (bot) f02c3048dc
Use _PyErr_ChainStackItem() inside gen_send_ex(). (GH-20173) (#20202)
_PyErr_ChainStackItem was just added in GH-19951 (for bpo-31033).
(cherry picked from commit ff7a8b03c4)

Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>

Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
2020-05-19 04:14:13 +02:00
Chris Jerdonek da742ba826
bpo-31033: Improve the traceback for cancelled asyncio tasks (GH-19951)
When an asyncio.Task is cancelled, the exception traceback now
starts with where the task was first interrupted.  Previously,
the traceback only had "depth one."
2020-05-17 22:47:31 -07:00
Zackery Spytz 6b6092f533
bpo-39075: types.SimpleNamespace no longer sorts attributes in its repr (GH-19430) 2020-05-15 18:27:54 -07:00
Victor Stinner 3d17c045b4
bpo-40521: Add PyInterpreterState.unicode (GH-20081)
Move PyInterpreterState.fs_codec into a new
PyInterpreterState.unicode structure.

Give a name to the fs_codec structure and use this structure in
unicodeobject.c.
2020-05-14 01:48:38 +02:00
Chris Jerdonek 75cd8e48c6
bpo-29587: Make gen.throw() chain exceptions with yield from (GH-19858)
The previous commits on bpo-29587 got exception chaining working
with gen.throw() in the `yield` case. This patch also gets the
`yield from` case working.

As a consequence, implicit exception chaining now also works in
the asyncio scenario of awaiting on a task when an exception is
already active.

Tests are included for both the asyncio case and the pure
generator-only case.
2020-05-13 16:18:27 -07:00
Victor Stinner d6fb53fe42
bpo-39465: Remove _PyUnicode_ClearStaticStrings() from C API (GH-20078)
Remove the _PyUnicode_ClearStaticStrings() function from the C API.
Make the function fully private (declare it with "static").
2020-05-14 01:11:54 +02:00
scoder 4c9ea093cd
bpo-38787: Add PyCFunction_CheckExact() macro for exact type checks (GH-20024)
… now that we allow subtypes of PyCFunction.

Also add PyCMethod_CheckExact() and PyCMethod_Check() for checks against the PyCMethod subtype.
2020-05-12 07:12:41 -07:00
Serhiy Storchaka 5650e76f63
bpo-40596: Fix str.isidentifier() for non-canonicalized strings containing non-BMP characters on Windows. (GH-20053) 2020-05-12 16:18:00 +03:00
Serhiy Storchaka 74ea6b5a75
bpo-40593: Improve syntax errors for invalid characters in source code. (GH-20033) 2020-05-12 12:42:04 +03:00
Victor Stinner 4804b5b3df
bpo-39465: Don't access directly _Py_Identifier members (GH-20043)
* Replace id->object with _PyUnicode_FromId(&id)
* Use _Py_static_string_init(str) macro to initialize statically
  name_op in typeobject.c.
2020-05-12 01:43:38 +02:00
Hai Shi 86d69444e7
bpo-40584: Update PyType_FromModuleAndSpec() to process tp_vectorcall_offset (GH-20026) 2020-05-11 23:38:55 +02:00
scoder 6067d4bc3c
bpo-40575: Avoid unnecessary overhead in _PyDict_GetItemIdWithError() (GH-20018)
Avoid unnecessary overhead in _PyDict_GetItemIdWithError() by calling
_PyDict_GetItem_KnownHash() instead of the more generic PyDict_GetItemWithError(),
since we already know the hash of interned strings.
2020-05-11 06:04:31 +02:00
Raymond Hettinger 2cc9b8486d
Improve code clarity for the set lookup logic (GH-20028) 2020-05-10 14:53:29 -07:00
Sergey Fedoseev 86a93fddf7
bpo-37986: Improve perfomance of PyLong_FromDouble() (GH-15611)
* bpo-37986: Improve perfomance of PyLong_FromDouble()

* Use strict bound check for safety and symmetry

* Remove possibly outdated performance claims

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2020-05-10 10:15:57 +01:00
Zackery Spytz 02fa0ea9c1
bpo-40273: Reversible mappingproxy (FH-19513) 2020-05-07 22:25:50 -07:00
Petr Viktorin e1becf46b4
bpo-38787: C API for module state access from extension methods (PEP 573) (GH-19936)
Module C state is now accessible from C-defined heap type methods (PEP 573).
Patch by Marcel Plch and Petr Viktorin.

Co-authored-by: Marcel Plch <mplch@redhat.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2020-05-07 15:39:59 +02:00
Victor Stinner b7aa23d29f
bpo-40521: Disable list free list in subinterpreters (GH-19959)
When Python is built with experimental isolated interpreters, disable
the list free list.

Temporary workaround until this cache is made per-interpreter.
2020-05-06 19:05:27 +02:00
Victor Stinner 89fc4a34cf
bpo-40521: Disable method cache in subinterpreters (GH-19960)
When Python is built with experimental isolated interpreters, disable
the type method cache.

Temporary workaround until the cache is made per-interpreter.
2020-05-06 18:23:58 +02:00
Pablo Galindo 96074de573
bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946) 2020-05-05 22:58:19 +01:00
Victor Stinner b4b53868d7
bpo-40521: Disable free lists in subinterpreters (GH-19937)
When Python is built with experimental isolated interpreters, disable
tuple, dict and free free lists.

Temporary workaround until these caches are made per-interpreter.

Add frame_alloc() and frame_get_builtins() subfunctions to simplify
_PyFrame_New_NoTrack().
2020-05-05 19:55:29 +02:00
Victor Stinner 607b1027fe
bpo-40521: Disable Unicode caches in isolated subinterpreters (GH-19933)
When Python is built in the experimental isolated subinterpreters
mode, disable Unicode singletons and Unicode interned strings since
they are shared by all interpreters.

Temporary workaround until these caches are made per-interpreter.
2020-05-05 18:50:30 +02:00
Victor Stinner b0be6b3b94
bpo-29587: _PyErr_ChainExceptions() checks exception (GH-19902)
_PyErr_ChainExceptions() now ensures that the first parameter is an
exception type, as done by _PyErr_SetObject().

* The following function now check PyExceptionInstance_Check() in an
  assertion using a new _PyBaseExceptionObject_cast() helper
  function:

  * PyException_GetTraceback(), PyException_SetTraceback()
  * PyException_GetCause(), PyException_SetCause()
  * PyException_GetContext(), PyException_SetContext()

* PyExceptionClass_Name() now checks PyExceptionClass_Check() with an
  assertion.

* Remove XXX comment and add gi_exc_state variable to _gen_throw().

* Remove comment from test_generators
2020-05-05 17:07:41 +02:00
Dong-hee Na b88cd585d3
bpo-40455: Remove gcc10 warning about x_digits (#19852)
* bpo-40455: Remove gcc10 warning about x_digits

* bpo-40455: nit

* bpo-40455: fix logic error
2020-05-04 22:32:42 +09:00