summaryrefslogtreecommitdiffstats
path: root/Objects/sliceobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-125063: Emit slices as constants in the bytecode compiler (#125064)Michael Droettboom2024-10-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * Make slices marshallable * Emit slices as constants * Update Python/marshal.c Co-authored-by: Peter Bierma <zintensitydev@gmail.com> * Refactor codegen_slice into two functions so it always has the same net effect * Fix for free-threaded builds * Simplify marshal loading of slices * Only return SUCCESS/ERROR from codegen_slice --------- Co-authored-by: Mark Shannon <mark@hotpy.org> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* gh-100240: Use a consistent implementation for freelists (#121934)Sam Gross2024-07-221-35/+4
| | | | | | | | This combines and updates our freelist handling to use a consistent implementation. Objects in the freelist are linked together using the first word of memory block. If configured with freelists disabled, these operations are essentially no-ops.
* gh-117764: Add docstrings and signatures for the types of None, Ellipsis and ↵Serhiy Storchaka2024-04-121-1/+6
| | | | NotImplemented (GH-117813)
* gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329)Donghee Na2024-02-141-10/+10
|
* gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists ↵Donghee Na2024-02-101-8/+4
| | | | (gh-114899)
* gh-111968: Unify freelist naming schema to Eric's suggestion (gh-114581)Donghee Na2024-01-261-7/+7
|
* gh-111968: Fix --without-freelists build (gh-114270)Donghee Na2024-01-181-5/+14
|
* gh-111968: Use per-thread slice_cache in free-threading (gh-113972)Donghee Na2024-01-151-11/+15
|
* gh-110481: Implement biased reference counting (gh-110764)Sam Gross2023-10-301-4/+1
|
* gh-110964: Remove private _PyArg functions (#110966)Victor Stinner2023-10-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the following private functions and structures to pycore_modsupport.h internal C API: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() Changes: * Python/getargs.h now includes pycore_modsupport.h to export functions. * clinic.py now adds pycore_modsupport.h when one of these functions is used. * Add pycore_modsupport.h includes when a C extension uses one of these functions. * Define Py_BUILD_CORE_MODULE in C extensions which now include directly or indirectly (via code generated by Argument Clinic) pycore_modsupport.h: * _csv * _curses_panel * _dbm * _gdbm * _multiprocessing.posixshmem * _sqlite.row * _statistics * grp * resource * syslog * _testcapi: bad_get() no longer uses METH_FASTCALL calling convention but METH_VARARGS. Replace _PyArg_UnpackStack() with PyArg_ParseTuple(). * _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined by _testcapi sub-modules which need the internal C API (pycore_modsupport.h): exceptions.c, float.c, vectorcall.c, watchers.c. * Remove Include/cpython/modsupport.h header file. Include/modsupport.h no longer includes the removed header file. * Fix mypy clinic.py
* gh-108634: Py_TRACE_REFS uses a hash table (#108663)Victor Stinner2023-08-311-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python built with "configure --with-trace-refs" (tracing references) is now ABI compatible with Python release build and debug build. Moreover, it now also supports the Limited API. Change Py_TRACE_REFS build: * Remove _PyObject_EXTRA_INIT macro. * The PyObject structure no longer has two extra members (_ob_prev and _ob_next). * Use a hash table (_Py_hashtable_t) to trace references (all objects): PyInterpreterState.object_state.refchain. * Py_TRACE_REFS build is now ABI compatible with release build and debug build. * Limited C API extensions can now be built with Py_TRACE_REFS: xxlimited, xxlimited_35, _testclinic_limited. * No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2() functions to PyModule_Create2TraceRefs() and PyModule_FromDefAndSpec2TraceRefs(). * _Py_PrintReferenceAddresses() is now called before finalize_interp_delete() which deletes the refchain hash table. * test_tracemalloc find_trace() now also filters by size to ignore the memory allocated by _PyRefchain_Trace(). Test changes for Py_TRACE_REFS: * Add test.support.Py_TRACE_REFS constant. * Add test_sys.test_getobjects() to test sys.getobjects() function. * test_exceptions skips test_recursion_normalizing_with_no_memory() and test_memory_error_in_PyErr_PrintEx() if Python is built with Py_TRACE_REFS. * test_repl skips test_no_memory(). * test_capi skisp test_set_nomemory().
* GH-84436: Skip refcounting for known immortals (GH-107605)Brandt Bucher2023-08-041-2/+2
|
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-103906: Remove immortal refcounting in compile/marshal.c (gh-103922)Dong-hee Na2023-06-051-1/+1
|
* gh-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-2/+13
| | | | | | | | | This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
* GH-101291: Rearrange the size bits in PyLongObject (GH-102464)Mark Shannon2023-03-221-3/+3
| | | | | | | | | | * Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
* GH-84783: Make the slice object hashable (GH-101264)Furkan Onder2023-02-191-1/+37
|
* gh-99537: Use Py_SETREF() function in C code (#99657)Victor Stinner2022-11-221-16/+6
| | | | | | | | | | | | | | | Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
* gh-99300: Use Py_NewRef() in Objects/ directory (#99354)Victor Stinner2022-11-101-17/+9
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)Mark Shannon2022-06-271-17/+34
|
* gh-91731: Replace Py_BUILD_ASSERT() with static_assert() (#91730)Victor Stinner2022-04-201-1/+2
| | | | | | | | | | | | Python 3.11 now uses C11 standard which adds static_assert() to <assert.h>. * In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on SIZEOF_TIME_T with #error. * On macOS, py_mach_timebase_info() now accepts timebase members with the same size than _PyTime_t. * py_get_monotonic_clock() now saturates GetTickCount64() to _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is signed.
* bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)Victor Stinner2021-02-191-2/+1
| | | | | | | | | | | | | | | Pass the current interpreter (interp) rather than the current Python thread state (tstate) to internal functions which only use the interpreter. Modified functions: * _PyXXX_Fini() and _PyXXX_ClearFreeList() functions * _PyEval_SignalAsyncExc(), make_pending_calls() * _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str() * should_audit(), set_flags_from_config(), make_flags() * _PyAtExit_Call() * init_stdio_encoding() * etc.
* bpo-42161: Use _PyLong_GetZero() and _PyLong_GetOne() (GH-22995)Victor Stinner2020-10-271-2/+3
| | | | Use _PyLong_GetZero() and _PyLong_GetOne() in Objects/ and Python/ directories.
* bpo-40521: Cleanup code of free lists (GH-21082)Victor Stinner2020-06-231-8/+16
| | | Add get_xxx_state() function to factorize duplicated code.
* bpo-40521: Make slice cache per-interpreter (GH-20637)Victor Stinner2020-06-041-14/+15
| | | | | | Each interpreter now has its own slice cache: * Move slice cache into PyInterpreterState. * Add tstate parameter to _PySlice_Fini().
* bpo-40268: Remove unused pycore_pymem.h includes (GH-19531)Victor Stinner2020-04-151-1/+0
|
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-2/+2
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-1/+0
|
* bpo-40170: Add _PyIndex_Check() internal function (GH-19426)Victor Stinner2020-04-081-1/+2
| | | | | | | | | Add _PyIndex_Check() function to the internal C API: fast inlined verson of PyIndex_Check(). Add Include/internal/pycore_abstract.h header file. Replace PyIndex_Check() with _PyIndex_Check() in C files of Objects and Python subdirectories.
* Make PyXXX_Fini() functions private (GH-15531)Victor Stinner2019-08-261-1/+2
| | | | | For example, rename PyTuple_Fini() to _PyTuple_Fini(). These functions are only declared in the internal C API.
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-4/+4
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-35961: Fix a crash in slice_richcompare() (GH-11830)Victor Stinner2019-02-131-24/+14
| | | | | | | | Fix a crash in slice_richcompare(): use strong references rather than stolen references for the two temporary internal tuples. The crash (or assertion error) occurred if a garbage collection occurred during slice_richcompare(), especially while calling PyObject_RichCompare(t1, t2, op).
* bpo-35081: Add Include/internal/pycore_object.h (GH-10640)Victor Stinner2018-11-211-0/+1
| | | | Move _PyObject_GC_TRACK() and _PyObject_GC_UNTRACK() from Include/objimpl.h to Include/internal/pycore_object.h.
* bpo-35081: Rename internal headers (GH-10275)Victor Stinner2018-11-121-2/+2
| | | | | | | | | | | | | | Rename Include/internal/ headers: * pycore_hash.h -> pycore_pyhash.h * pycore_lifecycle.h -> pycore_pylifecycle.h * pycore_mem.h -> pycore_pymem.h * pycore_state.h -> pycore_pystate.h Add missing headers to Makefile.pre.in and PCbuild: * pycore_condvar.h. * pycore_hamt.h * pycore_pyhash.h
* bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner2018-10-311-2/+2
| | | | | | | | | | | | | | | | | | | | * Rename Include/internal/ header files: * pyatomic.h -> pycore_atomic.h * ceval.h -> pycore_ceval.h * condvar.h -> pycore_condvar.h * context.h -> pycore_context.h * pygetopt.h -> pycore_getopt.h * gil.h -> pycore_gil.h * hamt.h -> pycore_hamt.h * hash.h -> pycore_hash.h * mem.h -> pycore_mem.h * pystate.h -> pycore_state.h * warnings.h -> pycore_warnings.h * PCbuild project, Makefile.pre.in, Modules/Setup: add the Include/internal/ directory to the search paths of header files. * Update includes. For example, replace #include "internal/mem.h" with #include "pycore_mem.h".
* bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. ↵Siddhesh Poyarekar2018-04-291-3/+3
| | | | | | | | | (GH-6030) METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 due to the argument mismatch. Fix this by adding a dummy unused argument.
* bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow2017-09-081-0/+2
| | | | | | | * group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
* bpo-30592: Fixed error messages for some builtins. (#1996)Serhiy Storchaka2017-06-081-1/+1
| | | | | Error messages when pass keyword arguments to some builtins that don't support keyword arguments contained double parenthesis: "()()". The regression was introduced by bpo-30534.
* bpo-30281: Fix the default value for stop in PySlice_Unpack() (#1480)Xiang Zhang2017-05-101-3/+5
|
* bpo-29878: Add global instances of int for 0 and 1. (#852)Serhiy Storchaka2017-03-301-7/+4
|
* Issue #27867: Function PySlice_GetIndicesEx() is deprecated and replaced withSerhiy Storchaka2017-01-251-24/+54
|\ | | | | | | | | | | a macro if Py_LIMITED_API is not set or set to the value between 0x03050400 and 0x03060000 (not including) or 0x03060100 or higher. Added functions PySlice_Unpack() and PySlice_AdjustIndices().
| * Issue #27867: Function PySlice_GetIndicesEx() is replaced with a macro ifSerhiy Storchaka2017-01-251-24/+54
| | | | | | | | | | Py_LIMITED_API is not set or set to the value between 0x03050400 and 0x03060000 (not including) or 0x03060100 or higher.
* | Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of ↵Serhiy Storchaka2016-12-161-1/+1
|/ | | | dict.
* fix slice cache finalization to use gc delBenjamin Peterson2016-04-161-1/+1
|
* add gc support to slice (closes #26659)Benjamin Peterson2016-04-161-4/+15
|
* Make Ellipsis and NotImplemented picklable through the reduce protocol.Alexandre Vassalotti2013-11-241-1/+12
|
* Issue #16451: Refactor to remove duplication between range and slice in ↵Mark Dickinson2012-11-171-70/+78
| | | | slice index computations.
* Issue #14794: slice.indices no longer returns OverflowError for out-of-range ↵Mark Dickinson2012-11-101-8/+175
| | | | start, stop, step or length.
* Issue #14783: Merge changes from 3.2.Chris Jerdonek2012-10-071-1/+2
|\
| * Issue #14783: Improve int() docstring and also str(), range(), and slice().Chris Jerdonek2012-10-071-1/+2
| | | | | | | | | | | | This commit rewrites the docstring for int() to incorporate the documentation changes made in issue #16036. It also switches the docstrings for int(), str(), range(), and slice() to use multi-line signatures.