summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* bpo-40170: PyType_SUPPORTS_WEAKREFS() becomes a regular function (GH-30938)Victor Stinner2022-01-273-5/+14
| | | | | | | | Convert the PyType_SUPPORTS_WEAKREFS() macro to a regular function. It no longer access the PyTypeObject.tp_weaklistoffset member directly. Add _PyType_SUPPORTS_WEAKREFS() static inline functions, used internally by Python for best performance.
* bpo-46527: allow calling enumerate(iterable=...) again (GH-30904)Jelle Zijlstra2022-01-261-10/+37
|
* bpo-46504: faster code for trial quotient in x_divrem() (GH-30856)Tim Peters2022-01-251-1/+8
| | | | | | | | | | * bpo-46504: faster code for trial quotient in x_divrem() This brings x_divrem() back into synch with x_divrem1(), which was changed in bpo-46406 to generate faster code to find machine-word division quotients and remainders. Modern processors compute both with a single machine instruction, but convincing C to exploit that requires writing _less_ "clever" C code.
* bpo-46431: improve error message on invalid calls to ↵Irit Katriel2022-01-241-1/+4
| | | | BaseExceptionGroup.__new__ (GH-30854)
* bpo-43683: Streamline YIELD_VALUE and SEND (GH-30723)Mark Shannon2022-01-241-2/+4
| | | | | | | | * Split YIELD_VALUE into ASYNC_GEN_WRAP; YIELD_VALUE for async generators. * Split SEND into SEND; YIELD_VALUE. * Document new opcodes.
* bpo-46481: Implement vectorcall for weakref.ref.__call__ method. (GH-30820)Dong-hee Na2022-01-231-50/+30
|
* bpo-46406: Faster single digit int division. (#30626)Gregory P. Smith2022-01-231-10/+26
| | | | | | | | | * bpo-46406: Faster single digit int division. This expresses the algorithm in a more basic manner resulting in better instruction generation by todays compilers. See https://mail.python.org/archives/list/python-dev@python.org/thread/ZICIMX5VFCX4IOFH5NUPVHCUJCQ4Q7QM/#NEUNFZU3TQU4CPTYZNF3WCN7DOJBBTK5
* bpo-46417: _PyList_Fini() clears indexerr (GH-30815)Victor Stinner2022-01-231-2/+6
| | | _PyList_Fini() now clears the 'indexerr' error message.
* bpo-46417: Fix _PyStaticType_Dealloc() (GH-30810)Victor Stinner2022-01-221-3/+11
| | | | _PyStaticType_Dealloc() now only calls PyObject_ClearWeakRefs() if the call is not going to fail.
* bpo-46417: Clear Unicode static types at exit (GH-30806)Victor Stinner2022-01-224-22/+23
| | | | | | | | | | | Add _PyUnicode_FiniTypes() function, called by finalize_interp_types(). It clears these static types: * EncodingMapType * PyFieldNameIter_Type * PyFormatterIter_Type _PyStaticType_Dealloc() now does nothing if tp_subclasses is not NULL.
* bpo-46417: Py_Finalize() clears static exceptioins (GH-30805)Victor Stinner2022-01-221-1/+26
| | | | | | The Py_Finalize() function now clears exceptions implemented as static types. Add _PyExc_FiniTypes() function, called by _PyExc_Fini().
* bpo-46417: Factorize _PyExc_InitTypes() code (GH-30804)Victor Stinner2022-01-221-170/+132
| | | | | | | | Add 'static_exceptions' list to factorize code between _PyExc_InitTypes() and _PyBuiltins_AddExceptions(). _PyExc_InitTypes() does nothing if it's not the main interpreter. Sort exceptions in Lib/test/exception_hierarchy.txt.
* bpo-46417: _PyTypes_FiniTypes() clears object and type (GH-30798)Victor Stinner2022-01-221-15/+11
|
* bpo-46417: Cleanup typeobject.c code (GH-30795)Victor Stinner2022-01-221-159/+164
| | | | | | | | | | | | | | | | | | | | | | * Add comment to recurse_down_subclasses() explaining why it's safe to use a borrowed reference to tp_subclasses. * remove_all_subclasses() no longer accept NULL cases * type_set_bases() now relies on the fact that new_bases is not NULL. * type_dealloc_common() avoids PyErr_Fetch/PyErr_Restore if tp_bases is NULL. * remove_all_subclasses() makes sure that no exception is raised. * Don't test at runtime if tp_mro only contains types: rely on _PyType_CAST() assertion for that. * _PyStaticType_Dealloc() no longer clears tp_subclasses which is already NULL. * mro_hierarchy() avoids calling _PyType_GetSubclasses() if tp_subclasses is NULL. Coding style: * Use Py_NewRef(). * Add braces and move variable declarations to the first variable assignement. * Rename a few variables and parameters to use better names.
* bpo-46417: Clear more static types (GH-30796)Victor Stinner2022-01-221-0/+15
| | | | | | | * Move PyContext static types into object.c static_types list. * Rename PyContextTokenMissing_Type to _PyContextTokenMissing_Type and declare it in pycore_context.h. * _PyHamtItems types are no long exported: replace PyAPI_DATA() with extern.
* bpo-46417: remove_subclass() clears tp_subclasses (GH-30793)Victor Stinner2022-01-221-9/+15
| | | | | | | | | The remove_subclass() function now deletes the dictionary when removing the last subclass (if the dictionary becomes empty) to save memory: set PyTypeObject.tp_subclasses to NULL. remove_subclass() is called when a type is deallocated. _PyType_GetSubclasses() no longer holds a reference to tp_subclasses: its loop cannot modify tp_subclasses.
* bpo-46417: Fix race condition on setting type __bases__ (GH-30788)Victor Stinner2022-01-221-11/+16
| | | | | | | Fix a race condition on setting a type __bases__ attribute: the internal function add_subclass() now gets the PyTypeObject.tp_subclasses member after calling PyWeakref_NewRef() which can trigger a garbage collection which can indirectly modify PyTypeObject.tp_subclasses.
* bpo-46417: Use _PyType_CAST() in Objects directory (GH-30764)Victor Stinner2022-01-219-20/+13
|
* bpo-46417: Add _PyType_GetSubclasses() function (GH-30761)Victor Stinner2022-01-211-40/+60
| | | | | | | | | | | | | | Add a new _PyType_GetSubclasses() function to get type's subclasses. _PyType_GetSubclasses(type) returns a list which holds strong refererences to subclasses. It is safer than iterating on type->tp_subclasses which yields weak references and can be modified in the loop. _PyType_GetSubclasses(type) now holds a reference to the tp_subclasses dict while creating the list of subclasses. set_collection_flag_recursive() of _abc.c now uses _PyType_GetSubclasses().
* bpo-46417: Add _PyType_CAST() macro (GH-30760)Victor Stinner2022-01-211-57/+47
| | | | In debug mode, the macro makes sure that its argument is a type using an assertion.
* bpo-46417: Add missing types of _PyTypes_InitTypes() (GH-30749)Victor Stinner2022-01-213-3/+11
| | | | | | | | | Add types removed by mistake by the commit adding _PyTypes_FiniTypes(). Move also PyBool_Type at the end, since it depends on PyLong_Type. PyBytes_Type and PyUnicode_Type no longer depend explicitly on PyBaseObject_Type: it's the default of PyType_Ready().
* bpo-46417: Revert remove_subclass() change (GH-30750)Victor Stinner2022-01-211-4/+0
| | | | remove_subclass() doesn't clear the tp_subclasses dict if the dict becomes empty.
* bpo-46417: Py_Finalize() clears static types (GH-30743)Victor Stinner2022-01-212-85/+142
| | | | | | | Add _PyTypes_FiniTypes() best-effort function to clear static types: don't deallocate a type if it still has subclasses. remove_subclass() now sets tp_subclasses to NULL when removing the last subclass.
* bpo-46417: _curses uses PyStructSequence_NewType() (GH-30736)Victor Stinner2022-01-213-2/+11
| | | | | | | | The _curses module now creates its ncurses_version type as a heap type using PyStructSequence_NewType(), rather than using a static type. * Move _PyStructSequence_FiniType() definition to pycore_structseq.h. * test.pythoninfo: log curses.ncurses_version.
* bpo-46417: Finalize structseq types at exit (GH-30645)Victor Stinner2022-01-214-2/+70
| | | | | | | | | | | | | | | | | | Add _PyStructSequence_FiniType() and _PyStaticType_Dealloc() functions to finalize a structseq static type in Py_Finalize(). Currrently, these functions do nothing if Python is built in release mode. Clear static types: * AsyncGenHooksType: sys.set_asyncgen_hooks() * FlagsType: sys.flags * FloatInfoType: sys.float_info * Hash_InfoType: sys.hash_info * Int_InfoType: sys.int_info * ThreadInfoType: sys.thread_info * UnraisableHookArgsType: sys.unraisablehook * VersionInfoType: sys.version * WindowsVersionType: sys.getwindowsversion()
* bpo-46409: Make generators in bytecode (GH-30633)Mark Shannon2022-01-202-24/+43
| | | | | | | | | | | | * Add RETURN_GENERATOR and JUMP_NO_INTERRUPT opcodes. * Trim frame and generator by word each. * Minor refactor of frame.c * Update test.test_sys to account for smaller frames. * Treat generator functions as normal functions when evaluating and specializing.
* docs: correct outdated MappingProxyType docstrings (#30281)Joshua Bronson2022-01-191-3/+3
| | | | | The docstrings for MappingProxyType's keys(), values(), and items() methods were never updated to reflect the changes that Python 3 brought to these APIs, namely returning views rather than lists.
* bpo-42161: Hoist the _PyLong_GetOne() call out of the inner loop. (GH-30656)Raymond Hettinger2022-01-181-2/+4
|
* bpo-46361: Fix "small" `int` caching (GH-30583)Brandt Bucher2022-01-161-1/+1
|
* bpo-46020: Optimize long_pow for the common case (GH-30555)Tim Peters2022-01-121-6/+13
| | | | This cuts a bit of overhead by not initializing the table of small odd powers unless it's needed for a large exponent.
* bpo-45953: Statically allocate and initialize global bytes objects. (gh-30096)Eric Snow2022-01-111-78/+14
| | | | | The empty bytes object (b'') and the 256 one-character bytes objects were allocated at runtime init. Now we statically allocate and initialize them. https://bugs.python.org/issue45953
* bpo-46235: Do all ref-counting at once during list/tuple multiplication ↵Dennis Sweeney2022-01-082-26/+48
| | | | | | | | | | (GH-30346) When multiplying lists and tuples by `n`, increment each element's refcount, by `n`, just once. Saves `n-1` increments per element, and allows for a leaner & faster copying loop. Code by sweeneyde (Dennis Sweeney).
* bpo-46006: Revert "bpo-40521: Per-interpreter interned strings (GH-20085)" ↵Victor Stinner2022-01-062-19/+69
| | | | | | | | | | | (GH-30422) This reverts commit ea251806b8dffff11b30d2182af1e589caf88acf. Keep "assert(interned == NULL);" in _PyUnicode_Fini(), but only for the main interpreter. Keep _PyUnicode_ClearInterned() changes avoiding the creation of a temporary Python list object.
* bpo-46236: Fix PyFunction_GetAnnotations() returned tuple. (GH-30409)Inada Naoki2022-01-051-22/+33
| | | Automerge-Triggered-By: GH:pablogsal
* bpo-46009: Remove GEN_START (GH-30367)Brandt Bucher2022-01-041-3/+5
|
* bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE (GH-30302)Irit Katriel2022-01-041-1/+0
| | | | | | * bpo-46202: remove opcode POP_EXCEPT_AND_RERAISE * do not assume that an exception group is truthy
* bpo-46233: Minor speedup for bigint squaring (GH-30345)Tim Peters2022-01-041-5/+19
| | | | | | | x_mul()'s squaring code can do some redundant and/or useless work at the end of each digit pass. A more careful analysis of worst-case carries at various digit positions allows making that code leaner.
* bpo-46219, 46221: simplify except* implementation following exc_info ↵Irit Katriel2022-01-021-2/+118
| | | | changes. Move helpers to exceptions.c. Do not assume that exception groups are truthy. (GH-30289)
* bpo-46218: Change long_pow() to sliding window algorithm (GH-30319)Tim Peters2022-01-021-24/+84
| | | | | | | | | | | * bpo-46218: Change long_pow() to sliding window algorithm The primary motivation is to eliminate long_pow's reliance on that the number of bits in a long "digit" is a multiple of 5. Now it no longer cares how many bits are in a digit. But the sliding window approach also allows cutting the precomputed table of small powers in half, which reduces initialization overhead enough that the approach pays off for smaller exponents too. Depending on exponent bit patterns, a sliding window may also be able to save some bigint multiplies (sometimes when at least 5 consecutive exponent bits are 0, regardless of their starting bit position modulo 5). Note: boosting the window width to 6 didn't work well overall. It give marginal speed improvements for huge exponents, but the increased overhead (the small-power table needs twice as many entries) made it a loss for smaller exponents. Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* bpo-46085: Fix iterator cache mechanism of OrderedDict. (GH-30290)Dong-hee Na2021-12-301-3/+5
|
* bpo-46055: Speed up binary shifting operators (GH-30044)Xinhang Xu2021-12-271-1/+16
| | | Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* bpo-46055: Streamline inner loop for right shifts (#30243)Mark Dickinson2021-12-271-7/+8
|
* bpo-43413: Revert changes in set.__init__ (GH-28403)Serhiy Storchaka2021-12-261-3/+1
| | | | Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
* bpo-46140: take more Py_buffer arguments as const * (GH-30217)David Hewitt2021-12-222-12/+13
|
* bpo-46107: ExceptionGroup.subgroup()/split() should copy __note__ to the ↵Irit Katriel2021-12-211-0/+5
| | | | parts (GH-30159)
* Revert "bpo-46131: add fastpath for PyFloat_Check() (GH-30200)" (GH-30208)Raymond Hettinger2021-12-192-4/+0
| | | This reverts commit 2ef06d412531d1163dbc72877c88aedf3ed82a25.
* bpo-46131: add fastpath for PyFloat_Check() (#30200)Matti Picus2021-12-192-0/+4
|
* bpo-45711: Remove type and traceback from exc_info (GH-30122)Irit Katriel2021-12-171-6/+0
| | | | | | | | * Do not PUSH/POP traceback or type to the stack as part of exc_info * Remove exc_traceback and exc_type from _PyErr_StackItem * Add to what's new, because this change breaks things like Cython
* bpo-46039: Split yield from in two (GH-30035)Mark Shannon2021-12-152-8/+18
| | | | | | * Split YIELD_FROM opcode into SEND and JUMP_ABSOLUTE. * Remove YIELD_FROM opcode.
* bpo-44525: Split calls into PRECALL and CALL (GH-30011)Mark Shannon2021-12-142-5/+5
| | | | | | | | | | * Add 3 new opcodes for calls: PRECALL_METHOD, CALL_NO_KW, CALL_KW. * Update specialization to handle new CALL opcodes. * Specialize call to method descriptors. * Remove old CALL opcodes: CALL_FUNCTION, CALL_METHOD, CALL_METHOD_KW, CALL_FUNCTION_KW.